volt 0.4.8 → 0.4.9

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: d5fa5dd92e489dfa4a0257eccd5509aa2324cb25
4
- data.tar.gz: 21e58768017cd4b82ec09ee9b9b06a828d3289e8
3
+ metadata.gz: e0ae38f2f69535b60b4fe850f9c6a9073da98b75
4
+ data.tar.gz: a2a08253c6f76f71ac495ec91d13efa4a35f0a98
5
5
  SHA512:
6
- metadata.gz: fd684af9e5c24c317c62e97bff34c8a7f732082074424e225db3712386fb1ded60f30b686a5046961600f0f9a48b12a14da42500434f700f50b681b57125de94
7
- data.tar.gz: bc38cdd81e222e1ed407fa44819ee1b0adc6edf1796ec597b7022dfd7f7abb74583fbfcd266409d3299f02afe31cc62daea8f387211c82996e21217cbfab4d45
6
+ metadata.gz: f39067395499d7b5bd46088b343612d9dc8b79d1fa5b53885777fa9deb5bde1f42215f6ab111264935636e0a7971d8212edd3f235a49df6c2f388aec62a01c44
7
+ data.tar.gz: a0713dc5334f151bd05bf9b95e879be1b02ae4cd59ae1e9f8bbdbf90e9474f9ff35286f2b998f66d91f1247cc05ddc07c49f3996fbfc9b7ff672bc97619abbf0
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.8
1
+ 0.4.9
@@ -16,28 +16,32 @@ class StoreTasks
16
16
 
17
17
  def save(collection, data)
18
18
  puts "Insert: #{data.inspect} on #{collection.inspect}"
19
+
20
+ data = data.symbolize_keys
21
+ id = data[:_id]
22
+
19
23
  # Try to create
20
24
  # TODO: Seems mongo is dumb and doesn't let you upsert with custom id's
21
25
  begin
22
26
  @@db[collection].insert(data)
23
- id = {'_id' => data.delete('_id')}
24
27
 
25
28
  # Message that we inserted a new item
26
- ChannelTasks.send_message_to_channel("#{collection}", ['added', nil, collection, data.merge('_id' => id).symbolize_keys], @channel)
29
+ puts "SENDING DATA: #{data.inspect}"
30
+ ChannelTasks.send_message_to_channel("#{collection}-added", ['added', nil, collection, data], @channel)
27
31
  rescue Mongo::OperationFailure => error
28
32
  # Really mongo client?
29
33
  if error.message[/^11000[:]/]
30
34
  # Update because the id already exists
31
- id = {'_id' => data.delete('_id')}
32
- @@db[collection].update(id, data)
35
+ update_data = data.dup
36
+ update_data.delete(:_id)
37
+ @@db[collection].update({:_id => id}, update_data)
33
38
  else
34
39
  raise
35
40
  end
36
41
  end
37
42
 
38
- id = id['_id']
39
43
 
40
- ChannelTasks.send_message_to_channel("#{collection}##{id}", ['changed', nil, id, data.merge('_id' => id).symbolize_keys], @channel)
44
+ ChannelTasks.send_message_to_channel("#{collection}##{id}", ['changed', nil, id, data], @channel)
41
45
  end
42
46
 
43
47
  def find(collection, scope, query=nil)
@@ -46,4 +50,11 @@ class StoreTasks
46
50
 
47
51
  return results
48
52
  end
53
+
54
+ def delete(collection, id)
55
+ puts "DELETE: #{collection.inspect} - #{id.inspect}"
56
+ @@db[collection].remove('_id' => id)
57
+
58
+ ChannelTasks.send_message_to_channel("#{collection}-removed", ['removed', nil, id], @channel)
59
+ end
49
60
  end
@@ -0,0 +1,6 @@
1
+ require 'sass'
2
+
3
+ sass_engine = Sass::Engine.new(template, {syntax: :scss, filename: 'cool.css.scss', sourcemap: true}) ; output =
4
+ sass_engine.render_with_sourcemap('/source_maps/')
5
+
6
+ puts a[1].to_json(:css_path => '/cool.css', :sourcemap_path => '/source_maps/cool.css.map')
@@ -17,6 +17,10 @@ class Store < Model
17
17
 
18
18
  value_updated
19
19
  end
20
+
21
+ def self.from_id(id)
22
+ @@identity_map[id]
23
+ end
20
24
 
21
25
  def event_added(event, scope_provider, first)
22
26
  if first && event == :changed
