Skip to content

Commit

Permalink
Merge pull request #61 from borisjoffe/use-tabs-argument
Browse files Browse the repository at this point in the history
Use tabs argument
  • Loading branch information
donpark committed Oct 7, 2013
2 parents dab0d81 + 2d5a06e commit 9cbf802
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -44,6 +44,7 @@ To generate [Scalate](http://scalate.fusesource.org/) compatible output:
* `-s, --scalate` - generate jade syntax compatible with Scalate
* `-o, --outdir <dir>` - path to output generated jade file(s) to
* `-n, --nspaces <n>` - the number of spaces to indent generated files with. Default is 2 spaces
* `-t, --tabs` - use tabs instead of spaces

## Programmatic Usage (>= 0.0.7)

Expand Down
1 change: 1 addition & 0 deletions cli.js
Expand Up @@ -49,6 +49,7 @@ program
.version('0.5.0')
.option('-d, --double', 'use double quotes for attributes')
.option('-s, --scalate', 'generate jade syntax compatible with Scalate')
.option('-t, --tabs', 'use tabs instead of spaces')
.option('-o, --outdir <dir>', 'path to output generated jade file(s) to', parsePath)
.option('-n, --nspaces <n>', 'the number of spaces to indent generated files with', parseInt)

Expand Down
13 changes: 11 additions & 2 deletions lib/html2jade.coffee
Expand Up @@ -4,6 +4,7 @@ Ent = require("ent")

scope = exports ? this.Html2Jade ?= {}
nspaces = 2 # default
useTabs = false

class Parser
constructor: (@options = {}) ->
Expand Down Expand Up @@ -318,9 +319,15 @@ class Output
constructor: ->
@indents = ''
enter: ->
@indents += ' ' for i in [1..nspaces]
if useTabs
@indents += '\t'
else
@indents += ' ' for i in [1..nspaces]
leave: ->
@indents = @indents.substring(nspaces)
if useTabs
@indents = @indents.substring(1)
else
@indents = @indents.substring(nspaces)
write: (data, indent=true) ->
writeln: (data, indent=true) ->

Expand Down Expand Up @@ -373,6 +380,8 @@ if exports?
scope.convert = (input, output, options) ->
if options.nspaces
nspaces = options.nspaces
if options.tabs
useTabs = true
options ?= {}
# specify parser and converter to override default instance
options.parser ?= new Parser(options)
Expand Down
25 changes: 19 additions & 6 deletions lib/html2jade.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9cbf802

Please sign in to comment.