|
1 | | -class React::Rails::ControllerRenderer |
2 | | - include React::Rails::ViewHelper |
3 | | - include ActionView::Helpers::TagHelper |
4 | | - include ActionView::Helpers::TextHelper |
| 1 | +module React |
| 2 | + module Rails |
| 3 | + # A renderer class suitable for `ActionController::Renderers`. |
| 4 | + # It is associated to `:component` in the Railtie. |
| 5 | + # |
| 6 | + # It is prerendered with {React::ServerRendering}. |
| 7 | + # |
| 8 | + # @example Rendering a component from a controller |
| 9 | + # class TodosController < ApplicationController |
| 10 | + # def index |
| 11 | + # @todos = Todo.all |
| 12 | + # render component: 'TodoList', props: { todos: @todos }, tag: 'span', class: 'todo' |
| 13 | + # end |
| 14 | + # end |
| 15 | + class ControllerRenderer |
| 16 | + include React::Rails::ViewHelper |
| 17 | + include ActionView::Helpers::TagHelper |
| 18 | + include ActionView::Helpers::TextHelper |
5 | 19 |
|
6 | | - attr_accessor :output_buffer |
| 20 | + attr_accessor :output_buffer |
7 | 21 |
|
8 | | - def initialize(options={}) |
9 | | - controller = options[:controller] |
10 | | - @__react_component_helper = controller.__react_component_helper |
11 | | - end |
| 22 | + def initialize(options={}) |
| 23 | + controller = options[:controller] |
| 24 | + @__react_component_helper = controller.__react_component_helper |
| 25 | + end |
12 | 26 |
|
13 | | - def call(name, options, &block) |
14 | | - props = options.fetch(:props, {}) |
15 | | - options = options.slice(:data, :aria, :tag, :class, :id).merge(prerender: true) |
16 | | - react_component(name, props, options, &block) |
| 27 | + # @return [String] Prerendered HTML for `component_name` with `options[:props]` |
| 28 | + def call(component_name, options, &block) |
| 29 | + props = options.fetch(:props, {}) |
| 30 | + options = options.slice(:data, :aria, :tag, :class, :id).merge(prerender: true) |
| 31 | + react_component(component_name, props, options, &block) |
| 32 | + end |
| 33 | + end |
17 | 34 | end |
18 | 35 | end |
0 commit comments