@@ -36,6 +40,7 @@ class Store < Model
36
40
  def change_channel_connection(add_or_remove)
37
41
  if attributes && path.size > 1
38
42
  channel_name = "#{path[-2]}##{attributes[:_id]}"
43
+ puts "Event Added: #{channel_name} -- #{attributes.inspect}"
39
44
  @tasks.call('ChannelTasks', "#{add_or_remove}_listener", channel_name)
40
45
  end
41
46
  end
@@ -121,49 +126,51 @@ class Store < Model
121
126
  # On stores, we store the model so we don't have to look it up
122
127
  # every time we do a read.
123
128
  def read_new_model(method_name)
124
- model = new_model(nil, self, path + [method_name])
129
+ # On stores, plural associations are automatically assumed to be
130
+ # collections.
131
+ if method_name.plural?
132
+ model = new_array_model([], self, path + [method_name])
133
+ else
134
+ model = new_model(nil, self, path + [method_name])
135
+ end
125
136
 
126
137
  self.attributes ||= {}
127
138
  attributes[method_name] = model
128
139
 
129
- if model.state == :not_loaded
140
+ if model.is_a?(StoreArray)# && model.state == :not_loaded
130
141
  model.load!
131
142
  end
132
143
 
133
144
  return model
134
145
  end
146
+
135
147
 
136
- def load!
137
- if @state == :not_loaded
138
- @state = :loading
148
+ # When called, this model is deleted from its current parent collection
149
+ # and from the database
150
+ def delete!
151
+ if path.size == 0
152
+ raise "Not in a collection"
153
+ end
139
154
 
140
- if @tasks && path.last.plural?
141
- # Check to see the parents scope so we can only lookup associated
142
- # models.
143
- scope = {}
144
-
145
- # Scope to the parent
146
- if path.size > 2 && (attrs = parent.attributes) && attrs[:_id].true?
147
- scope[:"#{path[-3].singularize}_id"] = parent._id
148
- end
149
-
150
- load_child_models(scope)
155
+ # TEMP: Find this model in the parent's collection
156
+ parent.each_with_index do |child,index|
157
+ puts "CHECK #{child.inspect} vs #{self.inspect}"
158
+ if child._id == self._id
159
+ puts "FOUND AT: #{index}"
160
+ parent.delete_at(index)
161
+ break
151
162
  end
152
163
  end
153
-
154
- return self
164
+
165
+ # Send to the DB that we got deleted
166
+ unless $loading_models
167
+ puts "delete #{collection} - #{attributes[:_id]}"
168
+ @tasks.call('StoreTasks', 'delete', collection, attributes[:_id])
169
+ end
155
170
  end
156
171
 
157
- def load_child_models(scope)
158
- # puts "FIND: #{collection(path).inspect} at #{scope.inspect}"
159
- @tasks.call('StoreTasks', 'find', collection(path), scope) do |results|
160
- # TODO: Globals evil, replace
161
- $loading_models = true
162
- results.each do |result|
163
- self << Store.new(@tasks, result, self, path + [:[]], @class_paths)
164
- end
165
- $loading_models = false
166
- end
172
+ def inspect
173
+ "<#{self.class.to_s}-#{@state} #{attributes.inspect}>"
167
174
  end
168
175
 
169
176
  def new_model(attributes={}, parent=nil, path=nil, class_paths=nil)
@@ -1,31 +1,73 @@
1
1
  class StoreArray < ArrayModel
2
+ attr_reader :state
3
+
2
4
  def initialize(tasks=nil, array=[], parent=nil, path=nil)
3
5
  @tasks = tasks
6
+ @state = :not_loaded
4
7
 
5
8
  super(array, parent, path)
9
+
10
+ # TEMP: TODO: Setup the listeners right away
11
+ change_channel_connection('add', 'added')
12
+ change_channel_connection('add', 'removed')
6
13
  end
7
14
 
8
- def event_added(event, scope_provider, first)
9
- puts "New event: #{event.inspect} - #{first}"
10
- if first && [:added, :removed].include?(event)
11
- # Start listening for added items on the collection
15
+ # def event_added(event, scope_provider, first)
16
+ # puts "New event1: #{event.inspect} - #{first}"
17
+ # if first && [:added, :removed].include?(event)
18
+ # # Start listening for added items on the collection
19
+ #
20
+ # change_channel_connection('add', event)
21
+ # end
22
+ # end
23
+ #
24
+ # def event_removed(event, no_more_events)
25
+ # if no_more_events && [:added, :removed].include?(event)
26
+ # # Stop listening
27
+ # change_channel_connection("remove", event)
28
+ # end
29
+ # end
30
+
31
+
32
+ def load!
33
+ if @state == :not_loaded
34
+ @state = :loading
35
+
36
+ if @tasks && path.last.plural?
37
+ # Check to see the parents scope so we can only lookup associated
38
+ # models.
39
+ scope = {}
12
40
 
