Browse files

Add exports option, documentation, & version bump

  • Loading branch information...
1 parent f592458 commit 42138fc1a0702359b0a4e8e41d57e5e910b90f43 @brandonbloom committed Nov 2, 2011
Showing with 17 additions and 5 deletions.
  1. +1 −0 lib/cli.coffee
  2. +11 −4 lib/convert.coffee
  3. +1 −1 package.json
  4. +4 −0 readme.md
View
1 lib/cli.coffee
@@ -17,6 +17,7 @@ exports.main = ->
prefix = match[1]
#TODO: Expose --selectors and --no-selectors flags
+ #TODO: Expose --exports option
if args.length != 1
console.log """
View
15 lib/convert.coffee
@@ -11,9 +11,9 @@ exports.convert = (html, stream, options, callback) ->
if not callback
callback = (->)
- {prefix, selectors} = options
- prefix ?= ''
- selectors ?= true
+ prefix = options.prefix ? ''
+ selectors = options.selectors ? true
+ export_ = options.export ? false
depth = 0
@@ -104,7 +104,14 @@ exports.convert = (html, stream, options, callback) ->
handler = new htmlparser.DefaultHandler (err, dom) =>
return callback err if err
try
- visit.array dom
+ if export_
+ if export_ == true
+ emit 'module.exports = ->'
+ else
+ emit "exports.#{export_} = ->"
+ nest -> visit.array dom
+ else
+ visit.array dom
catch exception
err = exception
callback err
View
2 package.json
@@ -2,7 +2,7 @@
"name": "html2coffeekup",
"description": "Converts HTML to Coffeekup markup",
"author": "Brandon Bloom <brandon@brandonbloom.name>",
- "version": "1.2.0",
+ "version": "1.3.0",
"repository" : {
"type" : "git",
"url" : "git://github.com/brandonbloom/html2coffeekup.git"
View
4 readme.md
@@ -60,6 +60,10 @@ html ->
> For example, when true you get `div '#id.cls1.cls2`. When false you get `div id: "id", class: "cls1 cls2"`
+* `exports` is a boolean or a string name. When truthy, wraps the output in a Node.js style function export. (default: false).
+
+> When `true` you get `module.exports = ->`. When a `"foo"` you get `exports.foo = ->`
+
# Example REPL Session
```

0 comments on commit 42138fc

Please sign in to comment.