class Tilt::ReactTemplate
Public Class Methods
components()
click to toggle source
# File lib/tilt/react.rb, line 44 def self.components @@context.eval('window.TiltReact.componentNames()').to_a end
file_to_class_name(file)
click to toggle source
# File lib/tilt/react.rb, line 40 def self.file_to_class_name(file) File.basename(file, '.jsx').split('_').map(&:capitalize).join end
load_directory(glob)
click to toggle source
# File lib/tilt/react.rb, line 26 def self.load_directory(glob) Dir.glob(glob).to_a.sort_by { |bundle| case bundle when %r{/tilt_react_client_bundle.js$} then 0 when %r{/tilt_react_server_bundle.js$} then 1 else 2 end }.each do |bundle| @@context.load(bundle) end @@renderer = @@context.eval('window.TiltReact') end
new(file=nil, line=1, options={}, &block)
click to toggle source
# File lib/tilt/react.rb, line 9 def initialize(file=nil, line=1, options={}, &block) file = File.expand_path(file) @component_class = File.basename(file, '.jsx').split('_').map(&:capitalize).join end
prepare_context()
click to toggle source
# File lib/tilt/react.rb, line 21 def self.prepare_context @@context = V8::Context.new @@context.eval('window = {};') end
Public Instance Methods
evaluate(scope, props, &block)
click to toggle source
# File lib/tilt/react.rb, line 14 def evaluate(scope, props, &block) @output ||= begin component = @@renderer.renderToString(@component_class, props) %{<div data-react-class="#{@component_class}">#{component}</div><script data-react-class="#{@component_class}" type="application/json">#{props.to_json}</script>} end end