require 'glue/hash' require 'nitro/markup' module Nitro # FormBuilder. module FormBuilderMixin # Render a standard form for the given managed object. # If show_all is false then apply field filtering. # # Example: # #

#

# #{o.build_form(entry)} #
#

def build_form(obj, lc = nil, show_all = false) str = '
' for p in obj.class.properties unless show_all next if :oid == p.symbol end if p.klass.ancestors.include?(Integer) or p.klass.ancestors.include?(Float) str << %{
} elsif p.klass.ancestors.include?(String) str << %{
} 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 << %{ } else str << %{ } end str << %{
} elsif p.klass.ancestors.include?(TrueClass) str << %{
} elsif p.klass.ancestors.include?(Time) str << %{
} =begin 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 << %{
} self << str end end # Abstract class for the FormBuilderMixin. class FormBuilder include FormBuilderMixin class << self def build(obj, lc = nil, show_all = false) FormBuilder.new.build_form(obj, lc, show_all) end end end end