module Hyalite

Constants

ESCAPE_LOOKUP
ESCAPE_REGEX
RESERVED_PROPS
VERSION

Public Class Methods

create_element(type, config = nil, *children) click to toggle source
# File lib/hyalite/main.rb, line 15
def create_element(type, config = nil, *children)
  key = nil
  ref = nil

  props = {}

  case config
  when String
    children = [config]
  when Array
    children = config
  when Hash
    key = config[:key]
    ref = config[:ref]

    config.each do |name, value|
      unless RESERVED_PROPS.include?(name)
        props[name] = config[name];
      end
    end
  end

  props[:children] = case children.length
                     when 0
                       nil
                     when 1
                       children.first
                     else
                       children
                     end

  ElementObject.new(type, key, ref, Hyalite.current_owner, props).tap do |el|
    children.each {|child| child.parent = el if child.is_a?(ElementObject) }
    element_created(el)
  end
end
create_element_hook(key) { |hook_setter| ... } click to toggle source
# File lib/hyalite/main.rb, line 59
def create_element_hook(key, &block)
  @hooks ||= []
  hook_setter = HookSetter.new(@hooks)
  yield hook_setter
ensure
  hook_setter.destroy
end
current_owner(current_owner = nil) { |current_owner| ... } click to toggle source
# File lib/hyalite/main.rb, line 143
def current_owner(current_owner = nil)
  if current_owner && block_given?
    begin
      @current_owner = current_owner
      yield(@current_owner)
    ensure
      @current_owner = nil
    end
  else
    @current_owner
  end
end
element_created(element) click to toggle source
# File lib/hyalite/main.rb, line 52
def element_created(element)
  return unless @hooks
  @hooks.each do |hook|
    hook.call(element)
  end
end
escape_text_content_for_browser(text) click to toggle source
# File lib/hyalite/utils.rb, line 16
def self.escape_text_content_for_browser(text)
  text.gsub(ESCAPE_REGEX) {|s| ESCAPE_LOOKUP[s] }
end
find_dom_node(component_or_element) click to toggle source
# File lib/hyalite/main.rb, line 156
def find_dom_node(component_or_element)
  return component_or_element if component_or_element.is_a?(DOM::Node) && component_or_element.element?

  if instance_map.has_key?(component_or_element)
    return Mount.node(instance_map[component_or_element].root_node_id)
  end
end
fn(&block) click to toggle source
# File lib/hyalite/main.rb, line 85
def fn(&block)
  Class.new {
    include Component
    include Component::ShortHand

    def self.render_proc=(proc)
      @render_proc = proc
    end

    def self.render_proc
      @render_proc
    end

    def render
      self.instance_exec(@props, &self.class.render_proc)
    end
  }.tap{|cl| cl.render_proc = block }
end
instance_map() click to toggle source
# File lib/hyalite/main.rb, line 139
def instance_map
  @instance_map ||= {}
end
instantiate_component(node) click to toggle source
# File lib/hyalite/main.rb, line 104
def instantiate_component(node)
  node = EmptyComponent.empty_element if node.nil?

  case node
  when ElementObject
    case node.type
    when String
      DOMComponent.new node
    when Class
      if node.type.include?(InternalComponent)
        node.type.new
      elsif node.type.include?(Component)
        CompositeComponent.new node
      else
        raise "Encountered invalid type of Hyalite node. type: #{node.type}"
      end
    end
  when String, Numeric
    TextComponent.new node
  when EmptyComponent
    CompositeComponent.new node
  else
    raise "Encountered invalid Hyalite node: #{node}"
  end
end
quote_attribute_value_for_browser(text) click to toggle source
# File lib/hyalite/utils.rb, line 12
def self.quote_attribute_value_for_browser(text)
  "\"#{escape_text_content_for_browser(text)}\""
end
render() click to toggle source
# File lib/hyalite/main.rb, line 98
def render
  self.instance_exec(@props, &self.class.render_proc)
end
render_proc() click to toggle source
# File lib/hyalite/main.rb, line 94
def self.render_proc
  @render_proc
end
render_proc=(proc) click to toggle source
# File lib/hyalite/main.rb, line 90
def self.render_proc=(proc)
  @render_proc = proc
end
updates() click to toggle source
# File lib/hyalite/updates.rb, line 126
def self.updates
  @updates ||= Updates.new
end