Organizando plugins e gems.
This commit is contained in:
@@ -66,7 +66,7 @@ module Synthesis
|
||||
|
||||
def delete_all
|
||||
@@asset_packages_yml.keys.each do |asset_type|
|
||||
@@asset_packages_yml[asset_type].each { |p| self.new(asset_type, p).delete_all_builds }
|
||||
@@asset_packages_yml[asset_type].each { |p| self.new(asset_type, p).delete_previous_build }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -102,61 +102,38 @@ module Synthesis
|
||||
@asset_path = ($asset_base_path ? "#{$asset_base_path}/" : "#{RAILS_ROOT}/public/") +
|
||||
"#{@asset_type}#{@target_dir.gsub(/^(.+)$/, '/\1')}"
|
||||
@extension = get_extension
|
||||
@match_regex = Regexp.new("\\A#{@target}_\\d+.#{@extension}\\z")
|
||||
@file_name = "#{@target}_packaged.#{@extension}"
|
||||
@full_path = File.join(@asset_path, @file_name)
|
||||
end
|
||||
|
||||
def package_exists?
|
||||
File.exists?(@full_path)
|
||||
end
|
||||
|
||||
def current_file
|
||||
@target_dir.gsub(/^(.+)$/, '\1/') +
|
||||
Dir.new(@asset_path).entries.delete_if { |x| ! (x =~ @match_regex) }.sort.reverse[0].chomp(".#{@extension}")
|
||||
build unless package_exists?
|
||||
|
||||
path = @target_dir.gsub(/^(.+)$/, '\1/')
|
||||
"#{path}#{@target}_packaged"
|
||||
end
|
||||
|
||||
def build
|
||||
delete_old_builds
|
||||
delete_previous_build
|
||||
create_new_build
|
||||
end
|
||||
|
||||
def delete_old_builds
|
||||
Dir.new(@asset_path).entries.delete_if { |x| ! (x =~ @match_regex) }.each do |x|
|
||||
File.delete("#{@asset_path}/#{x}") unless x.index(revision.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
def delete_all_builds
|
||||
Dir.new(@asset_path).entries.delete_if { |x| ! (x =~ @match_regex) }.each do |x|
|
||||
File.delete("#{@asset_path}/#{x}")
|
||||
end
|
||||
def delete_previous_build
|
||||
File.delete(@full_path) if File.exists?(@full_path)
|
||||
end
|
||||
|
||||
private
|
||||
def revision
|
||||
unless @revision
|
||||
revisions = [1]
|
||||
@sources.each do |source|
|
||||
revisions << get_file_revision("#{@asset_path}/#{source}.#{@extension}")
|
||||
end
|
||||
@revision = revisions.max
|
||||
end
|
||||
@revision
|
||||
end
|
||||
|
||||
def get_file_revision(path)
|
||||
if File.exists?(path)
|
||||
begin
|
||||
`svn info #{path}`[/Last Changed Rev: (.*?)\n/][/(\d+)/].to_i
|
||||
rescue # use filename timestamp if not in subversion
|
||||
File.mtime(path).to_i
|
||||
end
|
||||
else
|
||||
0
|
||||
end
|
||||
end
|
||||
|
||||
def create_new_build
|
||||
if File.exists?("#{@asset_path}/#{@target}_#{revision}.#{@extension}")
|
||||
log "Latest version already exists: #{@asset_path}/#{@target}_#{revision}.#{@extension}"
|
||||
new_build_path = "#{@asset_path}/#{@target}_packaged.#{@extension}"
|
||||
if File.exists?(new_build_path)
|
||||
log "Latest version already exists: #{new_build_path}"
|
||||
else
|
||||
File.open("#{@asset_path}/#{@target}_#{revision}.#{@extension}", "w") {|f| f.write(compressed_file) }
|
||||
log "Created #{@asset_path}/#{@target}_#{revision}.#{@extension}"
|
||||
File.open(new_build_path, "w") {|f| f.write(compressed_file) }
|
||||
log "Created #{new_build_path}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -179,7 +156,7 @@ module Synthesis
|
||||
|
||||
def compress_js(source)
|
||||
jsmin_path = "#{RAILS_ROOT}/vendor/plugins/asset_packager/lib"
|
||||
tmp_path = "#{RAILS_ROOT}/tmp/#{@target}_#{revision}"
|
||||
tmp_path = "#{RAILS_ROOT}/tmp/#{@target}_packaged"
|
||||
|
||||
# write out to a temp file
|
||||
File.open("#{tmp_path}_uncompressed.js", "w") {|f| f.write(source) }
|
||||
@@ -200,7 +177,7 @@ module Synthesis
|
||||
|
||||
def compress_css(source)
|
||||
source.gsub!(/\s+/, " ") # collapse space
|
||||
source.gsub!(/\/\*(.*?)\*\/ /, "") # remove comments - caution, might want to remove this if using css hacks
|
||||
source.gsub!(/\/\*(.*?)\*\//, "") # remove comments - caution, might want to remove this if using css hacks
|
||||
source.gsub!(/\} /, "}\n") # add line breaks
|
||||
source.gsub!(/\n$/, "") # remove last break
|
||||
source.gsub!(/ \{ /, " {") # trim inside brackets
|
||||
|
||||
@@ -32,36 +32,8 @@ module Synthesis
|
||||
AssetPackage.targets_from_sources("stylesheets", sources) :
|
||||
AssetPackage.sources_from_targets("stylesheets", sources))
|
||||
|
||||
sources.collect { |source|
|
||||
source = stylesheet_path(source)
|
||||
tag("link", { "rel" => "Stylesheet", "type" => "text/css", "media" => "screen", "href" => source }.merge(options))
|
||||
}.join("\n")
|
||||
sources.collect { |source| stylesheet_link_tag(source, options) }.join("\n")
|
||||
end
|
||||
|
||||
private
|
||||
# rewrite compute_public_path to allow us to not include the query string timestamp
|
||||
# used by ActionView::Helpers::AssetTagHelper
|
||||
def compute_public_path(source, dir, ext=nil, add_asset_id=true)
|
||||
source = source.dup
|
||||
source << ".#{ext}" if File.extname(source).blank? && ext
|
||||
unless source =~ %r{^[-a-z]+://}
|
||||
source = "/#{dir}/#{source}" unless source[0] == ?/
|
||||
asset_id = rails_asset_id(source)
|
||||
source << '?' + asset_id if defined?(RAILS_ROOT) and add_asset_id and not asset_id.blank?
|
||||
source = "#{ActionController::Base.asset_host}#{@controller.request.relative_url_root}#{source}"
|
||||
end
|
||||
source
|
||||
end
|
||||
|
||||
# rewrite javascript path function to not include query string timestamp
|
||||
def javascript_path(source)
|
||||
compute_public_path(source, 'javascripts', 'js', false)
|
||||
end
|
||||
|
||||
# rewrite stylesheet path function to not include query string timestamp
|
||||
def stylesheet_path(source)
|
||||
compute_public_path(source, 'stylesheets', 'css', false)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user