opal-connect 0.0.18 → 0.0.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f2e57162da7ac4bd3fc41ada4606bd64205fcad1
4
- data.tar.gz: 0bb2a2454b6940f77fdfb0557a89328cf5063019
3
+ metadata.gz: fe1ee2bd589bcae56d268c56765f46280bfd0146
4
+ data.tar.gz: 3a614ea3d01482ac6509f07afd9db3be40019670
5
5
  SHA512:
6
- metadata.gz: 1ab4f5a1339d0b8a55ec6bae2d91a3eab616e3262ee007b9529f21d42be1239ca134733e3adc0397c52cb067dda7129b85c7622dbb7310ee3b801bd20ee94543
7
- data.tar.gz: cee41da3f156eb5777a24eeb4ca9721f986b4313032ae62b13ab31318b017aadf0d01cb79ad21f0dfc65bf6521216a021a29b6a94d5b2a0ff47315cec622b6fd
6
+ metadata.gz: 4e9db48b0348df56b6fa68d7c6728e7c460034f615f6fa4c648f554221717d1988673354b9521c42473d385f076bf5576dd8ee3ce3374c96a2d034aa49ee45c4
7
+ data.tar.gz: fe3bb40b23e8b24678e03afc7b8330beef3358100ca87e39557512e475a391767daddaf416868749acc697eda379a3dc267104b45f8d86bafcef7b83e1ceea8f
data/Gemfile CHANGED
@@ -1,10 +1,13 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem 'roda', '2.14.0'
4
+ gem 'roda-sprocket_assets', '0.0.9'
4
5
  gem 'thin', '1.6.4'
5
6
  gem 'rack-unreloader', '1.5.0'
6
7
  gem 'rack-livereload'
7
- # gem 'opal-rspec', github: 'opal/opal-rspec'
8
+ gem 'rspec'
9
+ gem 'opal-connect-rspec'
10
+ gem 'opal', '0.10.0'
8
11
  gem 'pry'
9
12
  gem 'awesome_print'
10
13
 
data/Makefile CHANGED
@@ -1,2 +1,4 @@
1
1
  server:
2
- bundle exec rake webpack:run& bundle exec thin start --port=3000
2
+ bundle exec rake webpack:run& bundle exec thin start --port=3001
3
+ run:
4
+ bundle exec thin start --port=3001
data/Rakefile CHANGED
@@ -7,3 +7,11 @@ require 'opal-connect'
7
7
  require 'opal/connect/rake_task'
8
8
 
9
9
  Opal::Connect::RakeTask.new('webpack')
10
+
11
+ require 'opal/rspec/rake_task'
12
+ Opal::RSpec::RakeTask.new('opal:rspec') do |s|
13
+ s.index_path = 'spec/index.html.erb'
14
+ end
15
+
16
+ require 'rspec/core/rake_task'
17
+ RSpec::Core::RakeTask.new('ruby:rspec')
data/app/app.rb CHANGED
@@ -2,14 +2,18 @@ require_relative 'config/connect'
2
2
 
3
3
  class App < Roda
4
4
  plugin :assets,
5
- path: '.connect/output',
5
+ path: '',
6
6
  css_dir: '',
7
7
  js_dir: '',
8
8
  group_subdirs: false,
9
9
  gzip: true,
10
- js: { connect: [ 'opal.js', 'connect.js' ] }
10
+ js_opts: { builder: Opal::Connect.builder },
11
+ js: {
12
+ app: ['node_modules/jquery/dist/jquery.js', '.connect/opal.js', '.connect/connect.js', '.connect/entry.rb'],
13
+ rspec: ['.connect/rspec.js', '.connect/rspec_tests.js']
14
+ }
11
15
 
12
- use Rack::LiveReload
16
+ # use Rack::LiveReload
13
17
 
14
18
  route do |r|
15
19
  r.assets
@@ -17,5 +21,9 @@ class App < Roda
17
21
  r.root do
18
22
  Components::Example.scope(self).render :display
19
23
  end
24
+
25
+ r.on "rspec" do
26
+ Opal::Connect.run_rspec
27
+ end
20
28
  end
21
29
  end
@@ -0,0 +1,2 @@
1
+ //=require opal.js
2
+ //=require output/connect.js
@@ -0,0 +1 @@
1
+ //=require rspec.js
@@ -3,7 +3,7 @@ class App
3
3
  class Example
4
4
  include Opal::Connect
