Skip to content
Open
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@
"url": "https://github.com/netzpirat/haml-coffee/issues"
},
"scripts": {
"test": "jasmine-node --coffee spec"
"test": "grunt test"
}
}
22 changes: 14 additions & 8 deletions spec/compiler_spec.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
fs = require 'fs'
fs = require 'fs'
path = require 'path'

CoffeeScript = require 'coffee-script'
HamlCoffee = require '../src/haml-coffee'
Expand Down Expand Up @@ -33,18 +34,21 @@ for suite in suites
extendScope : if spec.config?.extend_scope is 'true' then true else false
placement : spec.config?.placement || 'global'
format : spec.config?.format || 'xhtml'
pwd : spec.config?.pwd || ''
}

if spec.haml_template
hamlTemplatePath = "spec/suites/templates/#{ spec.haml_template }.haml"
spec.haml = fs.readFileSync(hamlTemplatePath).toString()
if config.pwd is ''
config.pwd = path.resolve(path.dirname(hamlTemplatePath))

compiler = new HamlCoffee(config)

report = "Generated output doesn't match the expected result.\n\n"
report += "-------------------- Compiler settings ------------------------\n"
report += JSON.stringify(config)
report += "\n-------------------- Haml template ----------------------------\n"

if spec.haml_template
spec.haml = fs.readFileSync("spec/suites/templates/#{ spec.haml_template }.haml").toString()

report += spec.haml

if spec.partials && config.placement is 'global'
Expand Down Expand Up @@ -75,9 +79,11 @@ for suite in suites
try
template = CoffeeScript.compile cst

eval template

html = window.HAML.test(spec.locals)
if config.placement is 'standalone'
html = eval(template)(spec.locals)
else # global
eval template
html = window.HAML.test(spec.locals)

catch error
report += "\n-------------- Error compiling JST -------------------------\n"
Expand Down
14 changes: 12 additions & 2 deletions spec/suites/haml_coffee_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
"format" : "html5"
}
},

"class concatenation" : {
"haml_template" : "coffee/class",
"html_template" : "coffee/class"
Expand Down Expand Up @@ -542,7 +542,7 @@
},

"directives" : {
"include" : {
"include global" : {
"haml_template" : "directives/include",
"html_template" : "directives/include",
"config": {
Expand All @@ -554,6 +554,16 @@
"locals" : {
"title": "Title For the partial."
}
},
"include standalone" : {
"haml_template" : "directives/include",
"html_template" : "directives/include",
"config": {
"placement": "standalone"
},
"locals" : {
"title": "Title For the partial."
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/haml-coffee.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ module.exports = class HamlCoffee
@options.hyphenateDataAttrs ?= true
@options.preserveTags ?= 'pre,textarea'
@options.selfCloseTags ?= 'meta,img,link,br,hr,input,area,param,col,base'
@options.extension ?= 'haml'

if @options.placement is 'global'
@options.name ?= 'test'
Expand Down Expand Up @@ -168,6 +169,7 @@ module.exports = class HamlCoffee
placement : override.placement || @options.placement
namespace : override.namespace || @options.namespace
name : override.name || @options.name
compilerOptions : @options
}

# Get the matching node type for the given expression. This
Expand Down
6 changes: 4 additions & 2 deletions src/hamlc.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
fs = require 'fs'
fs = require 'fs'
path = require 'path'

Compiler = require './haml-coffee'

Expand Down Expand Up @@ -105,7 +106,8 @@ module.exports =

else
options.filename = filename
source = fs.readFileSync(filename, 'utf8')
options.pwd = path.dirname(filename)
source = fs.readFileSync(filename, 'utf8')

if options.cache
__expressCache[filename] = module.exports.compile(source, options)
Expand Down
9 changes: 7 additions & 2 deletions src/nodes/directive.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,21 @@ module.exports = class Directive extends Node
# we need to compile the referenced template and attach it as a
# precompiled (standalone) template here.

templatePath = path.join(
@options.compilerOptions.pwd,
"#{ name }.#{ @options.compilerOptions.extension }"
)

# Read the source.
try
source = fs.readFileSync(name).toString()
source = fs.readFileSync(templatePath).toString()
catch error
console.error " Error opening file: %s", error
console.error error

# Compile and build the source function.
Compiler = require '../haml-coffee'
compiler = new Compiler(@options)
compiler = new Compiler(@options.compilerOptions)
compiler.parse source
code = CoffeeScript.compile(compiler.precompile(), bare: true)
statement = "`(function(){#{code}}).apply(#{context})`"
Expand Down
30 changes: 15 additions & 15 deletions src/nodes/node.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ module.exports = class Node
# @option options [Boolean] escapeHtml whether to escape the rendered HTML or not
# @option options [String] format the template format, either `xhtml`, `html4` or `html5`
#
constructor: (@expression = '', options = {}) ->
@parentNode = options.parentNode
constructor: (@expression = '', @options = {}) ->
@parentNode = @options.parentNode
@children = []

@opener = @closer = null
Expand All @@ -42,28 +42,28 @@ module.exports = class Node
@silent = false

# Preserve whitespace on all children
@preserveTags = options.preserveTags.split(',')
@preserveTags = @options.preserveTags.split(',')
@preserve = false

@wsRemoval = {
around: false
inside: false
}

@escapeHtml = options.escapeHtml
@escapeAttributes = options.escapeAttributes
@cleanValue = options.cleanValue
@format = options.format
@hyphenateDataAttrs = options.hyphenateDataAttrs
@selfCloseTags = options.selfCloseTags.split(',')
@uglify = options.uglify
@escapeHtml = @options.escapeHtml
@escapeAttributes = @options.escapeAttributes
@cleanValue = @options.cleanValue
@format = @options.format
@hyphenateDataAttrs = @options.hyphenateDataAttrs
@selfCloseTags = @options.selfCloseTags.split(',')
@uglify = @options.uglify

@codeBlockLevel = options.codeBlockLevel
@blockLevel = options.blockLevel
@codeBlockLevel = @options.codeBlockLevel
@blockLevel = @options.blockLevel

@placement = options.placement
@namespace = options.namespace
@name = options.name
@placement = @options.placement
@namespace = @options.namespace
@name = @options.name

# Add a child node.
#
Expand Down