Merge pull request #111 from rossta/register_custom_template_hook

Ability to register custom template engines...
This commit is contained in:
John Bintz 2012-03-22 04:17:13 -07:00
commit 21590a9a19
2 changed files with 53 additions and 0 deletions

View File

@ -17,6 +17,7 @@ module Jasmine::Headless
def reset! def reset!
@asset_paths = nil @asset_paths = nil
@registered_engines = {}
# register haml-sprockets and handlebars_assets if it's available... # register haml-sprockets and handlebars_assets if it's available...
%w{haml-sprockets handlebars_assets}.each do |library| %w{haml-sprockets handlebars_assets}.each do |library|
@ -46,6 +47,21 @@ module Jasmine::Headless
register_engine '.css', Jasmine::Headless::CSSTemplate register_engine '.css', Jasmine::Headless::CSSTemplate
register_engine '.jst', Jasmine::Headless::JSTTemplate register_engine '.jst', Jasmine::Headless::JSTTemplate
end 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 end
def default_files def default_files
@ -74,11 +90,21 @@ module Jasmine::Headless
@required_files = UniqueAssetList.new @required_files = UniqueAssetList.new
@potential_files_to_filter = [] @potential_files_to_filter = []
register_engines!
load_initial_assets load_initial_assets
use_config if config? use_config if config?
end end
def register_engines!
begin
require spec_helper
rescue LoadError
end
self.class.register_engines!
end
def load_initial_assets def load_initial_assets
self.class.default_files.each do |file| self.class.default_files.each do |file|
begin begin
@ -287,5 +313,17 @@ module Jasmine::Headless
end end
end 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
end end

View File

@ -174,6 +174,21 @@ describe Jasmine::Headless::FilesList do
files_list.files.any? { |file| file['.erb'] }.should be_false files_list.files.any? { |file| file['.erb'] }.should be_false
end end
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
end end