hyper-react 0.99.6 → 1.0.0.lap21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.codeclimate.yml +27 -0
- data/.gitignore +30 -37
- data/.rubocop.yml +1159 -0
- data/.travis.yml +32 -0
- data/Appraisals +31 -0
- data/CHANGELOG.md +143 -0
- data/DOCS.md +1515 -0
- data/Gemfile +2 -5
- data/LICENSE +19 -0
- data/README.md +5 -33
- data/Rakefile +25 -6
- data/UPGRADING.md +24 -0
- data/component-name-lookup.md +145 -0
- data/dciy.toml +3 -0
- data/dciy_prepare.sh +8 -0
- data/dciy_run.sh +10 -0
- data/hyper-react.gemspec +24 -18
- data/lib/generators/reactive_ruby/test_app/templates/assets/javascripts/components.rb +3 -0
- data/lib/generators/reactive_ruby/test_app/templates/assets/javascripts/server_rendering.js +5 -0
- data/lib/generators/reactive_ruby/test_app/templates/assets/javascripts/test_application.rb +2 -0
- data/lib/generators/reactive_ruby/test_app/templates/boot.rb.erb +6 -0
- data/lib/generators/reactive_ruby/test_app/templates/script/rails +5 -0
- data/lib/generators/reactive_ruby/test_app/templates/test_application.rb.erb +13 -0
- data/lib/generators/reactive_ruby/test_app/templates/views/components/hello_world.rb +11 -0
- data/lib/generators/reactive_ruby/test_app/templates/views/components/todo.rb +14 -0
- 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 +117 -0
- data/lib/hyper-react.rb +66 -4
- data/lib/rails-helpers/top_level_rails_component.rb +75 -0
- data/lib/react/api.rb +203 -0
- data/lib/react/callbacks.rb +41 -0
- data/lib/react/children.rb +30 -0
- data/lib/react/component.rb +177 -0
- data/lib/react/component/api.rb +69 -0
- data/lib/react/component/base.rb +13 -0
- data/lib/react/component/class_methods.rb +181 -0
- data/lib/react/component/dsl_instance_methods.rb +23 -0
- data/lib/react/component/params.rb +6 -0
- data/lib/react/component/props_wrapper.rb +78 -0
- data/lib/react/component/should_component_update.rb +99 -0
- data/lib/react/component/tags.rb +108 -0
- data/lib/react/config.rb +5 -0
- data/lib/react/config/client.rb.erb +19 -0
- data/lib/react/config/server.rb +23 -0
- data/lib/react/element.rb +150 -0
- data/lib/react/event.rb +76 -0
- data/lib/react/ext/hash.rb +9 -0
- data/lib/react/ext/opal-jquery/element.rb +26 -0
- data/lib/react/ext/string.rb +8 -0
- data/lib/react/hash.rb +13 -0
- data/lib/react/native_library.rb +87 -0
- data/lib/react/object.rb +15 -0
- data/lib/react/react-source-browser.rb +3 -0
- data/lib/react/react-source-server.rb +3 -0
- data/lib/react/react-source.rb +16 -0
- data/lib/react/ref_callback.rb +31 -0
- data/lib/react/rendering_context.rb +146 -0
- data/lib/react/server.rb +19 -0
- data/lib/react/state_wrapper.rb +23 -0
- data/lib/react/test.rb +16 -0
- data/lib/react/test/dsl.rb +17 -0
- data/lib/react/test/matchers/render_html_matcher.rb +56 -0
- data/lib/react/test/rspec.rb +15 -0
- data/lib/react/test/session.rb +37 -0
- data/lib/react/test/utils.rb +71 -0
- data/lib/react/top_level.rb +110 -0
- data/lib/react/top_level_render.rb +28 -0
- data/lib/react/validator.rb +136 -0
- data/lib/reactive-ruby/component_loader.rb +43 -0
- data/lib/reactive-ruby/isomorphic_helpers.rb +235 -0
- data/lib/reactive-ruby/rails.rb +8 -0
- data/lib/reactive-ruby/rails/component_mount.rb +48 -0
- data/lib/reactive-ruby/rails/controller_helper.rb +14 -0
- data/lib/reactive-ruby/rails/railtie.rb +20 -0
- data/lib/reactive-ruby/serializers.rb +15 -0
- data/lib/reactive-ruby/server_rendering/contextual_renderer.rb +41 -0
- data/lib/reactive-ruby/server_rendering/hyper_asset_container.rb +46 -0
- data/lib/reactive-ruby/version.rb +3 -0
- data/lib/reactrb/auto-import.rb +27 -0
- data/logo1.png +0 -0
- data/logo2.png +0 -0
- data/logo3.png +0 -0
- data/path_release_steps.md +9 -0
- data/spec/controller_helper_spec.rb +35 -0
- data/spec/index.html.erb +11 -0
- data/spec/react/callbacks_spec.rb +142 -0
- data/spec/react/children_spec.rb +132 -0
- data/spec/react/component/base_spec.rb +36 -0
- data/spec/react/component_spec.rb +1073 -0
- data/spec/react/dsl_spec.rb +323 -0
- data/spec/react/element_spec.rb +132 -0
- data/spec/react/event_spec.rb +39 -0
- data/spec/react/native_library_spec.rb +387 -0
- data/spec/react/observable_spec.rb +31 -0
- data/spec/react/opal_jquery_extensions_spec.rb +68 -0
- data/spec/react/param_declaration_spec.rb +253 -0
- data/spec/react/react_spec.rb +278 -0
- data/spec/react/refs_callback_spec.rb +65 -0
- data/spec/react/server_spec.rb +25 -0
- data/spec/react/state_spec.rb +52 -0
- data/spec/react/test/dsl_spec.rb +43 -0
- data/spec/react/test/matchers/render_html_matcher_spec.rb +83 -0
- data/spec/react/test/rspec_spec.rb +62 -0
- data/spec/react/test/session_spec.rb +88 -0
- data/spec/react/test/utils_spec.rb +28 -0
- data/spec/react/top_level_component_spec.rb +103 -0
- data/spec/react/tutorial/tutorial_spec.rb +42 -0
- data/spec/react/validator_spec.rb +134 -0
- data/spec/reactive-ruby/component_loader_spec.rb +74 -0
- data/spec/reactive-ruby/isomorphic_helpers_spec.rb +157 -0
- data/spec/reactive-ruby/rails/asset_pipeline_spec.rb +17 -0
- data/spec/reactive-ruby/rails/component_mount_spec.rb +64 -0
- data/spec/reactive-ruby/server_rendering/contextual_renderer_spec.rb +39 -0
- data/spec/spec_helper.rb +55 -0
- data/spec/test_app/README.md +24 -0
- data/spec/test_app/Rakefile +6 -0
- data/spec/test_app/app/assets/config/manifest.js +3 -0
- data/spec/test_app/app/assets/images/.keep +0 -0
- data/spec/test_app/app/assets/javascripts/application.rb +7 -0
- data/spec/test_app/app/assets/javascripts/cable.js +13 -0
- data/spec/test_app/app/assets/javascripts/channels/.keep +0 -0
- data/spec/test_app/app/assets/javascripts/server_rendering.js +5 -0
- data/spec/test_app/app/assets/stylesheets/application.css +15 -0
- data/spec/test_app/app/channels/application_cable/channel.rb +4 -0
- data/spec/test_app/app/channels/application_cable/connection.rb +4 -0
- data/spec/test_app/app/controllers/application_controller.rb +3 -0
- data/spec/test_app/app/controllers/concerns/.keep +0 -0
- data/spec/test_app/app/helpers/application_helper.rb +2 -0
- data/spec/test_app/app/jobs/application_job.rb +2 -0
- data/spec/test_app/app/mailers/application_mailer.rb +4 -0
- data/spec/test_app/app/models/application_record.rb +3 -0
- data/spec/test_app/app/models/concerns/.keep +0 -0
- data/spec/test_app/app/views/components.rb +11 -0
- data/spec/test_app/app/views/components/hello_world.rb +11 -0
- data/spec/test_app/app/views/components/todo.rb +14 -0
- data/spec/test_app/app/views/layouts/application.html.erb +14 -0
- data/spec/test_app/app/views/layouts/explicit_layout.html.erb +0 -0
- data/spec/test_app/app/views/layouts/mailer.html.erb +13 -0
- data/spec/test_app/app/views/layouts/mailer.text.erb +1 -0
- data/spec/test_app/app/views/layouts/test_layout.html.erb +0 -0
- data/spec/test_app/bin/bundle +3 -0
- data/spec/test_app/bin/rails +4 -0
- data/spec/test_app/bin/rake +4 -0
- data/spec/test_app/bin/setup +38 -0
- data/spec/test_app/bin/update +29 -0
- data/spec/test_app/bin/yarn +11 -0
- data/spec/test_app/config.ru +5 -0
- data/spec/test_app/config/application.rb +45 -0
- data/spec/test_app/config/boot.rb +6 -0
- data/spec/test_app/config/cable.yml +10 -0
- data/spec/test_app/config/database.yml +25 -0
- data/spec/test_app/config/environment.rb +5 -0
- data/spec/test_app/config/environments/development.rb +54 -0
- data/spec/test_app/config/environments/production.rb +91 -0
- data/spec/test_app/config/environments/test.rb +42 -0
- data/spec/test_app/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/test_app/config/initializers/assets.rb +14 -0
- data/spec/test_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/test_app/config/initializers/cookies_serializer.rb +5 -0
- data/spec/test_app/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/test_app/config/initializers/inflections.rb +16 -0
- data/spec/test_app/config/initializers/mime_types.rb +4 -0
- data/spec/test_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/test_app/config/locales/en.yml +33 -0
- data/spec/test_app/config/puma.rb +56 -0
- data/spec/test_app/config/routes.rb +3 -0
- data/spec/test_app/config/secrets.yml +32 -0
- data/spec/test_app/config/spring.rb +6 -0
- data/spec/test_app/db/development.sqlite3 +0 -0
- data/spec/test_app/db/schema.rb +15 -0
- data/spec/test_app/db/seeds.rb +7 -0
- data/spec/test_app/db/test.sqlite3 +0 -0
- data/spec/test_app/lib/assets/.keep +0 -0
- data/spec/test_app/log/.keep +0 -0
- data/spec/test_app/package.json +5 -0
- data/spec/test_app/public/404.html +67 -0
- data/spec/test_app/public/422.html +67 -0
- data/spec/test_app/public/500.html +66 -0
- data/spec/test_app/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/test_app/public/apple-touch-icon.png +0 -0
- data/spec/test_app/public/favicon.ico +0 -0
- data/spec/vendor/es5-shim.min.js +7 -0
- data/spec/vendor/jquery-2.2.4.min.js +4 -0
- metadata +401 -61
- data/CODE_OF_CONDUCT.md +0 -49
- data/lib/react/version.rb +0 -3
data/Gemfile
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
source 'https://rubygems.org'
|
|
2
|
-
|
|
3
|
-
gem
|
|
4
|
-
gem 'hyperloop-config', path: '../hyperloop-config'
|
|
5
|
-
gem 'hyper-store', path: '../hyper-store'
|
|
6
|
-
gem 'hyper-component', path: '../hyper-component'
|
|
2
|
+
gem "opal-jquery", git: "https://github.com/opal/opal-jquery.git", branch: "master"
|
|
3
|
+
gem "opal-rails", git: "https://github.com/opal/opal-rails.git", branch: "master"
|
|
7
4
|
gemspec
|
data/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2015 Yi-Cheng Chang (http://github.com/zetachang)
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
<img src="http://ruby-hyperloop.org/images/githubgitterbadge.png">
|
|
21
21
|
</a>
|
|
22
22
|
|
|
23
|
-
[](https://travis-ci.org/ruby-hyperloop/hyper-react)
|
|
24
|
+
[](https://badge.fury.io/rb/hyper-react)
|
|
24
25
|
|
|
25
26
|
<p align="center">
|
|
26
27
|
<img src="http://ruby-hyperloop.org/images/HyperComponents.png" width="100" alt="Hyper-components">
|
|
@@ -28,39 +29,11 @@
|
|
|
28
29
|
|
|
29
30
|
</div>
|
|
30
31
|
|
|
31
|
-
## Hyper-
|
|
32
|
+
## Hyper-React GEM is part of Hyperloop GEMS family
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
Hyper-react GEM comes with the Hyperloop GEM.
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
Everything has a place in our architecture. Components deliver interactive user experiences, Operations encapsulate business logic, Models magically synchronize data between clients and servers, Policies govern authorization and Stores hold local state.
|
|
38
|
-
|
|
39
|
-
**Hyper-component** brings Components modules uesed in the Hyperloop interface.
|
|
40
|
-
|
|
41
|
-
## Getting Started
|
|
42
|
-
|
|
43
|
-
1. Update your Gemfile:
|
|
44
|
-
|
|
45
|
-
```ruby
|
|
46
|
-
#Gemfile
|
|
47
|
-
|
|
48
|
-
gem 'hyperloop'
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
2. At the command prompt, update your bundle :
|
|
52
|
-
|
|
53
|
-
$ bundle update
|
|
54
|
-
|
|
55
|
-
3. Run the hyperloop install generator:
|
|
56
|
-
|
|
57
|
-
$ rails g hyperloop:install
|
|
58
|
-
|
|
59
|
-
4. Follow the guidelines to start developing your application. You may find
|
|
60
|
-
the following resources handy:
|
|
61
|
-
* [Getting Started with Hyperloop](http://ruby-hyperloop.org/start/components/)
|
|
62
|
-
* [Hyperloop Guides](http://ruby-hyperloop.org/docs/architecture)
|
|
63
|
-
* [Hyperloop Tutorial](http://ruby-hyperloop.org/tutorials)
|
|
36
|
+
But if you want to install it separately, please install the [Hyper-component GEM](https://github.com/ruby-hyperloop/hyper-component).
|
|
64
37
|
|
|
65
38
|
## Community
|
|
66
39
|
|
|
@@ -74,4 +47,3 @@ Please **do not post** usage questions to GitHub Issues. For these types of ques
|
|
|
74
47
|
## License
|
|
75
48
|
|
|
76
49
|
Hyperloop is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
|
77
|
-
|
data/Rakefile
CHANGED
|
@@ -1,11 +1,30 @@
|
|
|
1
|
-
require 'bundler
|
|
1
|
+
require 'bundler'
|
|
2
|
+
Bundler.require
|
|
3
|
+
Bundler::GemHelper.install_tasks
|
|
4
|
+
|
|
5
|
+
# Store the BUNDLE_GEMFILE env, since rake or rspec seems to clean it
|
|
6
|
+
# while invoking task.
|
|
7
|
+
ENV['REAL_BUNDLE_GEMFILE'] = ENV['BUNDLE_GEMFILE']
|
|
8
|
+
|
|
2
9
|
require 'rspec/core/rake_task'
|
|
10
|
+
require 'opal/rspec/rake_task'
|
|
11
|
+
|
|
12
|
+
RSpec::Core::RakeTask.new('ruby:rspec')
|
|
3
13
|
|
|
4
|
-
|
|
14
|
+
task :test do
|
|
15
|
+
Rake::Task['ruby:rspec'].invoke
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
require 'generators/reactive_ruby/test_app/test_app_generator'
|
|
19
|
+
desc "Generates a dummy app for testing"
|
|
20
|
+
task :test_app do
|
|
21
|
+
ReactiveRuby::TestAppGenerator.start
|
|
22
|
+
puts "Setting up test app database..."
|
|
23
|
+
system("bundle exec rake db:drop db:create db:migrate > #{File::NULL}")
|
|
24
|
+
end
|
|
5
25
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
end
|
|
26
|
+
task :test_prepare do
|
|
27
|
+
system("./dciy_prepare.sh")
|
|
9
28
|
end
|
|
10
29
|
|
|
11
|
-
task default: :
|
|
30
|
+
task default: [ :test ]
|
data/UPGRADING.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
## Upgrading to hyper-react from Reactrb
|
|
2
|
+
|
|
3
|
+
Follow these steps to upgrade:
|
|
4
|
+
|
|
5
|
+
1. Replace `reactrb` with `hyper-react` both in **Gemfile** and any `require`s in your code.
|
|
6
|
+
2. To include the React.js source, the suggested way is to add `require 'react/react-source'` before `require 'hyper-react'`. This will use the copy of React.js source from `react-rails` gem.
|
|
7
|
+
|
|
8
|
+
## Upgrading to Reactrb
|
|
9
|
+
|
|
10
|
+
The original gem `react.rb` was superceeded by `reactive-ruby`, which has had over 15,000 downloads. This name has now been superceeded by `reactrb` (see #144 for detailed discussion on why.)
|
|
11
|
+
|
|
12
|
+
Going forward the name `reactrb` will be used consistently as the organization name, the gem name, the domain name, the twitter handle, etc.
|
|
13
|
+
|
|
14
|
+
The first initial version of `reactrb` is 0.8.x.
|
|
15
|
+
|
|
16
|
+
It is very unlikely that there will be any more releases of the `reactive-ruby` gem, so users should upgrade to `reactrb`.
|
|
17
|
+
|
|
18
|
+
There are no syntactic or semantic breaking changes between `reactrb` v 0.8.x and
|
|
19
|
+
previous versions, however the `reactrb` gem does *not* include the react-js source as previous versions did. This allows you to pick the react js source compatible with other gems and react js components you may be using.
|
|
20
|
+
|
|
21
|
+
Follow these steps to upgrade:
|
|
22
|
+
|
|
23
|
+
1. Replace `reactive-ruby` with `reactrb` both in **Gemfile** and any `require`s in your code.
|
|
24
|
+
2. To include the React.js source, the suggested way is to add `require 'react/react-source'` before `require 'reactrb'`. This will use the copy of React.js source from `react-rails` gem.
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
#### Notes on how component names are looked up
|
|
2
|
+
|
|
3
|
+
Given:
|
|
4
|
+
|
|
5
|
+
```ruby
|
|
6
|
+
|
|
7
|
+
class Blat < React::Component::Base
|
|
8
|
+
|
|
9
|
+
render do
|
|
10
|
+
Bar()
|
|
11
|
+
Foo::Bar()
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
class Bar < React::Component::Base
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
module Foo
|
|
20
|
+
|
|
21
|
+
class Bar < React::Component::Base
|
|
22
|
+
|
|
23
|
+
render do
|
|
24
|
+
Blat()
|
|
25
|
+
Baz()
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
class Baz < React::Component::Base
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The problem is that method lookup is different than constant lookup. We can prove it by running this code:
|
|
36
|
+
|
|
37
|
+
```ruby
|
|
38
|
+
def try_it(test, &block)
|
|
39
|
+
puts "trying #{test}"
|
|
40
|
+
result = yield
|
|
41
|
+
puts "success#{': '+result.to_s if result}"
|
|
42
|
+
rescue Exception => e
|
|
43
|
+
puts "failed: #{e}"
|
|
44
|
+
ensure
|
|
45
|
+
puts "---------------------------------"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
module Boom
|
|
49
|
+
|
|
50
|
+
Bar = 12
|
|
51
|
+
|
|
52
|
+
def self.Bar
|
|
53
|
+
puts " Boom::Bar says hi"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
class Baz
|
|
57
|
+
def doit
|
|
58
|
+
try_it("Bar()") { Bar() }
|
|
59
|
+
try_it("Boom::Bar()") {Boom::Bar()}
|
|
60
|
+
try_it("Bar") { Bar }
|
|
61
|
+
try_it("Boom::Bar") { Boom::Bar }
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
Boom::Baz.new.doit
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
which prints:
|
|
72
|
+
|
|
73
|
+
```text
|
|
74
|
+
trying Bar()
|
|
75
|
+
failed: Bar: undefined method `Bar' for #<Boom::Baz:0x774>
|
|
76
|
+
---------------------------------
|
|
77
|
+
trying Boom::Bar()
|
|
78
|
+
Boom::Bar says hi
|
|
79
|
+
success
|
|
80
|
+
---------------------------------
|
|
81
|
+
trying Bar
|
|
82
|
+
success: 12
|
|
83
|
+
---------------------------------
|
|
84
|
+
trying Boom::Bar
|
|
85
|
+
success: 12
|
|
86
|
+
---------------------------------
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
[try-it](http://opalrb.org/try/?code:def%20try_it(test%2C%20%26block)%0A%20%20puts%20%22trying%20%23%7Btest%7D%22%0A%20%20result%20%3D%20yield%0A%20%20puts%20%22success%23%7B%27%3A%20%27%2Bresult.to_s%20if%20result%7D%22%0Arescue%20Exception%20%3D%3E%20e%0A%20%20puts%20%22failed%3A%20%23%7Be%7D%22%0Aensure%0A%20%20puts%20%22---------------------------------%22%0Aend%0A%0Amodule%20Boom%0A%20%20%0A%20%20Bar%20%3D%2012%0A%20%20%0A%20%20def%20self.Bar%0A%20%20%20%20puts%20%22%20%20%20Boom%3A%3ABar%20says%20hi%22%0A%20%20end%0A%0A%20%20class%20Baz%0A%20%20%20%20def%20doit%0A%20%20%20%20%20%20try_it(%22Bar()%22)%20%7B%20Bar()%20%7D%0A%20%20%20%20%20%20try_it(%22Boom%3A%3ABar()%22)%20%7BBoom%3A%3ABar()%7D%0A%20%20%20%20%20%20try_it(%22Bar%22)%20%7B%20Bar%20%7D%0A%20%20%20%20%20%20try_it(%22Boom%3A%3ABar%22)%20%7B%20Boom%3A%3ABar%20%7D%0A%20%20%20%20end%0A%20%20end%0Aend%0A%20%20%0A%0A%0ABoom%3A%3ABaz.new.doit)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
What we need to do is:
|
|
93
|
+
|
|
94
|
+
1. when defining a component class `Foo`, also define in the same scope that Foo is being defined a method `self.Foo` that will accept Foo's params and child block, and render it.
|
|
95
|
+
|
|
96
|
+
2. As long as a name is qualified with at least one scope (i.e. `ModName::Foo()`) everything will work out, but if we say just `Foo()` then the only way I believe out of this is to handle it via method_missing, and let method_missing do a const_get on the method_name (which will return the class) and then render that component.
|
|
97
|
+
|
|
98
|
+
#### details
|
|
99
|
+
|
|
100
|
+
To define `self.Foo` in the same scope level as the class `Foo`, we need code like this:
|
|
101
|
+
|
|
102
|
+
```ruby
|
|
103
|
+
def register_component_dsl_method(component)
|
|
104
|
+
split_name = component.name && component.name.split('::')
|
|
105
|
+
return unless split_name && split_name.length > 2
|
|
106
|
+
component_name = split_name.last
|
|
107
|
+
parent = split_name.inject([Module]) { |nesting, next_const| nesting + [nesting.last.const_get(next_const)] }[-2]
|
|
108
|
+
class << parent
|
|
109
|
+
define_method component_name do |*args, &block|
|
|
110
|
+
React::RenderingContext.render(name, *args, &block)
|
|
111
|
+
end
|
|
112
|
+
define_method "#{component_name}_as_node" do |*args, &block|
|
|
113
|
+
React::Component.deprecation_warning("..._as_node is deprecated. Render component and then use the .node method instead")
|
|
114
|
+
send(component_name, *args, &block).node
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
module React
|
|
120
|
+
module Component
|
|
121
|
+
def self.included(base)
|
|
122
|
+
...
|
|
123
|
+
register_component_dsl_method(base.name)
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
The component's method_missing function will look like this:
|
|
130
|
+
|
|
131
|
+
```ruby
|
|
132
|
+
def method_missing(name, *args, &block)
|
|
133
|
+
if name =~ /_as_node$/
|
|
134
|
+
React::Component.deprecation_warning("..._as_node is deprecated. Render component and then use the .node method instead")
|
|
135
|
+
method_missing(name.gsub(/_as_node$/,""), *args, &block).node
|
|
136
|
+
else
|
|
137
|
+
component = const_get name if defined? name
|
|
138
|
+
React::RenderingContext.render(nil, component, *args, &block)
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### other related issues
|
|
144
|
+
|
|
145
|
+
The Kernel#p method conflicts with the <p> tag. However the p method can be invoked on any object so we are going to go ahead and use it, and deprecate the para method.
|
data/dciy.toml
ADDED
data/dciy_prepare.sh
ADDED
data/dciy_run.sh
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
export HYPER_DEV_GEM_SOURCE="https://gems.ruby-hyperloop.org"
|
|
3
|
+
export RAILS_ENV="test"
|
|
4
|
+
pwd
|
|
5
|
+
echo
|
|
6
|
+
echo "Running with Chrome headless"
|
|
7
|
+
DRIVER=headless bundle exec rspec
|
|
8
|
+
# echo
|
|
9
|
+
# echo "Running with Firefox headless"
|
|
10
|
+
# DRIVER=beheaded bundle exec rspec
|
data/hyper-react.gemspec
CHANGED
|
@@ -1,41 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
require '
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
$:.push File.expand_path('../lib/', __FILE__)
|
|
3
|
+
require 'reactive-ruby/version'
|
|
4
4
|
|
|
5
5
|
Gem::Specification.new do |spec|
|
|
6
6
|
spec.name = 'hyper-react'
|
|
7
7
|
spec.version = React::VERSION
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
spec.authors = ['David Chang', 'Adam Jahn', 'Mitch VanDuyn', 'Jan Biedermann']
|
|
9
10
|
spec.email = ['mitch@catprint.com', 'jan@kursator.com']
|
|
10
|
-
spec.summary = 'Write advanced React components in Ruby.'
|
|
11
11
|
spec.homepage = 'http://ruby-hyperloop.org'
|
|
12
|
+
spec.summary = 'Opal Ruby wrapper of React.js library.'
|
|
12
13
|
spec.license = 'MIT'
|
|
14
|
+
spec.description = 'Write React UI components in pure Ruby.'
|
|
13
15
|
# spec.metadata = {
|
|
14
16
|
# "homepage_uri" => 'http://ruby-hyperloop.org',
|
|
15
17
|
# "source_code_uri" => 'https://github.com/ruby-hyperloop/hyper-component'
|
|
16
18
|
# }
|
|
17
19
|
|
|
18
|
-
spec.files = `git ls-files
|
|
19
|
-
spec.
|
|
20
|
-
spec.
|
|
20
|
+
spec.files = `git ls-files`.split("\n").reject { |f| f.match(%r{^(gemfiles|spec)/}) }
|
|
21
|
+
spec.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
|
22
|
+
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
21
23
|
spec.require_paths = ['lib']
|
|
22
24
|
|
|
23
|
-
spec.add_dependency '
|
|
25
|
+
spec.add_dependency 'hyper-store', React::VERSION
|
|
26
|
+
spec.add_dependency 'opal', '>= 0.11.0', '< 0.12.0'
|
|
27
|
+
spec.add_dependency 'opal-activesupport', '~> 0.3.1'
|
|
24
28
|
|
|
25
|
-
spec.add_dependency 'hyper-component', React::VERSION
|
|
26
|
-
spec.add_development_dependency 'bundler'
|
|
27
29
|
spec.add_development_dependency 'chromedriver-helper'
|
|
28
30
|
spec.add_development_dependency 'hyper-spec', React::VERSION
|
|
31
|
+
spec.add_development_dependency 'jquery-rails'
|
|
29
32
|
spec.add_development_dependency 'listen'
|
|
30
|
-
spec.add_development_dependency '
|
|
31
|
-
spec.add_development_dependency '
|
|
32
|
-
spec.add_development_dependency 'opal-
|
|
33
|
-
spec.add_development_dependency 'opal-rails', '~> 0.9.
|
|
34
|
-
spec.add_development_dependency '
|
|
33
|
+
spec.add_development_dependency 'mime-types'
|
|
34
|
+
spec.add_development_dependency 'nokogiri'
|
|
35
|
+
spec.add_development_dependency 'opal-jquery'
|
|
36
|
+
spec.add_development_dependency 'opal-rails', '~> 0.9.3'
|
|
37
|
+
spec.add_development_dependency 'opal-rspec'
|
|
35
38
|
spec.add_development_dependency 'rails', '>= 4.0.0'
|
|
39
|
+
spec.add_development_dependency 'rails-controller-testing'
|
|
36
40
|
spec.add_development_dependency 'rake'
|
|
37
|
-
spec.add_development_dependency '
|
|
38
|
-
spec.add_development_dependency 'rspec-
|
|
41
|
+
spec.add_development_dependency 'react-rails', '>= 2.4.0', '< 2.5.0'
|
|
42
|
+
spec.add_development_dependency 'rspec-rails'
|
|
39
43
|
spec.add_development_dependency 'rubocop', '~> 0.51.0'
|
|
40
44
|
spec.add_development_dependency 'sqlite3'
|
|
45
|
+
spec.add_development_dependency 'mini_racer', '~> 0.1.15'
|
|
46
|
+
spec.add_development_dependency 'timecop', '~> 0.8.1'
|
|
41
47
|
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<% if defined? application_definition %>
|
|
2
|
+
require 'rails/all'
|
|
3
|
+
require File.expand_path('../boot', __FILE__)
|
|
4
|
+
|
|
5
|
+
# Require the gems listed in Gemfile, including any gems
|
|
6
|
+
# you've limited to :test, :development, or :production.
|
|
7
|
+
Bundler.require(*Rails.groups(assets: %w(development test)))
|
|
8
|
+
|
|
9
|
+
require 'opal-rails'
|
|
10
|
+
require 'hyper-react'
|
|
11
|
+
|
|
12
|
+
<%= application_definition %>
|
|
13
|
+
<% end %>
|