class Pump::Xml::Tag
Constants
- INSTRUCT
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
Pump::Xml::Node::new
# File lib/pump/xml/tag.rb, line 8 def initialize(*args) super if value_nodes? nodes.first.options = options end end
Public Instance Methods
to_s()
click to toggle source
# File lib/pump/xml/tag.rb, line 15 def to_s if options.has_key?(:static_value) "#{condition_start}#{open_tag}#{static_value_and_close_tag}#{condition_end}" elsif !value_nodes? || options[:never_nil] "#{condition_start}#{open_tag}#{value_and_close_tag}#{condition_end}" else "#{condition_start}#{open_tag}\#{v = #{nodes.first.plain};''}\#{#{value_and_close_tag_with_nil_check}}#{condition_end}" end end
Private Instance Methods
attributes_string()
click to toggle source
# File lib/pump/xml/tag.rb, line 57 def attributes_string return "" if !attributes || attributes.size == 0 attributes.inject('') do |str, (key, value)| str << " #{key}=\\\"#{value}\\\"" end end
condition_end()
click to toggle source
# File lib/pump/xml/tag.rb, line 68 def condition_end return unless conditional? conditions = [] if options[:partial] conditions << if options[:path] && options[:path].any? "field_hash[:'#{options[:path].join('.')}']" else "field_hash[:#{name.to_s.underscore}]" end end if options[:if] conditions << "object.#{options[:if]}" elsif options[:unless] conditions << "!object.#{options[:unless]}" end "\" if #{conditions.join(" && ")} }" if conditions.any? end
condition_start()
click to toggle source
# File lib/pump/xml/tag.rb, line 64 def condition_start "\#{\"" if conditional? end
conditional?()
click to toggle source
# File lib/pump/xml/tag.rb, line 90 def conditional? !!(options[:if] || options[:unless] || options[:partial]) end
open_tag()
click to toggle source
# File lib/pump/xml/tag.rb, line 31 def open_tag "#{prefix}<#{format_name(name)}#{attributes_string}" end
prefix()
click to toggle source
# File lib/pump/xml/tag.rb, line 35 def prefix if level == 0 options[:instruct] ? INSTRUCT : (tabs) else "#{tabs}" end end
static_value_and_close_tag()
click to toggle source
# File lib/pump/xml/tag.rb, line 52 def static_value_and_close_tag return " nil=\\\"true\\\"/>\n" if options[:static_value].nil? ">#{options[:static_value]}</#{format_name(name)}>\n" end
value_and_close_tag(path=nil)
click to toggle source
# File lib/pump/xml/tag.rb, line 43 def value_and_close_tag(path=nil) value = value_nodes? ? nodes.first.to_s(path) : ("\n" << nodes.map(&:to_s).join) ">#{value}#{tabs unless value_nodes?}</#{format_name(name)}>\n" end
value_and_close_tag_with_nil_check()
click to toggle source
# File lib/pump/xml/tag.rb, line 48 def value_and_close_tag_with_nil_check "v.nil? ? \" nil=\\\"true\\\"/>\n\" : \"#{value_and_close_tag('v')}\"" end
value_nodes?()
click to toggle source
# File lib/pump/xml/tag.rb, line 27 def value_nodes? Value === nodes.first end