enhance the rake task which forces to serialize page templates + do not import twice an asset with the same filename

This commit is contained in:
did 2011-07-19 11:49:15 +02:00
parent 53a83b5f79
commit 45ff488ae8
2 changed files with 22 additions and 15 deletions

View File

@ -30,7 +30,7 @@ module Locomotive
self.log "!ERROR! = #{e.message}, #{asset_path}"
end
site.reload
# site.reload
end
end
end
@ -42,21 +42,20 @@ module Locomotive
self.log "other asset = #{asset_path}"
name = File.basename(asset_path, File.extname(asset_path)).parameterize('_')
asset = site.assets.where(:source_filename => File.basename(asset_path)).first
self.site.assets.create! :name => name, :source => File.open(asset_path)
end
end
asset ||= self.site.assets.build
def build_regexps_in_withlist(rules)
rules.collect do |rule|
if rule.start_with?('^')
Regexp.new(rule.gsub('/', '\/'))
else
rule
asset.attributes = { :source => File.open(asset_path) }
begin
asset.save!
rescue Exception => e
self.log "!ERROR! = #{e.message}, #{asset_path}"
end
end
end
end
end
end

View File

@ -13,10 +13,18 @@ namespace :locomotive do
desc 'Rebuild the serialized template of all the site pages'
task :rebuild_serialized_page_templates => :environment do
Page.all.each do |page|
next unless page.template.nil?
page.send :_parse_and_serialize_template
page.save
Site.all.each do |site|
pages = site.pages.to_a
while !pages.empty? do
page = pages.pop
begin
page.send :_parse_and_serialize_template
page.save
puts "[#{site.name}] processing...#{page.title}"
rescue TypeError => e
pages.insert(0, page)
end
end
end
end