Skip to content

Commit cf206a2

Browse files
committed
add some docs
1 parent 7e06547 commit cf206a2

File tree

6 files changed

+48
-18
lines changed

6 files changed

+48
-18
lines changed

lib/react/jsx/babel_transformer.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'babel/transpiler'
22
module React
33
module JSX
4+
# A {React::JSX}-compliant transformer which uses `Babel::Transpiler` to transform JSX.
45
class BabelTransformer
56
DEPRECATED_OPTIONS = [:harmony, :strip_types, :asset_path]
67
DEFAULT_TRANSFORM_OPTIONS = { blacklist: ['spec.functionName', 'validation.react', 'strict'] }

lib/react/jsx/jsx_transformer.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module React
22
module JSX
3+
# A {React::JSX}-compliant transformer which uses the deprecated `JSXTransformer.js` to transform JSX.
34
class JSXTransformer
45
DEFAULT_ASSET_PATH = 'JSXTransformer.js'
56

lib/react/jsx/processor.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module React
22
module JSX
3+
# A Sprockets 3+-compliant processor
34
class Processor
45
def self.call(input)
56
JSX::transform(input[:data])

lib/react/jsx/template.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module React
44
module JSX
5-
5+
# Sprockets 2-compliant processor
66
class Template < Tilt::Template
77
self.default_mime_type = 'application/javascript'
88

lib/react/rails/asset_variant.rb

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
module React
22
module Rails
3+
# This class accepts some options for which build you want, then exposes where you can find
4+
# them. In general, these paths should be added to the sprockets environment.
35
class AssetVariant
46
GEM_ROOT = Pathname.new('../../../../').expand_path(__FILE__)
5-
attr_reader :react_build, :react_directory, :jsx_directory
7+
# @return [String] "production" or "development"
8+
attr_reader :react_build
69

10+
# @return [String] The path which contains the specified React.js build as "react.js"
11+
attr_reader :react_directory
12+
13+
# @return [String] The path which contains the JSX Transformer
14+
attr_reader :jsx_directory
15+
16+
# @param [Hash] Options for the asset variant
17+
# @option variant [Symbol] if `:production`, use the minified React.js build
18+
# @option addons [Boolean] if true, use a React.js build with all addons
719
def initialize(options={})
8-
# We want to include different files in dev/prod. The development builds
9-
# contain console logging for invariants and logging to help catch
10-
# common mistakes. These are all stripped out in the production build.
20+
1121
@react_build = options[:variant] == :production ? 'production' : 'development'
1222
options[:addons] && @react_build += '-with-addons'
1323

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,35 @@
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
519

6-
attr_accessor :output_buffer
20+
attr_accessor :output_buffer
721

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
1226

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
1734
end
1835
end

0 commit comments

Comments
 (0)