Module: React::Router::Rails::ViewHelper

Defined in:
lib/react/router/rails/view_helper.rb

Instance Method Summary collapse

Instance Method Details

#react_router(routes, location = 'HashLocation', args = {}, options = {}, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/react/router/rails/view_helper.rb', line 5

def react_router(routes, location = 'HashLocation', args = {}, options = {}, &block)
  options = {:tag => options} if options.is_a?(Symbol)
  if options[:prerender_location]
    fail "Server rendering doesn't work with HashLocation" if location == 'HashLocation'
    block = Proc.new do
      concat React::Router::Renderer.render(routes, options[:prerender_location], args)
    end
  end

  html_options = options.reverse_merge(:data => {})
  html_options[:data].tap do |data|
    data[:'react-router-class'] = routes
    data[:'react-router-location'] = location
  end
  html_tag = html_options[:tag] || :div

  html_options.except!(:tag, :prerender_location)
  
  (html_tag, '', html_options, &block)
end