Sha256: f90220f60c49e976487446b3c4063919c5f026802d8700c43526ada2cf5d8e2b
Contents?: true
Size: 813 Bytes
Versions: 7
Compression:
Stored size: 813 Bytes
Contents
module Rack::App::FrontEnd::Helpers::HtmlDsl::TagBuilder extend self def build(tag_name, *args, &block) content = args.select { |a| a.is_a?(String) }.join html_properties = args.select { |a| a.is_a?(Hash) }.reduce({}) do |properties, hash| hash.each { |k, v| properties.merge!(k.to_s => v) } properties end html = '' html << "<#{tag_name}" unless html_properties.empty? html << ' ' html << html_properties.reduce([]) { |m, (k, v)| m << "#{k}=#{v.to_s.inspect}" }.join(' ') end if not content.empty? or not block.nil? html << ">" html << content html << Rack::App::FrontEnd::Helpers::HtmlDsl::Block.new(&block).to_s unless block.nil? html << "</#{tag_name}>" else html << "/>" end return html end end
Version data entries
7 entries across 7 versions & 1 rubygems