Permalink
Browse files

configurable templates namespace

  • Loading branch information...
1 parent 11dc34b commit 74d4c5c9d5c6c8874d50b346da0e4045bab68d47 @tchak tchak committed Dec 26, 2012
@@ -28,6 +28,10 @@ class <%= camelized %> < Iridium::Application
#
# config.handlebars.compiler = proc { |source| "CustomHandlebars.compile(#{source});" }
+ # Specify a namespace for handlebars templates
+ #
+ # config.handlebars.namespace = "<%= underscored %>"
+
# Enable a proxy to an API. You can use this to get around CORS
# or use it for authentication hidding.
#
@@ -170,7 +170,9 @@ Iridium::Engine.subclasses.each do |engine|
handlebars :target => (app.config.handlebars.target || "Handlebars.TEMPLATES"),
:wrapper_proc => (app.config.handlebars.compiler || proc { |source| "Handlebars.compile(#{source});" }),
:key_name_proc => proc { |input|
- "#{engine.name.demodulize.underscore}/#{input.path.sub(File.extname(input.path), '').sub(/_view$/, '')}"
+ namespace = app.config.handlebars.namespace
+ name = input.path.sub(File.extname(input.path), '').sub(/_view$/, '')
+ [namespace, name].compact.join('/')
}
concat "templates.js"
@@ -211,7 +211,7 @@ def tests_compiles_handlebars_into_js_file
content = read "site/application.js"
- assert_includes content, "Handlebars.TEMPLATES['test_app/home']="
+ assert_includes content, "Handlebars.TEMPLATES['home']="
assert_includes content, "{{name}}"
assert_includes content, "Handlebars.compile"
end
@@ -223,7 +223,7 @@ def tests_maps_path_handlebars_template_name
content = read "site/application.js"
- assert_includes content, "Handlebars.TEMPLATES['test_app/dashboard/feed/header']="
+ assert_includes content, "Handlebars.TEMPLATES['dashboard/feed/header']="
end
def test_removes_view_from_handlebars_template_name
@@ -233,7 +233,19 @@ def test_removes_view_from_handlebars_template_name
content = read "site/application.js"
- assert_includes content, "Handlebars.TEMPLATES['test_app/dashboard/feed/header']="
+ assert_includes content, "Handlebars.TEMPLATES['dashboard/feed/header']="
+ end
+
+ def test_handlebars_namespace_is_configurbale
+ config.handlebars.namespace = "foo"
+
+ create_file "app/templates/home.handlebars", "{{name}}"
+
+ compile ; assert_file "site/application.js"
+
+ content = read "site/application.js"
+
+ assert_includes content, "Handlebars.TEMPLATES['foo/home']="
end
def test_handlebars_destination_is_configurbale
@@ -245,7 +257,7 @@ def test_handlebars_destination_is_configurbale
content = read "site/application.js"
- assert_includes content, "FOO['test_app/home']="
+ assert_includes content, "FOO['home']="
end
def test_handlebars_wrapper_is_configurable
@@ -273,7 +285,7 @@ def test_handlebars_files_work_with_precompilation
content = read "site/application.js"
- assert_match content, %r{Handlebars\.TEMPLATES\['test_app/home'\]=Handlebars\.template\(.+\);}m
+ assert_match content, %r{Handlebars\.TEMPLATES\['home'\]=Handlebars\.template\(.+\);}m
end
def test_inline_coffeescript_block_templates_with_line_breaks_are_compiled
@@ -963,7 +975,7 @@ def test_engines_can_add_their_own_templates
compile ; assert_file "site/application.js"
content = read "site/application.js"
- assert_includes content, %Q{Handlebars.TEMPLATES['test_engine/foo']=}
+ assert_includes content, %Q{Handlebars.TEMPLATES['foo']=}
end
def test_engine_vendor_css_comes_before_app_vendor_css

0 comments on commit 74d4c5c

Please sign in to comment.