hyper-react 0.12.7 → 0.99.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +48 -34
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +5 -6
- data/README.md +47 -98
- data/Rakefile +6 -28
- data/hyper-react.gemspec +36 -43
- data/lib/hyper-react.rb +4 -73
- data/lib/react/version.rb +3 -0
- metadata +91 -249
- data/.codeclimate.yml +0 -27
- data/.rubocop.yml +0 -1159
- data/.travis.yml +0 -62
- data/Appraisals +0 -31
- data/CHANGELOG.md +0 -143
- data/LICENSE +0 -19
- data/UPGRADING.md +0 -24
- data/component-name-lookup.md +0 -145
- data/config.ru +0 -26
- data/gemfiles/opal_0.10_react_13.gemfile +0 -15
- data/gemfiles/opal_0.10_react_14.gemfile +0 -15
- data/gemfiles/opal_0.10_react_15.gemfile +0 -15
- data/gemfiles/opal_0.8_react_13.gemfile +0 -15
- data/gemfiles/opal_0.8_react_14.gemfile +0 -15
- data/gemfiles/opal_0.8_react_15.gemfile +0 -15
- data/gemfiles/opal_0.9_react_13.gemfile +0 -15
- data/gemfiles/opal_0.9_react_14.gemfile +0 -15
- data/gemfiles/opal_0.9_react_15.gemfile +0 -15
- data/gemfiles/opal_master_react_15.gemfile +0 -16
- data/lib/generators/reactive_ruby/test_app/templates/assets/javascripts/components.rb +0 -3
- data/lib/generators/reactive_ruby/test_app/templates/assets/javascripts/test_application.rb +0 -2
- data/lib/generators/reactive_ruby/test_app/templates/boot.rb.erb +0 -6
- data/lib/generators/reactive_ruby/test_app/templates/script/rails +0 -5
- data/lib/generators/reactive_ruby/test_app/templates/test_application.rb.erb +0 -13
- data/lib/generators/reactive_ruby/test_app/templates/views/components/hello_world.rb +0 -11
- data/lib/generators/reactive_ruby/test_app/templates/views/components/todo.rb +0 -14
- data/lib/generators/reactive_ruby/test_app/templates/views/layouts/test_layout.html.erb +0 -0
- data/lib/generators/reactive_ruby/test_app/test_app_generator.rb +0 -111
- data/lib/rails-helpers/top_level_rails_component.rb +0 -54
- data/lib/react-sources/react-server.js +0 -2
- data/lib/react/api.rb +0 -173
- data/lib/react/callbacks.rb +0 -41
- data/lib/react/children.rb +0 -30
- data/lib/react/component.rb +0 -168
- data/lib/react/component/api.rb +0 -50
- data/lib/react/component/base.rb +0 -13
- data/lib/react/component/class_methods.rb +0 -189
- data/lib/react/component/dsl_instance_methods.rb +0 -23
- data/lib/react/component/params.rb +0 -6
- data/lib/react/component/props_wrapper.rb +0 -78
- data/lib/react/component/should_component_update.rb +0 -94
- data/lib/react/component/tags.rb +0 -129
- data/lib/react/config.rb +0 -5
- data/lib/react/config/client.rb.erb +0 -19
- data/lib/react/config/server.rb +0 -23
- data/lib/react/element.rb +0 -169
- data/lib/react/event.rb +0 -76
- data/lib/react/ext/hash.rb +0 -9
- data/lib/react/ext/opal-jquery/element.rb +0 -26
- data/lib/react/ext/string.rb +0 -8
- data/lib/react/hash.rb +0 -13
- data/lib/react/native_library.rb +0 -87
- data/lib/react/object.rb +0 -15
- data/lib/react/react-source-browser.rb +0 -3
- data/lib/react/react-source-server.rb +0 -3
- data/lib/react/react-source.rb +0 -20
- data/lib/react/ref_callback.rb +0 -31
- data/lib/react/rendering_context.rb +0 -144
- data/lib/react/server.rb +0 -23
- data/lib/react/state_wrapper.rb +0 -23
- data/lib/react/test.rb +0 -16
- data/lib/react/test/dsl.rb +0 -17
- data/lib/react/test/matchers/render_html_matcher.rb +0 -56
- data/lib/react/test/rspec.rb +0 -15
- data/lib/react/test/session.rb +0 -37
- data/lib/react/test/utils.rb +0 -25
- data/lib/react/top_level.rb +0 -118
- data/lib/react/top_level_render.rb +0 -29
- data/lib/react/validator.rb +0 -136
- data/lib/reactive-ruby/component_loader.rb +0 -50
- data/lib/reactive-ruby/isomorphic_helpers.rb +0 -212
- data/lib/reactive-ruby/rails.rb +0 -7
- data/lib/reactive-ruby/rails/component_mount.rb +0 -46
- data/lib/reactive-ruby/rails/controller_helper.rb +0 -15
- data/lib/reactive-ruby/rails/railtie.rb +0 -33
- data/lib/reactive-ruby/serializers.rb +0 -15
- data/lib/reactive-ruby/server_rendering/contextual_renderer.rb +0 -42
- data/lib/reactive-ruby/version.rb +0 -3
- data/lib/reactrb/auto-import.rb +0 -27
- data/lib/reactrb/deep-compare.rb +0 -24
- data/lib/reactrb/new-event-name-convention.rb +0 -11
- data/logo1.png +0 -0
- data/logo2.png +0 -0
- data/logo3.png +0 -0
- data/path_release_steps.md +0 -9
- data/spec/controller_helper_spec.rb +0 -34
- data/spec/index.html.erb +0 -11
- data/spec/react/callbacks_spec.rb +0 -138
- data/spec/react/children_spec.rb +0 -76
- data/spec/react/component/base_spec.rb +0 -32
- data/spec/react/component_spec.rb +0 -884
- data/spec/react/dsl_spec.rb +0 -303
- data/spec/react/element_spec.rb +0 -136
- data/spec/react/event_spec.rb +0 -24
- data/spec/react/native_library_spec.rb +0 -322
- data/spec/react/observable_spec.rb +0 -42
- data/spec/react/opal_jquery_extensions_spec.rb +0 -68
- data/spec/react/param_declaration_spec.rb +0 -269
- data/spec/react/react_spec.rb +0 -215
- data/spec/react/refs_callback_spec.rb +0 -56
- data/spec/react/server_spec.rb +0 -25
- data/spec/react/state_spec.rb +0 -55
- data/spec/react/test/dsl_spec.rb +0 -43
- data/spec/react/test/matchers/render_html_matcher_spec.rb +0 -83
- data/spec/react/test/rspec_spec.rb +0 -62
- data/spec/react/test/session_spec.rb +0 -88
- data/spec/react/test/utils_spec.rb +0 -28
- data/spec/react/top_level_component_spec.rb +0 -101
- data/spec/react/tutorial/tutorial_spec.rb +0 -36
- data/spec/react/validator_spec.rb +0 -124
- data/spec/reactive-ruby/component_loader_spec.rb +0 -77
- data/spec/reactive-ruby/isomorphic_helpers_spec.rb +0 -160
- data/spec/reactive-ruby/rails/asset_pipeline_spec.rb +0 -10
- data/spec/reactive-ruby/rails/component_mount_spec.rb +0 -66
- data/spec/reactive-ruby/server_rendering/contextual_renderer_spec.rb +0 -35
- data/spec/spec_helper.rb +0 -149
- data/spec/support/react/spec_helpers.rb +0 -44
- data/spec/vendor/es5-shim.min.js +0 -6
- data/spec/vendor/jquery-2.2.4.min.js +0 -4
data/lib/react/event.rb
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
module React
|
2
|
-
class Event
|
3
|
-
include Native
|
4
|
-
alias_native :bubbles, :bubbles
|
5
|
-
alias_native :cancelable, :cancelable
|
6
|
-
alias_native :current_target, :currentTarget
|
7
|
-
alias_native :default_prevented, :defaultPrevented
|
8
|
-
alias_native :event_phase, :eventPhase
|
9
|
-
alias_native :is_trusted?, :isTrusted
|
10
|
-
alias_native :native_event, :nativeEvent
|
11
|
-
alias_native :target, :target
|
12
|
-
alias_native :timestamp, :timeStamp
|
13
|
-
alias_native :event_type, :type
|
14
|
-
alias_native :prevent_default, :preventDefault
|
15
|
-
alias_native :stop_propagation, :stopPropagation
|
16
|
-
# Clipboard
|
17
|
-
alias_native :clipboard_data, :clipboardData
|
18
|
-
# Keyboard
|
19
|
-
alias_native :alt_key, :altKey
|
20
|
-
alias_native :char_code, :charCode
|
21
|
-
alias_native :ctrl_key, :ctrlKey
|
22
|
-
alias_native :get_modifier_state, :getModifierState
|
23
|
-
alias_native :key, :key
|
24
|
-
alias_native :key_code, :keyCode
|
25
|
-
alias_native :locale, :locale
|
26
|
-
alias_native :location, :location
|
27
|
-
alias_native :meta_key, :metaKey
|
28
|
-
alias_native :repeat, :repeat
|
29
|
-
alias_native :shift_key, :shiftKey
|
30
|
-
alias_native :which, :which
|
31
|
-
# Focus
|
32
|
-
alias_native :related_target, :relatedTarget
|
33
|
-
# Mouse
|
34
|
-
alias_native :alt_key, :altKey
|
35
|
-
alias_native :button, :button
|
36
|
-
alias_native :buttons, :buttons
|
37
|
-
alias_native :client_x, :clientX
|
38
|
-
alias_native :client_y, :clientY
|
39
|
-
alias_native :ctrl_key, :ctrlKey
|
40
|
-
alias_native :get_modifier_state, :getModifierState
|
41
|
-
alias_native :meta_key, :metaKey
|
42
|
-
alias_native :page_x, :pageX
|
43
|
-
alias_native :page_y, :pageY
|
44
|
-
alias_native :related_target, :relatedTarget
|
45
|
-
alias_native :screen_x, :screen_x
|
46
|
-
alias_native :screen_y, :screen_y
|
47
|
-
alias_native :shift_key, :shift_key
|
48
|
-
# Touch
|
49
|
-
alias_native :alt_key, :altKey
|
50
|
-
alias_native :changed_touches, :changedTouches
|
51
|
-
alias_native :ctrl_key, :ctrlKey
|
52
|
-
alias_native :get_modifier_state, :getModifierState
|
53
|
-
alias_native :meta_key, :metaKey
|
54
|
-
alias_native :shift_key, :shiftKey
|
55
|
-
alias_native :target_touches, :targetTouches
|
56
|
-
alias_native :touches, :touches
|
57
|
-
# UI
|
58
|
-
alias_native :detail, :detail
|
59
|
-
alias_native :view, :view
|
60
|
-
# Wheel
|
61
|
-
alias_native :delta_mode, :deltaMode
|
62
|
-
alias_native :delta_x, :deltaX
|
63
|
-
alias_native :delta_y, :deltaY
|
64
|
-
alias_native :delta_z, :deltaZ
|
65
|
-
|
66
|
-
BUILT_IN_EVENTS = %w{onCopy onCut onPaste onKeyDown onKeyPress onKeyUp
|
67
|
-
onFocus onBlur onChange onInput onSubmit onClick onDoubleClick onDrag
|
68
|
-
onDragEnd onDragEnter onDragExit onDragLeave onDragOver onDragStart onDrop
|
69
|
-
onMouseDown onMouseEnter onMouseLeave onMouseMove onMouseOut onMouseOver
|
70
|
-
onMouseUp onTouchCancel onTouchEnd onTouchMove onTouchStart onScroll}
|
71
|
-
|
72
|
-
def initialize(native_element)
|
73
|
-
@native = native_element
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
data/lib/react/ext/hash.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
Element.instance_eval do
|
2
|
-
def self.find(selector)
|
3
|
-
selector = begin
|
4
|
-
selector.dom_node
|
5
|
-
rescue
|
6
|
-
selector
|
7
|
-
end if `#{selector}.$dom_node !== undefined`
|
8
|
-
`$(#{selector})`
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.[](selector)
|
12
|
-
find(selector)
|
13
|
-
end
|
14
|
-
|
15
|
-
define_method :render do |container = nil, params = {}, &block|
|
16
|
-
if `#{self.to_n}._reactrb_component_class === undefined`
|
17
|
-
`#{self.to_n}._reactrb_component_class = #{Class.new(Hyperloop::Component)}`
|
18
|
-
end
|
19
|
-
klass = `#{self.to_n}._reactrb_component_class`
|
20
|
-
klass.class_eval do
|
21
|
-
render(container, params, &block)
|
22
|
-
end
|
23
|
-
|
24
|
-
React.render(React.create_element(`#{self.to_n}._reactrb_component_class`), self)
|
25
|
-
end
|
26
|
-
end if Object.const_defined?('Element')
|
data/lib/react/ext/string.rb
DELETED
data/lib/react/hash.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
class Hash
|
2
|
-
|
3
|
-
alias_method :_pre_react_patch_initialize, :initialize
|
4
|
-
|
5
|
-
def initialize(defaults = undefined, &block)
|
6
|
-
if (`defaults===null`)
|
7
|
-
_pre_react_patch_initialize(&block)
|
8
|
-
else
|
9
|
-
_pre_react_patch_initialize(defaults, &block)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
data/lib/react/native_library.rb
DELETED
@@ -1,87 +0,0 @@
|
|
1
|
-
module React
|
2
|
-
# NativeLibrary handles importing JS libraries. Importing native components is handled
|
3
|
-
# by the React::Base. It also provides several methods used by auto-import.rb
|
4
|
-
|
5
|
-
# A NativeLibrary is simply a wrapper that holds the name of the native js library.
|
6
|
-
# It responds to const_missing and method_missing by looking up objects within the js library.
|
7
|
-
# If the object is a react component it is wrapped by a reactrb component class, otherwise
|
8
|
-
# a nested NativeLibrary is returned.
|
9
|
-
|
10
|
-
# Two macros are provided: imports (for naming the native library) and renames which allows
|
11
|
-
# the members of a library to be given different names within the ruby name space.
|
12
|
-
|
13
|
-
# Public methods used by auto-import.rb are import_const_from_native and find_and_render_component
|
14
|
-
class NativeLibrary
|
15
|
-
class << self
|
16
|
-
def imports(native_name)
|
17
|
-
@native_prefix = "#{native_name}."
|
18
|
-
self
|
19
|
-
end
|
20
|
-
|
21
|
-
def rename(rename_list)
|
22
|
-
# rename_list is a hash in the form: native_name => ruby_name, native_name => ruby_name
|
23
|
-
rename_list.each do |js_name, ruby_name|
|
24
|
-
native_name = lookup_native_name(js_name)
|
25
|
-
if lookup_native_name(js_name)
|
26
|
-
create_component_wrapper(self, native_name, ruby_name) ||
|
27
|
-
create_library_wrapper(self, native_name, ruby_name)
|
28
|
-
else
|
29
|
-
raise "class #{name} < React::NativeLibrary could not import #{js_name}. "\
|
30
|
-
"Native value #{scope_native_name(js_name)} is undefined."
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def import_const_from_native(klass, const_name, create_library)
|
36
|
-
native_name = lookup_native_name(const_name) ||
|
37
|
-
lookup_native_name(const_name[0].downcase + const_name[1..-1])
|
38
|
-
native_name && (
|
39
|
-
create_component_wrapper(klass, native_name, const_name) || (
|
40
|
-
create_library &&
|
41
|
-
create_library_wrapper(klass, native_name, const_name)))
|
42
|
-
end
|
43
|
-
|
44
|
-
def const_missing(const_name)
|
45
|
-
import_const_from_native(self, const_name, true) || super
|
46
|
-
end
|
47
|
-
|
48
|
-
def method_missing(method, *args, &block)
|
49
|
-
component_class = get_const(method) if const_defined?(method)
|
50
|
-
component_class ||= import_const_from_native(self, method, false)
|
51
|
-
raise 'could not import a react component named: '\
|
52
|
-
"#{scope_native_name method}" unless component_class
|
53
|
-
React::RenderingContext.render(component_class, *args, &block)
|
54
|
-
end
|
55
|
-
|
56
|
-
private
|
57
|
-
|
58
|
-
def lookup_native_name(js_name)
|
59
|
-
native_name = scope_native_name(js_name)
|
60
|
-
`eval(#{native_name}) !== undefined && native_name`
|
61
|
-
# rubocop:disable Lint/RescueException # that is what eval raises in Opal >= 0.10.
|
62
|
-
rescue Exception
|
63
|
-
nil
|
64
|
-
# rubocop:enable Lint/RescueException
|
65
|
-
end
|
66
|
-
|
67
|
-
def scope_native_name(js_name)
|
68
|
-
"#{@native_prefix}#{js_name}"
|
69
|
-
end
|
70
|
-
|
71
|
-
def create_component_wrapper(klass, native_name, ruby_name)
|
72
|
-
if React::API.native_react_component?(native_name)
|
73
|
-
new_klass = klass.const_set ruby_name, Class.new
|
74
|
-
new_klass.class_eval do
|
75
|
-
include Hyperloop::Component::Mixin
|
76
|
-
imports native_name
|
77
|
-
end
|
78
|
-
new_klass
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def create_library_wrapper(klass, native_name, ruby_name)
|
83
|
-
klass.const_set ruby_name, Class.new(React::NativeLibrary).imports(native_name)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
data/lib/react/object.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# Lazy load HTML tag constants in the form DIV or A
|
2
|
-
# This is needed to allow for a HAML expression like this DIV.my_class
|
3
|
-
class Object
|
4
|
-
class << self
|
5
|
-
alias _reactrb_tag_original_const_missing const_missing
|
6
|
-
|
7
|
-
def const_missing(const_name)
|
8
|
-
# Opal uses const_missing to initially define things,
|
9
|
-
# so we always call the original, and respond to the exception
|
10
|
-
_reactrb_tag_original_const_missing(const_name)
|
11
|
-
rescue StandardError => e
|
12
|
-
React::Component::Tags.html_tag_class_for(const_name) || raise(e)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
data/lib/react/react-source.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
if RUBY_ENGINE == 'opal'
|
2
|
-
%x{
|
3
|
-
var ms = [
|
4
|
-
"Warning: `react/react-source` is deprecated, ",
|
5
|
-
"use `react/react-source-browser` or `react/react-source-server` instead."
|
6
|
-
]
|
7
|
-
console.error(ms.join(""));
|
8
|
-
}
|
9
|
-
require 'react.js'
|
10
|
-
require "react-server.js"
|
11
|
-
else
|
12
|
-
require "react/config"
|
13
|
-
require "react/rails/asset_variant"
|
14
|
-
react_directory = React::Rails::AssetVariant.new(
|
15
|
-
addons: true,
|
16
|
-
variant: React::Config.config[:environment].to_sym
|
17
|
-
).react_directory
|
18
|
-
Opal.append_path react_directory.untaint
|
19
|
-
Opal.append_path File.expand_path('../../react-sources/', __FILE__).untaint
|
20
|
-
end
|
data/lib/react/ref_callback.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'react/native_library'
|
2
|
-
|
3
|
-
module React
|
4
|
-
module RefsCallbackExtension
|
5
|
-
end
|
6
|
-
|
7
|
-
class API
|
8
|
-
class << self
|
9
|
-
alias :orig_convert_props :convert_props
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.convert_props(properties)
|
13
|
-
props = self.orig_convert_props(properties)
|
14
|
-
props.map do |key, value|
|
15
|
-
if key == "ref" && value.is_a?(Proc)
|
16
|
-
new_proc = Proc.new do |native_inst|
|
17
|
-
if `#{native_inst}._getOpalInstance !== undefined`
|
18
|
-
value.call(`#{native_inst}._getOpalInstance()`)
|
19
|
-
elsif `React.findDOMNode !== undefined && #{native_inst}.nodeType === undefined`
|
20
|
-
value.call(`React.findDOMNode(#{native_inst})`)
|
21
|
-
else
|
22
|
-
value.call(native_inst)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
props[key] = new_proc
|
26
|
-
end
|
27
|
-
end
|
28
|
-
props
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,144 +0,0 @@
|
|
1
|
-
module React
|
2
|
-
class RenderingContext
|
3
|
-
class << self
|
4
|
-
attr_accessor :waiting_on_resources
|
5
|
-
|
6
|
-
def render(name, *args, &block)
|
7
|
-
was_outer_most = !@not_outer_most
|
8
|
-
@not_outer_most = true
|
9
|
-
remove_nodes_from_args(args)
|
10
|
-
@buffer ||= [] unless @buffer
|
11
|
-
if block
|
12
|
-
element = build do
|
13
|
-
saved_waiting_on_resources = waiting_on_resources
|
14
|
-
self.waiting_on_resources = nil
|
15
|
-
run_child_block(name.nil?, &block)
|
16
|
-
if name
|
17
|
-
buffer = @buffer.dup
|
18
|
-
React.create_element(name, *args) { buffer }.tap do |element|
|
19
|
-
element.waiting_on_resources = saved_waiting_on_resources || !!buffer.detect { |e| e.waiting_on_resources if e.respond_to?(:waiting_on_resources) }
|
20
|
-
element.waiting_on_resources ||= buffer.last.is_a?(String) && waiting_on_resources
|
21
|
-
end
|
22
|
-
elsif @buffer.last.is_a? React::Element
|
23
|
-
@buffer.last.tap { |element| element.waiting_on_resources ||= saved_waiting_on_resources }
|
24
|
-
else
|
25
|
-
@buffer.last.to_s.span.tap { |element| element.waiting_on_resources = saved_waiting_on_resources }
|
26
|
-
end
|
27
|
-
end
|
28
|
-
elsif name.is_a? React::Element
|
29
|
-
element = name
|
30
|
-
else
|
31
|
-
element = React.create_element(name, *args)
|
32
|
-
element.waiting_on_resources = waiting_on_resources
|
33
|
-
end
|
34
|
-
@buffer << element
|
35
|
-
self.waiting_on_resources = nil
|
36
|
-
element
|
37
|
-
ensure
|
38
|
-
@not_outer_most = @buffer = nil if was_outer_most
|
39
|
-
end
|
40
|
-
|
41
|
-
def build
|
42
|
-
current = @buffer
|
43
|
-
@buffer = []
|
44
|
-
return_val = yield @buffer
|
45
|
-
@buffer = current
|
46
|
-
return_val
|
47
|
-
end
|
48
|
-
|
49
|
-
def as_node(element)
|
50
|
-
@buffer.delete(element)
|
51
|
-
element
|
52
|
-
end
|
53
|
-
|
54
|
-
alias delete as_node
|
55
|
-
|
56
|
-
def rendered?(element)
|
57
|
-
@buffer.include? element
|
58
|
-
end
|
59
|
-
|
60
|
-
def replace(e1, e2)
|
61
|
-
@buffer[@buffer.index(e1)] = e2
|
62
|
-
end
|
63
|
-
|
64
|
-
def remove_nodes_from_args(args)
|
65
|
-
args[0].each do |key, value|
|
66
|
-
begin
|
67
|
-
value.as_node if value.is_a?(Element)
|
68
|
-
rescue Exception
|
69
|
-
end
|
70
|
-
end if args[0] && args[0].is_a?(Hash)
|
71
|
-
end
|
72
|
-
|
73
|
-
# run_child_block gathers the element(s) generated by a child block.
|
74
|
-
# for example when rendering this div: div { "hello".span; "goodby".span }
|
75
|
-
# two child Elements will be generated.
|
76
|
-
#
|
77
|
-
# the final value of the block should either be
|
78
|
-
# 1 an object that responds to :acts_as_string?
|
79
|
-
# 2 a string,
|
80
|
-
# 3 an element that is NOT yet pushed on the rendering buffer
|
81
|
-
# 4 or the last element pushed on the buffer
|
82
|
-
#
|
83
|
-
# in case 1 we change the object to a string, and then it becomes case 2
|
84
|
-
# in case 2 we automatically push the string onto the buffer
|
85
|
-
# in case 3 we also push the Element onto the buffer IF the buffer is empty
|
86
|
-
# case 4 requires no special processing
|
87
|
-
#
|
88
|
-
# Once we have taken care of these special cases we do a check IF we are in an
|
89
|
-
# outer rendering scope. In this case react only allows us to generate 1 Element
|
90
|
-
# so we insure that is the case, and also check to make sure that element in the buffer
|
91
|
-
# is the element returned
|
92
|
-
|
93
|
-
|
94
|
-
def run_child_block(is_outer_scope)
|
95
|
-
result = yield
|
96
|
-
result = result.to_s.span if result.try :acts_as_string? || result.is_a?(String)
|
97
|
-
@buffer << result if result.is_a?(String) || (result.is_a?(React::Element) && @buffer.empty?)
|
98
|
-
raise_render_error(result) if is_outer_scope && @buffer != [result]
|
99
|
-
end
|
100
|
-
|
101
|
-
# heurestically raise a meaningful error based on the situation
|
102
|
-
|
103
|
-
def raise_render_error(result)
|
104
|
-
improper_render 'A different element was returned than was generated within the DSL.',
|
105
|
-
'Possibly improper use of Element#delete.' if @buffer.count == 1
|
106
|
-
improper_render "Instead #{@buffer.count} elements were generated.",
|
107
|
-
'Do you want to wrap your elements in a div?' if @buffer.count > 1
|
108
|
-
improper_render "Instead the component #{result} was returned.",
|
109
|
-
"Did you mean #{result}()?" if result.try :reactrb_component?
|
110
|
-
improper_render "Instead the #{result.class} #{result} was returned.",
|
111
|
-
'You may need to convert this to a string.'
|
112
|
-
end
|
113
|
-
|
114
|
-
def improper_render(message, solution)
|
115
|
-
raise "a component's render method must generate and return exactly 1 element or a string.\n"\
|
116
|
-
" #{message} #{solution}"
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
class ::Object
|
122
|
-
[:span, :td, :th, :while_loading].each do |tag|
|
123
|
-
define_method(tag) do |*args, &block|
|
124
|
-
args.unshift(tag)
|
125
|
-
return send(*args, &block) if is_a? React::Component
|
126
|
-
React::RenderingContext.render(*args) { to_s }
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
def para(*args, &block)
|
131
|
-
args.unshift(:p)
|
132
|
-
return send(*args, &block) if is_a? React::Component
|
133
|
-
React::RenderingContext.render(*args) { to_s }
|
134
|
-
end
|
135
|
-
|
136
|
-
def br
|
137
|
-
return send(:br) if is_a? React::Component
|
138
|
-
React::RenderingContext.render(:span) do
|
139
|
-
React::RenderingContext.render(to_s)
|
140
|
-
React::RenderingContext.render(:br)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|