embarista 1.1.5 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +1 -1
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +2 -1
  5. data/Gemfile +4 -9
  6. data/embarista.gemspec +4 -5
  7. data/lib/embarista.rb +7 -0
  8. data/lib/embarista/app.rb +46 -0
  9. data/lib/embarista/dynamic_index.rb +3 -207
  10. data/lib/embarista/dynamic_index/context.rb +32 -0
  11. data/lib/embarista/dynamic_index/generator.rb +27 -0
  12. data/lib/embarista/dynamic_index/middleware.rb +25 -0
  13. data/lib/embarista/filters/manifest_url_filter.rb +12 -0
  14. data/lib/embarista/filters/precompile_handlebars_filter.rb +32 -5
  15. data/lib/embarista/filters/rewrite_minispade_requires_filter.rb +11 -7
  16. data/lib/embarista/helpers.rb +12 -12
  17. data/lib/embarista/precompiler.rb +84 -0
  18. data/lib/embarista/redis.rb +34 -0
  19. data/lib/embarista/s3.rb +59 -0
  20. data/lib/embarista/s3sync.rb +23 -75
  21. data/lib/embarista/sass_functions.rb +17 -7
  22. data/lib/embarista/tasks.rb +5 -0
  23. data/lib/embarista/tasks/assets.rb +41 -0
  24. data/lib/embarista/tasks/generate_index.rb +46 -0
  25. data/lib/embarista/tasks/generate_s3_index.rb +33 -0
  26. data/lib/embarista/tasks/set_current_index.rb +31 -0
  27. data/lib/embarista/tasks/updater.rb +114 -8
  28. data/lib/embarista/tasks/upload_index.rb +45 -0
  29. data/lib/embarista/version.rb +1 -1
  30. data/spec/manifest_builder_spec.rb +3 -3
  31. data/spec/manifest_url_filter_spec.rb +9 -3
  32. data/spec/precompile_handlebars_filter_spec.rb +6 -5
  33. data/spec/spec_helper.rb +3 -1
  34. data/vendor/ember-template-compiler.js +195 -0
  35. metadata +67 -98
  36. data/.rvmrc +0 -49
  37. data/lib/embarista/server.rb +0 -171
  38. data/vendor/ember.js +0 -21051
@@ -1,2 +1,7 @@
1
1
  require 'embarista/tasks/coffeelint'
2
2
  require 'embarista/tasks/updater'
