reactive-ruby 0.7.27 → 0.7.28

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -0
  3. data/Gemfile.lock +1 -1
  4. data/README.md +2 -0
  5. data/example/examples/Gemfile.lock +5 -5
  6. data/example/examples/app/nodes.rb +61 -0
  7. data/example/examples/app/react_api_demo.rb +29 -0
  8. data/example/examples/app/show.rb +6 -0
  9. data/example/rails-tutorial/Gemfile.lock +1 -1
  10. data/example/rails-tutorial/app/controllers/home_controller.rb +1 -1
  11. data/example/rails-tutorial/app/views/components/home/show.rb +12 -13
  12. data/lib/reactive-ruby/component.rb +18 -5
  13. data/lib/reactive-ruby/version.rb +1 -1
  14. data/reactive-ruby.gemspec +2 -1
  15. data/spec/controller_helper_spec.rb +2 -0
  16. data/spec/reactive-ruby/component_loader_spec.rb +2 -0
  17. data/spec/reactive-ruby/rails/component_mount_spec.rb +4 -5
  18. data/spec/reactive-ruby/server_rendering/contextual_renderer_spec.rb +8 -6
  19. data/spec/spec_helper.rb +1 -0
  20. metadata +4 -24
  21. data/lib/generators/reactive_ruby/test_app/templates/application.rb +0 -11
  22. data/lib/generators/reactive_ruby/test_app/templates/assets/javascripts/application.rb +0 -2
  23. data/lib/generators/reactive_ruby/test_app/templates/assets/javascripts/components.rb +0 -3
  24. data/lib/generators/reactive_ruby/test_app/templates/boot.rb +0 -6
  25. data/lib/generators/reactive_ruby/test_app/templates/script/rails +0 -5
  26. data/lib/generators/reactive_ruby/test_app/templates/views/components/hello_world.rb +0 -11
  27. data/lib/generators/reactive_ruby/test_app/templates/views/components/todo.rb +0 -14
  28. data/lib/generators/reactive_ruby/test_app/test_app_generator.rb +0 -105
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 579a244953ecf04793186edfc376b776ee208bfa
4
- data.tar.gz: cbd731345dd42377ab1d8890f5ff13eab3dacf08
3
+ metadata.gz: 7b3ccefdd8c89194824329a42a3f700461a3349c
4
+ data.tar.gz: 8f93442f60fa15f99bc7545e125f11ac9fc5b11e
5
5
  SHA512:
6
- metadata.gz: 2b7aef0925c62a1e75cf8a6d7da93ab633ccbe0af4a6940b8d80af13213324b18323a3c9203c147c706e0742acfbf1dca13189a9ca5381e8b72738e494159168
7
- data.tar.gz: d8df70a1a64040aae4e2a621353276d5df6da37f51928e286c8d598596a36e45aca958960d7821582eea0085e0619c486c99bc49abfeb4585f472299817cf4bc
6
+ metadata.gz: f49d3a2e156abbf32602e494a0c7fb356f090526ea8a19a3fc53d65e4d02be16dc84b79119cefcbc46ba25f280fe8f57085491a5780084db8453acce12b3da78
7
+ data.tar.gz: 7828530b6d13396f33d8a91bd1fd6c02b80d8ccb3a1209af0dc5001b49b43fc8668b77a5c8a5f8b2802d4fff05e13354a583ea5766285a1843422a7a6d94578a
data/Gemfile CHANGED
@@ -3,5 +3,6 @@ group :development, :test do
3
3
  gem 'therubyracer', platforms: :ruby
4
4
  gem 'rails'
5
5
  gem 'react-rails'
6
+ gem 'opal-rails'
6
7
  end
7
8
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- reactive-ruby (0.7.25)
4
+ reactive-ruby (0.7.27)
5
5
  opal
6
6
  opal-activesupport (>= 0.2.0)
7
7
  opal-browser
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Reactive-Ruby
2
2
 
