Sha256: 2854fbc8cf9f1fab809ca4d663a1be975fccd73061edb3f5b876c9e18caf979f
Contents?: true
Size: 1.96 KB
Versions: 1
Compression:
Stored size: 1.96 KB
Contents
# code: # * George Moschovitis <gm@navel.gr> # # (c) 2004 Navel, all rights reserved. # $Id: form.rb 200 2004-12-27 11:24:41Z gmosx $ require 'glue/hash' require 'nitro/markup' module N # = FormBuilder # class FormBuilder @@cache = N::SafeHash.new # Render a standard form for the given managed object. # If show_all is false then apply field filtering. # # Example: # # <p> # <form name="test"> # #{N::FormBuilder.render(entry)} # </form> # </p> # def self.render(obj, lc = nil, show_all = false) str = '<dl>' for p in obj.class.__props unless show_all next if :oid == p.symbol end if p.klass.ancestors.include?(Integer) or p.klass.ancestors.include?(Float) str << %{ <dt><label for="#{p.name}">#{p.name}</label></dt> <dd> <input type="text" id="#{p.name}" name="#{p.name}" value="#{obj.send(p.symbol)}" /> </dd> } elsif p.klass.ancestors.include?(String) str << %{ <dt><label for="#{p.name}">#{p.name}</label></dt> <dd> } if p.meta[:markup] val = N::Markup.compact(obj.send(p.symbol)) else val = obj.send(p.symbol) end if :textarea == p.meta[:ui] str << %{ <textarea id="#{p.name}" name="#{p.name}">#{val}</textarea> } else str << %{ <input type="text" id="#{p.name}" name="#{p.name}" value="#{val}" /> } end str << %{ </dd> } elsif p.klass.ancestors.include?(TrueClass) str << %{ <dt><label for="#{p.name}">#{p.name}</label></dt> <dd> <input type="checkbox" id="#{p.name}" name="#{p.name}" /> </dd> } =begin elsif p.klass.ancestors.include?(Time) return %|#\{@#{p.symbol} ? "'#\{Og::Utils.timestamp(@#{p.symbol})\}'" : 'NULL'\}| elsif p.klass.ancestors.include?(Date) return %|#\{@#{p.symbol} ? "'#\{Og::Utils.date(@#{p.symbol})\}'" : 'NULL'\}| else return %|#\{@#{p.symbol} ? "'#\{Og::Utils.escape(@#{p.symbol}.to_yaml)\}'" : "''"\}| =end end end str << %{ </dl>} return str end end end # module
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
nitro-0.8.0 | lib/nitro/builders/form.rb |