diff --git a/lib/liquid/template.rb b/lib/liquid/template.rb index 276cdbf..adcf6bd 100644 --- a/lib/liquid/template.rb +++ b/lib/liquid/template.rb @@ -106,16 +106,8 @@ module Liquid # Parse source code. # Returns self for easy chaining def parse(source, options = {}) - if (profiling = options[:profile]) - raise "Profiler not loaded, require 'liquid/profiler' first" unless defined?(Liquid::Profiler) - end - - @options = options - @profiling = profiling - @line_numbers = options[:line_numbers] || profiling - parse_context = options.is_a?(ParseContext) ? options : ParseContext.new(options) + parse_context = configure_options(options) @root = Document.parse(tokenize(source), parse_context) - @warnings = parse_context.warnings self end @@ -218,6 +210,19 @@ module Liquid private + def configure_options(options) + if (profiling = options[:profile]) + raise "Profiler not loaded, require 'liquid/profiler' first" unless defined?(Liquid::Profiler) + end + + @options = options + @profiling = profiling + @line_numbers = options[:line_numbers] || @profiling + parse_context = options.is_a?(ParseContext) ? options : ParseContext.new(options) + @warnings = parse_context.warnings + parse_context + end + def tokenize(source) Tokenizer.new(source, @line_numbers) end