3
+ [![Build Status](https://travis-ci.org/zetachang/react.rb.svg?branch=reactive-ruby)](https://travis-ci.org/zetachang/react.rb)
4
+
3
5
  **Reactive-Ruby is an [Opal Ruby](http://opalrb.org) wrapper of [React.js library](http://facebook.github.io/react/)**.
4
6
 
5
7
  It lets you write reactive UI components, with Ruby's elegance using the tried and true React.js engine. :heart:
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- reactive-ruby (0.7.25)
4
+ reactive-ruby (0.7.27)
5
5
  opal
6
6
  opal-activesupport (>= 0.2.0)
7
7
  opal-browser
@@ -65,7 +65,7 @@ GEM
65
65
  minitest (5.8.1)
66
66
  nokogiri (1.6.6.2)
67
67
  mini_portile (~> 0.6.0)
68
- opal (0.8.0)
68
+ opal (0.8.1)
69
69
  hike (~> 1.2)
70
70
  sourcemap (~> 0.1.0)
71
71
  sprockets (~> 3.1)
@@ -117,15 +117,15 @@ GEM
117
117
  rake (>= 0.8.7)
118
118
  thor (>= 0.18.1, < 2.0)
119
119
  rake (10.4.2)
120
- reactive-router (0.7.8)
120
+ reactive-router (0.7.11)
121
121
  reactive-ruby
122
122
  sinatra (1.4.6)
123
123
  rack (~> 1.4)
124
124
  rack-protection (~> 1.4)
125
125
  tilt (>= 1.3, < 3)
126
126
  sourcemap (0.1.1)
127
- sprockets (3.3.4)
128
- rack (~> 1.0)
127
+ sprockets (3.4.0)
128
+ rack (> 1, < 3)
129
129
  sprockets-rails (2.3.3)
130
130
  actionpack (>= 3.0)
131
131
  activesupport (>= 3.0)
@@ -0,0 +1,61 @@
1
+ # This example shows how to save a node, instead of rendering it.
2
+
3
+ # Normally the DSL "emits" nodes into the rendering buffer as they are generated
4
+ # similar to a put statement.
5
+
6
+ # But what if you want to create some nodes and then use them later.
7
+
8
+ # The following example shows how to do this. The key is the "as_node" method
9
+ # which "pulls" the rendered node back out of the rendering buffer and returns it.
10
+ # You may store it in some structure, or pass it as a parameter to another component.
11
+
12
+ # When it is time to render the component use the .render method, which pushes the
13
+ # node into the render buffer.
14
+
15
+ # The example is also good to understand the difference between generating a node, and
16
+ # rendering it. You can see from the time stamps, that creating the node, does not
17
+ # render it. That happens only when react generates the rendered virtual DOM. Cool huh?
18
+
19
+ # This is slightly different and MORE typing than react, which is contrary to the goals
20
+ # of reactive-ruby, so some explanation is in order.
21
+
22
+ # In order to keep the DSL as short and sweet as possible, reactive-ruby assumes that
23
+ # normally when you generate a node, you will want it pushed into the render buffer
24
+ # (again just like a put statement.)
25
+
26
+ # So when you DONT want this behavior you do have to do some extra typing, i.e. you have
27
+ # explicitly use the .to_node and .render methods, to circumvent the rendering process.
28
+
29
+ # Note that under the hood there is nothing going on different than in straight react.
30
+
31
+ class NodeChildren
32
+
33
+ include React::Component
34
+
35
+ required_param :name
36
+
37
+ def render
38
+ tr { td {name}; td { '%.04f' % Time.now.to_f } }
39
+ end
40
+
41
+ end
42
+
43
+ class Nodes
44
+
45
+ include React::Component
46
+
47
+ def render
48
+ start_time = Time.now
49
+ nodes = (0..10).collect { |i| NodeChildren(name: "I am node #{i}!").as_node }
50
+ div {
51
+ table {
52
+ tbody {
53
+ tr { th {"Node"}; th {"rendered at"} }
54
+ tr { td {"table (parent)"}; td {'%.04f' % Time.now.to_f}}
55
+ nodes.each &:render
56
+ }
57
+ }
58
+ }
59
+ end
60
+
61
+ end
@@ -0,0 +1,29 @@
1
+ class ReactAPIDemo
2
+
3
+ include React::Component
4
+
5
+ before_mount do
6
+ @click_count = 0 # normally we would just use a state variable, but we want to demo using force_update!
7
+ end
8
+
9
+ after_mount do
10
+ # to demonstrate the use of dom_node we will attach a click handler AFTER rendering is complete
11
+ Element[dom_node].on(:click) do
12
+ alert("I got attached using some low level stuff... now watch and you will see I will force a rerender") if @click_count == 0
13
+ @click_count += 1
14
+ force_update!
15
+ end
16
+ end
17
+
18
+ def render
19
+ # Normally you would just attach the handler directly to the node like this:
20
+ # "Click Me Please".on(:click) { alert 'I was attached during rendering' }
21
+ if mounted?
22
+ "I was already mounted, and you have clicked me #{@click_count} time#{'s' if @click_count > 1}, but you can click me again!" #.on(:click) { alert("I was attached the normal way")}
23
+ else
24
+ "This is the first render. click me to rerender!"
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -10,6 +10,8 @@ require 'basics'
10
10
  require 'reuse'
11
11
  require 'items'
12
12
  require 'rerendering'
13
+ require 'nodes'
14
+ require 'react_api_demo'
13
15
 
14
16
 
15
17
  class Show
@@ -22,6 +24,8 @@ class Show
22
24
  route(path: "basics", name: "basics", handler: Basics)
23
25
  route(path: "reuse", name: "reuse", handler: Reuse)
24
26
  route(path: "rerendering", name: "rerendering", handler: Rerendering)
27
+ route(path: "nodes", name: "nodes", handler: Nodes)
28
+ route(path: "api_demo", name: "api_demo", handler: ReactAPIDemo)
25
29
  redirect(from: "/", to: "basics")
26
30
  end
27
31
 
@@ -32,6 +36,8 @@ class Show
32
36
  link(to: "basics") { "Basics" }; br
33
37
  link(to: "reuse") { "Reusable Components" }; br
34
38
  link(to: "rerendering") { "Rerendering Test" }; br
39
+ link(to: "nodes") { "Saving and using rendered nodes" }; br
40
+ link(to: "api_demo") { "Low Level React API" }; br
35
41
  end
36
42
  route_handler
37
43
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- reactive-ruby (0.7.25)
4
+ reactive-ruby (0.7.27)
5
5
  opal
6
6
  opal-activesupport (>= 0.2.0)
7
7
  opal-browser
@@ -3,4 +3,4 @@ class HomeController < ApplicationController
3
3
  def show
4
4
  render_component "Show", say_hello_to: params[:say_hello_to] # by default render_component will use the controller name to find the appropriate component
5
5
  end
6
- end
6
+ end
@@ -1,33 +1,33 @@
1
1
  # app/views/components/home/show.rb
2
2
 
3
3
  module Components
4
-
4
+
5
5
  module Home
6
-
6
+
7
7
  class Show
8
8
 
9
9
  include React::Component # will create a new component named Show
10
-
10
+
11
11
  optional_param :say_hello_to
12
12
  backtrace :on
13
- def render
13
+ def render
14
14
  puts "Rendering my first component!"
15
15
  List(first_element: div { "bhwahaha" }) do
16
16
  "hello #{'there '+say_hello_to if say_hello_to}".span # render "hello" with optional 'there ...'
17
- "goodby".span
17
+ "goodby".span
18
18
  end
19
19
  end
20
20
 
21
21
  end
22
-
22
+
23
23
  class List
24
-
25
- include React::Component
26
-
24
+
25
+ include React::Component
26
+
27
27
  required_param :first_element #, type: React::Element
28
-
28
+
29
29
  backtrace :on
30
-
30
+
31
31
  def render
32
32
  ul do
33
33
  li do
@@ -43,6 +43,5 @@ module Components
43
43
  end
44
44
  end
45
45
  end
46
-
47
- end
48
46
 
47
+ end
@@ -311,9 +311,10 @@ module React
311
311
  if param_type == React::Observable
312
312
  (@two_way_params ||= []) << name
313
313
  define_method("#{name}") do
314
- params[name].instance_variable_get("@value")
314
+ params[name].instance_variable_get("@value") if params[name]
315
315
  end
316
316
  define_method("#{name}!") do |*args|
317
+ return unless params[name]
317
318
  if args.count > 0
318
319
  current_value = params[name].instance_variable_get("@value")
319
320
  params[name].call args[0]
@@ -326,7 +327,7 @@ module React
326
327
  end
327
328
  elsif param_type == Proc
328
329
  define_method("#{name}") do |*args, &block|
329
- params[name].call *args, &block
330
+ params[name].call(*args, &block) if params[name]
330
331
  end
331
332
  else
332
333
  define_method("#{name}") do
@@ -444,9 +445,21 @@ module React
444
445
  module API
445
446
  #include Native
446
447
 
447
- alias_native :dom_node, :getDOMNode
448
- alias_native :mounted?, :isMounted
449
- alias_native :force_update!, :forceUpdate
448
+ def dom_node
449
+ if `typeof React.findDOMNode === 'undefined'`
450
+ `#{self}.native.getDOMNode` # v0.12.0
451
+ else
452
+ `React.findDOMNode(#{self}.native)` # v0.13.0
453
+ end
454
+ end
455
+
456
+ def mounted?
457
+ `#{self}.native.isMounted()`
458
+ end
459
+
460
+ def force_update!
461
+ `#{self}.native.forceUpdate()`
462
+ end
450
463
 
451
464
  def set_props(prop, &block)
452
465
  raise "No native ReactComponent associated" unless @native
@@ -1,3 +1,3 @@
1
1
  module React
2
- VERSION = "0.7.27"
2
+ VERSION = "0.7.28"
3
3
  end
@@ -6,6 +6,7 @@ require 'reactive-ruby/version'
6
6
  Gem::Specification.new do |s|
7
7
  s.name = 'reactive-ruby'
8
8
  s.version = React::VERSION
9
+
9
10
  s.author = 'David Chang'
10
11
  s.email = 'zeta11235813@gmail.com'
11
12
  s.homepage = 'https://github.com/zetachang/react.rb'
@@ -19,10 +20,10 @@ Gem::Specification.new do |s|
19
20
  s.require_paths = ['lib']
20
21
 
21
22
 
23
+
22
24
  s.add_dependency 'opal'
23
25
  s.add_dependency 'opal-activesupport', '>= 0.2.0'
24
26
  s.add_dependency 'opal-browser'
25
- s.add_development_dependency 'opal-rails'
26
27
  s.add_development_dependency 'rake'
27
28
  s.add_development_dependency 'rspec-rails'
28
29
  s.add_development_dependency 'timecop'
@@ -1,5 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
+ if ruby?
3
4
  class TestController < ActionController::Base; end
4
5
 
5
6
  RSpec.describe TestController, type: :controller do
@@ -18,3 +19,4 @@ RSpec.describe TestController, type: :controller do
18
19
  end
19
20
  end
20
21
  end
22
+ end
@@ -1,5 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
+ if ruby?
3
4
  RSpec.describe ReactiveRuby::ComponentLoader do
4
5
  GLOBAL_WRAPPER = <<-JS
5
6
  var global = global || this;
@@ -56,3 +57,4 @@ RSpec.describe ReactiveRuby::ComponentLoader do
56
57
  end
57
58
  end
58
59
  end
60
+ end
@@ -1,13 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
+ if ruby?
3
4
  RSpec.describe ReactiveRuby::Rails::ComponentMount do
4
5
  let(:helper) { described_class.new }
5
6
 
6
7
  before do
7
- env = double
8
- allow(env).to receive(:request).and_return(
9
- { 'controller' => ActionView::TestCase::TestController.new })
10
- helper.setup(env)
8
+ helper.setup(ActionView::TestCase::TestController.new)
11
9
  end
12
10
 
13
11
  describe '#react_component' do
@@ -45,7 +43,7 @@ RSpec.describe ReactiveRuby::Rails::ComponentMount do
45
43
  html = helper.react_component('Components::HelloWorld')
46
44
  props = react_props_for(html)
47
45
 
48
- expect(props['controller']).to eq('ActionView::TestCase::TestController')
46
+ expect(props['controller']).to eq('ActionView::TestCase::Test')
49
47
  end
50
48
 
51
49
  it 'passes additional options through as html attributes' do
@@ -65,3 +63,4 @@ RSpec.describe ReactiveRuby::Rails::ComponentMount do
65
63
  JSON.parse(CGI.unescapeHTML("#{attr_value(html, 'data-react-props')}"))
66
64
  end
67
65
  end
66
+ end
@@ -1,5 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
+ if ruby?
3
4
  RSpec.describe ReactiveRuby::ServerRendering::ContextualRenderer do
4
5
  let(:renderer) { described_class.new({}) }
5
6
  let(:init) { Proc.new {} }
@@ -8,26 +9,27 @@ RSpec.describe ReactiveRuby::ServerRendering::ContextualRenderer do
8
9
  describe '#render' do
9
10
  it 'pre-renders HTML' do
10
11
  result = renderer.render('Components.Todo',
11
- { todo: 'finish reactive-ruby' },
12
- options)
12
+ { todo: 'finish reactive-ruby' },
13
+ options)
13
14
  expect(result).to match(/<li.*>finish reactive-ruby<\/li>/)
14
15
  expect(result).to match(/data-react-checksum/)
15
16
  end
16
17
 
17
18
  it 'accepts props as a string' do
18
19
  result = renderer.render('Components.Todo',
19
- { todo: 'finish reactive-ruby' }.to_json,
20
- options)
20
+ { todo: 'finish reactive-ruby' }.to_json,
21
+ options)
21
22
  expect(result).to match(/<li.*>finish reactive-ruby<\/li>/)
22
23
  expect(result).to match(/data-react-checksum/)
23
24
  end
24
25
 
25
26
  it 'pre-renders static content' do
26
27
  result = renderer.render('Components.Todo',
27
- { todo: 'finish reactive-ruby' },
28
- :static)
28
+ { todo: 'finish reactive-ruby' },
29
+ :static)
29
30
  expect(result).to match(/<li.*>finish reactive-ruby<\/li>/)