3
+ require 'embarista/tasks/assets'
4
+ require 'embarista/tasks/generate_index'
5
+ require 'embarista/tasks/upload_index'
6
+ require 'embarista/tasks/generate_s3_index'
7
+ require 'embarista/tasks/set_current_index'
@@ -0,0 +1,41 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+
4
+ module Embarista
5
+ class AssetsTask < ::Rake::TaskLib
6
+ attr_accessor :name, :app, :assets_bucket
7
+
8
+ def initialize(name = :assets)
9
+ @name = name
10
+
11
+ yield self if block_given?
12
+
13
+ @assets_bucket ||= App.assets_bucket
14
+
15
+ raise 'app must be set' unless @app
16
+ define
17
+ end
18
+
19
+ private
20
+ def define
21
+ assets_task = task name, :manifest_id do |t, args|
22
+ manifest_id = args[:manifest_id] || App.latest_manifest_id
23
+
24
+ raise "assets distro not found for ID #{manifest_id}" unless File.exist? "tmp/public/#{manifest_id}.yml"
25
+
26
+ Embarista::S3sync.sync('tmp/public',
27
+ bucket_name: assets_bucket,
28
+ local_manifest_path: "#{manifest_id}.yml",
29
+ remote_manifest_path: "#{app}-manifest-latest.yml",
30
+ )
31
+ puts generate_index_command(t, manifest_id)
32
+ end
33
+ assets_task.add_description "deploy assets to S3"
34
+ end
35
+
36
+ def generate_index_command(task, manifest_id)
37
+ generate_index_task_name = ::Rake::Task.scope_name(task.scope, 'generate_index')
38
+ "#{App.env_var}=qa|prod be rake \"#{generate_index_task_name}[#{manifest_id}]\""
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,46 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+
4
+ module Embarista
5
+ class GenerateIndexTask < ::Rake::TaskLib
6
+ attr_accessor :name, :erb_path, :app, :redis
7
+
8
+ def initialize(name = :generate_index)
9
+ @name = name
10
+ @erb_path = "app/index.html.erb"
11
+
12
+ yield self if block_given?
13
+
14
+ @redis ||= Redis.client
15
+
16
+ raise 'app must be set' unless @app
17
+ define
18
+ end
19
+
20
+ private
21
+ def define
22
+ generate_index_task = task name, :manifest_id do |t, args|
23
+ manifest_id = args[:manifest_id] || App.env.to_s
24
+ generator = DynamicIndex::Generator.generator(erb_path, manifest_id)
25
+ html = generator.html
26
+
27
+ puts "redis.set('#{app}:index:#{manifest_id}', '#{html[0,10].strip}...')"
28
+
29
+ redis.set("#{app}:index:#{manifest_id}", html)
30
+
31
+ puts "To preview: #{preview_url(app, manifest_id)}"
32
+ puts "To activate: #{set_current_command(t, manifest_id)}"
33
+ end
34
+ generate_index_task.add_description "Generate a manifest for the specified #{App.env_var}, run once with dev to boostrap environment"
35
+ end
36
+
37
+ def preview_url(app, manifest_id)
38
+ "#{App.app_base_url}/#{app}/?manifest_id=#{manifest_id}"
39
+ end
40
+
41
+ def set_current_command(task, manifest_id)
42
+ set_current_task_name = ::Rake::Task.scope_name(task.scope, 'set_current_index')
43
+ "#{App.env_var}=#{App.env} rake \"#{set_current_task_name}[#{manifest_id}]\""
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,33 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+
4
+ module Embarista
5
+ class GenerateS3IndexTask < ::Rake::TaskLib
6
+ attr_accessor :name, :erb_path, :app, :assets_bucket
7
+
8
+ def initialize(name = :generate_s3_index)
9
+ @name = name
10
+ @erb_path = "app/index.html.erb"
11
+
12
+ yield self if block_given?
13
+
14
+ @assets_bucket ||= App.assets_bucket
15
+
16
+ raise 'app must be set' unless @app
17
+ define
18
+ end
19
+
20
+ private
21
+ def define
22
+ generate_s3_index_task = task name, :manifest_id do |t, args|
23
+ manifest_id = args[:manifest_id] || App.latest_manifest_id
24
+ generator = DynamicIndex::Generator.generator(erb_path, manifest_id, "//s3.amazonaws.com/#{assets_bucket}")
25
+ io = StringIO.new(generator.html)
26
+
27
+ s3 = S3.new(assets_bucket)
28
+ s3.store("#{app}/index-#{App.env}.html", io)
29
+ end
30
+ generate_s3_index_task.add_description "Generate a index for the app and deploy it to S3"
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,31 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+
4
+ module Embarista
5
+ class SetCurrentIndexTask < ::Rake::TaskLib
6
+ attr_accessor :name, :app, :key, :redis
7
+
8
+ def initialize(name = :set_current_index, key = 'index')
9
+ @name = name
10
+ @key = key
11
+
12
+ yield self if block_given?
13
+
14
+ @redis ||= Redis.client
15
+
16
+ raise 'app must be set' unless @app
17
+ define
18
+ end
19
+
20
+ private
21
+ def define
22
+ set_current_task = task(name, :manifest_id) do |t, args|
23
+ manifest_id = args[:manifest_id] || App.env.to_s
24
+
25
+ puts "redis.set('#{app}:#{key}:current', '#{manifest_id}')"
26
+ redis.set("#{app}:#{key}:current", manifest_id)
27
+ end
28
+ set_current_task.add_description "Activates a manifest in the given #{App.env_var}"
29
+ end
30
+ end
31
+ end
@@ -22,9 +22,9 @@ module Embarista
22
22
  end
