Class: Web::Narflates::Select

Inherits:
Object
  • Object
show all
Defined in:
lib/web/template.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, values) ⇒ Select

Returns a new instance of Select.



451
452
453
454
# File 'lib/web/template.rb', line 451

def initialize (name,values)
	@name = name
	@values = values
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



450
451
452
# File 'lib/web/template.rb', line 450

def name
  @name
end

#valuesObject (readonly)

Returns the value of attribute values.



450
451
452
# File 'lib/web/template.rb', line 450

def values
  @values
end

Instance Method Details



456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
# File 'lib/web/template.rb', line 456

def print (globals,io) 
	value = globals.resolve(@name).value
	values = globals.resolve(@values).value
	io << "<select name=\"#{@name}\">"
	
	values = values.collect { |i|
	  unless i.kind_of? Hash
	    { "name" => i, "value" => i }
	  else
	    { "name" => i["name"], "value" => i["value"] }
	  end
	}

	values.each { |item|
	  item = item
	  selected = if item["value"].to_s == value.to_s
   " selected"
 else
   ""
 end
	  io << "<option value=\"#{item['value']}\"#{selected}>#{item['name']}</option>"
	}
	io << "</select>"
end