30
31
  expect(result).to_not match(/data-react-checksum/)
31
32
  end
32
33
  end
33
34
  end
35
+ end
data/spec/spec_helper.rb CHANGED
@@ -12,6 +12,7 @@ def ruby?
12
12
  end
13
13
 
14
14
  if RUBY_ENGINE == 'opal'
15
+ require 'reactive-ruby'
15
16
  RSpec.configure do |config|
16
17
  config.filter_run_excluding :ruby
17
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reactive-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.27
4
+ version: 0.7.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Chang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-19 00:00:00.000000000 Z
11
+ date: 2015-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: opal-rails
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: rake
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -170,7 +156,9 @@ files:
170
156
  - example/examples/app/basics.js.rb
171
157
  - example/examples/app/items.rb
172
158
  - example/examples/app/jquery.js
159
+ - example/examples/app/nodes.rb
173
160
  - example/examples/app/react-router.js
161
+ - example/examples/app/react_api_demo.rb
174
162
  - example/examples/app/rerendering.rb
175
163
  - example/examples/app/reuse.rb
176
164
  - example/examples/app/show.rb
@@ -260,14 +248,6 @@ files:
260
248
  - example/todos/vendor/base.css
261
249
  - example/todos/vendor/bg.png
262
250
  - example/todos/vendor/jquery.js
