Class: Pubba::Assets::SprocketsHandler

Inherits:
Handler
  • Object
show all
Defined in:
lib/pubba/assets/sprockets_handler.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Handler

asset, #build, #process

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

#assetObject (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

.sprocketsObject



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