5
5
 
6
- def display
6
+ setup do
7
7
  dom.set! html! {
8
8
  html do
9
9
  head do
@@ -16,14 +16,23 @@ class App
16
16
  end
17
17
  }
18
18
 
19
+ dom.find('html').append assets([:js, :app])
20
+
21
+ dom.save!
22
+ end unless RUBY_ENGINE == 'opal'
23
+
24
+ def display
19
25
  if RUBY_ENGINE == 'opal'
20
26
  dom.find('body').append 'cow'
21
- else
22
- dom.find('html').append assets([:js, :connect])
23
27
  end
24
28
 
25
29
  dom
26
30
  end
31
+
32
+ def moo
33
+ dom.find('body').append 'cow'
34
+ 'cow'
35
+ end
27
36
  end
28
37
  end
29
38
  end
File without changes
data/app/config/boot.rb CHANGED
@@ -1,4 +1,4 @@
1
- $:.unshift './app'
1
+ $:.unshift Dir.pwd
2
2
  $:.unshift './lib'
3
3
 
4
4
  require 'bundler'
@@ -16,3 +16,5 @@ Unreloader.require './lib/opal/connect.rb'
16
16
  Unreloader.require 'app/config/connect'
17
17
  Unreloader.require 'app'
18
18
  Unreloader.require 'app/components/**/*.rb'
19
+
20
+ Opal::Connect.setup
@@ -1,7 +1,10 @@
1
1
  require 'opal-connect'
2
2
 
3
3
  Opal::Connect.setup do
4
- options[:plugins] = [ :server, :html, :dom, :events, :scope ]
4
+ options[:plugins] = [ :server, :html, :dom, :events ]
5
5
  options[:livereload] = true
6
+
7
+ plugin :scope, App.new('')
8
+ plugin :rspec, code: -> { assets([:js, :app]) + assets([:js, :rspec]) }
6
9
  end
7
10
 
@@ -1,11 +1,3 @@
1
- if RUBY_ENGINE == 'opal'
2
- `require("expose?$!expose?jQuery!jquery/dist/jquery.min.js")`;
3
- else
4
- require 'oga'
5
- end
6
-
7
- require 'opal-jquery'
8
-
9
1
  module Opal
10
2
  module Connect
11
3
  module ConnectPlugins
@@ -42,6 +34,7 @@ module Opal
42
34
  end
43
35
 
44
36
  def cache
37
+ # fix: instead of {} it needs to use ConnectCache.new
45
38
  @cache ||= (Connect.templates[self.name] ||= {})
46
39
  end
47
40
 
@@ -123,7 +116,7 @@ module Opal
123
116
  def save template_name = false, remove = true
124
117
  if template_name
125
118
  cache[:"#{template_name}"] = self.to_html
126
- dom.remove if remove
119
+ dom.remove if !dom.is_a?(Oga::XML::Document) && remove
127
120
  else
128
121
  cache[:html] = self.to_html
129
122
  end
@@ -164,14 +157,28 @@ module Opal
164
157
  end
165
158
  end
166
159
 
167
- def text(content)
168
- if node.respond_to?(:inner_text)
169
- node.inner_text = content
160
+ def text(content = false)
161
+ if content
162
+ if node.respond_to?(:inner_text)
163
+ node.inner_text = content
164
+ else
165
+ node.each { |n| n.inner_text = content }
166
+ end
167
+
168
+ self
170
169
  else
171
- node.each { |n| n.inner_text = content }
170
+ if node.respond_to?(:inner_text)
171
+ node.inner_text
172
+ else
173
+ text = ''
174
+ node.each { |n| text << n.inner_text }
175
+ text
176
+ end
172
177
  end
178
+ end
173
179
 
174
- self
180
+ def val(value = false)
181
+ self.attr('value', value)
175
182
  end
176
183
 
177
184
  def attr(key, value = false)
