lib/liquid-rails/file_system.rb in liquid-rails-0.1.4 vs lib/liquid-rails/file_system.rb in liquid-rails-0.2.0.beta1

- old
+ new

@@ -1,13 +1,38 @@ require 'liquid/file_system' module Liquid module Rails - class FileSystem < ::Liquid::LocalFileSystem - def read_template_file(template_path, context) - controller_path = context.registers[:controller].controller_path + class FileSystem + def initialize(view) + @view = view + end + + def read_template_file(template_path) + controller_path = view.controller_path template_path = "#{controller_path}/#{template_path}" unless template_path.include?('/') - super + + name = template_path.split('/').last + prefix = template_path.split('/')[0...-1].join('/') + + result = view.view_paths.find_all(name, prefix, true, lookup_details) + raise FileSystemError, "No such template '#{template_path}'" unless result.present? + + result.first.source + end + + private + + attr_reader :view + + def lookup_details + { + locale: [view.locale, :en], + formats: view.formats, + variants: [], + handlers: [:liquid], + versions: [] + } end end end end