lib/csl/node.rb in csl-1.0.2 vs lib/csl/node.rb in csl-1.1.0

- old
+ new

@@ -135,12 +135,14 @@ class << self attr_reader :keys end - def initialize(attrs = {}) - super(*attrs.symbolize_keys.values_at(*keys)) + CSL.silence_warnings do + def initialize(attrs = {}) + super(*attrs.symbolize_keys.values_at(*keys)) + end end # @return [<Symbol>] a list of symbols representing the names/keys # of the attribute variables. def keys @@ -188,10 +190,11 @@ send(:'[]=', part, value) if !value.nil? && keys.include?(part) end self end + alias merge! merge # @overload values_at(selector, ... ) # Returns an array containing the attributes in self according # to the given selector(s). The selectors may be either integer # indices, ranges (functionality inherited from Struct) or @@ -229,13 +232,11 @@ yield self if block_given? end def initialize_copy(other) super - @attributes = self.class.create_attributes(other.attributes) - @children = self.class.create_children - @parent, @ancestors, @descendants, @siblings, @root, @depth = nil + initialize(other.attributes) end def deep_copy copy = dup @@ -244,10 +245,23 @@ end copy end + def merge!(options) + attributes.merge!(options) + self + end + + def reverse_merge!(options) + options.each_pair do |key, value| + attributes[key] = value unless attribute? key + end + + self + end + # @return [Boolean] whether or not the node has default attributes def has_default_attributes? !default_attributes.empty? end alias has_defaults? has_default_attributes? @@ -415,15 +429,47 @@ Hash[map { |name, value| !value.nil? && filter.include?(name) ? [name, value.to_s] : nil }.compact] end + # @return [Hash] the node's formatting options def formatting_options - attributes_for Schema.attr(:formatting) + options = attributes_for Schema.attr(:formatting) + + if !root? && parent.respond_to?(:inheritable_formatting_options) + parent.inheritable_formatting_options.merge(options) + else + options + end end + # Whether or not page ranges should be formatted when + # rendering this node. + # + # Page ranges must be formatted if the node is part of + # a {Style} with a page-range-format value. + # + # @return [Boolean] whether or not page ranges should + # be formatted + def format_page_ranges? + root.respond_to?(:has_page_range_format?) && root.has_page_range_format? + end + + def page_range_format + return unless format_page_ranges? + root.page_range_format + end + + def strip_periods? + attribute?(:'strip-periods') && !!(attributes[:'strip-periods'].to_s =~ /^true$/i) + end + + def quotes? + attribute?(:'quotes') && !!(attributes[:'quotes'].to_s =~ /^true$/i) + end + def <=>(other) [nodename, attributes, children] <=> [other.nodename, other.attributes, other.children] rescue nil end @@ -533,9 +579,11 @@ end def textnode? true end + + remove_method :empty? def empty? text.nil? || text.empty? end