lib/stache/asset_helper.rb in stache-0.2.2 vs lib/stache/asset_helper.rb in stache-0.9.0

- old
+ new

@@ -1,33 +1,26 @@ module Stache module AssetHelper # template_include_tag("widgets/basic_text_api_data") # template_include_tag("shared/test_thing") def template_include_tag(*sources) + options = sources.extract_options! sources.collect do |source| - exploded = source.split("/") - file = exploded.pop - file = file.split(".").first - - base_path = Stache.template_base_path.join(*exploded) - template_path = locate_template_for(base_path, file) - if template_path - template = ::File.open(template_path, "rb" , :encoding => Rails.configuration.encoding) - content_tag(:script, template.read.html_safe, :type => "text/html", :id => "#{file.dasherize.underscore}_template") - else - raise ActionView::MissingTemplate.new(potential_paths(base_path, file), file, [base_path], false, { :handlers => [:mustache] }) + template_finder = lambda do |partial| + if ActionPack::VERSION::MAJOR == 3 && ActionPack::VERSION::MINOR < 2 + lookup_context.find(source, [], partial) + else # Rails 3.2 and higher + lookup_context.find(source, [], partial, [], { formats: [:html] }) + end end + + template = template_finder.call(true) rescue template_finder.call(false) + template_id = source.split("/").last + + options = options.reverse_merge(:type => "text/html", :id => "#{template_id.dasherize.underscore}_template") + content_tag(:script, template.source.html_safe, options) + end.join("\n").html_safe end - - def potential_paths(path, candidate_file_name) - [ - path.join("_#{candidate_file_name}.#{Stache.template_extension}"), - path.join("#{candidate_file_name}.#{Stache.template_extension}") - ] - end - - def locate_template_for(path, candidate_file_name) - potential_paths(path, candidate_file_name).find { |file| File.file?(file.to_s) } - end + end end