@@ -0,0 +1,58 @@
1
+ module Opal::Connect
2
+ module ConnectPlugins
3
+ module Modal
4
+ if RUBY_ENGINE == 'opal'
5
+ # `require('expose?RModal!rmodal/dist/rmodal.min.js')`
6
+ # `require('rmodal/dist/rmodal.css')`
7
+ # `require('rmodal/dist/rmodal-no-bootstrap.css')`
8
+
9
+ module InstanceMethods
10
+ def modal(msg = '', options = {})
11
+ style = (options[:style] || {}).map { |k, v| "#{k}: #{v}" }.join(';')
12
+
13
+ dom.find('body').append do
14
+ div id: 'modal', class: "modal #{options[:class]}" do
15
+ div class: 'modal-dialog', style: style do
16
+ div class: 'modal-content' do
17
+ if header = options[:header]
18
+ div header, class: 'modal-header'
19
+ end
20
+ div msg, class: 'modal-body'
21
+
22
+ div class: 'modal-footer' do
23
+ if btn = options[:button]
24
+ button btn, class: 'close btn btn-primary'
25
+ end
26
+ button 'Close', class: 'close btn btn'
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ modal_content = dom.find('#modal .modal-content')
34
+ modal = Native `new RModal(document.getElementById('modal'), {})`
35
+ modal.open
36
+
37
+ modal_content.find('.close.btn').on :click do
38
+ modal.close
39
+ dom.find('#modal').remove
40
+ end
41
+
42
+ # remove the modal if they click on the background
43
+ dom.find('#modal').on(:click) do
44
+ unless modal_content.is(':hover')
45
+ modal.close
46
+ dom.find('#modal').remove
47
+ end
48
+ end
49
+
50
+ modal
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ register_plugin :modal, Modal
57
+ end
58
+ end
@@ -0,0 +1,66 @@
1
+ module Opal::Connect
2
+ module ConnectPlugins
3
+ module ConnectRSpec
4
+ def self.configure(connect, options = {})
5
+ connect.options[:rspec] = { folder: "spec"}.merge options
6
+ end
7
+
8
+ module ConnectClassMethods
9
+ def run_rspec
10
+ read, write = IO.pipe
11
+
12
+ pid = fork do
13
+ read.close
14
+
15
+ rspec_requires = []
16
+ options = Opal::Connect.options[:rspec]
17
+
18
+ Opal.append_path "./#{options[:folder]}"
19
+ $:.unshift "./#{options[:folder]}"
20
+
21
+ require 'rspec'
22
+ require 'opal-rspec'
23
+
24
+ Dir.glob("./#{options[:folder]}/**/*_spec.rb").each do |file|
25
+ rspec_requires << "require '#{file.sub('./', '')}'"
26
+ end
27
+
28
+ Opal::Connect.write_file :rspec, %{
29
+ require 'opal/connect/puts'
30
+ require 'opal/rspec'
31
+ }, "#{::RSpec::Version::STRING}#{Opal::RSpec::VERSION}"
32
+
33
+ File.write "#{Dir.pwd}/.connect/rspec_tests.js", build(%{
34
+ #{rspec_requires.join(';')}
35
+ RSpec::Core::Runner.autorun
36
+ })
37
+
38
+ Dir["#{options[:folder]}/**/*_spec.rb"].each { |file| load file }
39
+ Opal::Connect.setup
40
+ Opal::Connect.write_entry_file(self)
41
+
42
+ string = html! {
43
+ html do
44
+ head { meta charset: 'utf-8' }
45
+ body Class.new {
46
+ include Opal::Connect
47
+ }.instance_exec(&options[:code])
48
+ end
49
+ }
50
+
51
+ Marshal.dump(string, write)
52
+ exit!(0) # skips exit handlers.
53
+ end
54
+
55
+ write.close
56
+ result = read.read
57
+ Process.wait(pid)
58
+ raise "child failed" if result.empty?
59
+ Marshal.load(result)
60
+ end
61
+ end unless RUBY_ENGINE == 'opal'
62
+ end
63
+
64
+ register_plugin :rspec, ConnectRSpec
65
+ end
66
+ end
@@ -24,8 +24,9 @@ module Opal
24
24
  end
25
25
 
26
26
  def server(method = false, *args, &block)
27
- if RUBY_ENGINE != 'opal'
28
-
27
+ if RUBY_ENGINE == 'opal'
28
+ self.new.server(method, *args)
29
+ else
29
30
  if method
30
31
  include method
31
32
  else
@@ -2,49 +2,38 @@ module Opal
2
2
  module Connect
3
3
  class RakeTask
4
4
  include Rake::DSL if defined? Rake::DSL
5
- STUBS = %w'opal native promise console base64 json'
6
5
 
7
6
  def initialize(name = 'webpack', opts = {})
8
7
  namespace name do
