generate a real version hash
This commit is contained in:
parent
e4048f3d81
commit
4402a36c2e
|
@ -7,6 +7,8 @@ require 'compass'
|
||||||
Compass.configuration.images_path = 'assets/images'
|
Compass.configuration.images_path = 'assets/images'
|
||||||
Compass.configuration.add_import_path File.expand_path('../assets/stylesheets', __FILE__)
|
Compass.configuration.add_import_path File.expand_path('../assets/stylesheets', __FILE__)
|
||||||
|
|
||||||
|
Travis::Version.update
|
||||||
|
|
||||||
output 'public/javascripts'
|
output 'public/javascripts'
|
||||||
input 'assets/javascripts' do
|
input 'assets/javascripts' do
|
||||||
match 'app/templates/**/*.hbs' do
|
match 'app/templates/**/*.hbs' do
|
||||||
|
|
|
@ -1,65 +1,6 @@
|
||||||
require 'rake-pipeline'
|
|
||||||
require 'execjs'
|
|
||||||
require 'uglifier'
|
|
||||||
|
|
||||||
module Travis
|
module Travis
|
||||||
class HandlebarsFilter < Rake::Pipeline::Filter
|
autoload :HandlebarsFilter, 'rake-pipeline/travis/filters'
|
||||||
class << self
|
autoload :SafeConcatFilter, 'rake-pipeline/travis/filters'
|
||||||
def source
|
autoload :ProductionFilter, 'rake-pipeline/travis/filters'
|
||||||
[
|
autoload :Version, 'rake-pipeline/travis/version'
|
||||||
File.read('lib/rake-pipeline/ember-headless.js'),
|
|
||||||
File.read('assets/javascripts/vendor/handlebars.js'),
|
|
||||||
File.read('assets/javascripts/vendor/ember.js')
|
|
||||||
].join("\n")
|
|
||||||
end
|
|
||||||
|
|
||||||
def context
|
|
||||||
@@context ||= ExecJS.compile(source)
|
|
||||||
end
|
|
||||||
|
|
||||||
def compile(source)
|
|
||||||
context.call('compileHandlebarsTemplate', source + "\n")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def generate_output(inputs, output)
|
|
||||||
inputs.each do |input|
|
|
||||||
source = self.class.compile(input.read)
|
|
||||||
source = wrap(name(input.path), source)
|
|
||||||
output.write source
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def wrap(name, source)
|
|
||||||
"\nEmber.TEMPLATES['#{name}'] = Ember.Handlebars.template(#{source});\n"
|
|
||||||
end
|
|
||||||
|
|
||||||
def name(path)
|
|
||||||
path.sub(%r(^app/templates/), '').sub(/\.hbs$/, '')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class SafeConcatFilter < Rake::Pipeline::Filter
|
|
||||||
def generate_output(inputs, output)
|
|
||||||
inputs.each do |input|
|
|
||||||
source = File.read(input.fullpath) + ";"
|
|
||||||
output.write source
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class ProductionFilter < Rake::Pipeline::Filter
|
|
||||||
def generate_output(inputs, output)
|
|
||||||
inputs.each do |input|
|
|
||||||
source = File.read(input.fullpath)
|
|
||||||
source = strip_debug(source)
|
|
||||||
source = Uglifier.compile(source)
|
|
||||||
output.write source
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def strip_debug(source)
|
|
||||||
source.gsub(%r{^(\s)*Ember\.(assert|deprecate|warn)\((.*)\).*$}, "")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
65
lib/rake-pipeline/travis/filters.rb
Normal file
65
lib/rake-pipeline/travis/filters.rb
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
require 'rake-pipeline'
|
||||||
|
require 'execjs'
|
||||||
|
require 'uglifier'
|
||||||
|
|
||||||
|
module Travis
|
||||||
|
class HandlebarsFilter < Rake::Pipeline::Filter
|
||||||
|
class << self
|
||||||
|
def source
|
||||||
|
[
|
||||||
|
File.read('lib/rake-pipeline/ember-headless.js'),
|
||||||
|
File.read('assets/javascripts/vendor/handlebars.js'),
|
||||||
|
File.read('assets/javascripts/vendor/ember.js')
|
||||||
|
].join("\n")
|
||||||
|
end
|
||||||
|
|
||||||
|
def context
|
||||||
|
@@context ||= ExecJS.compile(source)
|
||||||
|
end
|
||||||
|
|
||||||
|
def compile(source)
|
||||||
|
context.call('compileHandlebarsTemplate', source + "\n")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def generate_output(inputs, output)
|
||||||
|
inputs.each do |input|
|
||||||
|
source = self.class.compile(input.read)
|
||||||
|
source = wrap(name(input.path), source)
|
||||||
|
output.write source
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def wrap(name, source)
|
||||||
|
"\nEmber.TEMPLATES['#{name}'] = Ember.Handlebars.template(#{source});\n"
|
||||||
|
end
|
||||||
|
|
||||||
|
def name(path)
|
||||||
|
path.sub(%r(^app/templates/), '').sub(/\.hbs$/, '')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class SafeConcatFilter < Rake::Pipeline::Filter
|
||||||
|
def generate_output(inputs, output)
|
||||||
|
inputs.each do |input|
|
||||||
|
source = File.read(input.fullpath) + ";"
|
||||||
|
output.write source
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class ProductionFilter < Rake::Pipeline::Filter
|
||||||
|
def generate_output(inputs, output)
|
||||||
|
inputs.each do |input|
|
||||||
|
source = File.read(input.fullpath)
|
||||||
|
source = strip_debug(source)
|
||||||
|
source = Uglifier.compile(source)
|
||||||
|
output.write source
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def strip_debug(source)
|
||||||
|
source.gsub(%r{^(\s)*Ember\.(assert|deprecate|warn)\((.*)\).*$}, "")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
54
lib/rake-pipeline/travis/version.rb
Normal file
54
lib/rake-pipeline/travis/version.rb
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
require 'pathname'
|
||||||
|
require 'digest/md5'
|
||||||
|
|
||||||
|
module Travis
|
||||||
|
class Version
|
||||||
|
FILE_NAME = 'public/version'
|
||||||
|
SOURCES = %w(AssetFile Gemfile.lock assets)
|
||||||
|
|
||||||
|
def self.update
|
||||||
|
new.update
|
||||||
|
end
|
||||||
|
|
||||||
|
attr_reader :root
|
||||||
|
|
||||||
|
def initialize(root = nil)
|
||||||
|
@root = Pathname.new(root || File.expand_path('.'))
|
||||||
|
end
|
||||||
|
|
||||||
|
def read
|
||||||
|
file.read
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@hash = nil
|
||||||
|
write(hash)
|
||||||
|
hash
|
||||||
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
def file
|
||||||
|
root.join(FILE_NAME)
|
||||||
|
end
|
||||||
|
|
||||||
|
def write(version)
|
||||||
|
file.open('w+') { |f| f.write(version) }
|
||||||
|
end
|
||||||
|
|
||||||
|
def hash
|
||||||
|
@hash ||= digest.to_s[0..7]
|
||||||
|
end
|
||||||
|
|
||||||
|
def digest
|
||||||
|
Digest::MD5.new << `ls -lAR #{sources.join(' ')} | awk '{print $5, $6, $7, $9}'`
|
||||||
|
end
|
||||||
|
|
||||||
|
def sources
|
||||||
|
SOURCES.map do |source|
|
||||||
|
source = root.join(source)
|
||||||
|
source.to_s if source.exist?
|
||||||
|
end.compact
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1 +1 @@
|
||||||
1
|
bcf31bce
|
Loading…
Reference in New Issue
Block a user