wedge 0.1.3 → 0.1.5

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: bec19fa97267952287dd19eb59c0ef60ea1ec798
4
- data.tar.gz: 99539718ec725a14caada41cb292ebc2d607c706
3
+ metadata.gz: ac3731821b07863c0126576d57b06874e3bfec63
4
+ data.tar.gz: b0d87766926902c7b17e26cd5e1ac007efed2a91
5
5
  SHA512:
6
- metadata.gz: b6291df78a9eb3c351d65013afb6719f59a4d08f7b5edffc674aeb7fd53ebf8481020977d47dcb36588c17760398c7d28b6e978fa875a861d062c8a0dfebe0fc
7
- data.tar.gz: d27efe62f63e0f26e833541ae466042f81fb20dfbbd8f7f83441ea97d658d458b50e0aa3d66b1f8443b356365b700e8ae2a8b911c7cb6972dc38db9477ba7360
6
+ metadata.gz: 13daa53b74eb6a37c688d24c74612519deea48f08a4fe89a87bebb90f538914e5735bdc9d59d6876a68c2eaae06ddd862d5827a491db9a8a153adf096abb98d7
7
+ data.tar.gz: 0f86a4b29929e42e6efc10907d5fc9b2ae856e7e80be843e1fd629fb2585bc05dfc5236156374141230efc0ae8bbdbd84b4d6615d05b65119681d890265018c6
@@ -45,8 +45,12 @@ class Wedge
45
45
  "#{config.assets_url}#{config.cache_assets ? "/#{config.assets_key}" : ''}"
46
46
  end
47
47
 
48
- def html!(&b)
49
- DOM.new HTML::DSL.html(&b).to_html
48
+ def html!(scope = false, &block)
49
+ if !block_given?
50
+ DOM.new HTML::DSL.html(&scope).to_html
51
+ else
52
+ DOM.new HTML::DSL.scope!(scope).html(&block).to_html
53
+ end
50
54
  end
51
55
 
52
56
  def script_tag
@@ -139,7 +143,7 @@ class Wedge
139
143
 
140
144
  if server?
141
145
  javascript_cache[path_name] ||= begin
142
- js = build(path_name, options).javascript
146
+ js = options.delete(:js) || build(path_name, options).javascript
143
147
 
144
148
  if path_name == 'wedge'
145
149
  compiled_data = Base64.encode64 config.client_data.to_json
@@ -151,6 +155,7 @@ class Wedge
151
155
  js << Wedge.javascript(path)
152
156
  end
