embarista 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc ADDED
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
7
+ environment_id="ruby-1.9.3-p327"
8
+
9
+ #
10
+ # First we attempt to load the desired environment directly from the environment
11
+ # file. This is very fast and efficicent compared to running through the entire
12
+ # CLI and selector. If you want feedback on which environment was used then
13
+ # insert the word 'use' after --create as this triggers verbose mode.
14
+ #
15
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
16
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]] ; then
17
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
18
+
19
+ [[ -s ".rvm/hooks/after_use" ]] && . ".rvm/hooks/after_use"
20
+ else
21
+ # If the environment file has not yet been created, use the RVM CLI to select.
22
+ rvm --create use "$environment_id"
23
+ fi
24
+
25
+ #
26
+ # If you use an RVM gemset file to install a list of gems (*.gems), you can have
27
+ # it be automatically loaded. Uncomment the following and adjust the filename if
28
+ # necessary.
29
+ #
30
+ # filename=".gems"
31
+ # if [[ -s "$filename" ]] ; then
32
+ # rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
33
+ # fi
34
+
35
+ #
36
+ # If you use bundler and would like to run bundle each time you enter the
37
+ # directory, you can uncomment the following code.
38
+ #
39
+ # # Ensure that Bundler is installed. Install it if it is not.
40
+ # if ! command -v bundle >/dev/null; then
41
+ # printf "The rubygem 'bundler' is not installed. Installing it now.\n"
42
+ # gem install bundler
43
+ # fi
44
+ #
45
+ # # Bundle while reducing excess noise.
46
+ # printf "Bundling your gems. This may take a few minutes on a fresh clone.\n"
47
+ # bundle | grep -v '^Using ' | grep -v ' is complete' | sed '/^$/d'
48
+ #
49
+
data/.travis.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.2
3
+ - 1.9.3-p327
4
4
  bundler_args: --without docs
5
5
  notifications:
6
6
  tech@yapp.us
data/Gemfile CHANGED
@@ -4,8 +4,9 @@ gemspec
4
4
 
5
5
  gem 'rake-pipeline', github: 'livingsocial/rake-pipeline'
6
6
  gem 'rake-pipeline-web-filters', github: 'wycats/rake-pipeline-web-filters'
7
+ gem 'barber'
8
+ gem 'aws-s3' # Uploading data to S3
7
9
  gem 'debugger'
8
10
  gem 'pry'
9
11
  gem 'pry-debugger'
10
12
  gem 'pry-remote'
11
- gem 'aws-s3' # Uploading data to S3
data/embarista.gemspec CHANGED
@@ -16,6 +16,7 @@ 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 "barber"
19
20
  gem.add_dependency "ruby_gntp"
20
21
  gem.add_dependency "listen"
21
22
  gem.add_dependency "colored"
data/lib/embarista.rb CHANGED
@@ -8,11 +8,11 @@ module Embarista
8
8
  autoload :JavascriptPipeline, 'embarista/javascript_pipeline'
9
9
  autoload :Server, 'embarista/server'
10
10
 
11
- autoload :Git, 'embarista/git'
12
- autoload :S3sync, 'embarista/s3sync'
13
- autoload :DigestHelper, 'embarista/digest_helper'
14
- autoload :ManifestHelper, 'embarista/manifest_helper'
15
- autoload :SassFunctions, 'embarista/sass_functions'
11
+ autoload :Git, 'embarista/git'
12
+ autoload :S3sync, 'embarista/s3sync'
13
+ autoload :SassFunctions, 'embarista/sass_functions'
14
+ autoload :ManifestBuilder, 'embarista/manifest_builder'
15
+ autoload :DynamicIndex, 'embarista/dynamic_index'
16
16
  end
17
17
 
18
18
  Rake::Pipeline::DSL::PipelineDSL.send(:include, Embarista::Helpers)
@@ -0,0 +1,207 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
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
@@ -3,8 +3,9 @@ require "rake-pipeline-web-filters"
3
3
  module Embarista
4
4
  module Filters
5
5
  autoload :ErbFilter, 'embarista/filters/erb_filter'
6
- autoload :StripEmberAssertsFilter, 'embarista/filters/strip_ember_asserts_filter'
6
+ autoload :ManifestUrlFilter, 'embarista/filters/manifest_url_filter'
7
7
  autoload :PrecompileHandlebarsFilter, 'embarista/filters/precompile_handlebars_filter'
8
8
  autoload :RewriteMinispadeRequiresFilter, 'embarista/filters/rewrite_minispade_requires_filter'
9
+ autoload :StripEmberAssertsFilter, 'embarista/filters/strip_ember_asserts_filter'
9
10
  end
10
11
  end
