Class: SWS::TemplateToken
- Inherits:
-
Object
- Object
- SWS::TemplateToken
- Defined in:
- lib/sws/parsers.rb
Overview
Internal class - used only by TemplateParser. Represents a HTML tag or text token
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#data ⇒ Object
Returns the value of attribute data.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
-
#comment? ⇒ Boolean
Returns true if the receiver is a HTML comment.
-
#dump(prefix) ⇒ Object
Dumps the token recursively in a tree form.
-
#initialize(parent, name, standalone = false, comment = false) ⇒ TemplateToken
constructor
Creates new Token with given parent.
-
#reverse ⇒ Object
Reverses receiver’s children array.
-
#standalone? ⇒ Boolean
Returns true if the receiver is a standalone tag.
-
#sws? ⇒ Boolean
Returns true if the receiver represents a Component.
-
#sws_name ⇒ Object
Returns name of the Component.
-
#tag? ⇒ Boolean
Returns true if the receiver represents a HTML tag.
-
#text? ⇒ Boolean
Returns true if the receiver is a purely text one.
-
#to_s ⇒ Object
Returns string representation of the receiver.
Constructor Details
#initialize(parent, name, standalone = false, comment = false) ⇒ TemplateToken
Creates new Token with given parent
286 287 288 289 290 291 292 293 294 295 |
# File 'lib/sws/parsers.rb', line 286 def initialize ( parent,name,standalone=false,comment=false ) @parent = parent @name = name @children = Array.new @comment = comment @standalone = standalone @data = nil end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
282 283 284 |
# File 'lib/sws/parsers.rb', line 282 def attributes @attributes end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
281 282 283 |
# File 'lib/sws/parsers.rb', line 281 def children @children end |
#data ⇒ Object
Returns the value of attribute data.
282 283 284 |
# File 'lib/sws/parsers.rb', line 282 def data @data end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
281 282 283 |
# File 'lib/sws/parsers.rb', line 281 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
281 282 283 |
# File 'lib/sws/parsers.rb', line 281 def parent @parent end |
Instance Method Details
#comment? ⇒ Boolean
Returns true if the receiver is a HTML comment
329 330 331 |
# File 'lib/sws/parsers.rb', line 329 def comment? () return @comment end |
#dump(prefix) ⇒ Object
Dumps the token recursively in a tree form.
357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
# File 'lib/sws/parsers.rb', line 357 def dump ( prefix ) if( comment? ) puts "#{prefix}comment" elsif ( text? ) puts "#{prefix}text" elsif( tag? ) puts "#{prefix}#{data}" @children.each { |child| child.dump( prefix + " " ) } else attrs = @attributes.to_a.join( "| " ) puts "#{prefix}#{@name} #{attrs}" @children.each { |child| child.dump( prefix + " " ) } end end |
#reverse ⇒ Object
Reverses receiver’s children array. Used at the end of parsing process, as parsing is performed backwards (otherwise it is hard to distinguish open/close and standalone tags)
300 301 302 303 |
# File 'lib/sws/parsers.rb', line 300 def reverse () @children.reverse! @children.each { |child| child.reverse() } end |
#standalone? ⇒ Boolean
Returns true if the receiver is a standalone tag
335 336 337 |
# File 'lib/sws/parsers.rb', line 335 def standalone? () return @standalone end |
#sws? ⇒ Boolean
Returns true if the receiver represents a Component
306 307 308 |
# File 'lib/sws/parsers.rb', line 306 def sws? () return @name != nil && @attributes != nil end |
#sws_name ⇒ Object
Returns name of the Component
311 312 313 |
# File 'lib/sws/parsers.rb', line 311 def sws_name () return @attributes["sws"] end |
#tag? ⇒ Boolean
Returns true if the receiver represents a HTML tag
317 318 319 |
# File 'lib/sws/parsers.rb', line 317 def tag? () return @name != nil && @data != nil end |
#text? ⇒ Boolean
Returns true if the receiver is a purely text one
323 324 325 |
# File 'lib/sws/parsers.rb', line 323 def text? () return @name == nil end |
#to_s ⇒ Object
Returns string representation of the receiver
341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'lib/sws/parsers.rb', line 341 def to_s () if( comment? ) return "comment" elsif ( text? ) return "text" elsif( tag? ) return "#{data}" else attrs = @attributes.to_a.join( "| " ) return "#{@name} #{attrs}" end end |