mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Merge branch 'master' into yard
Conflicts: lib/sass/css.rb
This commit is contained in:
commit
651ae068a4
1 changed files with 0 additions and 78 deletions
|
@ -49,84 +49,6 @@ module Sass
|
|||
end
|
||||
end
|
||||
|
||||
# This class is based on the Ruby 1.9 ordered hashes.
|
||||
# It keeps the semantics and most of the efficiency of normal hashes
|
||||
# while also keeping track of the order in which elements were set.
|
||||
class OrderedHash
|
||||
Node = Struct.new(:key, :value, :next, :prev)
|
||||
include Enumerable
|
||||
|
||||
def initialize
|
||||
@hash = {}
|
||||
end
|
||||
|
||||
# Replaces the contents of this hash with the context of `other`.
|
||||
#
|
||||
# @param [OrderedHash] other
|
||||
# @return `self`
|
||||
def initialize_copy(other)
|
||||
@hash = other.instance_variable_get('@hash').clone
|
||||
self
|
||||
end
|
||||
|
||||
# Returns the value corresponding to `key`, or `nil` if not found.
|
||||
#
|
||||
# @param key
|
||||
# @return The value or `nil`
|
||||
def [](key)
|
||||
@hash[key] && @hash[key].value
|
||||
end
|
||||
|
||||
# Sets the value corresponding to `key` to `value`
|
||||
#
|
||||
# @param key
|
||||
# @param value
|
||||
# @return `value`
|
||||
def []=(key, value)
|
||||
node = Node.new(key, value)
|
||||
|
||||
if old = @hash[key]
|
||||
if old.prev
|
||||
old.prev.next = old.next
|
||||
else # old is @first and @last
|
||||
@first = @last = nil
|
||||
end
|
||||
end
|
||||
|
||||
if @first.nil?
|
||||
@first = @last = node
|
||||
else
|
||||
node.prev = @last
|
||||
@last.next = node
|
||||
@last = node
|
||||
end
|
||||
|
||||
@hash[key] = node
|
||||
value
|
||||
end
|
||||
|
||||
# Yields each key-value pair in the hash
|
||||
# in the order in which they were inserted.
|
||||
#
|
||||
# @yield [key, value] The key-value pairs
|
||||
# @return `self`
|
||||
def each
|
||||
return unless @first
|
||||
yield [@first.key, @first.value]
|
||||
node = @first
|
||||
yield [node.key, node.value] while node = node.next
|
||||
self
|
||||
end
|
||||
|
||||
# Returns an array of the values in the hash
|
||||
# in the order in which they were inserted.
|
||||
#
|
||||
# @return [Object] The values
|
||||
def values
|
||||
self.map {|k, v| v}
|
||||
end
|
||||
end
|
||||
|
||||
# This class converts CSS documents into Sass templates.
|
||||
# It works by parsing the CSS document into a {Sass::Tree} structure,
|
||||
# and then applying various transformations to the structure
|
||||
|
|
Loading…
Add table
Reference in a new issue