23
23
 
24
24
  def define
25
- task name do |t, args|
25
+ update_ember_task = task name do |t, args|
26
26
  old_sha, new_sha = nil, nil
27
- regexp = /ember-([0-9a-f]{40})/
27
+ regexp = /ember-([0-9a-f]{4,40})/
28
28
  app_vendor_path = File.expand_path("app/vendor")
29
29
  cd(app_vendor_path) do
30
30
  old_filename = Dir['*'].grep(regexp)[0]
@@ -34,21 +34,26 @@ module Embarista
34
34
  raise "Couldn't find current ember.js version" if old_sha.nil?
35
35
  cd('../ember.js') do
36
36
  new_sha = `git rev-parse HEAD`.chomp
37
- `bundle && bundle exec rake dist`
37
+ Bundler.with_clean_env do
38
+ `bundle && bundle exec rake dist`
39
+ end
38
40
  cd('./dist') do
39
41
  cp('ember.js', "#{app_vendor_path}/ember-#{new_sha}.js")
40
42
  cp('ember.min.js', "#{app_vendor_path}/ember-#{new_sha}.min.js")
43
+ cp('ember-template-compiler.js', "#{app_vendor_path}/ember-template-compiler-#{new_sha}.js")
41
44
  end
42
45
  end
43
46
  if old_sha != new_sha
44
47
  cd(app_vendor_path) do
45
48
  rm("ember-#{old_sha}.js")
46
49
  rm("ember-#{old_sha}.min.js")
50
+ rm("ember-template-compiler-#{old_sha}.js")
47
51
  end
48
52
  Embarista::Updater.update_asset_file(old_sha, new_sha)
49
53
  end
50
54
  puts "Updated from #{old_sha} to #{new_sha}"
51
55
  end
56
+ update_ember_task.add_description "Update Ember from a repo in ../ember.js"
52
57
  end
53
58
  end
54
59
 
@@ -62,9 +67,9 @@ module Embarista
62
67
  end
63
68
 
64
69
  def define
65
- task name do |t, args|
70
+ update_ember_data_task = task name do |t, args|
66
71
  old_sha, new_sha = nil, nil
67
- regexp = /ember-data-([0-9a-f]{40})/
72
+ regexp = /ember-data-([0-9a-f]{4,40})/
68
73
  app_vendor_path = File.expand_path("app/vendor")
69
74
  cd(app_vendor_path) do
70
75
  old_filename = Dir['*'].grep(regexp)[0]
@@ -74,7 +79,9 @@ module Embarista
74
79
  raise "Couldn't find current ember-data js version" if old_sha.nil?
75
80
  cd('../ember-data') do
76
81
  new_sha = `git rev-parse HEAD`.chomp
77
- `bundle && bundle exec rake dist`
82
+ Bundler.with_clean_env do
83
+ `npm install; ./node_modules/.bin/grunt dist`
84
+ end
78
85
  cd('./dist') do
79
86
  cp('ember-data.js', "#{app_vendor_path}/ember-data-#{new_sha}.js")
80
87
  cp('ember-data.min.js', "#{app_vendor_path}/ember-data-#{new_sha}.min.js")
@@ -89,6 +96,76 @@ module Embarista
89
96
  end
90
97
  puts "Updated from #{old_sha} to #{new_sha}"
91
98
  end