13
- change_channel_connection('add')
41
+ # Scope to the parent
42
+ if path.size > 1 && attributes && attributes[:_id].true?
43
+ scope[:"#{path[-2].singularize}_id"] = _id
44
+ end
45
+
46
+ puts "Load At Scope: #{scope.inspect}"
47
+
48
+ load_child_models(scope)
49
+ end
14
50
  end
51
+
52
+ return self
15
53
  end
16
54
 
17
- def event_removed(event, no_more_events)
18
- if no_more_events && [:added, :removed].include?(event)
19
- # Stop listening
20
- change_channel_connection("remove", event)
55
+ def load_child_models(scope)
56
+ # puts "FIND: #{collection(path).inspect} at #{scope.inspect}"
57
+ @tasks.call('StoreTasks', 'find', path.last, scope) do |results|
58
+ # TODO: Globals evil, replace
59
+ $loading_models = true
60
+ results.each do |result|
61
+ self << Store.new(@tasks, result, self, path + [:[]], @class_paths)
62
+ end
63
+ $loading_models = false
21
64
  end
22
65
  end
23
66
 
24
-
25
67
  def change_channel_connection(add_or_remove, event)
26
- if parent.attributes && path.size != 0
68
+ if @tasks && parent.attributes && path.size != 0
27
69
  channel_name = "#{path[-1]}-#{event}"
28
- puts "Listen on #{channel_name}"
70
+ puts "Listen on #{channel_name} - #{add_or_remove}"
29
71
  @tasks.call('ChannelTasks', "#{add_or_remove}_listener", channel_name)
30
72
  end
31
73
  end
@@ -29,7 +29,7 @@ class ChannelStub
29
29
  destructive!
30
30
  end
31
31
  def send_message(message)
32
- ChannelHandlerStub.new(self).process_message(message)
32
+ SocketConnectionHandlerStub.new(self).process_message(message)
33
33
  end
34
34
 
35
35
  def close!
@@ -35,6 +35,8 @@ class Tasks
35
35
  changed(*args)
36
36
  when 'added'
37
37
  added(*args)
38
+ when 'removed'
39
+ removed(*args)
38
40
  when 'reload'
39
41
  reload
40
42
  end
@@ -62,6 +64,12 @@ class Tasks
62
64
  $loading_models = false
63
65
  end
64
66
 
67
+ def removed(id)
68
+ $loading_models = true
69
+ Store.from_id(id).delete!
70
+ $loading_models = false
71
+ end
72
+
65
73
  def reload
66
74
  puts "RELOAD"
67
75
  $page.page._reloading = true
@@ -100,6 +100,14 @@ end
100
100
  module Events
101
101
  # Add a listener for an event
102
102
  def on(event, scope_provider=nil, &block)
103
+
104
+
105
+ # if reactive? && [:added, :removed].include?(event)
106
+ # self.object_tracker.queue_update
107
+ # ObjectTracker.process_queue
108
+ # end
109
+
110
+
103
111
  # puts "Register: #{event} on #{self.inspect}"
104
112
  event = event.to_sym
105
113
 
@@ -35,6 +35,7 @@ class ObjectTracker
35
35
  end
36
36
 
37
37
  def queue_update
38
+ # puts "Queue: #{@main_object.inspect}"
38
39
  @@queue[self] = true
39
40
  end
40
41
 
@@ -15,7 +15,7 @@ class ComponentTemplates
15
15
  views_path = "#{@component_path}/views/"
16
16
 
17
17
  # Load all templates in the folder
18
- Dir["#{views_path}*/*.html"].each do |view_path|
18
+ Dir["#{views_path}*/*.html"].sort.each do |view_path|
19
19
  # Get the path for the template, supports templates in folders
20
20
  template_path = view_path[views_path.size..((-1 * ('.html'.size + 1)))]
21
21
  template_path = "#{@component_name}/#{template_path}"
@@ -45,7 +45,7 @@ class ComponentTemplates
45
45
  code = ''
46
46
  controllers_path = "#{@component_path}/controllers/"
47
47
 
