Skip to content

Commit 902ff53

Browse files
feat: add bundle, debug tags
also update some styling
1 parent e989d07 commit 902ff53

File tree

9 files changed

+81
-26
lines changed

9 files changed

+81
-26
lines changed

bundler.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const REACT_WRAPPER = process.env.IS_DEV ? 'src/components/react-wrapper.jsx' :
77

88
const pathCrossEnv = path => (process.platform !== 'win32' ? path : path.replace(/\\/g, '/'))
99

10-
module.exports = function bundle(Components, out, config) {
10+
module.exports = function bundle(Components, functions, out, config) {
1111
if (!Components.length) {
1212
return
1313
}
@@ -18,6 +18,7 @@ module.exports = function bundle(Components, out, config) {
1818
let init = `
1919
window.reactComponents = {};\n
2020
window.vueComponents = {};\n
21+
window.Components = {};\n
2122
`
2223
if (vueComponents.length) {
2324
init += `
@@ -28,6 +29,7 @@ module.exports = function bundle(Components, out, config) {
2829
window.VueWrapper = VueWrapper;\n
2930
`
3031
}
32+
3133
if (reactComponents.length) {
3234
const reactWrapperRelPath = pathCrossEnv(
3335
path.relative(absoluteOut, path.join(__dirname, REACT_WRAPPER)),
@@ -50,6 +52,23 @@ module.exports = function bundle(Components, out, config) {
5052
import './styles/iframe.css';\n
5153
`
5254

55+
let functionImports = ''
56+
57+
if (functions && functions.length) {
58+
functionImports = functions.map((fnDocLet, i) => {
59+
const { name: displayName, meta } = fnDocLet
60+
const { path: filePath, filename } = meta
61+
const relativePath = pathCrossEnv(path.relative(absoluteOut, path.join(filePath, filename)))
62+
const name = `FnComponent${i}`
63+
return [
64+
`import ${name} from '${relativePath}';`,
65+
`Components['${displayName}'] = ${name};`,
66+
].join('\n')
67+
}).join('\n\n')
68+
69+
functionImports = `${functionImports}\n\n`
70+
}
71+
5372
if (config.betterDocs.component) {
5473
if (config.betterDocs.component.wrapper) {
5574
const absolute = path.resolve(config.betterDocs.component.wrapper)
@@ -65,7 +84,7 @@ module.exports = function bundle(Components, out, config) {
6584
}
6685
}
6786

68-
const entryFile = init + Components.map((c, i) => {
87+
const entryFile = init + functionImports + Components.map((c, i) => {
6988
const { displayName, filePath, type } = c.component
7089
const relativePath = pathCrossEnv(path.relative(absoluteOut, filePath))
7190
const name = `Component${i}`

navigation.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,16 @@ exports.defineTags = (dictionary) => {
3131
},
3232
})
3333
})
34+
35+
dictionary.defineTag('debug', {
36+
onTagged: (doclet, tag) => {
37+
console.log({ doclet })
38+
},
39+
})
40+
41+
dictionary.defineTag('bundle', {
42+
onTagged: (doclet) => {
43+
doclet.bundle = true
44+
},
45+
})
3446
}

publish.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,9 @@ exports.publish = function (taffyData, opts, tutorials) {
501501

502502
view.tutorialsNav = buildNav(members, ['tutorials'], conf.betterDocs, env).global
503503

504-
bundler(members.components, outdir, conf)
504+
const bundleFunctions = helper.find(data, { bundle: { isUndefined: false } })
505+
506+
bundler(members.components, bundleFunctions, outdir, conf)
505507
attachModuleSymbols(find({ longname: { left: 'module:' } }), members.modules)
506508

507509
// generate the pretty-printed source files first so other pages can link to them

src/components/react-wrapper.jsx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ class Wrapper extends React.Component {
2222
this.executeScript(example)
2323
}
2424

25+
componentDidMount() {
26+
this.heightInterval = setInterval(() => {
27+
this.computeHeight()
28+
}, 1000)
29+
}
30+
31+
componentDidUpdate() {
32+
this.computeHeight()
33+
}
34+
35+
componentWillUnmount() {
36+
clearInterval(this.heightInterval)
37+
}
38+
2539
executeScript(source) {
2640
const { uniqId } = this.props
2741
const script = document.createElement('script')
@@ -35,6 +49,7 @@ class Wrapper extends React.Component {
3549
}
3650
const wrapper = `window.component['${uniqId}'] = (() => {
3751
${Object.keys(reactComponents).map(k => `const ${k} = reactComponents['${k}'];`).join('\n')}
52+
${Object.keys(Components).map(k => `const ${k} = Components['${k}'];`).join('\n')}
3853
try {
3954
${source}
4055
} catch (error) {
@@ -74,20 +89,6 @@ class Wrapper extends React.Component {
7489
}
7590
}
7691

77-
componentDidUpdate() {
78-
this.computeHeight()
79-
}
80-
81-
componentDidMount() {
82-
this.heightInterval = setInterval(() => {
83-
this.computeHeight()
84-
}, 1000)
85-
}
86-
87-
componentWillUnmount() {
88-
clearInterval(this.heightInterval)
89-
}
90-
9192
render() {
9293
const { component, height } = this.state
9394
return (

src/navigation/build-nav.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ function buildMemberNav(items, itemHeading, itemsSeen, linktoFn, env) {
4444
cssClasses.push('new')
4545
}
4646

47-
4847
itemsNav += `<li>${linktoFn(
4948
item.longname,
5049
displayName.replace(/\b(module|event):/g, ''),
@@ -114,8 +113,16 @@ function buildGroupNav(members, title, env) {
114113
globalNav = ''
115114

116115
members.globals.forEach((g) => {
116+
const cssClasses: Array<string> = []
117+
if (g.deprecated) {
118+
cssClasses.push('deprecated')
119+
}
120+
121+
if (g.new) {
122+
cssClasses.push('new')
123+
}
117124
if (g.kind !== 'typedef' && !hasOwnProperty.call(seen, g.longname)) {
118-
globalNav += `<li>${linkto(g.longname, g.name)}</li>`
125+
globalNav += `<li>${linkto(g.longname, g.name, cssClasses.join(' '))}</li>`
119126
}
120127
seen[g.longname] = true
121128
})

styles/base/layout.sass

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ body
8787
color: #fff
8888
&:hover
8989
border-color: $red-active
90-
color: #fff
90+
color: $red-active
91+
background: $white
9192
&:hover
9293
border-color: $red-active
9394
color: $red-active

styles/components/details.sass

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
.details
2-
margin-top: 20px
2+
margin-top: 40px
33
dt
44
font-size: 20px
55
border-left: 2px solid $blue
66
padding-left: 16px
77
margin-top: 10px
88

9-
.tag-deprecated.important
9+
.tag-deprecated
1010
background: $red-active
1111
color: $white
1212
border-left: 0px;
@@ -15,5 +15,12 @@
1515
border-bottom: 1px solid $red-active
1616
padding-bottom: 14px
1717

18-
.tag-new.important
19-
border-color: $red-active
18+
.tag-new
19+
border-color: $red-active
20+
21+
22+
dt.tag-see + dd.tag-see
23+
margin-bottom: 40px
24+
25+
.important + dd
26+
margin-bottom: 40px

tmpl/layout.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ var search = env.conf.templates && env.conf.templates.search
6060
</div>
6161
<div class="main column is-8-tablet is-10-desktop">
6262
<h4>
63-
Software House with a passion to both JavaScript and TypeScript.
63+
Software House with a passion for both JavaScript and TypeScript.
6464
</h4>
6565
<p class="buttons">
6666
<a class="button what-we-do" href="https://softwarebrothers.co/services">See what we do</a>
67-
<a class="button what-we-believe is-outlined" href="https://softwarebrothers.co/about-us">See what believe</a>
67+
<a class="button what-we-believe is-outlined" href="https://softwarebrothers.co/about-us">See what we believe in</a>
6868
</p>
6969
</div>
7070
</div>

tmpl/members.tmpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ var self = this;
1818
<span class="code-name">
1919
<?js= name ?>
2020
</span>
21+
<?js if (data.new) { ?>
22+
<span class="tag-new" />
23+
<?js } ?>
24+
<?js if (data.deprecated) { ?>
25+
<span class="tag-deprecated" />
26+
<?js } ?>
2127
<?js if (data.optional) { ?>
2228
<span class='tag'>Optional</span>
2329
<?js }; ?>

0 commit comments

Comments
 (0)