99
+ update_ember_data_task.add_description "Update Ember data from a repo in ../ember-data"
100
+ end
101
+ end
102
+
103
+ class UpdateEmberStatesTask < ::Rake::TaskLib
104
+ attr_accessor :name
105
+
106
+ def initialize(name = :update_ember_states)
107
+ @name = name
108
+ yield self if block_given?
109
+ define
110
+ end
111
+
112
+ def define
113
+ update_ember_states_task = task name do |t, args|
114
+ old_sha, new_sha = nil, nil
115
+ regexp = /ember-states-([0-9a-f]{40})/
116
+ app_vendor_path = File.expand_path("app/vendor")
117
+ cd(app_vendor_path) do
118
+ old_filename = Dir['*'].grep(regexp)[0]
119
+ old_filename =~ regexp
120
+ old_sha = $1
121
+ end
122
+ raise "Couldn't find current ember-states js version" if old_sha.nil?
123
+ cd('../ember-states') do
124
+ new_sha = `git rev-parse HEAD`.chomp
125
+ Bundler.with_clean_env do
126
+ `bundle && bundle exec rake dist`
127
+ end
128
+ cd('./dist') do
129
+ cp('ember-states.js', "#{app_vendor_path}/ember-states-#{new_sha}.js")
130
+ cp('ember-states.min.js', "#{app_vendor_path}/ember-states-#{new_sha}.min.js")
131
+ end
132
+ end
133
+ if old_sha != new_sha
134
+ cd(app_vendor_path) do
135
+ rm("ember-states-#{old_sha}.js")
136
+ rm("ember-states-#{old_sha}.min.js")
137
+ end
138
+ Embarista::Updater.update_asset_file(old_sha, new_sha)
139
+ end
140
+ puts "Updated from #{old_sha} to #{new_sha}"
141
+ end
142
+ update_ember_states_task.add_description "Update Ember States from a repo in ../ember-states"
143
+ end
144
+ end
145
+
146
+ class UpdateQunitTask < ::Rake::TaskLib
147
+ attr_accessor :name
148
+
149
+ def initialize(name = :update_qunit)
150
+ @name = name
151
+ yield self if block_given?
152
+ define
153
+ end
154
+
155
+ def define
156
+ update_qunit_task = task name do |t, args|
157
+ version = ENV['VERSION']
158
+ raise "please supply VERSION env var to specify QUnit version (specify \"git\" for nightly)" if version.nil?
159
+ cd('./test/vendor') do
160
+ # remove old qunit
161
+ rm Dir['qunit-*.js']
162
+ rm Dir['qunit-*.css']
163
+ sh "curl -O http://code.jquery.com/qunit/qunit-#{version}.js"
164
+ sh "curl -O http://code.jquery.com/qunit/qunit-#{version}.css"
165
+ end
166
+ puts "Updated to QUnit #{version}"
167
+ end
168
+ update_qunit_task.add_description "Update QUnit to VERSION from code.jquery.com"
92
169
  end
93
170
  end
94
171
 
@@ -102,7 +179,7 @@ module Embarista
102
179
  end
103
180
 
104
181
  def define
105
- task name do |t, args|
182
+ update_jquery_task = task name do |t, args|
106
183
  version = ENV['VERSION']
107
184
  raise "please supply VERSION env var to specify jQuery version" if version.nil?
108
185
  cd('./app/vendor') do
@@ -111,9 +188,38 @@ module Embarista
111
188
  sh "curl -O http://code.jquery.com/jquery-#{version}.js"
112
189
  sh "curl -O http://code.jquery.com/jquery-#{version}.min.js"
113
190
  end
