Skip to content

Commit 5611a16

Browse files
authored
Merge pull request tachyons-css#98 from tachyons-css/cson-build
Add a quick cson build for atom-tachyons
2 parents c366a88 + 64880b4 commit 5611a16

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"doc:lib": "watch 'npm run doc' lib",
1616
"doc:images": "watch 'node src/modules/images.js' src/templates/docs/images",
1717
"doc:bgsize": "watch 'node src/modules/background-size.js' src/templates/docs/background-size",
18-
"build:all": "node build.js && bash script.sh"
18+
"build:all": "node build.js && bash script.sh",
19+
"cson": "node src/components-cson-build.js"
1920
},
2021
"repository": "tachyons-css/tachyons-css.github.io",
2122
"author": "mrmrs",

src/components-cson-build.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
var fs = require('fs')
2+
var _ = require('lodash')
3+
var path = require('path')
4+
var glob = require('glob')
5+
var titleize = require('titleize')
6+
var fm = require('json-front-matter')
7+
var rmHtmlExt = require('remove-html-extension')
8+
9+
glob('src/components/**/*.html', {}, function (err, components) {
10+
if (err) {
11+
console.error(err)
12+
return
13+
}
14+
15+
var cson = '".text.html":\n\n'
16+
components.forEach(function (component) {
17+
var prefix = rmHtmlExt(component.replace('src/components/', '')).split('/')[1]
18+
var componentHtml = fs.readFileSync(component, 'utf8')
19+
20+
var fmParsed = fm.parse(componentHtml)
21+
var frontMatter = fmParsed.attributes || {}
22+
23+
cson += `
24+
'${frontMatter.title || getTitle(component)}':
25+
'prefix': '${prefix}'
26+
'body': """
27+
${fmParsed.body.trim()}
28+
"""
29+
`
30+
})
31+
32+
console.log(cson)
33+
})
34+
35+
function getTitle(component) {
36+
var title = rmHtmlExt(component).replace('src/components/', '').replace(/(\/|_|-)/g, ' ')
37+
return titleize(title)
38+
}
39+
40+
function getName(component) {
41+
return titleize(getTitle(component.split('/')[3]))
42+
}

0 commit comments

Comments
 (0)