48
- Dir["#{controllers_path}*_controller.rb"].each do |controller_path|
48
+ Dir["#{controllers_path}*_controller.rb"].sort.each do |controller_path|
49
49
  code << File.read(controller_path) + "\n\n"
50
50
  end
51
51
 
@@ -56,7 +56,7 @@ class ComponentTemplates
56
56
  code = ''
57
57
  models_path = "#{@component_path}/models/"
58
58
 
59
- Dir["#{models_path}*.rb"].each do |model_path|
59
+ Dir["#{models_path}*.rb"].sort.each do |model_path|
60
60
  code << File.read(model_path) + "\n\n"
61
61
 
62
62
  model_name = model_path.match(/([^\/]+)[.]rb$/)[1]
@@ -70,7 +70,7 @@ class AssetFiles
70
70
  @assets.each do |type, path|
71
71
  case type
72
72
  when :folder
73
- javascript_files += Dir["#{path}/**/*.js"].map {|folder| '/assets' + folder[path.size..-1] }
73
+ javascript_files += Dir["#{path}/**/*.js"].sort.map {|folder| '/assets' + folder[path.size..-1] }
74
74
  when :javascript_file
75
75
  javascript_files << path
76
76
  end
@@ -94,7 +94,7 @@ class AssetFiles
94
94
  @assets.each do |type, path|
95
95
  case type
96
96
  when :folder
97
- css_files += Dir["#{path}/**/*.{css,scss}"].map {|folder| '/assets' + folder[path.size..-1].gsub(/[.]scss$/, '') }
97
+ css_files += Dir["#{path}/**/*.{css,scss}"].sort.map {|folder| '/assets' + folder[path.size..-1].gsub(/[.]scss$/, '') }
98
98
  when :css_file
99
99
  css_files << path
100
100
  end
@@ -34,7 +34,7 @@ class ComponentPaths
34
34
 
35
35
  @components = {}
36
36
  app_folders do |app_folder|
37
- Dir["#{app_folder}/*"].each do |folder|
37
+ Dir["#{app_folder}/*"].sort.each do |folder|
38
38
  if File.directory?(folder)
39
39
  folder_name = folder[/[^\/]+$/]
40
40
 
@@ -51,7 +51,7 @@ class ComponentPaths
51
51
  def setup_components_load_path
52
52
  components.each do |name,component_folders|
53
53
  component_folders.each do |component_folder|
54
- Dir["#{component_folder}/tasks"].each do |tasks_folder|
54
+ Dir["#{component_folder}/tasks"].sort.each do |tasks_folder|
55
55
  $LOAD_PATH.unshift(tasks_folder)
56
56
  end
57
57
  end
@@ -73,7 +73,7 @@ class ComponentPaths
73
73
  def asset_folders
74
74
  folders = []
75
75
  app_folders do |app_folder|
76
- Dir["#{app_folder}/*/assets"].each do |asset_folder|
76
+ Dir["#{app_folder}/*/assets"].sort.each do |asset_folder|
77
77
  folders << yield(asset_folder)
78
78
  end
79
79
  end
@@ -1,4 +1,8 @@
1
1
  require 'volt/server/rack/source_map_server'
2
+ if Volt.env.production?
3
+ # Compress assets in production
4
+ require 'uglifier'
5
+ end
2
6
 
3
7
  # Sets up the maps for the opal assets, and source maps if enabled.
4
8
  class OpalFiles
@@ -19,6 +23,12 @@ class OpalFiles
19
23
  environment = @environment
20
24
 
21
25
  environment.cache = Sprockets::Cache::FileStore.new("./tmp")
26
+
27
+ if Volt.env.production?
28
+ # Compress in production
29
+ environment.js_compressor = Sprockets::UglifierCompressor
30
+ environment.css_compressor = Sprockets::YUICompressor
31
+ end
22
32
 
23
33
  environment.append_path(app_path)
24
34
 
@@ -291,7 +291,7 @@ describe Model do
291
291
  # expect(changed_count).to eq(1)
292
292
  end
293
293
 
294
- it "should handle a basic todo list exvoltle with no setup" do
294
+ it "should handle a basic todo list with no setup" do
295
295
  store = ReactiveValue.new(Model.new)
296
296
  params = ReactiveValue.new(Params.new)
297
297
 
@@ -411,4 +411,31 @@ describe Model do
411
411
  expect(count2).to eq(2)
412
412
 
413
413
  end