114
- Embarista::Updater.update_asset_file(%r{JQUERY_VERSION = '\d+\.\d+\.\d+'}, "JQUERY_VERSION = '#{version}'")
191
+ Embarista::Updater.update_asset_file(%r{JQUERY_VERSION = '[^']+'}, "JQUERY_VERSION = '#{version}'")
115
192
  puts "Updated to jQuery #{version}"
116
193
  end
194
+ update_jquery_task.add_description "Update jQuery to VERSION from code.jquery.com"
195
+ end
196
+ end
197
+
198
+ class UpdateHandlebarsTask < ::Rake::TaskLib
199
+ attr_accessor :name
200
+
201
+ def initialize(name = :update_handlebars)
202
+ @name = name
203
+ yield self if block_given?
204
+ define
205
+ end
206
+
207
+ def define
208
+ update_handlebars_task = task name do |t, args|
209
+ version = ENV['VERSION']
210
+ raise "please supply VERSION env var to specify Handlebars version (specify \"git\" for nightly)" if version.nil?
211
+ cd('./app/vendor') do
212
+ # remove old qunit
213
+ rm Dir['handlebars-*.js']
214
+ rm Dir['handlebars.runtime-*.js']
215
+ sh "curl http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-#{version}.js > handlebars-#{version}.js"
216
+ sh "curl http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars.runtime-#{version}.js > handlebars.runtime-#{version}.js"
217
+ sh "uglifyjs < handlebars.runtime-#{version}.js > handlebars.runtime-#{version}.min.js"
218
+ end
219
+ Embarista::Updater.update_asset_file(%r{HANDLEBARS_VERSION = '[^']+'}, "HANDLEBARS_VERSION = '#{version}'")
220
+ puts "Updated to Handlebars #{version}"
221
+ end
222
+ update_handlebars_task.add_description "Update Handlebars to VERSION from github.com/wycats/handlebars.js"
117
223
  end
118
224
  end
119
225
 
@@ -0,0 +1,45 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+
4
+ module Embarista
5
+ class UploadIndexTask < ::Rake::TaskLib
6
+ attr_accessor :name, :erb_path, :app, :redis
7
+
8
+ def initialize(name = :upload_index)
9
+ @name = name
10
+ @html_path = "dist/index.html"
11
+
12
+ yield self if block_given?
13
+
14
+ @redis ||= Redis.client
15
+
16
+ raise 'app must be set' unless @app
17
+ define
18
+ end
19
+
20
+ private
21
+ def define
22
+ generate_index_task = task name, :manifest_id do |t, args|
23
+ manifest_id = args[:manifest_id] || App.env.to_s
24
+ html = File.read(@html_path)
25
+
26
+ puts "redis.set('#{app}:index:#{manifest_id}', '#{html[0,10].strip}...')"
27
+
28
+ redis.set("#{app}:index:#{manifest_id}", html)
29
+
30
+ puts "To preview: #{preview_url(app, manifest_id)}"
31
+ puts "To activate: #{set_current_command(t, manifest_id)}"
32
+ end
33
+ generate_index_task.add_description "Upload index file at dist/index.html to redis, run once with dev to boostrap environment"
34
+ end
35
+
36
+ def preview_url(app, manifest_id)
37
+ "#{App.app_base_url}/#{app}/?manifest_id=#{manifest_id}"
38
+ end
39
+
40
+ def set_current_command(task, manifest_id)
41
+ set_current_task_name = ::Rake::Task.scope_name(task.scope, 'set_current_index')
42
+ "#{App.env_var}=#{App.env} rake \"#{set_current_task_name}[#{manifest_id}]\""
43
+ end
44
+ end
45
+ end
@@ -1,3 +1,3 @@
1
1
  module Embarista
2
- VERSION = '1.1.5'
2
+ VERSION = '2.0.3'
3
3
  end
@@ -53,20 +53,20 @@ CONTENT
53
53
 
54
54
 
55
55
  subject.add('public/foo/bar/hello.txt')
56
- File.exist?('tmp/public/foo/bar/hello-8ddd8be4b179a529afa5f2ffae4b9858.txt').should be_true
56
+ File.exist?('tmp/public/foo/bar/hello-8ddd8be4b179a529afa5f2ffae4b9858.txt').should eq(true)
57
57
  subject.manifest.should == {
58
58
  '/foo/bar/hello.txt' => '/foo/bar/hello-8ddd8be4b179a529afa5f2ffae4b9858.txt'
59
59
  }
60
60
 
61
61
  subject.add('public/foo/baz/goodbye.txt')
62
- File.exist?('tmp/public/foo/baz/goodbye-8dcca69d946ae9576734c2c91dfddec4.txt').should be_true
62
+ File.exist?('tmp/public/foo/baz/goodbye-8dcca69d946ae9576734c2c91dfddec4.txt').should eq(true)
63
63
  subject.manifest.should == {
64
64
  '/foo/bar/hello.txt' => '/foo/bar/hello-8ddd8be4b179a529afa5f2ffae4b9858.txt',
65
65
  '/foo/baz/goodbye.txt' => '/foo/baz/goodbye-8dcca69d946ae9576734c2c91dfddec4.txt'
66
66
  }
67
67
 
68
68
  subject.add('images/foo.png', 'editor/images/foo.png')
69
- File.exist?('tmp/public/editor/images/foo-4802fcebd761ca4f04c9a6320330fd10.png').should be_true
69
+ File.exist?('tmp/public/editor/images/foo-4802fcebd761ca4f04c9a6320330fd10.png').should eq(true)
70
70
  subject.manifest.should == {
71
71
  '/foo/bar/hello.txt' => '/foo/bar/hello-8ddd8be4b179a529afa5f2ffae4b9858.txt',
72
72
  '/foo/baz/goodbye.txt' => '/foo/baz/goodbye-8dcca69d946ae9576734c2c91dfddec4.txt',
@@ -7,7 +7,9 @@ describe Embarista::Filters::ManifestUrlFilter do
7
7
  <<-JS
8
8
  var a = manifest_url('baz.jpg');
9
9
  var b = manifest_url("baz/bar.jpg");
10
- var c = manifest_url("doesnt-exist.jpg");
10
+ var c = manifest_url("baz/bar.jpg#bay");
11
+ var d = manifest_url("baz/bar.jpg?#bay");
12
+ var e = manifest_url("doesnt-exist.jpg");
11
13
  JS
12
14
  }
13
15
 
@@ -58,7 +60,9 @@ JS
58
60
  file.body.should eq(<<-JS)
59
61
  var a = ('//' + YappEditorConfig.assetsCdn + '/editor/images/baz-123abc.jpg');
60
62
  var b = ('//' + YappEditorConfig.assetsCdn + '/editor/images/baz/bar-456def.jpg');
61
- var c = ('//' + YappEditorConfig.assetsCdn + '/editor/images/doesnt-exist.jpg');
63
+ var c = ('//' + YappEditorConfig.assetsCdn + '/editor/images/baz/bar-456def.jpg#bay');
64
+ var d = ('//' + YappEditorConfig.assetsCdn + '/editor/images/baz/bar-456def.jpg?#bay');
65
+ var e = ('//' + YappEditorConfig.assetsCdn + '/editor/images/doesnt-exist.jpg');
62
66
  JS
63
67
  file.encoding.should eq('UTF-8')
64
68
  end
@@ -72,7 +76,9 @@ JS
72
76
  file.body.should eq(<<-JS)
73
77
  var a = ('//' + YappEditorConfig.assetsCdn + '/editor/images/baz.jpg');
74
78
  var b = ('//' + YappEditorConfig.assetsCdn + '/editor/images/baz/bar.jpg');
75
- var c = ('//' + YappEditorConfig.assetsCdn + '/editor/images/doesnt-exist.jpg');
79
+ var c = ('//' + YappEditorConfig.assetsCdn + '/editor/images/baz/bar.jpg#bay');
80
+ var d = ('//' + YappEditorConfig.assetsCdn + '/editor/images/baz/bar.jpg?#bay');
81
+ var e = ('//' + YappEditorConfig.assetsCdn + '/editor/images/doesnt-exist.jpg');
76
82
  JS
77
83
  file.encoding.should eq('UTF-8')
78
84
  end