module React::IsomorphicHelpers

Public Class Methods

included(base) click to toggle source
# File lib/reactive-ruby/isomorphic_helpers.rb, line 3
def self.included(base)
  base.extend(ClassMethods)
end
load_context(ctx, controller, name = nil) click to toggle source
# File lib/reactive-ruby/isomorphic_helpers.rb, line 8
def self.load_context(ctx, controller, name = nil)
  puts "************************** React Server Context Initialized #{name} *********************************************"
  @context = Context.new("#{controller.object_id}-#{Time.now.to_i}", ctx, controller, name)
end
log(message, message_type = :info) click to toggle source
# File lib/reactive-ruby/isomorphic_helpers.rb, line 28
def self.log(message, message_type = :info)
  message = [message] unless message.is_a? Array
  if message_type == :info
    if on_opal_server?
      style = 'background: #00FFFF; color: red'
    else
      style = 'background: #222; color: #bada55'
    end
    message = ["%c" + message[0], style]+message[1..-1]
    `console.log.apply(console, message)`
  elsif message_type == :warning
    `console.warn.apply(console, message)`
  else
    `console.error.apply(console, message)`
  end
end
on_opal_client?() click to toggle source
# File lib/reactive-ruby/isomorphic_helpers.rb, line 50
def self.on_opal_client?
  false
end
on_opal_server?() click to toggle source
# File lib/reactive-ruby/isomorphic_helpers.rb, line 46
def self.on_opal_server?
  false
end
prerender_footers() click to toggle source
# File lib/reactive-ruby/isomorphic_helpers.rb, line 75
def self.prerender_footers
  footer = Context.prerender_footer_blocks.collect { |block| block.call }.join("\n")
  if RUBY_ENGINE != 'opal'
    footer = (footer + "#{@context.send_to_opal(:prerender_footers)}") if @context
    footer = footer.html_safe
  end
  footer
end

Public Instance Methods

log(*args) click to toggle source
# File lib/reactive-ruby/isomorphic_helpers.rb, line 63
def log(*args)
  IsomorphicHelpers.log(*args)
end
on_opal_client?() click to toggle source
# File lib/reactive-ruby/isomorphic_helpers.rb, line 71
def on_opal_client?
  self.class.on_opal_client?
end
on_opal_server?() click to toggle source
# File lib/reactive-ruby/isomorphic_helpers.rb, line 67
def on_opal_server?
  self.class.on_opal_server?
end