9
- return unless defined? Opal.append_path
10
-
11
- Opal::Connect.write_entry_file
12
-
13
- Opal.append_path Dir.pwd
14
-
15
- write_opal_file
16
-
17
- envs = ENV.to_h.merge({
18
- BUNDLE_BIN: true,
19
- CONNECT_STUBS: STUBS.concat(Opal::Config.stubbed_files.to_a).join(','),
20
- OPAL_LOAD_PATH: Opal.paths.join(":"),
21
- OPAL_USE_BUNDLER: true
22
- }).inject({}) { |env, (k, v)| env[k.to_s] = v.to_s; env }
23
-
24
8
  desc "Start webpack"
25
9
  task :run do
10
+ envs = initialize_connect
26
11
  exec(envs, 'webpack --progress --watch')
27
12
  end
28
13
 
29
14
  desc "Build webpack"
30
15
  task :build do
16
+ envs = initialize_connect
31
17
  exec(envs, 'webpack --progress')
32
18
  end
33
19
  end
34
20
  end
35
21
 
36
- def write_opal_file
37
- file_path = "#{Dir.pwd}/.connect"
38
- version_path = "#{file_path}/opal_version"
39
- version = File.exist?(version_path) ? File.read(version_path) : false
22
+ def initialize_connect
23
+ return unless defined? Opal.append_path
40
24
 
41
- if !File.exist?("#{file_path}/opal.js") || !version || (version && version != Opal::VERSION)
42
- builder = Opal::Builder.new
43
- build_str = STUBS.map { |stub| "require '#{stub}'" }.join(";")
44
- builder.build_str(build_str, '(inline)', { dynamic_require_severity: :ignore })
45
- File.write version_path, Opal::VERSION
46
- File.write "#{file_path}/opal.js", builder.to_s
47
- end
25
+ Opal::Connect.write_entry_file
26
+
27
+ code = Opal::Connect::STUBS.map { |stub| "require '#{stub}'" }.join(";")
28
+ stubs = Opal::Config.stubbed_files.to_a
29
+ Opal::Connect.write_file(:opal, code, Opal::VERSION, stubs)
30
+
31
+ ENV.to_h.merge({
32
+ BUNDLE_BIN: true,
33
+ CONNECT_STUBS: "#{Opal::Connect.stubbed_files.join(',')},opal-connect,opal-jquery,opal-rspec",
34
+ OPAL_LOAD_PATH: Opal.paths.join(":"),
35
+ OPAL_USE_BUNDLER: true
36
+ }).inject({}) { |env, (k, v)| env[k.to_s] = v.to_s; env }
48
37
  end
49
38
  end
50
39
  end
@@ -0,0 +1,45 @@
1
+ if RUBY_ENGINE == 'opal'
2
+ module Opal
3
+ module Connect
4
+ module ConnectPlugins
5
+ module Dom
6
+ module ClassMethods
7
+ def dom(selector = false)
8
+ d = Opal::Connect::ConnectPlugins::Dom::Instance.new('html')
9
+ selector = d.find('#rspec-iframe').dom.JS.contents
10
+ Instance.new selector, cache, self
11
+ end
12
+ end
13
+
14
+ module InstanceMethods
15
+ def dom(selector = false)
16
+ d = Opal::Connect::ConnectPlugins::Dom::Instance.new('html')
17
+ selector = d.find('#rspec-iframe').dom.JS.contents
18
+ Instance.new selector, cache, self
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ module RSpecHelpers
28
+ include Opal::Connect::ConnectPlugins::HTML::InstanceMethods
29
+
30
+ def rspec_dom
31
+ Opal::Connect::ConnectPlugins::Dom::Instance.new('html')
32
+ end
33
+ end
34
+
35
+ RSpec.configure do |config|
36
+ config.extend RSpecHelpers
37
+ config.include RSpecHelpers
38
+ config.before(:suite) { Opal::Connect.setup }
39
+
40
+ if RUBY_ENGINE == 'opal'
41
+ config.formatter = ::Opal::RSpec::BrowserFormatter
42
+ config.before { rspec_dom.find('body').append html! { iframe id: 'rspec-iframe' } }
43
+ config.after { rspec_dom.find('#rspec-iframe').remove }
44
+ end
45
+ end
@@ -1,5 +1,5 @@
1
1
  module Opal
2
2
  module Connect
3
- VERSION = "0.0.18"
3
+ VERSION = "0.0.19"
4
4
  end
5
5
  end
