generate a real version hash

This commit is contained in:
Sven Fuchs 2012-10-01 13:11:26 +02:00
parent e4048f3d81
commit 4402a36c2e
5 changed files with 126 additions and 64 deletions

View File

@ -7,6 +7,8 @@ require 'compass'
Compass.configuration.images_path = 'assets/images'
Compass.configuration.add_import_path File.expand_path('../assets/stylesheets', __FILE__)
Travis::Version.update
output 'public/javascripts'
input 'assets/javascripts' do
match 'app/templates/**/*.hbs' do

View File

@ -1,65 +1,6 @@
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
autoload :HandlebarsFilter, 'rake-pipeline/travis/filters'
autoload :SafeConcatFilter, 'rake-pipeline/travis/filters'
autoload :ProductionFilter, 'rake-pipeline/travis/filters'
autoload :Version, 'rake-pipeline/travis/version'
end

View 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

View 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

View File

@ -1 +1 @@
1
bcf31bce