Ejemplo n.º 1
0
    def test_root(self):
        import jstc.compiler
        compiler = jstc.compiler.Compiler(
            overrides=dict(inline=True, precompile=False))
        with fso.push() as overlay:
            self.writecontent({
                'test/one/template.hbs': 'template "one".',
                'test/two/template.hbs': 'template "two".',
            })
            self.assertEqual(
                compiler.render_assets('jstc:test/one/template.hbs',
                                       'test/one'), '''\
<script type="text/x-handlebars" data-template-name="template">template "one".</script>\
''')
            self.assertEqual(
                compiler.render_assets('jstc:test/two/template.hbs',
                                       'test/two'), '''\
<script type="text/x-handlebars" data-template-name="template">template "two".</script>\
''')
            self.assertEqual(
                compiler.render_assets([
                    'jstc:test/one/template.hbs', 'jstc:test/two/template.hbs'
                ], 'test'), '''\
<script type="text/x-handlebars" data-template-name="one/template">template "one".</script>\
<script type="text/x-handlebars" data-template-name="two/template">template "two".</script>\
''')
Ejemplo n.º 2
0
    def test_collision_pertemplate(self):
        import jstc.compiler
        compiler = jstc.compiler.Compiler(
            defaults=dict(collision='ignore'),
            overrides=dict(inline=True, precompile=False),
        )
        with fso.push() as overlay:
            self.writecontent({
                'test/one/template.hbs':
                '''\
            ##! a
              template "one/a".
            ##! b
              template "one/b".
          ''',
                'test/two/template.hbs':
                '''\
            ##! a; collision: ignore
              template "two/a".
            ##! b; collision: override
              template "two/b".
          ''',
            })
            self.assertEqual(
                compiler.render_assets([
                    'jstc:test/one/template.hbs', 'jstc:test/two/template.hbs'
                ], ['test/one', 'test/two']), '''\
<script type="text/x-handlebars" data-template-name="template/a">template "one/a".</script>\
<script type="text/x-handlebars" data-template-name="template/b">template "two/b".</script>\
''')
Ejemplo n.º 3
0
    def test_render_space_dedent(self):
        import jstc.compiler
        compiler = jstc.compiler.Compiler(
            overrides=dict(inline=True, precompile=False))
        with fso.push() as overlay:
            self.writecontent({
                'test.hbs':
                '''\
            ##! dedent; space: dedent
              {{#if value}}
                <span>
                  {{value}}
                </span>
              {{else}}
                <span>default</span>
              {{/if}}
          '''
            })
            self.assertEqual(
                compiler.render_assets('jstc:test.hbs'), '''\
<script type="text/x-handlebars" data-template-name="test/dedent">{{#if value}}
  <span>
    {{value}}
  </span>
{{else}}
  <span>default</span>
{{/if}}</script>\
''')
Ejemplo n.º 4
0
    def test_render_trim_deprecated(self):
        import jstc.compiler
        compiler = jstc.compiler.Compiler(
            overrides=dict(inline=True, precompile=False))
        with fso.push() as overlay:
            self.writecontent({
                'test.hbs':
                '''\
            ##! 0-default
              <span>
                text
              </span>
            ##! 1-trim; trim
              <span>
                text
              </span>
            ##! 2-notrim; !trim
              <span>
                text
              </span>
          '''
            })
            self.assertEqual(
                compiler.render_assets('jstc:test.hbs'), '''\
<script type="text/x-handlebars" data-template-name="test/0-default"><span>
  text
</span></script>\
<script type="text/x-handlebars" data-template-name="test/1-trim"><span>
  text
</span></script>\
<script type="text/x-handlebars" data-template-name="test/2-notrim">  <span>
    text
  </span>
</script>\
''')
Ejemplo n.º 5
0
 def test_collision_error(self):
     import jstc.compiler
     compiler = jstc.compiler.Compiler(
         overrides=dict(inline=True, precompile=False))
     with fso.push() as overlay:
         self.writecontent({
             'test/one/template.hbs': 'template "one".',
             'test/two/template.hbs': 'template "two".',
         })
         with self.assertRaises(jstc.TemplateCollision) as cm:
             compiler.render_assets([
                 'jstc:test/one/template.hbs', 'jstc:test/two/template.hbs'
             ], ['test/one', 'test/two'])
         self.assertEqual(
             str(cm.exception),
             ''''text/x-handlebars' template 'template' is already defined'''
         )
Ejemplo n.º 6
0
 def test_compiler(self):
     import jstc.compiler
     compiler = jstc.compiler.Compiler(
         defaults=dict(inline=True, precompile=True))
     with fso.push() as overlay:
         self.writecontent({
             'test/template.mustache': 'A mustache template.',
         })
         self.assertEqual(
             compiler.render_assets('jstc:engines/test/template.mustache',
                                    'engines/test'),
             '<script type="text/x-mustache" data-template-name="template">A mustache template.</script>'
         )
Ejemplo n.º 7
0
    def test_render_simple(self):
        import jstc.compiler
        compiler = jstc.compiler.Compiler(
            overrides=dict(inline=True, precompile=False))
        with fso.push() as overlay:
            self.writecontent({
                'test/common/hello.hbs':
                '''\
            ##! __here__
              Hello, world!
            ##! name
              Hello, {{name}}!
          '''
            })
            self.assertEqual(
                compiler.render_assets('jstc:test/common/hello.hbs', 'test'),
                '''\
<script type="text/x-handlebars" data-template-name="common/hello">Hello, world!</script>\
<script type="text/x-handlebars" data-template-name="common/hello/name">Hello, {{name}}!</script>\
''')
Ejemplo n.º 8
0
    def test_comments(self):
        import jstc.compiler
        compiler = jstc.compiler.Compiler(
            overrides=dict(inline=True, precompile=False))
        with fso.push() as overlay:
            self.writecontent({
                'test/application.hbs':
                '''\
            <div>
              ## TODO: super-secret comment!
              Nothing to see here.
            </div>
          '''
            })
            self.assertEqual(
                compiler.render_assets('jstc:test/application.hbs', 'test'),
                '''\
<script type="text/x-handlebars" data-template-name="application"><div>
  Nothing to see here.
</div>\
</script>\
''')