Skip to content

Commit

Permalink
Add integration test for +include directive. (See #55)
Browse files Browse the repository at this point in the history
  • Loading branch information
netzpirat committed Feb 15, 2013
1 parent f20897d commit ba5a0f5
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
16 changes: 15 additions & 1 deletion spec/compiler_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ for suite in suites
describe group, ->
it "handles #{ desc }", ->

window = {}
window.HAML = {}

config = {
escapeHtml : if spec.config?.escape_html is 'true' then true else false
escapeAttributes : if spec.config?.escape_attributes is 'true' then true else false
extendScope : if spec.config?.extend_scope is 'true' then true else false
placement : spec.config?.placement || 'global'
format : spec.config?.format || 'xhtml'
}

Expand All @@ -42,6 +46,17 @@ for suite in suites

report += spec.haml

if spec.partials && config.placement is 'global'
report += "\n-------------------- Partial templates --------------------------\n"

for name, partial of spec.partials
try
source = fs.readFileSync("spec/suites/templates/#{ partial }.haml").toString()
window.HAML[name] = require('haml-coffee').compile(source)
report += "window.HAML['#{ name }'] compiled from source '#{ partial }'\n"
catch error
report += "Error compiling partial #{ name }: #{ error }"

if spec.locals
report += "\n-------------------- Local variables --------------------------\n"
report += JSON.stringify(spec.locals)
Expand All @@ -59,7 +74,6 @@ for suite in suites
try
template = CoffeeScript.compile cst

window = {}
eval template

html = window.HAML.test(spec.locals)
Expand Down
16 changes: 15 additions & 1 deletion spec/suites/haml_coffee_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@
"html_template" : "coffee/evaluation_in_function"
},

"evaluation in inserting functions" : {
"extending the scope" : {
"haml_template" : "coffee/extend_scope",
"html_template" : "coffee/extend_scope",
"config" : {
Expand Down Expand Up @@ -531,5 +531,19 @@
"html_template" : "text/indention"
}

},

"directives" : {
"include" : {
"haml_template" : "directives/include",
"html_template" : "directives/include",
"config": {
"placement": "global"
},
"partials" : {
"partials/test" : "directives/partials/test"
}
}
}

}
4 changes: 4 additions & 0 deletions spec/suites/templates/directives/include.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
%h1 Include test
%p Demonstrating how includes work.
+include 'partials/test'
%p After text
5 changes: 5 additions & 0 deletions spec/suites/templates/directives/include.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>Include test</h1>
<p>Demonstrating how includes work.</p>
<h2>Partial</h2>
<p>This is a partial that can be included</p>
<p>After text</p>
2 changes: 2 additions & 0 deletions spec/suites/templates/directives/partials/test.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
%h2 Partial
%p This is a partial that can be included

0 comments on commit ba5a0f5

Please sign in to comment.