Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #111 from rossta/register_custom_template_hook

Ability to register custom template engines...
  • Loading branch information...
commit 21590a9a194ee80b39fa206706b9b93563b216e1 2 parents 68683e4 + 75dce5b
@johnbintz authored
View
38 lib/jasmine/headless/files_list.rb
@@ -17,6 +17,7 @@ def asset_paths
def reset!
@asset_paths = nil
+ @registered_engines = {}
# register haml-sprockets and handlebars_assets if it's available...
%w{haml-sprockets handlebars_assets}.each do |library|
@@ -46,6 +47,21 @@ def reset!
register_engine '.css', Jasmine::Headless::CSSTemplate
register_engine '.jst', Jasmine::Headless::JSTTemplate
end
+
+ end
+
+ def registered_engines
+ @registered_engines ||= {}
+ end
+
+ def register_engine(file_extension, template_class)
+ registered_engines[file_extension] = template_class
+ end
+
+ def register_engines!
+ registered_engines.each do |file_extension, template_class|
+ Sprockets.register_engine file_extension, template_class
+ end
end
def default_files
@@ -74,11 +90,21 @@ def initialize(options = {})
@required_files = UniqueAssetList.new
@potential_files_to_filter = []
+ register_engines!
+
load_initial_assets
use_config if config?
end
+ def register_engines!
+ begin
+ require spec_helper
+ rescue LoadError
+ end
+ self.class.register_engines!
+ end
+
def load_initial_assets
self.class.default_files.each do |file|
begin
@@ -287,5 +313,17 @@ def filter_for_requested_specs(files)
end
end
end
+
+ def spec_helper
+ File.join(spec_dir, "helpers", "spec_helper")
+ end
+ end
+end
+
+module Jasmine::Headless
+ extend self
+
+ def register_engine(file_extension, template_class)
+ Jasmine::Headless::FilesList.register_engine(file_extension, template_class)
end
end
View
15 spec/lib/jasmine/headless/files_list_spec.rb
@@ -174,6 +174,21 @@
files_list.files.any? { |file| file['.erb'] }.should be_false
end
end
+
+ describe "#register_engine!" do
+
+ before(:each) do
+ Jasmine::Headless::FilesList.reset!
+ end
+
+ it "should register code added via configure blocks" do
+ template_class = mock()
+ described_class.register_engine ".foo", template_class
+ Sprockets.expects(:register_engine).with(".foo", template_class)
+ described_class.new
+ end
+
+ end
end
end

0 comments on commit 21590a9

Please sign in to comment.
Something went wrong with that request. Please try again.