Skip to content

Commit

Permalink
Respect changes in Haml::Options.defaults
Browse files Browse the repository at this point in the history
in `Haml::TempleEngine` options.

Since the feature has been noted here:
https://github.com/haml/haml/blob/master/REFERENCE.md#options

Note that `Haml::Engine#initialize` in Haml 4 calls
`#initialize_encoding` with the argument `options[:encoding]`, which
should return `nil` instead of `"UTF-8"` (default of `Haml::Options`),
so this is the most backward-compatible behavior.

Fix #1004
  • Loading branch information
k0kubun committed Jan 19, 2019
1 parent 26a7d25 commit 99ded8b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/haml/engine.rb
Expand Up @@ -51,6 +51,9 @@ def options_for_buffer
# see {file:REFERENCE.md#options the Haml options documentation}
# @raise [Haml::Error] if there's a Haml syntax error in the template
def initialize(template, options = {})
# Reflect changes of `Haml::Options.defaults` to `Haml::TempleEngine` options, but `#initialize_encoding`
# should be run against the arguemnt `options[:encoding]` for backward compatibility with old `Haml::Engine`.
options = Options.defaults.dup.tap { |o| o.delete(:encoding) }.merge!(options)
@options = Options.new(options)

@template = check_haml_encoding(template) do |msg, line|
Expand Down
8 changes: 8 additions & 0 deletions test/engine_test.rb
Expand Up @@ -2141,6 +2141,14 @@ def test_unsafe_static_attribute_name_raises_invalid_attribute_name_error
end
end

def test_engine_reflects_defaults
defaults = Haml::Options.defaults.dup
Haml::Options.defaults[:attr_wrapper] = '"'
assert_equal %Q[<a a="a"></a>\n], Haml::Engine.new('%a(a="a")').render
ensure
Haml::Options.defaults.replace(defaults)
end

private

def assert_valid_encoding_comment(comment)
Expand Down

0 comments on commit 99ded8b

Please sign in to comment.