Pass options to include tags

This commit is contained in:
Tristan Hume
2014-08-26 10:50:25 -04:00
parent dfb6c20493
commit 68af2d6e2a
4 changed files with 41 additions and 3 deletions
+11 -1
View File
@@ -69,7 +69,7 @@ module Liquid
return cached
end
source = read_template_from_file_system(context)
partial = Liquid::Template.parse(source)
partial = Liquid::Template.parse(source, pass_options)
cached_partials[template_name] = partial
context.registers[:cached_partials] = cached_partials
partial
@@ -88,6 +88,16 @@ module Liquid
raise ArgumentError, "file_system.read_template_file expects two parameters: (template_name, context)"
end
end
def pass_options
dont_pass = @options[:include_options_blacklist]
return {locale: @options[:locale]} if dont_pass == true
opts = @options.merge(included: true, include_options_blacklist: false)
if dont_pass.is_a?(Array)
dont_pass.each {|o| opts.delete(o)}
end
opts
end
end
Template.register_tag('include'.freeze, Include)
+3 -2
View File
@@ -103,7 +103,8 @@ module Liquid
# Parse source code.
# Returns self for easy chaining
def parse(source, options = {})
@profiling = options.delete(:profile)
@options = options
@profiling = options[:profile]
@root = Document.parse(tokenize(source), DEFAULT_OPTIONS.merge(options))
@warnings = nil
self
@@ -234,7 +235,7 @@ module Liquid
end
def with_profiling
if @profiling
if @profiling && !@options[:included]
@profiler = Profiler.new
@profiler.start