Sha256: 7f0836ff4a3c19d6173ebbc9f5bb6ce590ffe46287b9d9eb98d3e7f3493d2c83

Contents?: true

Size: 845 Bytes

Versions: 5

Compression:

Stored size: 845 Bytes

Contents

module It
  # A generic class for html tags.
  class Tag
    include ActionView::Helpers::TagHelper
    
    attr_reader :tag_name, :options
    
    # See It.tag for details. You can do everything there and save 6 characters.
    def initialize(tag_name, options = {})
      raise TypeError, "tag_name must be specified as a String or Symbol" unless tag_name.is_a?(String) || tag_name.is_a?(Symbol)
      raise TypeError, "options must be specified as a Hash" unless options.is_a?(Hash)
      @tag_name = tag_name.to_sym
      @options = options.symbolize_keys
    end
    
    # Will be called from inside the helper to return the tag with the given content.
    def process(content = nil) # :nodoc:
      if content.nil?
        tag(@tag_name, @options)
      else
        content_tag(@tag_name, content, @options)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
it-0.2.5 lib/it/tag.rb
it-0.2.4 lib/it/tag.rb
it-0.2.3 lib/it/tag.rb
it-0.2.1 lib/it/tag.rb
it-0.2.0 lib/it/tag.rb