diff --git a/lib/liquid/template.rb b/lib/liquid/template.rb index 3e62765..a596bf8 100644 --- a/lib/liquid/template.rb +++ b/lib/liquid/template.rb @@ -14,6 +14,10 @@ module Liquid # template.render('user_name' => 'bob') # class Template + DEFAULT_OPTIONS = { + :locale => I18n.new + } + attr_accessor :root, :resource_limits @@file_system = BlankFileSystem.new @@ -68,7 +72,7 @@ module Liquid # Parse source code. # Returns self for easy chaining def parse(source, options = {}) - @root = Document.new(tokenize(source), options) + @root = Document.new(tokenize(source), DEFAULT_OPTIONS.merge(options)) @warnings = nil self end @@ -79,7 +83,7 @@ module Liquid end def registers - @registers ||= {:locale => Liquid::I18n.new} + @registers ||= {} end def assigns diff --git a/test/liquid/template_test.rb b/test/liquid/template_test.rb index 8f3a6fc..939d4e8 100644 --- a/test/liquid/template_test.rb +++ b/test/liquid/template_test.rb @@ -144,17 +144,16 @@ class TemplateTest < Test::Unit::TestCase assert_equal 'haha', t.parse("{{baz}}").render(drop) end - def test_sets_default_localization_in_context + def test_sets_default_localization_in_document t = Template.new - assert_instance_of I18n, t.registers[:locale] + assert_instance_of I18n, t.root.options[:locale] end def test_sets_default_localization_in_context_with_quick_initialization t = Template.new - t.registers[:locale] = I18n.new(fixture("en_locale.yml")) - t.parse('{{foo}}') + t.parse('{{foo}}', locale: I18n.new(fixture("en_locale.yml"))) - assert_instance_of I18n, t.registers[:locale] - assert_equal fixture("en_locale.yml"), t.registers[:locale].path + assert_instance_of I18n, t.root.options[:locale] + assert_equal fixture("en_locale.yml"), t.root.options[:locale].path end end