@@ -6,12 +6,15 @@ defaultEngine = require('../lib/client_asset_manager/template_engines/default').
6
6
7
7
formatters =
8
8
html : require (' ./testdata_stubs/formatter_html' ).init ()
9
+ const : require (' ./testdata_stubs/formatter_const' ).init ()
10
+
9
11
root = __dirname
10
12
dir = ' testdata_files'
11
13
12
14
testTmpl = fs .readFileSync (" #{ root} /#{ dir} /template.html" )
13
15
testTmpl_2 = fs .readFileSync (" #{ root} /#{ dir} /foo/template2.html" )
14
16
testTmpl_3 = fs .readFileSync (" #{ root} /#{ dir} /template.foo" )
17
+ testTmpl_4 = fs .readFileSync (" #{ root} /#{ dir} /template.const" )
15
18
16
19
17
20
describe ' wrapTemplate' , ->
@@ -59,13 +62,41 @@ describe 'wrapTemplate', ->
59
62
processWithWrap (engine_2, testTmpl, null , ' template' )
60
63
output .should .equal expected
61
64
65
+ lib .generate root, dir, [' foo/template2.html' , ' template.const' ], formatters, (output ) ->
66
+ expected = processWithWrap (engine, testTmpl_2, null , ' foo-template2' ) +
67
+ processWithWrap (engine_2, ' CONST' , null , ' template' )
68
+ output .should .equal expected
69
+
62
70
63
71
it ' should not modify template content for unrecognized file extensions' , ->
64
72
lib = EngineLib .init ()
65
73
lib .generate root, dir, [' template.foo' ], formatters, (output ) ->
66
74
output .should .equal defaultEngine .process (testTmpl_3, null , ' template' )
67
75
68
76
77
+ it ' should allow the use of a formatter specified by the engine' , ->
78
+ engine = EngineStub .init ' X'
79
+ engine .selectFormatter = -> formatters .const
80
+
81
+ lib = EngineLib .init ()
82
+ lib .use (init : -> engine)
83
+ lib .generate root, dir, [' template.html' ], formatters, (output ) ->
84
+ # The const formatter always outputs 'CONST'
85
+ output .should .equal processWithWrap (engine, ' CONST' , null , ' template' )
86
+
87
+
88
+ it ' should allow the engine to specify no formatting of the template file' , ->
89
+ engine = EngineStub .init ' X'
90
+ engine .selectFormatter = -> false
91
+
92
+ lib = EngineLib .init ()
93
+ lib .use (init : -> engine)
94
+ lib .generate root, dir, [' template.const' ], formatters, (output ) ->
95
+ # The const formatter always outputs 'CONST' In this case it should
96
+ # not equal 'CONST' because it should not be using any formatter.
97
+ output .should .equal processWithWrap (engine, testTmpl_4, null , ' template' )
98
+
99
+
69
100
70
101
processWithWrap = (engine , tmpl , path , id ) ->
71
102
engine .prefix () +
0 commit comments