module React

Constants

ATTRIBUTES
HTML_TAGS
VERSION

Public Class Methods

clear_component_class_cache() click to toggle source
# File lib/react/api.rb, line 97
def self.clear_component_class_cache
  @@component_classes = {}
end
convert_props(properties) click to toggle source
# File lib/react/api.rb, line 101
def self.convert_props(properties)
  raise "Component parameters must be a hash. Instead you sent #{properties}" unless properties.is_a? Hash
  props = {}
  properties.map do |key, value|
    if key == "class_name" && value.is_a?(Hash)
      props[lower_camelize(key)] = `React.addons.classSet(#{value.to_n})`
    elsif key == "class"
      props["className"] = value
    elsif ["style", "dangerously_set_inner_HTML"].include? key
      props[lower_camelize(key)] = value.to_n
    else
      props[React::ATTRIBUTES.include?(lower_camelize(key)) ? lower_camelize(key) : key] = value
    end
  end
  props.shallow_to_n
end
create_element(type, properties = {}, &block) click to toggle source
# File lib/react/top_level.rb, line 26
def self.create_element(type, properties = {}, &block)
  React::API.create_element(type, properties, &block)
end
is_valid_element(element) click to toggle source
# File lib/react/top_level.rb, line 37
def self.is_valid_element(element)
  element.kind_of?(React::Element) && `React.isValidElement(#{element.to_n})`
end
render(element, container) click to toggle source
# File lib/react/top_level.rb, line 30
def self.render(element, container)
  container = `container.$$class ? container[0] : container`
  component = Native(`React.render(#{element.to_n}, container, function(){#{yield if block_given?}})`)
  component.class.include(React::Component::API)
  component
end
render_to_static_markup(element) click to toggle source
# File lib/react/top_level.rb, line 45
def self.render_to_static_markup(element)
  React::RenderingContext.build { `React.renderToStaticMarkup(#{element.to_n})` }
end
render_to_string(element) click to toggle source
# File lib/react/top_level.rb, line 41
def self.render_to_string(element)
  React::RenderingContext.build { `React.renderToString(#{element.to_n})` }
end
unmount_component_at_node(node) click to toggle source
# File lib/react/top_level.rb, line 49
def self.unmount_component_at_node(node)
  `React.unmountComponentAtNode(node.$$class ? node[0] : node)`
end

Private Class Methods

lower_camelize(snake_cased_word) click to toggle source
# File lib/react/api.rb, line 120
def self.lower_camelize(snake_cased_word)
  words = snake_cased_word.split("_")
  result = [words.first]
  result.concat(words[1..-1].map {|word| word[0].upcase + word[1..-1] })
  result.join("")
end