diff --git a/lib/haml.rb b/lib/haml.rb index a0a6a509..15be8e98 100644 --- a/lib/haml.rb +++ b/lib/haml.rb @@ -1044,4 +1044,5 @@ module Haml end end +require 'haml/util' require 'haml/engine' diff --git a/lib/haml/buffer.rb b/lib/haml/buffer.rb index cd6d1a00..7ca63401 100644 --- a/lib/haml/buffer.rb +++ b/lib/haml/buffer.rb @@ -5,6 +5,7 @@ module Haml # processing done within instance_eval'd code. class Buffer include Haml::Helpers + include Haml::Util # The string that holds the compiled XHTML. This is aliased as # _erbout for compatibility with ERB-specific code. @@ -152,7 +153,7 @@ module Haml attributes = class_id attributes_hashes.each do |old| - self.class.merge_attrs(attributes, old.inject({}) {|h, (key, val)| h[key.to_s] = val; h}) + self.class.merge_attrs(attributes, to_hash(old.map {|k, v| [k.to_s, v]})) end self.class.merge_attrs(attributes, parse_object_ref(obj_ref)) if obj_ref diff --git a/lib/haml/html.rb b/lib/haml/html.rb index d0ee9b32..297d0e29 100644 --- a/lib/haml/html.rb +++ b/lib/haml/html.rb @@ -162,19 +162,15 @@ module Haml def dynamic_attributes @dynamic_attributes ||= begin - attributes.inject({}) do |dynamic, pair| - name, value = pair - unless value.empty? - full_match = nil - ruby_value = value.gsub(%r{\s*(.+?)\s*}) do - full_match = $`.empty? && $'.empty? - full_match ? $1: "\#{#{$1}}" - end - unless ruby_value == value - dynamic[name] = full_match ? ruby_value : %("#{ruby_value}") - end + Haml::Util.map_hash(attributes) do |name, value| + next if value.empty? + full_match = nil + ruby_value = value.gsub(%r{\s*(.+?)\s*}) do + full_match = $`.empty? && $'.empty? + full_match ? $1: "\#{#{$1}}" end - dynamic + next if ruby_value == value + [name, full_match ? ruby_value : %("#{ruby_value}")] end end end diff --git a/lib/haml/template/patch.rb b/lib/haml/template/patch.rb index 49f5014e..2fe4867b 100644 --- a/lib/haml/template/patch.rb +++ b/lib/haml/template/patch.rb @@ -29,7 +29,7 @@ module ActionView @@template_args[render_symbol] ||= {} locals_keys = @@template_args[render_symbol].keys | locals - @@template_args[render_symbol] = locals_keys.inject({}) { |h, k| h[k] = true; h } + @@template_args[render_symbol] = to_hash(locals_keys.map {|k| [k, true]}) options = Haml::Template.options.dup options[:filename] = file_name || 'compiled-template' diff --git a/lib/haml/util.rb b/lib/haml/util.rb new file mode 100644 index 00000000..8d715ea5 --- /dev/null +++ b/lib/haml/util.rb @@ -0,0 +1,21 @@ +module Haml + module Util + class << self; include Haml::Util; end + + def to_hash(arr) + arr.compact.inject({}) {|h, (k, v)| h[k] = v; h} + end + + def map_keys(hash) + to_hash(hash.map {|k, v| [yield(k), v]}) + end + + def map_vals(hash) + to_hash(hash.map {|k, v| [k, yield(v)]}) + end + + def map_hash(hash, &block) + to_hash(hash.map(&block)) + end + end +end diff --git a/lib/sass.rb b/lib/sass.rb index 92d587c0..7462b8f8 100644 --- a/lib/sass.rb +++ b/lib/sass.rb @@ -968,5 +968,6 @@ $LOAD_PATH.unshift dir unless $LOAD_PATH.include?(dir) # module Sass; end +require 'haml/util' require 'sass/engine' require 'sass/plugin' if defined?(Merb::Plugins) diff --git a/lib/sass/script/color.rb b/lib/sass/script/color.rb index 1652b84d..96df7e86 100644 --- a/lib/sass/script/color.rb +++ b/lib/sass/script/color.rb @@ -2,25 +2,24 @@ require 'sass/script/literal' module Sass::Script class Color < Literal # :nodoc: - HTML4_COLORS = { - 'black' => 0x000000, - 'silver' => 0xc0c0c0, - 'gray' => 0x808080, - 'white' => 0xffffff, - 'maroon' => 0x800000, - 'red' => 0xff0000, - 'purple' => 0x800080, - 'fuchsia' => 0xff00ff, - 'green' => 0x008000, - 'lime' => 0x00ff00, - 'olive' => 0x808000, - 'yellow' => 0xffff00, - 'navy' => 0x000080, - 'blue' => 0x0000ff, - 'teal' => 0x008080, - 'aqua' => 0x00ffff - } + 'black' => 0x000000, + 'silver' => 0xc0c0c0, + 'gray' => 0x808080, + 'white' => 0xffffff, + 'maroon' => 0x800000, + 'red' => 0xff0000, + 'purple' => 0x800080, + 'fuchsia' => 0xff00ff, + 'green' => 0x008000, + 'lime' => 0x00ff00, + 'olive' => 0x808000, + 'yellow' => 0xffff00, + 'navy' => 0x000080, + 'blue' => 0x0000ff, + 'teal' => 0x008080, + 'aqua' => 0x00ffff + } def initialize(rgb) rgb = rgb.map {|c| c.to_i}