Class: SWS::TemplateToken

Inherits:
Object
  • Object
show all
Defined in:
lib/sws/parsers.rb

Overview

Internal class - used only by TemplateParser. Represents a HTML tag or text token

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#attributesObject

Returns the value of attribute attributes.



282
283
284
# File 'lib/sws/parsers.rb', line 282

def attributes
  @attributes
end

#childrenObject (readonly)

Returns the value of attribute children.



281
282
283
# File 'lib/sws/parsers.rb', line 281

def children
  @children
end

#dataObject

Returns the value of attribute data.



282
283
284
# File 'lib/sws/parsers.rb', line 282

def data
  @data
end

#nameObject (readonly)

Returns the value of attribute name.



281
282
283
# File 'lib/sws/parsers.rb', line 281

def name
  @name
end

#parentObject (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

Returns:

  • (Boolean)


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

#reverseObject

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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


306
307
308
# File 'lib/sws/parsers.rb', line 306

def sws? ()
	return @name != nil && @attributes != nil
end

#sws_nameObject

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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


323
324
325
# File 'lib/sws/parsers.rb', line 323

def text? ()
	return @name == nil
end

#to_sObject

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