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.



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

def method_missing(name, *params, &children)
  if name =~ /_as_node$/
    # handle deprecated _as_node style
    component = find_component(name.gsub(/_as_node$/, ''))
    return React::RenderingContext.build_only(component, *params, &children) if component
  else
    component = find_component(name)
    return React::RenderingContext.render(component, *params, &children) if component
  end
  Object.method_missing(name, *params, &children)
end

Class Method Details

.html_tag_class_for(tag) ⇒ Object



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

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



99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/react/component/tags.rb', line 99

def included(component)
  _name, parent = find_name_and_parent(component)
  class << parent
    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
end

Instance Method Details

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

the present method is retained as a legacy behavior



34
35
36
# File 'lib/react/component/tags.rb', line 34

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

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



38
39
40
# File 'lib/react/component/tags.rb', line 38

def present_as_node(component, *params, &children)
  React::RenderingContext.build_only(component, *params, &children)
end