Skip to content

Add a quick cson build for atom-tachyons #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"doc:lib": "watch 'npm run doc' lib",
"doc:images": "watch 'node src/modules/images.js' src/templates/docs/images",
"doc:bgsize": "watch 'node src/modules/background-size.js' src/templates/docs/background-size",
"build:all": "node build.js && bash script.sh"
"build:all": "node build.js && bash script.sh",
"cson": "node src/components-cson-build.js"
},
"repository": "tachyons-css/tachyons-css.github.io",
"author": "mrmrs",
Expand Down
42 changes: 42 additions & 0 deletions src/components-cson-build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
var fs = require('fs')
var _ = require('lodash')
var path = require('path')
var glob = require('glob')
var titleize = require('titleize')
var fm = require('json-front-matter')
var rmHtmlExt = require('remove-html-extension')

glob('src/components/**/*.html', {}, function (err, components) {
if (err) {
console.error(err)
return
}

var cson = '".text.html":\n\n'
components.forEach(function (component) {
var prefix = rmHtmlExt(component.replace('src/components/', '')).split('/')[1]
var componentHtml = fs.readFileSync(component, 'utf8')

var fmParsed = fm.parse(componentHtml)
var frontMatter = fmParsed.attributes || {}

cson += `
'${frontMatter.title || getTitle(component)}':
'prefix': '${prefix}'
'body': """
${fmParsed.body.trim()}
"""
`
})

console.log(cson)
})

function getTitle(component) {
var title = rmHtmlExt(component).replace('src/components/', '').replace(/(\/|_|-)/g, ' ')
return titleize(title)
}

function getName(component) {
return titleize(getTitle(component.split('/')[3]))
}