Top Level Namespace

Defined Under Namespace

Modules: HtmlTag Classes: Hash, String

Instance Method Summary collapse

Instance Method Details

#HtmlTag(*args, &block) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/html-tag/globals.rb', line 34

def HtmlTag *args, &block
  if [Class, Module].include?(args[0].class)
    # imports tag method without poluting ancesstors namespace
    # class SomeClass
    #   HtmlTag self
    args[0].define_method :tag do |*tag_args, &tag_block|
      HtmlTag *tag_args, &tag_block
    end
  else
    # HtmlTag do ...
    args[0] ||= :div

    if args[0].class == Hash
      args[1] = args[0]
      args[0] = :div
    end

    if block
      # HtmlTag(:ul) { li ... }
      out = HtmlTag::Inbound.new self
      out.send(*args, &block)
      out.render
    else
      # HtmlTag._foo 123
      HtmlTag::Proxy.new self
    end
  end
end