module LucidApp::Api

Public Class Methods

included(base) click to toggle source
# File lib/isomorfeus_react/lucid_app/api.rb, line 3
def self.included(base)
  base.instance_exec do
    def theme(theme_hash = nil, &block)
      if block_given?
        result = block.call(React::Component::Styles.new(`base.jss_theme`))
        %x{
          if (typeof result.$to_n === 'function') { base.jss_theme = result.$to_n(); }
          else { base.jss_theme = result; }
          return result;
        }
      elsif theme_hash
        `base.jss_theme = #{theme_hash.to_n}` if theme_hash
        theme_hash
      elsif `typeof base.jss_theme === 'object'`
        `Opal.Hash.$new(base.jss_theme)`
      else
        nil
      end
    end
    alias_method :theme=, :theme
  end
end

Public Instance Methods

theme(theme_hash = nil, &block) click to toggle source
# File lib/isomorfeus_react/lucid_app/api.rb, line 5
def theme(theme_hash = nil, &block)
  if block_given?
    result = block.call(React::Component::Styles.new(`base.jss_theme`))
    %x{
      if (typeof result.$to_n === 'function') { base.jss_theme = result.$to_n(); }
      else { base.jss_theme = result; }
      return result;
    }
  elsif theme_hash
    `base.jss_theme = #{theme_hash.to_n}` if theme_hash
    theme_hash
  elsif `typeof base.jss_theme === 'object'`
    `Opal.Hash.$new(base.jss_theme)`
  else
    nil
  end
end