Class: Undies::Element::Open

Inherits:
Object
  • Object
show all
Includes:
CSSProxy, MergeAttrs
Defined in:
lib/undies/element.rb

Constant Summary

Constants included from CSSProxy

CSSProxy::CLASS_METH_REGEX, CSSProxy::ID_METH_REGEX

Instance Method Summary collapse

Methods included from MergeAttrs

#__attrs

Methods included from CSSProxy

#method_missing, #respond_to?

Constructor Details

#initialize(name, *args, &build) ⇒ Open

Returns a new instance of Open.



79
80
81
82
83
84
85
86
# File 'lib/undies/element.rb', line 79

def initialize(name, *args, &build)
  @name    = name.to_s
  @attrs   = {}
  @content = []
  @build   = nil

  proxy(args, build)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Undies::Element::CSSProxy

Instance Method Details

#==(other) ⇒ Object



108
109
110
111
112
# File 'lib/undies/element.rb', line 108

def ==(other)
  other.instance_variable_get("@name")    == @name    &&
  other.instance_variable_get("@attrs")   == @attrs   &&
  other.instance_variable_get("@content") == @content
end

#__buildObject



96
97
98
# File 'lib/undies/element.rb', line 96

def __build
  @build.call if @build
end

#__contentObject



92
93
94
# File 'lib/undies/element.rb', line 92

def __content
  @content.collect{ |c| Undies::Template.escape_html(c) }.join
end

#__end_tagObject



100
101
102
# File 'lib/undies/element.rb', line 100

def __end_tag
  "</#{@name}>"
end

#__start_tagObject



88
89
90
# File 'lib/undies/element.rb', line 88

def __start_tag
  "<#{@name}#{Undies::Element.hash_attrs(@attrs)}>"
end

#to_sObject



104
105
106
# File 'lib/undies/element.rb', line 104

def to_s
  Undies::Raw.new("#{__start_tag}#{__content}#{__end_tag}")
end

#to_str(*args) ⇒ Object Also known as: inspect

overriding this because the base Node class defines a ‘to_s’ method that needs to be honored



116
117
118
119
# File 'lib/undies/element.rb', line 116

def to_str(*args)
  "Undies::Element::Open:#{self.object_id} " +
  "@name=#{@name.inspect}, @attrs=#{@attrs.inspect}, @content=#{@content.inspect}"
end