Class: Pubba::Assets::SprocketsHandler
- Defined in:
- lib/pubba/assets/sprockets_handler.rb
Instance Attribute Summary collapse
-
#asset ⇒ Object
readonly
Returns the value of attribute asset.
Class Method Summary collapse
- .asset_paths(*paths) ⇒ Object
- .build(name, type, ext, urls) ⇒ Object
- .find(file) ⇒ Object
- .process(source, destination) ⇒ Object
- .sprockets ⇒ Object
Instance Method Summary collapse
-
#initialize(asset) ⇒ SprocketsHandler
constructor
A new instance of SprocketsHandler.
- #save_as(file) ⇒ Object
Methods inherited from Handler
Constructor Details
#initialize(asset) ⇒ SprocketsHandler
Returns a new instance of SprocketsHandler.
44 45 46 |
# File 'lib/pubba/assets/sprockets_handler.rb', line 44 def initialize(asset) @asset = asset end |
Instance Attribute Details
#asset ⇒ Object (readonly)
Returns the value of attribute asset.
42 43 44 |
# File 'lib/pubba/assets/sprockets_handler.rb', line 42 def asset @asset end |
Class Method Details
.asset_paths(*paths) ⇒ Object
12 13 14 15 16 |
# File 'lib/pubba/assets/sprockets_handler.rb', line 12 def self.asset_paths(*paths) paths.each do |path| sprockets.append_path path end end |
.build(name, type, ext, urls) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/pubba/assets/sprockets_handler.rb', line 31 def self.build(name, type, ext, urls) content = urls.collect{|url| "//= require #{url}.#{ext}"}.compact.join("\n") out_folder = File.join(Pubba.asset_folder, "out", ext) FileUtils.mkdir_p out_folder fname = File.join(out_folder, "#{name}-#{type}.#{ext}") File.open(fname, 'w') do |f| f.write Site.asset_configuration.disclaimer f.write content end end |
.find(file) ⇒ Object
8 9 10 |
# File 'lib/pubba/assets/sprockets_handler.rb', line 8 def self.find(file) SprocketsHandler.new(sprockets.find_asset(file)) end |
.process(source, destination) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/pubba/assets/sprockets_handler.rb', line 22 def self.process(source, destination) FileUtils.mkdir_p destination Dir.glob("#{source}/*") do |file| asset = find(file) asset.save_as "#{destination}/#{File.basename(file)}" end end |
.sprockets ⇒ Object
18 19 20 |
# File 'lib/pubba/assets/sprockets_handler.rb', line 18 def self.sprockets @sprockets ||= Sprockets::Environment.new() end |
Instance Method Details
#save_as(file) ⇒ Object
48 49 50 |
# File 'lib/pubba/assets/sprockets_handler.rb', line 48 def save_as(file) asset.write_to(file) end |