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.



73
74
75
76
77
# File 'lib/react/component/tags.rb', line 73

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



63
64
65
66
67
68
# File 'lib/react/component/tags.rb', line 63

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



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/react/component/tags.rb', line 83

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



32
33
34
# File 'lib/react/component/tags.rb', line 32

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