data/lib/opal/connect.rb CHANGED
@@ -3,14 +3,21 @@ require 'base64'
3
3
  require "opal/connect/version"
4
4
 
5
5
  if RUBY_ENGINE == 'opal'
6
+ `if(typeof require === 'undefined') { require = function(){} }`
7
+ `require("expose?$!expose?jQuery!jquery/dist/jquery.min.js")`
6
8
  require 'opal/connect/puts'
7
9
  else
10
+ require 'oga'
11
+ require 'opal/patch'
8
12
  Opal.append_path File.expand_path('../..', __FILE__).untaint
9
13
  end
10
14
 
15
+ require 'opal-jquery'
16
+
11
17
  module Opal
12
18
  module Connect
13
19
  CLIENT_OPTIONS = %w'url plugins'
20
+ STUBS = %w'opal native promise console base64 json'
14
21
 
15
22
  class << self
16
23
  attr_accessor :pids
@@ -20,9 +27,10 @@ module Opal
20
27
  livereload: false,
21
28
  url: '/connect',
22
29
  plugins: [],
30
+ plugins_loaded: [],
23
31
  javascript: [],
24
32
  requires: [],
25
- setup_blocks: []
33
+ setup_blocks: {},
26
34
  )
27
35
  end
28
36
 
@@ -30,22 +38,42 @@ module Opal
30
38
  Connect.options.hash.select { |key, _| CLIENT_OPTIONS.include? key.to_s }
31
39
  end
32
40
 
41
+ def stubbed_files
42
+ STUBS.concat(Opal::Config.stubbed_files.to_a)
43
+ end
44
+
45
+ def files
46
+ @_files ||= { connect: ['require "opal-connect"', Connect::VERSION] }
47
+ end
48
+
33
49
  def setup(&block)
34
- if block_given?
50
+ if RUBY_ENGINE != 'opal' && block_given?
51
+ Opal.append_path Dir.pwd unless RUBY_ENGINE == 'opal'
52
+
35
53
  instance_exec(&block)
54
+
36
55
  # make sure we include the default plugins with connect
37
- options[:plugins].each { |plug| Connect.plugin plug }
56
+ options[:plugins].each do |plug|
57
+ unless options[:plugins_loaded].include? plug
58
+ options[:plugins_loaded] << plug
59
+ Connect.plugin(plug)
60
+ end
61
+ end
38
62
  end
39
63
 
40
64
  unless block_given?
41
- options[:setup_blocks].each { |b| b[:klass].instance_exec(&b[:block]) }
65
+ options[:setup_blocks].each do |klass, b|
66
+ klass.instance_exec(&b)
67
+ end
68
+
69
+ options[:setup_blocks] = {}
42
70
  end
43
71
  end
44
72
 
45
73
  def included(klass)
46
74
  if RUBY_ENGINE != 'opal'
47
75
  file = caller[0][/[^:]*/].sub(Dir.pwd, '')[1..-1]
48
- files << file unless files.include?(file)
76
+ included_files << file unless files.include?(file) || file[/^spec/]
49
77
  end
50
78
 
51
79
  klass.extend ConnectPlugins::Base::ClassMethods
@@ -142,11 +170,10 @@ module Opal
142
170
  if RUBY_ENGINE != 'opal'
143
171
  def render(method, *options, &block)
144
172
  code = Connect.javascript(self, method, *options)
145
- js = Opal::Builder.new.build_str(code, '(inline)').to_s
146
173
 
147
174
  Connect.write_entry_file(self, method, *options) if Connect.options[:livereload]
148
175
 
149
- "#{public_send(method, *options, &block)}<script>#{js}</script>"
176
+ "#{public_send(method, *options, &block)}<script>#{Connect.build(code)}</script>"
150
177
  end
151
178
  end
152
179
  end
@@ -159,10 +186,7 @@ module Opal
159
186
  def setup(&block)
160
187
  if block_given?
161
188
  @_setup_block = block
162
- Connect.options[:setup_blocks] << {
163
- block: @_setup_block,
164
- klass: self
165
- }
189
+ Connect.options[:setup_blocks][self] = @_setup_block
166
190
  end
167
191
 
168
192
  @_setup_block
@@ -180,6 +204,7 @@ module Opal
180
204
  raise ConnectError, "Cannot add a plugin to a frozen Connect class" if RUBY_ENGINE != 'opal' && frozen?
181
205
 
182
206
  if plugin.is_a?(Symbol)
