lib/ezframe/html.rb in ezframe-0.1.1 vs lib/ezframe/html.rb in ezframe-0.2.0

- old
+ new

@@ -10,26 +10,33 @@ return ht_h.to_s if ht_h.is_a?(String) || ht_h.is_a?(Symbol) || ht_h.is_a?(Integer) || ht_h.is_a?(Time) return ht_h.map { |args| convert(args) }.join if ht_h.is_a?(Array) tag = ht_h[:tag] case tag - when "input" - input(ht_h) + when "textarea" + textarea(ht_h) when "select" return select(ht_h) if ht_h[:item] when "icon" tag = "i" end tag = ht_h[:tag] - opt_s, child_s = join_attributes(ht_h) - if !child_s.strip.empty? || %w[div span table tr td th textarea].include?(tag) - return "<#{ht_h[:tag]} #{opt_s}>\n#{child_s}\n</#{ht_h[:tag]}>\n" + error_box = "" + if %w[input select textarea].include?(tag) + error_box = "<div id=\"error-box-#{ht_h[:name]}\" class=\"error-box hide\"></div>" end - "<#{ht_h[:tag]} #{opt_s} />" + opt_s, child_s = join_attribute(ht_h) + if !child_s.strip.empty? || !%w[img input hr br meta].include?(tag) + start_tag = [ht_h[:tag], opt_s].compact.join(" ").strip + return "<#{start_tag}>#{child_s}</#{ht_h[:tag]}>"+error_box + end + tag_content = [ ht_h[:tag], opt_s ].compact.join(" ") + return "<#{tag_content}/>"+error_box end - def join_attributes(attrs) + # attributeの連結文字列化 + def join_attribute(attrs) child_s = "" opt_a = attrs.map do |k, v| case k when :child child_s = convert(v) @@ -50,20 +57,14 @@ end end [opt_a.compact.join(" "), child_s] end - def input(ht_h) - size = ht_h[:size] - # puts "input: size=#{size.inspect}" - if size && (size.index("x") || size.index("*")) - if /(\d+)\s*[x\*]\s*(\d+)/ =~ size - ht_h[:cols], ht_h[:rows] = $1, $2 - ht_h.delete(:size) - end - ht_h[:tag] = "textarea" - ht_h[:child] = ht_h[:value] + def textarea(ht_h) + value = ht_h[:value] + if value + ht_h[:child] = value ht_h.delete(:value) end end def select(ht_h = {}) @@ -76,11 +77,11 @@ if v.is_a?(Array) v, selected = v h[:selected] = "selected" if selected end h[:child] = v - # mylog "select: hash: k=#{k}, v=#{v}, value=#{ht_h[:value]}" + # Logger.info "select: hash: k=#{k}, v=#{v}, value=#{ht_h[:value]}" if ht_h[:value] && ht_h[:value].to_s == k.to_s h[:selected] = "selected" end h end @@ -88,10 +89,10 @@ option_a = item.map do |v| h = { tag: "option", value: v[0], child: v[1] } if %w[selected default].include?(v[2]) h[:selected] = "selected" end - # mylog "select: array: v=#{v}, value=#{ht_h[:value]}" + # Logger.info "select: array: v=#{v}, value=#{ht_h[:value]}" if ht_h[:value] && ht_h[:value].to_s == v[0].to_s h[:selected] = "selected" end # puts h.inspect h