Class: It::Tag

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::TagHelper
Defined in:
lib/it/tag.rb

Overview

A generic class for html tags.

Direct Known Subclasses

Link, Plain

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, options = {}) ⇒ Tag

See It.tag for details. You can do everything there and save 6 characters.

Raises:

  • (TypeError)


9
10
11
12
13
14
15
# File 'lib/it/tag.rb', line 9

def initialize(tag_name, options = {})
  raise TypeError, 'tag_name must be a String or Symbol' unless [String, Symbol].include?(tag_name.class)
  raise TypeError, 'options must be a Hash' unless options.is_a?(Hash)

  @tag_name = tag_name.to_sym
  @options = options.symbolize_keys
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/it/tag.rb', line 6

def options
  @options
end

#tag_nameObject (readonly)

Returns the value of attribute tag_name.



6
7
8
# File 'lib/it/tag.rb', line 6

def tag_name
  @tag_name
end

Instance Method Details

#process(content = nil) ⇒ Object

Will be called from inside the helper to return the tag with the given content.



18
19
20
21
22
23
24
# File 'lib/it/tag.rb', line 18

def process(content = nil) # :nodoc:
  if content
    (@tag_name, content, @options)
  else
    tag(@tag_name, @options)
  end
end