Merge pull request #111 from rossta/register_custom_template_hook
Ability to register custom template engines...
This commit is contained in:
commit
21590a9a19
@ -17,6 +17,7 @@ module Jasmine::Headless
|
||||
|
||||
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 @@ module Jasmine::Headless
|
||||
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 @@ module Jasmine::Headless
|
||||
@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 @@ module Jasmine::Headless
|
||||
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
|
||||
|
@ -174,6 +174,21 @@ describe Jasmine::Headless::FilesList do
|
||||
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user