263
- - lib/generators/reactive_ruby/test_app/templates/application.rb
264
- - lib/generators/reactive_ruby/test_app/templates/assets/javascripts/application.rb
265
- - lib/generators/reactive_ruby/test_app/templates/assets/javascripts/components.rb
266
- - lib/generators/reactive_ruby/test_app/templates/boot.rb
267
- - lib/generators/reactive_ruby/test_app/templates/script/rails
268
- - lib/generators/reactive_ruby/test_app/templates/views/components/hello_world.rb
269
- - lib/generators/reactive_ruby/test_app/templates/views/components/todo.rb
270
- - lib/generators/reactive_ruby/test_app/test_app_generator.rb
271
251
  - lib/rails-helpers/top_level_rails_component.rb
272
252
  - lib/reactive-ruby.rb
273
253
  - lib/reactive-ruby/api.rb
@@ -1,11 +0,0 @@
1
- require File.expand_path('../boot', __FILE__)
2
-
3
- require 'rails/all'
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 'reactive-ruby'
10
-
11
- <%= application_definition %>
@@ -1,2 +0,0 @@
1
- require 'components'
2
- require 'react_ujs'
@@ -1,3 +0,0 @@
1
- require 'opal'
2
- require 'reactive-ruby'
3
- require_tree './components'
@@ -1,6 +0,0 @@
1
- require 'rubygems'
2
- gemfile = File.expand_path("<%= gemfile_path %>", __FILE__)
3
-
4
- ENV['BUNDLE_GEMFILE'] = gemfile
5
- require 'bundler'
6
- Bundler.setup
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- APP_PATH = File.expand_path('../../config/application', __FILE__)
4
- require File.expand_path('../../config/boot', __FILE__)
5
- require 'rails/commands'
@@ -1,11 +0,0 @@
1
- module Components
2
- class HelloWorld
3
- include React::Component
4
-
5
- def render
6
- div do
7
- "Hello, World!".span
8
- end
9
- end
10
- end
11
- end
@@ -1,14 +0,0 @@
1
- module Components
2
- class Todo
3
- include React::Component
4
- export_component
5
-
6
- params do
7
- requires :todo
8
- end
9
-
10
- def render
11
- li { "#{params[:todo]}" }
12
- end
13
- end
14
- end
@@ -1,105 +0,0 @@
1
- require 'rails/generators/rails/app/app_generator'
2
-
3
- module ReactiveRuby
4
- class TestAppGenerator < ::Rails::Generators::Base
5
- def self.source_paths
6
- paths = self.superclass.source_paths
7
- paths << File.expand_path('../templates', __FILE__)
8
- paths.flatten
9
- end
10
-
11
- def remove_existing_app
12
- remove_dir(test_app_path) if File.directory?(test_app_path)
13
- end
14
-
15
- def generate_test_app
16
- opts = options.dup
17
- opts[:database] = 'sqlite3' if opts[:database].blank?
18
- opts[:force] = true
19
- opts[:skip_bundle] = true
20
-
21
- puts "Generating Test Rails Application..."
22
- invoke ::Rails::Generators::AppGenerator,
23
- [ File.expand_path(test_app_path, destination_root) ], opts
24
- end
25
-
26
- def configure_test_app
27
- template 'boot.rb', "#{test_app_path}/config/boot.rb", force: true
28
- template 'application.rb', "#{test_app_path}/config/application.rb", force: true
29
- template 'assets/javascripts/application.rb',
30
- "#{test_app_path}/app/assets/javascripts/application.rb", force: true
31
- template 'assets/javascripts/components.rb',
32
- "#{test_app_path}/app/views/components.rb", force: true
33
- template 'views/components/hello_world.rb',
34
- "#{test_app_path}/app/views/components/hello_world.rb", force: true
35
- template 'views/components/todo.rb',
36
- "#{test_app_path}/app/views/components/todo.rb", force: true
37
- end
38
-
39
- def clean_superfluous_files
40
- inside test_app_path do
41
- remove_file '.gitignore'
42
- remove_file 'doc'
43
- remove_file 'Gemfile'
44
- remove_file 'lib/tasks'
45
- remove_file 'app/assets/images/rails.png'
46
- remove_file 'app/assets/javascripts/application.js'
47
- remove_file 'public/index.html'
48
- remove_file 'public/robots.txt'
49
- remove_file 'README.rdoc'
50
- remove_file 'test'
51
- remove_file 'vendor'
52
- remove_file 'spec'
53
- end
54
- end
55
-
56
- def configure_opal_rspec
57
- inject_into_file "#{test_app_path}/config/application.rb",
58
- after: /class Application < Rails::Application/, verbose: true do
59
- %Q[
60
- config.opal.method_missing = true
61
- config.opal.optimized_operators = true
62
- config.opal.arity_check = false
63
- config.opal.const_missing = true
64
- config.opal.dynamic_require_severity = :ignore
65
- config.opal.enable_specs = true
66
- config.opal.spec_location = 'spec-opal'
67
- ]
68
- end
69
- end
70
-
71
- protected
72
-
73
- def application_definition
74
- @application_definition ||= begin
75
- test_application_contents
76
- end
77
- end
78
- alias :store_application_definition! :application_definition
79
-
80
- private
81
-
82
- def test_app_path
83
- 'spec/test_app'
84
- end
85
-
86
- def test_application_path
87
- File.expand_path("#{test_app_path}/config/application.rb",
88
- destination_root)
89
- end
90
-
91
- def test_application_contents
92
- return unless File.exists?(test_application_path) && !options[:pretend]
93
- contents = File.read(test_application_path)
94
- contents[(contents.index("module #{module_name}"))..-1]
95
- end
96
-
97
- def module_name
98
- 'TestApp'
99
- end
100
-
101
- def gemfile_path
102
- '../../../../Gemfile'
103
- end
104
- end
105
- end