breezy 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/lib/assets/javascript/breezy.js +6067 -0
  3. data/lib/breezy.rb +0 -7
  4. data/lib/breezy/configuration.rb +9 -3
  5. data/lib/breezy/helpers.rb +1 -1
  6. data/lib/breezy/render.rb +1 -1
  7. data/lib/breezy/version.rb +1 -1
  8. data/lib/generators/breezy/view/templates/view.js +17 -0
  9. data/lib/generators/breezy/view/templates/view.js.breezy +2 -0
  10. data/lib/generators/breezy/view/templates/view.jsx +21 -0
  11. data/lib/generators/breezy/view/view_generator.rb +40 -7
  12. data/lib/install/mobile.rb +54 -0
  13. data/lib/install/templates/mobile/app.js +84 -0
  14. data/lib/install/templates/mobile/app.json +6 -0
  15. data/lib/install/templates/mobile/package.json +32 -0
  16. data/lib/install/templates/mobile/rn-cli.config.js +4 -0
  17. data/lib/install/templates/web/application.js +62 -0
  18. data/lib/install/web.rb +72 -0
  19. data/lib/tasks/install.rake +46 -0
  20. data/test/render_test.rb +2 -2
  21. data/test/test_helper.rb +2 -0
  22. metadata +37 -48
  23. data/README.md +0 -338
  24. data/lib/assets/javascripts/breezy.coffee +0 -4
  25. data/lib/assets/javascripts/breezy/component_url.coffee +0 -61
  26. data/lib/assets/javascripts/breezy/controller.coffee +0 -197
  27. data/lib/assets/javascripts/breezy/csrf_token.coffee +0 -9
  28. data/lib/assets/javascripts/breezy/doubly_linked_list.coffee +0 -57
  29. data/lib/assets/javascripts/breezy/parallel_queue.coffee +0 -35
  30. data/lib/assets/javascripts/breezy/progress_bar.coffee +0 -139
  31. data/lib/assets/javascripts/breezy/remote.coffee +0 -136
  32. data/lib/assets/javascripts/breezy/snapshot.coffee +0 -100
  33. data/lib/assets/javascripts/breezy/start.coffee +0 -60
  34. data/lib/assets/javascripts/breezy/utils.coffee +0 -174
  35. data/lib/breezy/active_support.rb +0 -21
  36. data/lib/breezy_template.rb +0 -320
  37. data/lib/breezy_template/deferment_extension.rb +0 -48
  38. data/lib/breezy_template/dependency_tracker.rb +0 -47
  39. data/lib/breezy_template/digestor.rb +0 -30
  40. data/lib/breezy_template/handler.rb +0 -43
  41. data/lib/breezy_template/partial_extension.rb +0 -87
  42. data/lib/breezy_template/search_extension.rb +0 -108
  43. data/lib/generators/breezy/install/install_generator.rb +0 -61
  44. data/lib/generators/breezy/install/templates/Default.js.jsx +0 -7
  45. data/lib/generators/breezy/install/templates/View.js.jsx +0 -7
  46. data/lib/generators/breezy/install/templates/boot.js +0 -5
  47. data/lib/generators/breezy/view/templates/view.js.jsx +0 -8
  48. data/test/blade_helper.rb +0 -22
  49. data/test/breezy_template_test.rb +0 -1095
  50. data/test/dependency_tracker_test.rb +0 -66
