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.
- checksums.yaml +7 -0
- data/.rspec +1 -1
- data/.ruby-version +1 -0
- data/.travis.yml +2 -1
- data/Gemfile +4 -9
- data/embarista.gemspec +4 -5
- data/lib/embarista.rb +7 -0
- data/lib/embarista/app.rb +46 -0
- data/lib/embarista/dynamic_index.rb +3 -207
- data/lib/embarista/dynamic_index/context.rb +32 -0
- data/lib/embarista/dynamic_index/generator.rb +27 -0
- data/lib/embarista/dynamic_index/middleware.rb +25 -0
- data/lib/embarista/filters/manifest_url_filter.rb +12 -0
- data/lib/embarista/filters/precompile_handlebars_filter.rb +32 -5
- data/lib/embarista/filters/rewrite_minispade_requires_filter.rb +11 -7
- data/lib/embarista/helpers.rb +12 -12
- data/lib/embarista/precompiler.rb +84 -0
- data/lib/embarista/redis.rb +34 -0
- data/lib/embarista/s3.rb +59 -0
- data/lib/embarista/s3sync.rb +23 -75
- data/lib/embarista/sass_functions.rb +17 -7
- data/lib/embarista/tasks.rb +5 -0
- data/lib/embarista/tasks/assets.rb +41 -0
- data/lib/embarista/tasks/generate_index.rb +46 -0
- data/lib/embarista/tasks/generate_s3_index.rb +33 -0
- data/lib/embarista/tasks/set_current_index.rb +31 -0
- data/lib/embarista/tasks/updater.rb +114 -8
- data/lib/embarista/tasks/upload_index.rb +45 -0
- data/lib/embarista/version.rb +1 -1
- data/spec/manifest_builder_spec.rb +3 -3
- data/spec/manifest_url_filter_spec.rb +9 -3
- data/spec/precompile_handlebars_filter_spec.rb +6 -5
- data/spec/spec_helper.rb +3 -1
- data/vendor/ember-template-compiler.js +195 -0
- metadata +67 -98
- data/.rvmrc +0 -49
- data/lib/embarista/server.rb +0 -171
- data/vendor/ember.js +0 -21051
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 60a6173f1e57277777c84c54f9924d09a72185fc
|
4
|
+
data.tar.gz: 84ea9a1867be4b34c42d963385780ee43dae0435
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e66da548fa17ecf3d856785b66efbfec0079c3c1b812908a6dcfa5e4b8f67d824da2bc73438acfe1e9e26d7be661c432eaf37426cc3a7c999b57aae19296c779
|
7
|
+
data.tar.gz: db526b8f5f7f40a3a82faf362a78cfdac49ee13bd1b7f7c540ffd45af6ecc52a08409def6bb43ef3934d440595abb88b9c4a7775936b48044c3d8e179f60f0fa
|
data/.rspec
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
--color
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.2.5
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,12 +1,7 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
gem 'rake-pipeline',
|
6
|
-
gem 'rake-pipeline-web-filters',
|
7
|
-
gem '
|
8
|
-
gem 'aws-s3' # Uploading data to S3
|
9
|
-
gem 'debugger'
|
10
|
-
gem 'pry'
|
11
|
-
gem 'pry-debugger'
|
12
|
-
gem 'pry-remote'
|
5
|
+
gem 'rake-pipeline', git: 'https://github.com/livingsocial/rake-pipeline.git'
|
6
|
+
gem 'rake-pipeline-web-filters', git: 'https://github.com/wycats/rake-pipeline-web-filters.git'
|
7
|
+
gem 'rspec-its'
|
data/embarista.gemspec
CHANGED
@@ -16,13 +16,12 @@ Gem::Specification.new do |gem|
|
|
16
16
|
|
17
17
|
gem.add_dependency "rake-pipeline", '> 0.6.0'
|
18
18
|
gem.add_dependency "rake-pipeline-web-filters", '>= 0.6.0'
|
19
|
-
gem.add_dependency "
|
20
|
-
gem.add_dependency "ruby_gntp"
|
21
|
-
gem.add_dependency "listen"
|
19
|
+
gem.add_dependency "execjs"
|
22
20
|
gem.add_dependency "colored"
|
23
|
-
gem.add_dependency "
|
21
|
+
gem.add_dependency "aws-sdk-s3", '~> 1'
|
22
|
+
gem.add_dependency "zopfli"
|
23
|
+
gem.add_dependency "mime-types"
|
24
24
|
|
25
25
|
gem.add_development_dependency "rspec"
|
26
26
|
gem.add_development_dependency "rb-readline"
|
27
|
-
gem.add_development_dependency "execjs"
|
28
27
|
end
|
data/lib/embarista.rb
CHANGED
@@ -8,11 +8,18 @@ module Embarista
|
|
8
8
|
autoload :JavascriptPipeline, 'embarista/javascript_pipeline'
|
9
9
|
autoload :Server, 'embarista/server'
|
10
10
|
|
11
|
+
autoload :App, 'embarista/app'
|
11
12
|
autoload :Git, 'embarista/git'
|
13
|
+
autoload :Redis, 'embarista/redis'
|
14
|
+
autoload :S3, 'embarista/s3'
|
12
15
|
autoload :S3sync, 'embarista/s3sync'
|
13
16
|
autoload :SassFunctions, 'embarista/sass_functions'
|
14
17
|
autoload :ManifestBuilder, 'embarista/manifest_builder'
|
15
18
|
autoload :DynamicIndex, 'embarista/dynamic_index'
|
19
|
+
|
20
|
+
autoload :Precompiler, 'embarista/precompiler'
|
21
|
+
autoload :PrecompilerError, 'embarista/precompiler'
|
22
|
+
autoload :PrecompilerConfigurationError, 'embarista/precompiler'
|
16
23
|
end
|
17
24
|
|
18
25
|
Rake::Pipeline::DSL::PipelineDSL.send(:include, Embarista::Helpers)
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Embarista
|
2
|
+
module App
|
3
|
+
class << self
|
4
|
+
def env_var
|
5
|
+
'YAPP_ENV'
|
6
|
+
end
|
7
|
+
|
8
|
+
def env
|
9
|
+
@env ||= (ENV[env_var] || 'dev').to_sym
|
10
|
+
end
|
11
|
+
|
12
|
+
def config_by_env
|
13
|
+
@config_by_env ||= Yapp.load_config
|
14
|
+
end
|
15
|
+
|
16
|
+
def config
|
17
|
+
@config ||= config_by_env[env]
|
18
|
+
end
|
19
|
+
|
20
|
+
def app_base_url
|
21
|
+
@app_base_url ||= "https://#{config.domains.app}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def assets_base_url
|
25
|
+
@assets_base_url ||= "//#{config.domains.assets_cdn}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def assets_bucket
|
29
|
+
# asset config is the same on qa and prod
|
30
|
+
@assets_bucket ||= config_by_env[:prod].s3.assets_bucket
|
31
|
+
end
|
32
|
+
|
33
|
+
def latest_manifest_id
|
34
|
+
File.read('tmp/public/LATEST_MANIFEST_ID').chomp rescue nil
|
35
|
+
end
|
36
|
+
|
37
|
+
def heroku_app
|
38
|
+
@heroku_app ||= case env
|
39
|
+
when :qa then 'qa-yapp-cedar'
|
40
|
+
when :prod then 'yapp-cedar'
|
41
|
+
else nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -1,207 +1,3 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
|
4
|
-
module Embarista
|
5
|
-
module DynamicIndex
|
6
|
-
# ENV.fetch does not behave as Hash#fetch,
|
7
|
-
# it fails to tell you which key failed.
|
8
|
-
def self.env_fetch(key)
|
9
|
-
ENV[key] or raise KeyError, "key not found: \"#{key}\""
|
10
|
-
end
|
11
|
-
|
12
|
-
class Generator
|
13
|
-
#TODO: remove YAPP reference
|
14
|
-
attr_reader :env_config, :yapp_env, :manifest_id, :yapp_config
|
15
|
-
|
16
|
-
def initialize(erb_path, manifest_id)
|
17
|
-
@erb_path = erb_path
|
18
|
-
#TODO: remove YAPP reference
|
19
|
-
@env_config = Yapp.load_config
|
20
|
-
|
21
|
-
#TODO: remove YAPP reference
|
22
|
-
@yapp_env = Embarista::DynamicIndex.env_fetch('YAPP_ENV').to_sym
|
23
|
-
|
24
|
-
@yapp_config = env_config.fetch(@yapp_env)
|
25
|
-
@manifest_id = manifest_id || @yapp_env
|
26
|
-
prepare_manifest
|
27
|
-
end
|
28
|
-
|
29
|
-
def prepare_manifest
|
30
|
-
if @manifest_id == 'dev'
|
31
|
-
@manifest = {}
|
32
|
-
else
|
33
|
-
#TODO: ensure the manifest is on s3
|
34
|
-
@manifest = YAML.load_file("tmp/public/#{@manifest_id}.yml")
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def manifest_url(source)
|
39
|
-
source = @manifest[source] || source
|
40
|
-
"//#{yapp_config.domains.assets_cdn}#{source}"
|
41
|
-
end
|
42
|
-
|
43
|
-
def html
|
44
|
-
File.open(@erb_path) do |f|
|
45
|
-
erb = ERB.new(f.read, nil, '-')
|
46
|
-
erb.result(binding)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def preview_url(app)
|
51
|
-
"https://#{yapp_config.domains.app}/#{app}/?manifest_id=#{manifest_id}"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
class Middleware
|
56
|
-
def initialize(app, opts = {})
|
57
|
-
@app = app
|
58
|
-
@erb_path = opts[:erb] || 'app/index.html.erb'
|
59
|
-
@path_info = opts.fetch(:path_info)
|
60
|
-
@generator = Embarista::DynamicIndex::Generator.new(@erb_path, 'dev')
|
61
|
-
end
|
62
|
-
|
63
|
-
def call(env)
|
64
|
-
path = env["PATH_INFO"]
|
65
|
-
if path == @path_info
|
66
|
-
[
|
67
|
-
200,
|
68
|
-
{ 'Content-Type' => "text/html" },
|
69
|
-
[ @generator.html ]
|
70
|
-
]
|
71
|
-
else
|
72
|
-
@app.call(env)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
class SetCurrentTask < ::Rake::TaskLib
|
78
|
-
attr_accessor :name, :app
|
79
|
-
|
80
|
-
def initialize(name = :set_current_index)
|
81
|
-
@name = name
|
82
|
-
|
83
|
-
yield self if block_given?
|
84
|
-
|
85
|
-
raise 'app must be set' unless @app
|
86
|
-
define
|
87
|
-
end
|
88
|
-
|
89
|
-
def yapp_env
|
90
|
-
@yapp_env ||= Embarista::DynamicIndex.env_fetch('YAPP_ENV')
|
91
|
-
end
|
92
|
-
|
93
|
-
def redis_url
|
94
|
-
ENV['REDISTOGO_URL'] ||= begin
|
95
|
-
|
96
|
-
case yapp_env
|
97
|
-
when 'dev'
|
98
|
-
'redis://0.0.0.0:6379/'
|
99
|
-
when 'qa'
|
100
|
-
Bundler.with_clean_env do
|
101
|
-
`heroku config:get REDISTOGO_URL --app qa-yapp-cedar`.chomp
|
102
|
-
end
|
103
|
-
when 'prod'
|
104
|
-
Bundler.with_clean_env do
|
105
|
-
`heroku config:get REDISTOGO_URL --app yapp-cedar`.chomp
|
106
|
-
end
|
107
|
-
else
|
108
|
-
raise "don't know how to get redis connection for #{yapp_env}"
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def redis
|
114
|
-
$redis ||= begin
|
115
|
-
require 'uri'
|
116
|
-
require 'redis'
|
117
|
-
|
118
|
-
uri = URI.parse(redis_url)
|
119
|
-
|
120
|
-
Redis.new(
|
121
|
-
:host => uri.host,
|
122
|
-
:port => uri.port,
|
123
|
-
:password => uri.password
|
124
|
-
)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
def define
|
129
|
-
task name, :manifest_id do |t, args|
|
130
|
-
require 'redis'
|
131
|
-
|
132
|
-
manifest_id = args[:manifest_id] || yapp_env
|
133
|
-
|
134
|
-
puts "redis.set('#{app}:index:current', '#{manifest_id}')"
|
135
|
-
redis.set("#{app}:index:current", manifest_id)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
class Task < ::Rake::TaskLib
|
141
|
-
attr_accessor :name, :erb_path, :app
|
142
|
-
|
143
|
-
def initialize(name = :generate_index)
|
144
|
-
@name = name
|
145
|
-
@erb_path = "app/index.html.erb"
|
146
|
-
yield self if block_given?
|
147
|
-
|
148
|
-
raise 'app must be set' unless @app
|
149
|
-
define
|
150
|
-
end
|
151
|
-
|
152
|
-
def yapp_env
|
153
|
-
@yapp_env ||= Embarista::DynamicIndex.env_fetch('YAPP_ENV')
|
154
|
-
end
|
155
|
-
|
156
|
-
def redis_url
|
157
|
-
ENV['REDISTOGO_URL'] ||= begin
|
158
|
-
|
159
|
-
case yapp_env
|
160
|
-
when 'dev'
|
161
|
-
'redis://0.0.0.0:6379/'
|
162
|
-
when 'qa'
|
163
|
-
Bundler.with_clean_env do
|
164
|
-
`heroku config:get REDISTOGO_URL --app qa-yapp-cedar`.chomp
|
165
|
-
end
|
166
|
-
when 'prod'
|
167
|
-
Bundler.with_clean_env do
|
168
|
-
`heroku config:get REDISTOGO_URL --app yapp-cedar`.chomp
|
169
|
-
end
|
170
|
-
else
|
171
|
-
raise "don't know how to get redis connection for #{yapp_env}"
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
def redis
|
177
|
-
$redis ||= begin
|
178
|
-
require 'uri'
|
179
|
-
require 'redis'
|
180
|
-
|
181
|
-
uri = URI.parse(redis_url)
|
182
|
-
|
183
|
-
Redis.new(
|
184
|
-
:host => uri.host,
|
185
|
-
:port => uri.port,
|
186
|
-
:password => uri.password
|
187
|
-
)
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
def define
|
192
|
-
task name, :manifest_id do |t, args|
|
193
|
-
require 'redis'
|
194
|
-
|
195
|
-
manifest_id = args[:manifest_id] || yapp_env
|
196
|
-
generator = Embarista::DynamicIndex::Generator.new(erb_path, manifest_id)
|
197
|
-
html = generator.html
|
198
|
-
|
199
|
-
puts "redis.set('#{app}:index:#{manifest_id}', '#{html[0,10].strip}...')"
|
200
|
-
redis.set("#{app}:index:#{manifest_id}", html)
|
201
|
-
puts "To preview: #{generator.preview_url(app)}"
|
202
|
-
puts "To activate: YAPP_ENV=#{yapp_env} rake \"deploy:set_current_index[#{manifest_id}]\""
|
203
|
-
end
|
204
|
-
end
|
205
|
-
end
|
206
|
-
end
|
207
|
-
end
|
1
|
+
require 'embarista/dynamic_index/context'
|
2
|
+
require 'embarista/dynamic_index/generator'
|
3
|
+
require 'embarista/dynamic_index/middleware'
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Embarista
|
2
|
+
module DynamicIndex
|
3
|
+
class Context
|
4
|
+
attr_reader :app_config, :manifest_id, :manifest, :assets_base_url
|
5
|
+
|
6
|
+
def initialize(app_config, manifest_id, manifest, assets_base_url)
|
7
|
+
@app_config = app_config
|
8
|
+
@manifest_id = manifest_id
|
9
|
+
@manifest = manifest
|
10
|
+
@assets_base_url = assets_base_url
|
11
|
+
end
|
12
|
+
|
13
|
+
def manifest_url(source)
|
14
|
+
source = manifest[source] || source
|
15
|
+
assets_base_url + source
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.context(manifest_id, assets_base_url=App.assets_base_url)
|
19
|
+
manifest = load_manifest(manifest_id)
|
20
|
+
self.new(App.config, manifest_id, manifest, assets_base_url)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.load_manifest(manifest_id)
|
24
|
+
if manifest_id == 'dev'
|
25
|
+
{}
|
26
|
+
else
|
27
|
+
YAML.load_file("tmp/public/#{manifest_id}.yml")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Embarista
|
2
|
+
module DynamicIndex
|
3
|
+
class Generator
|
4
|
+
attr_reader :erb_path, :context
|
5
|
+
|
6
|
+
def initialize(erb_path, context)
|
7
|
+
@erb_path = erb_path
|
8
|
+
@context = context
|
9
|
+
end
|
10
|
+
|
11
|
+
def html
|
12
|
+
File.open(erb_path, 'r:UTF-8') do |f|
|
13
|
+
erb = ERB.new(f.read, nil, '-')
|
14
|
+
erb.filename = erb_path
|
15
|
+
context.instance_eval do
|
16
|
+
erb.result(binding)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.generator(erb_path, manifest_id, assets_base_url=App.assets_base_url)
|
22
|
+
context = Context.context(manifest_id, assets_base_url)
|
23
|
+
self.new(erb_path, context)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Embarista
|
2
|
+
module DynamicIndex
|
3
|
+
class Middleware
|
4
|
+
def initialize(app, opts = {})
|
5
|
+
@app = app
|
6
|
+
@erb_path = opts[:erb] || 'app/index.html.erb'
|
7
|
+
@path_info = opts.fetch(:path_info)
|
8
|
+
@generator = Embarista::DynamicIndex::Generator.generator(@erb_path, 'dev')
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
path = env["PATH_INFO"]
|
13
|
+
if path == @path_info
|
14
|
+
[
|
15
|
+
200,
|
16
|
+
{ 'Content-Type' => "text/html" },
|
17
|
+
[ @generator.html ]
|
18
|
+
]
|
19
|
+
else
|
20
|
+
@app.call(env)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -26,9 +26,21 @@ module Embarista
|
|
26
26
|
code.gsub!(%r{\bmanifest_url\(\s*(["'/])([^"']+)\1\)}) do |m|
|
27
27
|
quote_char = $1
|
28
28
|
path = $2
|
29
|
+
|
30
|
+
# take the anchor/querystring off if there is one
|
31
|
+
post_path_start = path.index(/[?#]/)
|
32
|
+
if post_path_start
|
33
|
+
post_path = path[post_path_start..-1]
|
34
|
+
path = path[0..post_path_start-1]
|
35
|
+
end
|
36
|
+
|
29
37
|
path = "/#{path}" unless path =~ %r{^/}
|
30
38
|
path = "#{options[:prefix]}#{path}"
|
31
39
|
resolved_path = urls_manifest[path] || path
|
40
|
+
|
41
|
+
# put the anchor/querystring back on, if there is one
|
42
|
+
resolved_path = resolved_path + post_path if post_path
|
43
|
+
|
32
44
|
"(#{options[:prepend]}'#{resolved_path}')"
|
33
45
|
end
|
34
46
|
output.write(code)
|