def crushyform_types
      @crushyform_types ||= {
        :none => proc{''},
        :string => proc do |m,c,o|
          "<input type='%s' name='%s' value=\"%s\" id='%s' class='%s' %s />%s\n" % [o[:input_type]||'text', o[:input_name], o[:input_value], m.crushyid_for(c), o[:input_class], o[:required]&&'required', o[:required]]
        end,
        :boolean => proc do |m,c,o|
          crushid = m.crushyid_for(c)
          s = ['checked', nil]
          s.reverse! unless o[:input_value]
          out = "<span class='%s'>"
          out += "<input type='radio' name='%s' value='true' id='%s' %s /> <label for='%s'>Yes</label> "
          out += "<input type='radio' name='%s' value='false' id='%s-no' %s /> <label for='%s-no'>No</label>"
          out += "</span>\n"
          out % [o[:input_class], o[:input_name], crushid, s[0], crushid, o[:input_name], crushid, s[1], crushid]
        end,
        :text => proc do |m,c,o|
          "<textarea name='%s' id='%s' class='%s' %s>%s</textarea>%s\n" % [o[:input_name], m.crushyid_for(c), o[:input_class], o[:required]&&'required', o[:input_value], o[:required]]
        end,
        :date => proc do |m,c,o|
          o[:input_value] = o[:input_value].strftime("%Y-%m-%d") if o[:input_value].is_a?(Sequel.datetime_class)
          o[:required] = "%s Format: yyyy-mm-dd" % [o[:required]]
          crushyform_types[:string].call(m,c,o)
        end,
        :time => proc do |m,c,o|
          o[:input_value] = o[:input_value].strftime("%T") if o[:input_value].is_a?(Sequel.datetime_class)
          o[:required] = "%s Format: hh:mm:ss" % [o[:required]]
          crushyform_types[:string].call(m,c,o)
        end,
        :datetime => proc do |m,c,o|
          o[:input_value] = o[:input_value].strftime("%Y-%m-%d %T") if o[:input_value].is_a?(Sequel.datetime_class)
          o[:required] = "%s Format: yyyy-mm-dd hh:mm:ss" % [o[:required]]
          crushyform_types[:string].call(m,c,o)
        end,
        :parent => proc do |m,c,o|
          parent_class = association_reflection(c.to_s.sub(/_id$/,'').to_sym).associated_class
          option_list = parent_class.to_dropdown(o[:input_value])
          "<select name='%s' id='%s' class='%s'>%s</select>\n" % [o[:input_name], m.crushyid_for(c), o[:input_class], option_list]
        end,
        :attachment => proc do |m,c,o|
          "%s<input type='file' name='%s' id='%s' class='%s' />%s\n" % [m.to_thumb(c), o[:input_name], m.crushyid_for(c), o[:input_class], o[:required]]
        end,
        :select => proc do |m,c,o|
          out = "<select name='%s' id='%s' class='%s'>\n" % [o[:input_name], m.crushyid_for(c), o[:input_class]]
          o[:select_options] = m.__send__(o[:select_options]) unless o[:select_options].kind_of?(Array)
          if o[:select_options].kind_of?(Array)
            o[:select_options].each do |op|
              key,val = op.kind_of?(Array) ? [op[0],op[1]] : [op,op]
              selected = 'selected' if val==o[:input_value]
              out << "<option value='%s' %s>%s</option>\n" % [val,selected,key]
            end
          end
          out << "</select>%s\n" % [o[:required]]
        end
      }
    end
def crushyform_types
      @crushyform_types ||= {
        :none => proc{''},
        :string => proc do |m,c,o|
          "<input type='%s' name='%s' value=\"%s\" id='%s' class='%s' %s />%s\n" % [o[:input_type]||'text', o[:input_name], o[:input_value], m.crushyid_for(c), o[:input_class], o[:required]&&'required', o[:required]]
        end,
        :boolean => proc do |m,c,o|
          crushid = m.crushyid_for(c)
          s = ['checked', nil]
          s.reverse! unless o[:input_value]
          out = "<span class='%s'>"
          out += "<input type='radio' name='%s' value='true' id='%s' %s /> <label for='%s'>Yes</label> "
          out += "<input type='radio' name='%s' value='false' id='%s-no' %s /> <label for='%s-no'>No</label>"
          out += "</span>\n"
          out % [o[:input_class], o[:input_name], crushid, s[0], crushid, o[:input_name], crushid, s[1], crushid]
        end,
        :text => proc do |m,c,o|
          "<textarea name='%s' id='%s' class='%s' %s>%s</textarea>%s\n" % [o[:input_name], m.crushyid_for(c), o[:input_class], o[:required]&&'required', o[:input_value], o[:required]]
        end,
        :date => proc do |m,c,o|
          o[:input_value] = o[:input_value].strftime("%Y-%m-%d") if o[:input_value].is_a?(Sequel.datetime_class)
          o[:required] = "%s Format: yyyy-mm-dd" % [o[:required]]
          crushyform_types[:string].call(m,c,o)
        end,
        :time => proc do |m,c,o|
          o[:input_value] = o[:input_value].strftime("%T") if o[:input_value].is_a?(Sequel.datetime_class)
          o[:required] = "%s Format: hh:mm:ss" % [o[:required]]
          crushyform_types[:string].call(m,c,o)
        end,
        :datetime => proc do |m,c,o|
          o[:input_value] = o[:input_value].strftime("%Y-%m-%d %T") if o[:input_value].is_a?(Sequel.datetime_class)
          o[:required] = "%s Format: yyyy-mm-dd hh:mm:ss" % [o[:required]]
          crushyform_types[:string].call(m,c,o)
        end,
        :parent => proc do |m,c,o|
          parent_class = association_reflection(c.to_s.sub(/_id$/,'').to_sym).associated_class
          option_list = parent_class.to_dropdown(o[:input_value])
          "<select name='%s' id='%s' class='%s'>%s</select>\n" % [o[:input_name], m.crushyid_for(c), o[:input_class], option_list]
        end,
        :attachment => proc do |m,c,o|
          "%s<input type='file' name='%s' id='%s' class='%s' />%s\n" % [m.to_thumb(c), o[:input_name], m.crushyid_for(c), o[:input_class], o[:required]]
        end,
        :select => proc do |m,c,o|
          out = "<select name='%s' id='%s' class='%s'>\n" % [o[:input_name], m.crushyid_for(c), o[:input_class]]
          o[:select_options] = m.__send__(o[:select_options]) unless o[:select_options].kind_of?(Array)
          if o[:select_options].kind_of?(Array)
            o[:select_options].each do |op|
              key,val = op.kind_of?(Array) ? [op[0],op[1]] : [op,op]
              selected = 'selected' if val==o[:input_value]
              out << "<option value='%s' %s>%s</option>\n" % [val,selected,key]
            end
          end
          out << "</select>%s\n" % [o[:required]]
        end
      }
    end
Types