153
157
  elsif comp_class = Wedge.config.component_class[path_name.gsub(/\//, '__')]
158
+ comp_class.config.before_compile.each { |blk| comp_class.instance_eval(&blk) }
154
159
  comp_name = comp_class.config.name
155
160
  compiled_data = Base64.encode64 comp_class.config.client_data.to_json
156
161
 
@@ -166,10 +171,15 @@ class Wedge
166
171
  cache = options[:cache_assets]
167
172
 
168
173
  `jQuery.ajax({ url: url, dataType: "script", cache: cache }).done(function() {`
174
+ # fix: at the moment to_js called from the server will set the class
175
+ # store for whatever method it calls. we need to think of a better idea
176
+ # for global and local data store.
177
+ Wedge.config.component_class[options[:name]].config.store = options[:store].indifferent
178
+
169
179
  if initialize_args = options.delete(:initialize_args)
170
- comp = Wedge.store!(options[:store].indifferent)[options[:name], *initialize_args]
180
+ comp = Wedge[options[:name], *initialize_args]
171
181
  else
172
- comp = Wedge.store!(options[:store].indifferent)[options[:name]]
182
+ comp = Wedge[options[:name]]
173
183
  end
174
184
 
175
185
  if options[:method_args].any?
@@ -16,8 +16,10 @@ class Wedge
16
16
  end
17
17
  end
18
18
 
19
- obj.config.before_compile.each do |blk|
20
- obj.instance_exec &blk
19
+ unless RUBY_ENGINE == 'opal'
20
+ obj.config.before_compile.each do |blk|
21
+ obj.instance_exec &blk
22
+ end
21
23
  end
22
24
 
23
25
  if args.length > 0
@@ -208,7 +210,7 @@ class Wedge
208
210
 
209
211
  def html!(&b)
210
212
  unless RUBY_ENGINE == 'opal'
211
- Wedge.html!(&b)
213
+ Wedge.html!(self, &b)
212
214
  end
213
215
  end
214
216
 
@@ -308,7 +310,11 @@ class Wedge
308
310
  return unless server?
309
311
 
310
312
  client_data = config.client_data.dup
311
- client_data.merge! method_called: method, method_args: args, initialize_args: config.initialize_args
313
+ client_data.merge!(
314
+ method_called: method,
315
+ method_args: args,
316
+ initialize_args: config.initialize_args
317
+ )
312
318
 
313
319
  compiled_opts = Base64.encode64 client_data.to_json
314
320
  javascript = <<-JS
@@ -331,7 +337,7 @@ class Wedge
331
337
  end
332
338
 
333
339
  def wedge_html(&b)
334
- Wedge.html!(&b)
340
+ Wedge.html!(self, &b)
335
341
  end
336
342
  alias_method :html!, :wedge_html
337
343
 
@@ -28,6 +28,15 @@ class Wedge
28
28
  end
29
29
  end
30
30
 
31
+ TAGS = %w{a button abbr acronym address applet area article aside audio b base basefont bdi
32
+ bdo big blockquote body br canvas caption center cite code col colgroup command
33
+ datalist dd del details dfn dialog dir div dl dt em embed fieldset figcaption
34
+ figure font footer form frame frameset h1 head header hgroup hr html i iframe
35
+ img input ins kbd keygen label legend li link map mark menu meta meter nav noframes
36
+ noscript object ol optgroup option output p param pre progress q rp rt ruby s samp
37
+ script section select small source span strike strong style sub summary sup table tbody
38
+ td textarea tfoot th thead time title tr track tt u ul var video wbr}
39
+
31
40
  # http://erikonrails.snowedin.net/?p=379
32
41
  class DSL
33
42
  def initialize(tag, *args, &block)
@@ -55,13 +64,31 @@ class Wedge
55
64
  end
56
65
 
57
66
  def method_missing(tag, *args, &block)
58
- child = DSL.new(tag.to_s, *args, &block)
59
- children << child
60
- child
67
+ if !TAGS.include?(tag.to_s) && scope.respond_to?(tag, true)
68
+ scope.send(tag, *args, &block)
69
+ else
70
+ child = DSL.scope!(scope).new(tag.to_s, *args, &block)
71
+ children << child
72
+ child
73
+ end
74
+ end
75
+
76
+ def scope
77
+ self.class.scope
61
78
  end
62
79
 
63
80
  def self.method_missing(tag, *args, &block)
64
- DSL.new(tag.to_s, *args, &block)
81
+ DSL.scope!(scope).new(tag.to_s, *args, &block)
82
+ end
83
+
84
+ class << self
85
+ attr_accessor :scope
86
+
87
+ def scope! scope
88
+ klass = Class.new(self)
89
+ klass.instance_variable_set(:@scope, scope)
90
+ klass
91
+ end
65
92
  end
66
93
  end
67
94
  end
@@ -37,35 +37,34 @@ class Wedge
37
37
  body << File.read("#{ROOT_PATH}/#{wedge_path}.rb")
38
38
  end if Wedge.config.debug
39
39
  when 'call'
40
- body_data = request.body.read
41
- data = request.params
40
+ body_data = request.body.read
41
+ data = request.params
42
42
 
43
+ begin
44
+ # try json
45
+ data.merge!(body_data ? JSON.parse(body_data) : {})
46
+ rescue
43
47
  begin
44
- # try json
45
- data.merge!(body_data ? JSON.parse(body_data) : {})
48
+ # try form data
49
+ data.merge!(body_data ? Rack::Utils.parse_query(body_data) : {})
46
50
  rescue
47
- begin
48
- # try form data
49
- data.merge!(body_data ? Rack::Utils.parse_query(body_data) : {})
50
- rescue
51
- # no data
52
- end
51
+ # no data
53
52
  end
53
+ end
54
54
 
55
- data = data.indifferent
56
- name = data.delete(:__wedge_name__)
57
- method_called = data.delete(:__wedge_method__)
58
- method_args = data.delete(:__wedge_args__)
55
+ data = data.indifferent
56
+ name = data.delete(:__wedge_name__)
57
+ method_called = data.delete(:__wedge_method__)
58
+ method_args = data.delete(:__wedge_args__)
59
59
 
60
- binding.pry
61
60
  if method_args == '__wedge_data__' && data
62
61
  method_args = [data]
63
- body << Wedge.scope!(app)[name].send(method_called, *method_args) || ''
62
+ res = Wedge.scope!(self)[name].send(method_called, *method_args) || ''
64
63
  else
65
64
  # This used to send things like init, we need a better way to
66
65
  # send client config data to the server
67
66
  # res = scope.wedge(name, data).send(method_called, *method_args) || ''
68
- body << Wedge.scope!(app)[name].send(method_called, *method_args) || ''
67
+ res = Wedge.scope!(self)[name].send(method_called, *method_args) || ''
69
68
  end
70
69
 
71
70
  # headers["WEDGE-CSRF-TOKEN"] = scope.csrf_token if scope.methods.include? :csrf_token
@@ -92,6 +91,10 @@ class Wedge
92
91
  end
93
92
  end
94
93
 
94
+ def wedge(*args, &block)
95
+ Wedge[*args, &block]
96
+ end
97
+
95
98
  private
96
99
 
97
100
  def path
@@ -5,7 +5,7 @@ class Wedge
5
5
  before_compile do
6
6
  settings = Wedge.config.settings[:uploader]
7
7
  store[:settings] = settings.select do |k, v|
8
- client?? %w(aws_access_key_id bucket).include?(k) : true
8
+ client? ? %w(aws_access_key_id bucket).include?(k) : true
9
9
  end if settings
10
10
  end
11
11
 
@@ -82,7 +82,7 @@ class Wedge
82
82
  key = options.delete(:aws_name) || '{name}-{uuid}'
83
83
 
84
84
  # add s3 container
85
- el.after drag_n_drop_tmpl template_id
85
+ el.after drag_n_drop_tmpl template_id, options
86
86
  el.after "<div id='#{container_id}'></div>"
87
87
 
88
88
  container = dom.find("##{container_id}")
@@ -221,12 +221,12 @@ class Wedge
221
221
  end
222
222
  end
223
223
 
224
- def drag_n_drop_tmpl id
224
+ def drag_n_drop_tmpl id, options = {}
225
225
  <<-EOF
226
226
  <script type="text/template" id="#{id}">
227
227
  <div class="qq-uploader-selector qq-uploader">
228
228
  <div class="qq-upload-button-selector qq-upload-button">
229
- <div>Upload a file</div>
229
+ <div>#{options.delete(:button_name) || 'Upload a file'}</div>
230
230
  </div>
231
231
  <div class="qq-upload-drop-area-selector qq-upload-drop-area" qq-hide-dropzone>
232
232
  <span>Drop file here to upload</span> </div>
@@ -260,10 +260,7 @@ class Wedge
260
260
  end
261
261
 
262
262
  def settings
263
- @settings ||= {
264
- aws_access_key_id: 123456,
265
- bucket: 'wedge'
266
- }
263
+ @settings ||= store[:settings]
267
264
  end
268
265
  end
269
266
  end
@@ -1,3 +1,3 @@
1
1
  class Wedge
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.5'
3
3
  end
@@ -8,7 +8,17 @@ class Playground
8
8
  set_dom dom.find('body').html
9
9
  end
10
10
 
11
+ def initialize
12
+ store[:foo] = 'bar' if server?
13
+ end
14
+
11
15
  def display
16
+ # todo: make a test for this:
17
+ # puts html! {
18
+ # if foo = store[:foo]
19
+ # div foo
20
+ # end
21
+ # }.to_html
12
22
  wedge(:layout).display { dom }
13
23
  end
14
24
 
@@ -18,7 +18,7 @@ describe Playground::UploaderComponent do
18
18
 
19
19
  context 'browser_events' do
20
20
  before do
21
- Wedge::Plugins::Uploader.any_instance.stub(:settings).and_return({
21
+ allow_any_instance_of(Wedge::Plugins::Uploader).to receive(:settings).and_return({
22
22
  aws_access_key_id: 123456,
23
23
  bucket: 'wedge'
24
24
  })
@@ -4,6 +4,7 @@ if RUBY_ENGINE == 'opal'
4
4
  require 'opal/jquery'
5
5
  require 'opal/jquery/rspec'
6
6
  else
7
+
7
8
  ENV['RACK_ENV'] ||= 'test'
8
9
 
9
10
  $:.unshift(File.expand_path("../lib", File.dirname(__FILE__)))
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+ require 'wedge/plugins/uploader'
3
+
4
+ describe Wedge::Plugins::Uploader do
5
+ before do
6
+ allow(Wedge.config).to receive(:settings).and_return(
7
+ uploader: {
8
+ aws_access_key_id: 123456,
9
+ aws_secret_access_key: 654321,
10
+ bucket: 'wedge'
11
+ }
12
+ )
13
+ end
14
+
15
+ subject(:uploader) { Wedge[:uploader_plugin] }
16
+
17
+ context 'store#settings' do
18
+ it 'should have the correct settings' do
19
+ settings = uploader.config.store[:settings]
20
+
21
+ if Wedge.server?
22
+ expect(settings.keys).to include *%w'aws_access_key_id aws_secret_access_key bucket'
23
+ else
24
+ # expect(settings.keys).to include *%w'aws_access_key_id bucket'
25
+ # expect(settings.keys).not_to include *%w'aws_secret_access_key'
26
+ end
27
+ end
28
+ end
29
+ end
@@ -24,7 +24,6 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.add_development_dependency 'minitest-line'
26
26
  spec.add_development_dependency 'minitest-reporters'
27
- spec.add_development_dependency 'opal-rspec'
28
27
  spec.add_development_dependency 'rspec'
29
28
  spec.add_development_dependency "pry"
30
29
  spec.add_development_dependency "rake"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wedge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - cj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-20 00:00:00.000000000 Z
11
+ date: 2015-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal
@@ -80,20 +80,6 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: opal-rspec
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: rspec
99
85
  requirement: !ruby/object:Gem::Requirement
@@ -271,7 +257,7 @@ files:
271
257
  - spec/playground/layout_spec.rb
272
258
  - spec/playground/uploader_spec.rb
273
259
  - spec/spec_helper.rb
274
- - test.rb
260
+ - spec/wedge/plugins/uploader_spec.rb
275
261
  - test/test.js
276
262
  - test/test_basic_component.rb
277
263
  - test/test_browserio.rb
@@ -306,6 +292,7 @@ test_files:
306
292
  - spec/playground/layout_spec.rb
307
293
  - spec/playground/uploader_spec.rb
308
294
  - spec/spec_helper.rb
295
+ - spec/wedge/plugins/uploader_spec.rb
309
296
  - test/test.js
310
297
  - test/test_basic_component.rb
311
298
  - test/test_browserio.rb
data/test.rb DELETED
@@ -1,44 +0,0 @@
1
- require 'awesome_print'
2
-
3
- requires = {
4
- form_plugin: [],
5
- list: [
6
- {
7
- name: 'claim',
8
- requires: [
9
- {name: 'filter_form', requires: [{ name: 'form_plugin', requires: [] }]},
10
- {name: 'claim_form', requires: []}
11
- ],
12
- },
13
- {
14
- name: 'claim_form',
15
- requires: [
16
- {name: 'form_plugin', requires: []},
17
- {name: 'address_form', requires: [{ name: 'form_plugin', requires: [] }]}
18
- ],
19
- }
20
- ]
21
- }
22
-
23
- $loaded_requires = []
24
-
25
- def get_requires reqs, requires_array = []
26
- new_reqs = []
27
-
28
- reqs.each do |r|
29
- if r[:requires].any?
30
- get_requires(r[:requires], requires_array)
31
- end
32
-
33
- unless $loaded_requires.include? r[:name]
34
- $loaded_requires << r[:name]
35
- new_reqs << r[:name]
36
- end
37
- end
38
-
39
- requires_array << new_reqs if new_reqs.any?
40
-
41
- requires_array
42
- end
43
-
44
- ap get_requires requires[:list]