[Haml] [html2haml] Fix an incompatibility with Hpricot 0.8.2.
This commit is contained in:
parent
76bd406875
commit
0c44bbc755
|
@ -10,6 +10,8 @@
|
|||
This makes Haml templates not crash when given non-ASCII input
|
||||
that's marked as having an ASCII encoding.
|
||||
|
||||
* Fixed an incompatibility with Hpricot 0.8.2, which is used for `html2haml`.
|
||||
|
||||
## [2.2.12](http://github.com/nex3/haml/commit/2.2.12)
|
||||
|
||||
There were no changes made to Sass between versions 2.2.11 and 2.2.12.
|
||||
|
|
|
@ -23,6 +23,10 @@ module Haml
|
|||
' ' * tabs
|
||||
end
|
||||
|
||||
def attr_hash
|
||||
attributes.to_hash
|
||||
end
|
||||
|
||||
def parse_text(text, tabs)
|
||||
text.strip!
|
||||
text.gsub!('#{', '\#{') #'
|
||||
|
@ -177,16 +181,16 @@ module Haml
|
|||
output += "%#{name}" unless name == 'div' &&
|
||||
(static_id?(options) || static_classname?(options))
|
||||
|
||||
if attributes
|
||||
if attr_hash
|
||||
if static_id?(options)
|
||||
output += "##{attributes['id']}"
|
||||
output += "##{attr_hash['id']}"
|
||||
remove_attribute('id')
|
||||
end
|
||||
if static_classname?(options)
|
||||
attributes['class'].split(' ').each { |c| output += ".#{c}" }
|
||||
attr_hash['class'].split(' ').each { |c| output += ".#{c}" }
|
||||
remove_attribute('class')
|
||||
end
|
||||
output += haml_attributes(options) if attributes.length > 0
|
||||
output += haml_attributes(options) if attr_hash.length > 0
|
||||
end
|
||||
|
||||
(self.children || []).inject(output + "\n") do |output, child|
|
||||
|
@ -198,7 +202,7 @@ module Haml
|
|||
|
||||
def dynamic_attributes
|
||||
@dynamic_attributes ||= begin
|
||||
Haml::Util.map_hash(attributes) do |name, value|
|
||||
Haml::Util.map_hash(attr_hash) do |name, value|
|
||||
next if value.empty?
|
||||
full_match = nil
|
||||
ruby_value = value.gsub(%r{<haml:loud>\s*(.+?)\s*</haml:loud>}) do
|
||||
|
@ -220,7 +224,7 @@ module Haml
|
|||
end
|
||||
|
||||
def static_attribute?(name, options)
|
||||
attributes[name] and !dynamic_attribute?(name, options)
|
||||
attr_hash[name] and !dynamic_attribute?(name, options)
|
||||
end
|
||||
|
||||
def dynamic_attribute?(name, options)
|
||||
|
@ -238,7 +242,7 @@ module Haml
|
|||
# Returns a string representation of an attributes hash
|
||||
# that's prettier than that produced by Hash#inspect
|
||||
def haml_attributes(options)
|
||||
attrs = attributes.map do |name, value|
|
||||
attrs = attr_hash.map do |name, value|
|
||||
value = dynamic_attribute?(name, options) ? dynamic_attributes[name] : value.inspect
|
||||
name = name.index(/\W/) ? name.inspect : ":#{name}"
|
||||
"#{name} => #{value}"
|
||||
|
|
Loading…
Reference in New Issue