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

Version Path
rack-app-front_end-0.22.2 lib/rack/app/front_end/helpers/html_dsl/tag_builder.rb
rack-app-front_end-0.22.1 lib/rack/app/front_end/helpers/html_dsl/tag_builder.rb
rack-app-front_end-0.22.0 lib/rack/app/front_end/helpers/html_dsl/tag_builder.rb
rack-app-front_end-0.21.0 lib/rack/app/front_end/helpers/html_dsl/tag_builder.rb
rack-app-front_end-0.20.0 lib/rack/app/front_end/helpers/html_dsl/tag_builder.rb
rack-app-front_end-0.19.0 lib/rack/app/front_end/helpers/html_dsl/tag_builder.rb
rack-app-front_end-0.18.0 lib/rack/app/front_end/helpers/html_dsl/tag_builder.rb