Sha256: 74a0e8b07ff58a9feefc5aea4a2d82b6d095874702955ec66833fa83cd71219e

Contents?: true

Size: 802 Bytes

Versions: 6

Compression:

Stored size: 802 Bytes

Contents

module SinatraMore
  module TagHelpers
    # input_tag :text, :class => "test"
    def input_tag(type, options = {})
      options.reverse_merge!(:type => type)
      tag(:input, options)
    end

    def content_block_tag(name, options={}, &block)
      # TODO make this work with erb!!
      options.merge!(:content => block.call)
      tag(name, options)
    end

    def content_tag(name, content, options={})
      tag(name, options.merge(:content => content))
    end

    def tag(name, options={})
      content = options.delete(:content)
      html_attrs = options.collect { |a, v| v.blank? ? nil : "#{a}=\"#{v}\"" }.compact.join(" ")
      base_tag = (html_attrs.present? ? "<#{name} #{html_attrs}" : "<#{name}")
      base_tag << (content ? ">#{content}</#{name}>" : " />")
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sinatra_more-0.0.7 lib/sinatra_more/markup_plugin/tag_helpers.rb
sinatra_more-0.0.6 lib/sinatra_more/markup_plugin/tag_helpers.rb
sinatra_more-0.0.5 lib/sinatra_more/markup_plugin/tag_helpers.rb
sinatra_more-0.0.4 lib/sinatra_more/view_helpers/tag_helpers.rb
sinatra_more-0.0.3 lib/sinatra_more/view_helpers/tag_helpers.rb
sinatra_more-0.0.2 lib/sinatra_more/view_helpers/tag_helpers.rb