414
+
415
+ it "should set its self to be " do
416
+
417
+ end
418
+
419
+
420
+ describe "model paths" do
421
+ before do
422
+ @model = ReactiveValue.new(Model.new)
423
+ end
424
+
425
+ it "should set the model path" do
426
+ @model._object._name = 'Test'
427
+ expect(@model._object.path.cur).to eq([:_object])
428
+ end
429
+
430
+ it "should set the model path for a sub array" do
431
+ @model._items << {_name: 'Bob'}
432
+ expect(@model._items.path.cur).to eq([:_items])
433
+ expect(@model._items[0].path.cur).to eq([:_items, :[]])
434
+ end
435
+
436
+ it "should set the model path for sub sub arrays" do
437
+ @model._lists << {_name: 'List 1', _items: []}
438
+ expect(@model._lists[0]._items.path.cur).to eq([:_lists, :[], :_items])
439
+ end
440
+ end
414
441
  end
@@ -3,48 +3,6 @@
3
3
  #
4
4
  # describe Model do
5
5
  #
6
- # describe "model paths" do
7
- # before do
8
- # @model = ReactiveValue.new(Model.new)
9
- # end
10
- #
11
- # it "should set the model path" do
12
- # @model._object._name = 'Test'
13
- # @model._object.path.cur.should == ['_object']
14
- # end
15
- #
16
- # it "should set the model path for a sub array" do
17
- # @model._items << {_name: 'Bob'}
18
- # @model._items.path.cur.should == ['_items']
19
- # @model._items[0].path.cur.should == ['_items', '[]']
20
- # end
21
- #
22
- # it "should set the model path for sub sub arrays" do
23
- # @model._lists << {_name: 'List 1', _items: []}
24
- # @model._lists[0]._items.path.cur.should == ['_lists', '[]', '_items']
25
- # end
26
- # end
27
- #
28
- #
29
- # describe "paths" do
30
- # before do
31
- # @model = ReactiveValue.new(Model.new({}, nil, 'model'))
32
- # end
33
- #
34
- # it "should track paths" do
35
- # @model._test.path.cur.should == ['model', '_test']
36
- # end
37
- #
38
- # it "should track nested paths" do
39
- # @model._test._blue.path.cur.should == ['model', '_test', '_blue']
40
- # end
41
- #
42
- # it "should track paths with array lookup's" do
43
- # @model._test._green << {}
44
- # @model._test._green.path.cur.should == ['model', '_test', '_green']
45
- # @model._test._green[0].path.cur.should == ['model', '_test', '_green', '[]']
46
- # end
47
- # end
48
6
  #
49
7
  # describe "user models" do
50
8
  # class User < Model
data/volt.gemspec CHANGED
@@ -33,6 +33,8 @@ Gem::Specification.new do |spec|
33
33
  spec.add_dependency "oj", "~> 2.5.0"
34
34
  spec.add_dependency "rake", "~> 10.0.4"
35
35
  spec.add_dependency "listen", "~> 2.4.0"
36
+ spec.add_dependency "uglifier", "~> 2.4.0"
37
+ spec.add_dependency "yui-compressor", "~> 0.12.0"
36
38
  # spec.add_dependency "rack-colorized_logger", "~> 1.0.4"
37
39
 
38
40
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: volt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
4
+ version: 0.4.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Stout
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-24 00:00:00.000000000 Z
11
+ date: 2014-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -206,6 +206,34 @@ dependencies:
206
206
  - - "~>"
207
207
  - !ruby/object:Gem::Version
208
208
  version: 2.4.0
209
+ - !ruby/object:Gem::Dependency
210
+ name: uglifier
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - "~>"
214
+ - !ruby/object:Gem::Version
215
+ version: 2.4.0
216
+ type: :runtime
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - "~>"
221
+ - !ruby/object:Gem::Version
222
+ version: 2.4.0
223
+ - !ruby/object:Gem::Dependency
224
+ name: yui-compressor
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - "~>"
228
+ - !ruby/object:Gem::Version
229
+ version: 0.12.0
230
+ type: :runtime
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - "~>"
235
+ - !ruby/object:Gem::Version
236
+ version: 0.12.0
209
237
  - !ruby/object:Gem::Dependency
210
238
  name: bundler
211
239
  requirement: !ruby/object:Gem::Requirement
@@ -305,6 +333,7 @@ files:
305
333
  - docs/GETTING_STARTED.md
306
334
  - docs/WHY.md
307
335
  - lib/volt.rb
336
+ - lib/volt/assets/test.rb
308
337
  - lib/volt/benchmark/benchmark.rb
309
338
  - lib/volt/cli.rb
310
339
  - lib/volt/cli/new_gem.rb