207
+ Connect.options[:plugins_loaded] << plugin
183
208
  Connect.options[:plugins] << plugin unless Connect.options[:plugins].include? plugin
184
209
  plugin = ConnectPlugins.load_plugin(plugin)
185
210
  end
@@ -207,19 +232,26 @@ module Opal
207
232
  end
208
233
 
209
234
  if RUBY_ENGINE != 'opal'
210
- def files
211
- @files ||= []
235
+ def included_files
236
+ @_included_files ||= []
237
+ end
238
+
239
+ def builder(stubs = false)
240
+ Opal::Builder.new(
241
+ stubs: stubs || Connect.stubbed_files,
242
+ compiler_options: { dynamic_require_severity: :ignore }
243
+ )
244
+ end
245
+
246
+ def build(code, stubs = false)
247
+ builder(stubs).build_str(code, '(inline)').to_s
212
248
  end
213
249
 
214
250
  def javascript(klass, method, *opts)
215
251
  return unless klass
216
252
 
217
- js = []
218
- options[:javascript].uniq.each { |block| js << klass.instance_exec(&block) }
219
-
220
253
  %{
221
254
  Document.ready? do
222
- #{js.join(';')}
223
255
  klass = #{klass.class.name}.new
224
256
  klass.__send__(:#{method}, *JSON.parse(Base64.decode64('#{Base64.encode64 opts.to_json}'))) if klass.respond_to?(:#{method})
225
257
  end
@@ -227,14 +259,17 @@ module Opal
227
259
  end
228
260
 
229
261
  def write_entry_file(klass = false, method = false, *options)
230
- path = "#{Dir.pwd}/.connect/entry.rb"
231
- files = Connect.files.dup.uniq.map { |file| "require '#{file}'" }.join(';')
262
+ js = []
263
+ path = "#{Dir.pwd}/.connect"
264
+ files = Connect.included_files.dup.uniq.map { |file| "require '#{file}'" }.join(';')
232
265
  entry = Connect.options[:entry]
233
266
  client_options = Base64.encode64 Connect.client_options.to_json
234
267
  plugins = plugin_paths.dup.map { |plugin_path| plugin_path = "require '#{plugin_path}'" }.join(';')
235
268
 
236
- code = %{
237
- require 'opal/connect'
269
+ Connect.options[:javascript].uniq.each { |block| js << klass.instance_exec(&block) } if klass
270
+
271
+ entry_code = %{
272
+ require 'opal-connect'
238
273
  #{plugins}
239
274
  options = JSON.parse(Base64.decode64('#{client_options}'))
240
275
  options.each { |key, value| Opal::Connect.options[key] = value }
@@ -243,10 +278,29 @@ module Opal
243
278
  # make sure we include the default plugins with connect
244
279
  Opal::Connect.options[:plugins].each { |plug| Opal::Connect.plugin plug }
245
280
  Opal::Connect.setup
281
+ #{js.join(';')}
246
282
  }
247
283
 
248
- FileUtils.mkdir_p(File.dirname(path))
249
- File.write(path, code)
284
+ FileUtils.mkdir_p(path)
285
+ File.write("#{path}/entry.rb", entry_code)
286
+
287
+ Connect.files.each { |name, (code, version, stubs)| write_file name, code, version, stubs }
288
+ end
289
+
290
+ def write_file(name, code, current_version, stubs = false)
291
+ path = "#{Dir.pwd}/.connect"
292
+ version_path = "#{path}/#{name}_version"
293
+ version = File.exist?(version_path) ? File.read(version_path) : false
294
+ save_path = "#{path}/#{name}.js"
295
+
296
+ if !File.exist?(save_path) || !version || (version && version != current_version)
297
+ File.write version_path, current_version
298
+ File.write(save_path, build(code, stubs))
299
+ end
300
+ end
301
+
302
+ def read_file(file)
303
+ File.read "#{Dir.pwd}/.connect/#{file}"
250
304
  end
251
305
 
252
306
  def plugin_paths
data/lib/opal/patch.rb ADDED
@@ -0,0 +1,13 @@
1
+ Opal::Processor.instance_eval do
2
+ def stubbed_files
3
+ ::Opal::Config.stubbed_files
4
+ end
5
+
6
+ def stub_file(name)
7
+ ::Opal::Config.stubbed_files << name.to_s
8
+ end
9
+
10
+ def dynamic_require_severity=(value)
11
+ ::Opal::Config.dynamic_require_severity = value
12
+ end
13
+ end
data/opal-connect.gemspec CHANGED
@@ -18,11 +18,11 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "opal", ">= 0.10.0.beta3"
22
- spec.add_dependency "opal-jquery", ">= 0.4.1"
21
+ spec.add_dependency "opal", ">= 0.10.0"
22
+ spec.add_dependency "opal-jquery", ">= 0.4.2"
23
23
  spec.add_dependency "oga", ">= 2.2"
24
24
 
25
25
  spec.add_development_dependency "bundler", "~> 1.7"
26
26
  spec.add_development_dependency "rake", "~> 10.0"
27
- spec.add_development_dependency "opal-rspec", ">= 0.5.0"
27
+ spec.add_development_dependency "opal-connect-rspec", ">= 0.5.0"
28
28
  end
data/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "expose-loader": "^0.7.1",
13
13
  "jquery": "^2.2.3",
14
14
  "livereload": "^0.4.1",
15
- "opal-webpack": "1.0.6",
15
+ "opal-webpack": "1.0.8",
16
16
  "webpack": "2.1.0-beta.7",
17
17
  "webpack-livereload-plugin": "^0.8.1"
18
18
  }
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'components/example' do
4
+ let(:example) { App::Components::Example.new }
5
+
6
+ it 'should say cow when #moo is called' do
7
+ expect(example.moo).to eq 'cow'
8
+ expect(example.dom.find('body').text).to eq 'cow'
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Opal Server</title>
6
+ </head>
7
+ <body>
8
+ <%= javascript_include_tag @server.main %>
9
+ </body>
10
+ </html>
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ class DomTest
4
+ include Opal::Connect
5
+
6
+ setup do
7
+ dom.set! html! {
8
+ html do
9
+ head do
10
+ meta charset: 'utf-8'
11
+ end
12
+
13
+ body do
14
+ div do
15
+ ul class: 'list' do
16
+ li {}
17
+ end
18
+ end
19
+ end
20
+ end
21
+ }
22
+
23
+ dom.save! :html, false
24
+ end unless RUBY_ENGINE == 'opal'
25
+ end
26
+
27
+ describe 'plugin :dom' do
28
+ context 'ClassMethods' do
29
+ subject { DomTest }
30
+
31
+ it { is_expected.to respond_to :dom }
32
+ it { is_expected.to respond_to :cache }
33
+ it { is_expected.to respond_to :html }
34
+
35
+ unless RUBY_ENGINE == 'opal'
36
+ it { is_expected.to respond_to :html_file }
37
+ end
38
+ end
39
+
40
+ context 'InstanceMethods' do
41
+ subject { DomTest.new }
42
+
43
+ it { is_expected.to respond_to :dom }
44
+ it { is_expected.to respond_to :cache }
45
+ it { is_expected.to respond_to :element }
46
+
47
+ describe '#dom' do
48
+ let(:dom) { RUBY_ENGINE == 'opal' ? subject.dom.tmpl(:html) : subject.dom }
49
+
50
+ it '#append' do
51
+ dom.find('ul').append '<li>appended</li>'
52
+ expect(dom.find('ul li').length).to eq 2
53
+ expect(dom.find('ul li:last-child').text).to eq 'appended'
54
+ end
55
+
56
+ it '#prepend' do
57
+ dom.find('ul').prepend '<li>prepended</li>'
58
+ expect(dom.find('ul li').length).to eq 2
59
+ expect(dom.find('ul li:first-child').text).to eq 'prepended'
60
+ end
61
+
62
+ it '#remove' do
63
+ dom.find('ul li').remove
64
+ expect(dom.find('ul li').length).to eq 0
65
+ end
66
+
67
+ it '#attr' do
68
+ ul = dom.find('ul')
69
+ ul.attr('foo', 'bar')
70
+ ul.attr('number', 1)
71
+
72
+ expect(ul.attr('class')).to eq 'list'
73
+ expect(ul.attr('foo')).to eq 'bar'
74
+ expect(ul.attr('number')).to eq '1'
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,6 @@
1
+ unless RUBY_ENGINE == 'opal'
2
+ require 'rspec'
3
+ require './app/config/boot'
4
+ end
5
+
6
+ require 'opal/connect/rspec'
data/webpack.config.js CHANGED
@@ -1,11 +1,20 @@
1
- const path = require("path");
2
- const LiveReloadPlugin = require('webpack-livereload-plugin');
3
- const stubs = process.env.CONNECT_STUBS.split(',');
1
+ const path = require("path");
2
+ const LiveReloadPlugin = require('webpack-livereload-plugin');
3
+ const stubs = process.env.CONNECT_STUBS.split(',');
4
+ const WatchIgnorePlugin = require("webpack").WatchIgnorePlugin;
4
5
 
5
6
  module.exports = {
7
+ resolve: {
8
+ extensions: ['', '.js', '.css', '.rb'],
9
+ alias: {
10
+ app: path.resolve(__dirname, "app"),
11
+ spec: path.resolve(__dirname, "spec")
12
+ }
13
+ },
6
14
  entry: {
7
- opal: './.connect/opal.js',
8
- connect: './.connect/entry.rb',
15
+ connect: ['./.connect/opal.js', './.connect/connect.js'],
16
+ app: './.connect/entry.rb',
17
+ rspec: './.connect/rspec.js'
9
18
  },
10
19
  output: {
11
20
  path: path.resolve(__dirname, ".connect", "output"),
@@ -15,15 +24,15 @@ module.exports = {
15
24
  test: /\.rb$/,
16
25
  loaders: [
17
26
  {
18
- exclude: /node_modules|\.connect\/(opal|cache)/,
27
+ exclude: /node_modules|\.connect\/(opal|cache|connect|rspec|output)/,
19
28
  loader: "opal-webpack",
20
29
  query: { dynamic_require_severity: 'ignore' }
21
30
  }
22
31
  ]
23
32
  },
24
- watchOptions: { poll: true },
33
+ // watchOptions: { poll: true, lazy: true },
25
34
  plugins: [
26
- new LiveReloadPlugin({ ignore: '.connect' })
35
+ new LiveReloadPlugin({ ignore: /entry\.rb/ }),
27
36
  ],
28
37
  opal: {
29
38
  stubs: stubs,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-connect
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.18
4
+ version: 0.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - cj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-18 00:00:00.000000000 Z
11
+ date: 2016-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.10.0.beta3
19
+ version: 0.10.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.10.0.beta3
26
+ version: 0.10.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: opal-jquery
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.4.1
33
+ version: 0.4.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 0.4.1
40
+ version: 0.4.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: oga
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '10.0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: opal-rspec
84
+ name: opal-connect-rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -108,7 +108,10 @@ files:
108
108
  - README.md
109
109
  - Rakefile
110
110
  - app/app.rb
111
+ - app/assets/js/app.js
112
+ - app/assets/js/app.rspec.js
111
113
  - app/components/example.rb
114
+ - app/components/test.css
112
115
  - app/config/boot.rb
113
116
  - app/config/connect.rb
114
117
  - config.ru
@@ -120,14 +123,22 @@ files:
120
123
  - lib/opal/connect/plugins/events.rb
121
124
  - lib/opal/connect/plugins/form.rb
122
125
  - lib/opal/connect/plugins/html.rb
126
+ - lib/opal/connect/plugins/modal.rb
123
127
  - lib/opal/connect/plugins/pjax.rb
128
+ - lib/opal/connect/plugins/rspec.rb
124
129
  - lib/opal/connect/plugins/scope.rb
125
130
  - lib/opal/connect/plugins/server.rb
126
131
  - lib/opal/connect/puts.rb
127
132
  - lib/opal/connect/rake_task.rb
133
+ - lib/opal/connect/rspec.rb
128
134
  - lib/opal/connect/version.rb
135
+ - lib/opal/patch.rb
129
136
  - opal-connect.gemspec
130
137
  - package.json
138
+ - spec/example_spec.rb
139
+ - spec/index.html.erb
140
+ - spec/plugins/dom_spec.rb
141
+ - spec/spec_helper.rb
131
142
  - webpack.config.js
132
143
  homepage: ''
133
144
  licenses:
@@ -149,8 +160,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
160
  version: '0'
150
161
  requirements: []
151
162
  rubyforge_project:
152
- rubygems_version: 2.4.5.1
163
+ rubygems_version: 2.5.1
153
164
  signing_key:
154
165
  specification_version: 4
155
166
  summary: Connects Opal to Ruby.
156
- test_files: []
167
+ test_files:
168
+ - spec/example_spec.rb
169
+ - spec/index.html.erb
170
+ - spec/plugins/dom_spec.rb
171
+ - spec/spec_helper.rb