Class: Frontsau::Assets::Sprockets

Inherits:
Sprockets::Environment
  • Object
show all
Defined in:
lib/frontsau/assets/sprockets.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSprockets

Returns a new instance of Sprockets.



6
7
8
9
10
11
12
13
14
15
# File 'lib/frontsau/assets/sprockets.rb', line 6

def initialize
  super()
  self.output_path = File.expand_path Frontsau.config[:assets][:path]
  Frontsau.config[:assets][:sources].each do |glob_dir|
    Dir[File.expand_path(glob_dir)].each do |dir|
      append_path dir
    end
  end
  self.register_postprocessor 'text/css', UrlRewriter
end

Instance Attribute Details

#output_pathObject

Returns the value of attribute output_path.



4
5
6
# File 'lib/frontsau/assets/sprockets.rb', line 4

def output_path
  @output_path
end

#source_pathsObject

Returns the value of attribute source_paths.



4
5
6
# File 'lib/frontsau/assets/sprockets.rb', line 4

def source_paths
  @source_paths
end

Instance Method Details

#compilable_pathsObject



30
31
32
33
34
35
36
37
38
# File 'lib/frontsau/assets/sprockets.rb', line 30

def compilable_paths
  return enum_for(:compilable_paths) unless block_given?
  each_logical_path do |path|
    Frontsau.config[:assets][:compile].each do |glob|
      yield path if File.fnmatch(glob, path)
      #puts "#{path} => #{glob} :: #{File.fnmatch(glob, path)}"
    end
  end
end

#dump(path) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/frontsau/assets/sprockets.rb', line 40

def dump path

  file = File.join output_path, path

  if !Dir.exist? File.dirname(file)
    FileUtils.mkpath File.dirname(file)
  end

  begin
    content = self[path].to_s
    File.write file, content
    return true
  rescue
    return false
  end

end

#manifestObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/frontsau/assets/sprockets.rb', line 17

def manifest
  m = {}
  compilable_paths.each do |path|
    asset = self[path]
    next unless asset.present?
    m[path] = {
        digest: asset.digest,
        modified: asset.mtime
    }
  end
  m
end