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, get_external_resource, #process, resources

Constructor Details

#initialize(asset) ⇒ SprocketsHandler

Returns a new instance of SprocketsHandler.



53
54
55
# File 'lib/pubba/assets/sprockets_handler.rb', line 53

def initialize(asset)
  @asset = asset
end

Instance Attribute Details

#assetObject (readonly)

Returns the value of attribute asset.



51
52
53
# File 'lib/pubba/assets/sprockets_handler.rb', line 51

def asset
  @asset
end

Class Method Details

.asset_paths(*paths) ⇒ Object



13
14
15
16
17
# File 'lib/pubba/assets/sprockets_handler.rb', line 13

def asset_paths(*paths)
  paths.each do |path|
    sprockets.append_path path
  end
end

.build(name, type, ext, urls) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/pubba/assets/sprockets_handler.rb', line 32

def build(name, type, ext, urls)
  content = urls.collect do |url|
    if url.start_with?("github:")
      url,ext = get_external_resource(url)
    end

    "//= require #{url}.#{ext}"
  end.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



9
10
11
# File 'lib/pubba/assets/sprockets_handler.rb', line 9

def find(file)
  SprocketsHandler.new(sprockets.find_asset(file))
end

.process(source, destination) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/pubba/assets/sprockets_handler.rb', line 23

def 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



19
20
21
# File 'lib/pubba/assets/sprockets_handler.rb', line 19

def sprockets
  @sprockets ||= Sprockets::Environment.new()
end

Instance Method Details

#save_as(file) ⇒ Object



57
58
59
# File 'lib/pubba/assets/sprockets_handler.rb', line 57

def save_as(file)
  asset.write_to(file)
end