Class: Web::Narflates::Select
Overview
:nodoc:
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
-
#initialize(name, values) ⇒ Select
constructor
A new instance of Select.
- #print(globals, io) ⇒ Object
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
450 451 452 |
# File 'lib/web/template.rb', line 450 def name @name end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
450 451 452 |
# File 'lib/web/template.rb', line 450 def values @values end |
Instance Method Details
#print(globals, io) ⇒ Object
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 |