Sha256: 03b4eeadcc77ecfbb2c31a94dc9cbf7ae88d41ad2b928433ea84002a75c10d85
Contents?: true
Size: 1.53 KB
Versions: 2
Compression:
Stored size: 1.53 KB
Contents
require 'test_helper' module HandlebarsAssets class TiltHandlebarsTest < Test::Unit::TestCase include SprocketsScope def expected_haml_compiled(source) Haml::Engine.new(source, HandlebarsAssets::Config.haml_options).render end def expected_hbs_compiled(source) compiler_src = Pathname(HandlebarsAssets::Config.compiler_path).join(HandlebarsAssets::Config.compiler).read ExecJS.compile(compiler_src).call('Handlebars.precompile', source, HandlebarsAssets::Config.options) end def haml_compiled(template_name, source) compiled_haml = expected_haml_compiled(source) compiled_hbs = expected_hbs_compiled(compiled_haml) template_namespace = HandlebarsAssets::Config.template_namespace <<END_EXPECTED (function() { this.#{template_namespace} || (this.#{template_namespace} = {}); this.#{template_namespace}[#{template_name.dump}] = Handlebars.template(#{compiled_hbs}); return this.#{template_namespace}[#{template_name.dump}]; }).call(this); END_EXPECTED end def teardown HandlebarsAssets::Config.reset! HandlebarsAssets::Handlebars.reset! end def test_render_haml root = '/myapp/app/assets/templates' file = 'test_render.hamlbars' scope = make_scope root, file source = "%p This is {{handlebars}}" template = HandlebarsAssets::TiltHandlebars.new(scope.pathname.to_s) { source } assert_equal haml_compiled('test_render', source), template.render(scope, {}) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
handlebars_assets-0.7.1 | test/handlebars_assets/hamlbars_test.rb |
handlebars_assets-0.7.0 | test/handlebars_assets/hamlbars_test.rb |