2010-09-23 23:00:13 +00:00
|
|
|
module Locomotive
|
|
|
|
module Import
|
2010-10-28 23:36:45 +00:00
|
|
|
class Assets < Base
|
2010-09-23 23:00:13 +00:00
|
|
|
|
2010-10-28 23:36:45 +00:00
|
|
|
def process
|
2011-07-04 17:40:14 +00:00
|
|
|
self.add_theme_assets
|
2010-10-07 00:45:41 +00:00
|
|
|
|
2010-10-28 23:36:45 +00:00
|
|
|
self.add_other_assets
|
2010-09-23 23:00:13 +00:00
|
|
|
end
|
|
|
|
|
2010-10-28 23:36:45 +00:00
|
|
|
protected
|
|
|
|
|
2011-07-04 17:40:14 +00:00
|
|
|
def add_theme_assets
|
2010-10-07 00:45:41 +00:00
|
|
|
%w(images media fonts javascripts stylesheets).each do |kind|
|
|
|
|
Dir[File.join(theme_path, 'public', kind, '**/*')].each do |asset_path|
|
2010-09-23 23:00:13 +00:00
|
|
|
|
|
|
|
next if File.directory?(asset_path)
|
|
|
|
|
2010-10-07 00:45:41 +00:00
|
|
|
folder = asset_path.gsub(File.join(theme_path, 'public'), '').gsub(File.basename(asset_path), '').gsub(/^\//, '').gsub(/\/$/, '')
|
|
|
|
|
|
|
|
asset = site.theme_assets.where(:local_path => File.join(folder, File.basename(asset_path))).first
|
|
|
|
|
|
|
|
asset ||= site.theme_assets.build(:folder => folder)
|
2010-09-23 23:00:13 +00:00
|
|
|
|
2011-07-04 17:40:14 +00:00
|
|
|
asset.attributes = { :source => File.open(asset_path), :performing_plain_text => false }
|
2010-10-14 21:56:51 +00:00
|
|
|
|
2010-10-27 00:11:44 +00:00
|
|
|
begin
|
|
|
|
asset.save!
|
|
|
|
rescue Exception => e
|
2010-10-28 23:36:45 +00:00
|
|
|
self.log "!ERROR! = #{e.message}, #{asset_path}"
|
2010-10-27 00:11:44 +00:00
|
|
|
end
|
2010-09-23 23:00:13 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-10-28 23:36:45 +00:00
|
|
|
def add_other_assets
|
2010-09-23 23:00:13 +00:00
|
|
|
Dir[File.join(theme_path, 'public', 'samples', '*')].each do |asset_path|
|
|
|
|
|
|
|
|
next if File.directory?(asset_path)
|
|
|
|
|
2010-10-30 22:30:30 +00:00
|
|
|
self.log "other asset = #{asset_path}"
|
|
|
|
|
2011-07-19 09:49:15 +00:00
|
|
|
asset = site.assets.where(:source_filename => File.basename(asset_path)).first
|
2010-09-23 23:00:13 +00:00
|
|
|
|
2011-07-19 09:49:15 +00:00
|
|
|
asset ||= self.site.assets.build
|
2010-09-23 23:00:13 +00:00
|
|
|
|
2011-07-19 09:49:15 +00:00
|
|
|
asset.attributes = { :source => File.open(asset_path) }
|
|
|
|
|
|
|
|
begin
|
|
|
|
asset.save!
|
|
|
|
rescue Exception => e
|
|
|
|
self.log "!ERROR! = #{e.message}, #{asset_path}"
|
2010-10-07 00:45:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-07-19 09:49:15 +00:00
|
|
|
|
2010-09-23 23:00:13 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|