Module: React::Component::Tags

Defined in:
lib/react/component/tags.rb

Overview

contains the name of all HTML tags, and the mechanism to register a component class as a new tag

Constant Summary collapse

HTML_TAGS =
%w(a abbr address area article aside audio b base bdi bdo big blockquote body br
   button canvas caption cite code col colgroup data datalist dd del details dfn
   dialog div dl dt em embed fieldset figcaption figure footer form h1 h2 h3 h4 h5
   h6 head header hr html i iframe img input ins kbd keygen label legend li link
   main map mark menu menuitem meta meter nav noscript object ol optgroup option
   output p param picture pre progress q rp rt ruby s samp script section select
   small source span strong style sub summary sup table tbody td textarea tfoot th
   thead time title tr track u ul var video wbr) +
# The SVG Tags
%w(circle clipPath defs ellipse g line linearGradient mask path pattern polygon polyline
radialGradient rect stop svg text tspan)

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *params, &children) ⇒ Object

use method_missing to look up component names in the form of “Foo(..)” where there is no preceeding scope.



60
61
62
63
64
# File 'lib/react/component/tags.rb', line 60

def method_missing(name, *params, &children)
  component = find_component(name)
  return React::RenderingContext.render(component, *params, &children) if component
  Object.method_missing(name, *params, &children)
end

Class Method Details

.html_tag_class_for(tag) ⇒ Object

this is used for haml style (i.e. DIV.foo.bar) class tags which is deprecated



50
51
52
53
54
55
# File 'lib/react/component/tags.rb', line 50

def self.html_tag_class_for(tag)
  downcased_tag = tag.downcase
  if tag =~ /[A-Z]+/ && HTML_TAGS.include?(downcased_tag)
    Object.const_set tag, React.create_element(downcased_tag)
  end
end

.included(component) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/react/component/tags.rb', line 70

def included(component)
  name, parent = find_name_and_parent(component)
  tag_names_module = Module.new do
    define_method name do |*params, &children|
      React::RenderingContext.render(component, *params, &children)
    end
    # handle deprecated _as_node style
    define_method "#{name}_as_node" do |*params, &children|
      React::RenderingContext.build_only(component, *params, &children)
    end
  end
  parent.extend(tag_names_module)
end

Instance Method Details

#present(component, *params, &children) ⇒ Object

the present method is retained as a legacy behavior



19
20
21
# File 'lib/react/component/tags.rb', line 19

def present(component, *params, &children)
  React::RenderingContext.render(component, *params, &children)
end