@@ -1,21 +0,0 @@
1
- # https://github.com/rails/jbuilder/issues/204
2
-
3
- if Rails.version >= '4.1'
4
- module ActiveSupport
5
- module JSON
6
- module Encoding
7
- class JSONGemEncoder
8
- alias_method :original_jsonify, :jsonify
9
-
10
- def jsonify(value)
11
- if ::BreezyTemplate::Template::Digest === value
12
- value
13
- else
14
- original_jsonify(value)
15
- end
16
- end
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,320 +0,0 @@
1
- require 'jbuilder'
2
- require 'digest/md5'
3
- require 'action_view'
4
- require 'breezy_template/digestor'
5
- require 'breezy_template/handler'
6
- require 'breezy_template/partial_extension'
7
- require 'breezy_template/deferment_extension'
8
- require 'breezy_template/search_extension'
9
-
10
- module BreezyTemplate
11
- class Template < ::Jbuilder
12
- include PartialDigestor
13
-
14
- prepend PartialExtension
15
- prepend SearchExtension
16
- prepend DefermentExtension
17
-
18
- class << self
19
- attr_accessor :template_lookup_options
20
- end
21
-
22
- self.template_lookup_options = { handlers: [:breezy] }
23
-
24
-
25
- class Digest
26
- def initialize(digest)
27
- @digest = "Breezy.cache(\"#{digest}\")"
28
- end
29
-
30
- def to_json(*)
31
- @digest
32
- end
33
-
34
- def as_json(*)
35
- self
36
- end
37
-
38
- def encode_json(*)
39
- @digest
40
- end
41
- end
42
-
43
- def initialize(context, *args)
44
- @context = context
45
- @js = []
46
- @path = []
47
- super(*args)
48
- end
49
-
50
- def empty!
51
- attributes = @attributes
52
- @attributes = {}
53
- attributes
54
- end
55
-
56
- def _breezy_visit_current(path)
57
- uri = ::URI.parse(@request_path)
58
- qry = ::URI.decode_www_form(uri.query || '') << ["_breezy_filter", path.join('.')]
59
- uri.query = ::URI.encode_www_form(qry)
60
- "Breezy.visit('#{uri}', {async: true, pushState: false});"
61
- end
62
-
63
- def _blank
64
- BLANK
65
- end
66
-
67
- def method_missing(*args)
68
- key = args[0]
69
- @path.push(key)
70
- if ::Kernel.block_given?
71
- args = _args_for_set_with_block(*args)
72
- set!(*args, &::Proc.new)
73
- else
74
- args = _args_for_set(*args)
75
- set!(*args)
76
- end
77
- ensure
78
- @path.pop
79
- end
80
-
81
- def set!(key, value = BLANK, *args)
82
- options = args.first || {}
83
- options = _normalize_options(options)
84
- return super if !_cache_options?(options) && !_deferment_options?(options)
85
-
86
- result = if ::Kernel.block_given?
87
- _ensure_valid_key(key)
88
- _cache(*options[:cache]) { _scope { yield self } }
89
- elsif ::Jbuilder === value
90
- # json.age 32
91
- # json.person another_jbuilder
92
- # { "age": 32, "person": { ... }
93
- _ensure_valid_key(key)
94
- _cache(*options[:cache]) { value.attributes! }
95
- else
96
- # json.age 32
97
- # { "age": 32 }
98
- _ensure_valid_key(key)
99
- _cache(*options[:cache]) { value }
100
- end
101
-
102
- _set_value key, result
103
- end
104
-
105
- def child!(options = {})
106
- return super(&::Proc.new) if !_cache_options?(options)
107
- options = _normalize_options(options)
108
-
109
- @attributes = [] unless ::Array === @attributes
110
- @attributes << _cache(*options[:cache]) {
111
- _scope { yield self }
112
- }
113
- end
114
-
115
- def array!(collection = [], *attributes)
116
- options = attributes.first || {}
117
- options = _normalize_options(options)
118
-
119
- collection = [] if collection.nil?
120
- collection = _prepare_collection_for_map(collection)
121
- array = if ::Kernel.block_given?
122
- _map_collection(collection, options, &::Proc.new)
123
- elsif attributes.any?
124
- _map_collection(collection, options) { |element| extract! element, *attributes }
125
- else
126
- collection.to_a
127
- end
128
-
129
- merge! array #remove this depednacy
130
- end
131
-
132
- def target!
133
- js = _breezy_return(@attributes)
134
- @js.push(js)
135
- "(function(){#{@js.join}})()"
136
- end
137
-
138
- private
139
- def _merge_values(current_value, updates)
140
- # Always use the new values. This is because cached values
141
- # are no longer a Ruby object. They are JS values and can't
142
- # be merged.
143
-
144
- updates
145
- end
146
-
147
- def _prepare_collection_for_map(collection)
148
- collection
149
- end
150
-
151
- def _args_for_set_with_block(*args)
152
- key = args[0]
153
- if ::Hash === args[1] && _extended_options?(args[1])
154
- options = args[1]
155
- [key, BLANK, options]
156
- else
157
- [key, BLANK]
158
- end
159
- end
160
-
161
- def _args_for_set(*args)
162
- if args.length == 3
163
- key, value, options = args
164
-
165
- [key, value, options]
166
- elsif args.length == 2 && _extended_options?(args[1])
167
- options = args[1]
168
- key = args[0]
169
-
170
- [key, BLANK, options]
171
- else
172
- key, value = args
173
-
174
- [key, value]
175
- end
176
- end
177
-
178
- def _extended_options?(value)
179
- _partial_options?(value) || _cache_options?(value) || _deferment_options?(value)
180
- end
181
-
182
- def _mapping_element(element, options)
183
- opts = options.dup
184
- if opts[:cache]
185
- opts[:cache] = opts[:cache].dup
186
-
187
- if ::Array === opts[:cache] && ::Proc === opts[:cache].first
188
- key_proc = opts[:cache][0]
189
- opts[:cache][0] = key_proc.call(element)
190
- end
191
- end
192
- _cache(*opts[:cache]) {
193
- _scope { yield element }
194
- }
195
- end
196
-
197
- def _map_collection(collection, options)
198
- @path.push(nil)
199
- collection.map.with_index do |element, i|
200
- if options.has_key? :key
201
- id_name = options[:key]
202
- id_val = element[id_name]
203
- @path[-1] = "#{id_name}=#{id_val}"
204
- else
205
- @path[-1] = i
206
- end
207
-
208
- _mapping_element(element, options, &::Proc.new)
209
-
210
- end - [BLANK]
211
- ensure
212
- @path.pop
213
- end
214
-
215
- def _cache_key(key, options={})
216
- key = _fragment_name_with_digest(key, options)
217
- key = url_for(key).split('://', 2).last if ::Hash === key
218
- key = ::ActiveSupport::Cache.expand_cache_key(key, :jbuilder)
219
-
220
- ::Digest::MD5.hexdigest(key.to_s).tap do |digest|
221
- _logger.try :debug, "Cache key :#{key} was digested to #{digest}"
222
- end
223
- end
224
-
225
- def _cache(key=nil, options={})
226
- return yield self if !@context.controller.perform_caching || key.nil?
227
-
228
- parent_js = @js
229
- key = _cache_key(key, options)
230
- @js = []
231
-
232
- blank_or_value = begin
233
- ::Rails.cache.fetch(key, options) do
234
- result = yield self
235
- if result !=BLANK
236
- @js << _breezy_set_cache(key, result)
237
- @js.join
238
- else
239
- BLANK
240
- end
241
- end
242
- ensure
243
- @js = parent_js
244
- end
245
-
246
- if blank_or_value == BLANK
247
- BLANK
248
- else
249
- v = blank_or_value
250
- @js.push(v)
251
- Digest.new(key)
252
- end
253
- end
254
-
255
- def _breezy_set_cache(key, value)
256
- "Breezy.cache(\"#{key}\", #{_dump(value)});"
257
- end
258
-
259
- def _breezy_return(results)
260
- "return (#{_dump(results)});"
261
- end
262
-
263
- def _dump(value)
264
- ::MultiJson.dump(value)
265
- end
266
-
267
- def _ensure_valid_key(key)
268
- current_value = _blank? ? BLANK : @attributes.fetch(_key(key), BLANK)
269
- raise NullError.build(key) if current_value.nil?
270
- end
271
-
272
- def _normalize_options(options)
273
- options = options.dup
274
- key = options[:cache]
275
- opts = {}
276
- return options if !key
277
-
278
- if ::Array === key && key.length == 2 && ::Hash === key.last
279
- return options
280
- end
281
-
282
- if options[:partial]
283
- opts[:partial] = options[:partial]
284
- end
285
-
286
- key = case key
287
- when ::Array
288
- key
289
- when ::Proc
290
- key
291
- else
292
- [key]
293
- end
294
-
295
- options[:cache] = [key, opts]
296
- options
297
- end
298
-
299
- def _fragment_name_with_digest(key, options)
300
- if @context.respond_to?(:cache_fragment_name)
301
- # Current compatibility, fragment_name_with_digest is private again and cache_fragment_name
302
- # should be used instead.
303
- @context.cache_fragment_name(key, options)
304
- elsif @context.respond_to?(:fragment_name_with_digest)
305
- # Backwards compatibility for period of time when fragment_name_with_digest was made public.
306
- @context.fragment_name_with_digest(key)
307
- else
308
- key
309
- end
310
- end
311
-
312
- def _cache_options?(options)
313
- ::Hash === options && options.key?(:cache)
314
- end
315
-
316
- def _logger
317
- ::ActionView::Base.logger
318
- end
319
- end
320
- end
@@ -1,48 +0,0 @@
1
- module BreezyTemplate
2
- module DefermentExtension
3
- ACTIVE_MODES = [:auto, :manual].freeze
4
-
5
- def set!(key, value = BLANK, *args)
6
- options = args.first || {}
7
- options = _normalize_options(options)
8
- if ::Kernel.block_given? && _deferment_enabled?(options)
9
- if _deferment_auto?(options)
10
- @js.push(_breezy_visit_current(@path))
11
- end
12
- return _set_value key, nil
13
- else
14
- super
15
- end
16
- end
17
-
18
- def _deferment_auto?(options)
19
- options[:defer] == :auto
20
- end
21
-
22
- def _deferment_enabled?(options)
23
- ACTIVE_MODES.include?(options[:defer]) && (@search_path.nil? || @search_path.size == 0)
24
- end
25
-
26
- def _set_request_url(request_path)
27
- @request_path = request_path
28
- end
29
-
30
- def _deferment_options?(options)
31
- ::Hash === options && options.key?(:defer)
32
- end
33
-
34
- def _mapping_element(element, options)
35
- if _deferment_enabled? options
36
- if options.has_key? :key
37
- id_name = options[:key]
38
- id_val = element[id_name]
39
- ::Hash[id_name, id_val]
40
- else
41
- nil
42
- end
43
- else
44
- super
45
- end
46
- end
47
- end
48
- end
@@ -1,47 +0,0 @@
1
- # This was taken from jbuilder
2
-
3
- dependency_tracker = false
4
-
5
- begin
6
- require 'action_view'
7
- require 'action_view/dependency_tracker'
8
- dependency_tracker = ::ActionView::DependencyTracker
9
- rescue LoadError
10
- begin
11
- require 'cache_digests'
12
- dependency_tracker = ::CacheDigests::DependencyTracker
13
- rescue LoadError
14
- end
15
- end
16
-
17
- if dependency_tracker
18
- class BreezyTemplate::Template
19
- module DependencyTrackerMethods
20
- # Matches:
21
- # json.partial! partial: "comments/comment"
22
- # json.comments @post.comments, partial: "comments/comment", as: :comment
23
- # json.array! @posts, partial: "posts/post", as: :post
24
- # = render partial: "account"
25
- #
26
- INDIRECT_RENDERS = /
27
- (?::partial\s*=>|partial:) # partial: or :partial =>
28
- \s* # optional whitespace
29
- (['"])([^'"]+)\1 # quoted value
30
- /x
31
-
32
- def dependencies
33
- indirect_dependencies + explicit_dependencies
34
- end
35
-
36
- private
37
-
38
- def indirect_dependencies
39
- source.scan(INDIRECT_RENDERS).map(&:second)
40
- end
41
- end
42
- end
43
-
44
- ::BreezyTemplate::DependencyTracker = Class.new(dependency_tracker::ERBTracker)
45
- ::BreezyTemplate::DependencyTracker.send :include, ::BreezyTemplate::Template::DependencyTrackerMethods
46
- dependency_tracker.register_tracker :breezy, ::BreezyTemplate::DependencyTracker
47
- end
@@ -1,30 +0,0 @@
1
- require 'action_view'
2
- require 'action_view/digestor'
3
-
4
- module BreezyTemplate
5
- module PartialDigestor
6
- if ::Rails.version >= '5.0'
7
- def _partial_digestor(options)
8
- name = options[:name]
9
- finder = options[:finder]
10
- ::ActionView::Digestor.digest(name: name, finder: finder)
11
- end
12
- elsif ::Rails.version >= '4.1'
13
- def _partial_digestor(options)
14
- name = options[:name]
15
- finder = options[:finder]
16
- ::ActionView::PartialDigestor.new(name: name, finder: finder).digest
17
- end
18
- elsif ::Rails.version >= '4.0'
19
- def _partial_digestor(options={})
20
- name = options[:name]
21
- finder = options[:finder]
22
- ::ActionView::PartialDigestor.new(name, finder.formats.last, finder).digest
23
- end
24
- else
25
- def _partial_digestor(options)
26
- options[:name]
27
- end
28
- end
29
- end
30
- end