class Rudsl::Node

Attributes

attributes[RW]
children[RW]
node_type[RW]
text[RW]

Public Class Methods

new(node_type) click to toggle source
# File lib/rudsl.rb, line 39
def initialize(node_type)
  @node_type = node_type
  @attributes = {}
  @children = []
  @text = nil
end

Public Instance Methods

addClass(classToAdd) click to toggle source
# File lib/rudsl.rb, line 56
def addClass(classToAdd)
  if attributes[:class].is_a?(String) || attributes[:class].is_a?(Symbol)
    attributes[:class] = [attributes[:class].to_s]
  end
  attributes[:class] ||= []
  attributes[:class] << classToAdd.to_s
  attributes[:class].uniq!
end
removeClass(classToRemove) click to toggle source
# File lib/rudsl.rb, line 50
def removeClass(classToRemove)
  if !attributes[:class].nil?
    attributes[:class].delete(classToRemove)
  end
end
to_s() click to toggle source
# File lib/rudsl.rb, line 46
def to_s
  "<#{@node_type}#{@attributes.to_a.count == 0 ? "" : " "}#{@attributes.to_a.map{|e| "#{e[0]}=\"#{e[1].is_a?(Array) ? e[1].join(" ") : e[1]}\""}.join(" ")}>" + @text.to_s + @children.map(&:to_s).join("") + "</#{@node_type}>"
end