pakyow-presenter/lib/presenter/attributes.rb in pakyow-presenter-0.8.0 vs pakyow-presenter/lib/presenter/attributes.rb in pakyow-presenter-0.9.0
- old
+ new
@@ -51,27 +51,30 @@
# passes method call to `value`
def method_missing(method, *args)
ret = @value.send(method, *args)
update_value
-
return ret
end
# returns the full string value
def to_s
value = @value
- value = value.call(deconstruct_attribute_value_of_type(@doc[@name], @type)) if value.is_a? Proc
+ value = value.call(deconstruct_attribute_value_of_type(@doc.get_attribute(@name), @type)) if value.is_a? Proc
value = construct_attribute_value_of_type(value, @type, @name)
return value
end
def value
@value
end
+ def ancestors
+ self.class.ancestors
+ end
+
private
def update_value
updated_value = to_s
@@ -115,14 +118,13 @@
}
end
end
class Attributes
- def initialize(doc, composer = nil)
+ def initialize(doc)
@doc = doc
@attributes = {}
- @composer = composer
end
def method_missing(method, *args)
method_str = method.to_s
@@ -142,38 +144,32 @@
end
def class(*args)
method_missing(:class, *args)
end
-
+
def id(*args)
method_missing(:id, *args)
end
def update_value_for_attribute(attribute, value)
- if !@doc.is_a?(Nokogiri::XML::Element) && @doc.children.count == 1
- @doc.children.first[attribute] = value
- else
- @doc[attribute] = value
- end
+ @doc.update_attribute(attribute, value)
end
def remove_attribute(attribute)
@doc.remove_attribute(attribute)
- @composer.dirty! unless @composer.nil?
end
protected
def set_attribute(attribute, value)
get_attribute(attribute).set(value)
- @composer.dirty! unless @composer.nil?
end
def get_attribute(attribute)
unless a = @attributes[attribute]
- a = Attribute.new(attribute, @doc[attribute], self, @doc)
+ a = Attribute.new(attribute, @doc.get_attribute(attribute), self, @doc)
end
return a
end
end
@@ -185,23 +181,30 @@
@attributes = []
end
def <<(attributes)
@attributes << attributes
+ self
end
+ def each
+ @attributes.each { |a| yield(a) }
+ end
+
def method_missing(method, *args)
- @attributes.inject(AttributesCollection.new) { |coll, a| coll<< a.send(method, *args) }
+ @attributes.inject(AttributesCollection.new) { |coll, a|
+ coll << a.send(method, *args)
+ }
end
def to_s
@attributes.inject([]) { |arr, a| arr << a.to_s }
end
def class(*args)
method_missing(:class, *args)
end
-
+
def id(*args)
method_missing(:id, *args)
end
end
end