@@ -0,0 +1,39 @@
1
+ module Embarista
2
+ module Filters
3
+ class ManifestUrlFilter < Rake::Pipeline::Filter
4
+ attr_reader :options
5
+
6
+ def initialize(options= {}, &block)
7
+ @options = options || {}
8
+ raise 'Must pass :path option' unless @options.key?(:path)
9
+ super(&block)
10
+ end
11
+
12
+ attr_writer :urls_manifest
13
+ def urls_manifest
14
+ @urls_manifest ||= begin
15
+ if File.exists?(options[:path])
16
+ JSON.parse(IO.read(options[:path]))
17
+ else
18
+ {}
19
+ end
20
+ end
21
+ end
22
+
23
+ def generate_output(inputs, output)
24
+ inputs.each do |input|
25
+ code = input.read
26
+ code.gsub!(%r{\bmanifest_url\(\s*(["'/])([^"']+)\1\)}) do |m|
27
+ quote_char = $1
28
+ path = $2
29
+ path = "/#{path}" unless path =~ %r{^/}
30
+ path = "#{options[:prefix]}#{path}"
31
+ resolved_path = urls_manifest[path] || path
32
+ "(#{options[:prepend]}'#{resolved_path}')"
33
+ end
34
+ output.write(code)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,77 +1,9 @@
1
+ require 'barber'
2
+
1
3
  module Embarista
2
4
  module Filters
3
- class PrecompileHandlebarsFilter < Rake::Pipeline::Filter
4
- class << self
5
- def emberjs_path=(path)
6
- if defined?(@@emberjs_path)
7
- raise "Cannot set emberjs_path to #{path}. It was already set to #{@@emberjs_path}"
8
- else
9
- @@emberjs_path = path
10
- end
11
- end
12
-
13
- def handlebarsjs_path=(path)
14
- if defined?(@@handlebarsjs_path)
15
- raise "Cannot set handlebarsjs_path to #{path}. It was already set to #{@@handlebarsjs_path}"
16
- else
17
- @@handlebarsjs_path = path
18
- end
19
- end
20
-
21
- def jquery_version=(jquery_version)
22
- @@jquery_version = jquery_version
23
- end
24
-
25
- def headless_ember_preamble
26
- <<-JS
27
- // DOM
28
- var Element = {};
29
- Element.firstChild = function () { return Element; };
30
- Element.innerHTML = function () { return Element; };
31
-
32
- var document = { createRange: false, createElement: function() { return Element; } };
33
- var window = this;
34
- this.document = document;
35
-
36
- // Console
37
- var console = window.console = {};
38
- console.log = console.info = console.warn = console.error = function(){};
39
-
40
- // jQuery
41
- var jQuery = window.jQuery = function() { return jQuery; };
42
- jQuery.ready = function() { return jQuery; };
43
- jQuery.inArray = function() { return jQuery; };
44
- jQuery.jquery = "#{@@jquery_version}";
45
- jQuery.event = { fixHooks: {} };
46
- var $ = jQuery;
47
-
48
- // Ember
49
- function precompileEmberHandlebars(string) {
50
- return Ember.Handlebars.precompile(string).toString();
51
- }
52
- JS
53
- end
54
-
55
- def contents
56
- raise "Must set emberjs_path" unless @@emberjs_path
57
- raise "Must set handlebarsjs_path" unless @@handlebarsjs_path
58
- raise "Must set jquery_version" unless @@jquery_version
59
- @@contents ||= [File.read(@@handlebarsjs_path),
60
- headless_ember_preamble,
61
- File.read(@@emberjs_path)].join("\n")
62
- end
63
-
64
- def context
65
- @@context ||= ExecJS.compile(contents)
66
- end
67
- end
68
-
5
+ class PrecompileHandlebarsFilter < Rake::Pipeline::Filter
69
6
  def initialize(options= {}, &block)
70
- @options = options
71
- self.class.emberjs_path = options[:emberjs]
72
- self.class.handlebarsjs_path = options[:handlebarsjs]
73
- self.class.jquery_version = options[:jquery_version]
74
-
75
7
  @template_dir = options[:template_dir] || 'templates'
76
8
 
77
9
  super(&block)
@@ -89,16 +21,11 @@ module Embarista
89
21
  dirname.gsub!(/^\/?#{@template_dir}\/?/,'')
90
22
 
91
23
  full_name = [dirname, name].compact.reject(&:empty?).join('/')
24
+ compiled = Barber::Ember::FilePrecompiler.call(input.read)
92
25
 
93
- compiled = self.class.context.call("precompileEmberHandlebars", input.read)
94
- output.write "\nEmber.TEMPLATES['#{full_name}'] = Ember.Handlebars.template(#{compiled});\n"
26
+ output.write "\nEmber.TEMPLATES['#{full_name}'] = #{compiled};\n"
95
27
  end
96
28
  end
97
-
98
- private
99
- def external_dependencies
100
- [ 'execjs' ]
101
- end
102
29
  end
103
30
  end
104
31
  end