Class: Wake::Assets
- Inherits:
-
Object
show all
- Defined in:
- lib/wake/assets.rb,
lib/wake/assets/renderer.rb
Defined Under Namespace
Classes: InvalidReference, Renderer
Constant Summary
collapse
- DEFAULT_BUILD =
'min'
- DEFAULT_CACHE =
true
- DEFAULT_MODE =
:targets
- DEFAULT_WAKE =
'./node_modules/wake/bin/wake'
- CACHE_FILE =
'.wake.json'
- MANIFEST =
'.manifest.json'
- PACKAGE_FILE =
'package.json'
- WAKE_FILE =
'wake.json'
- CSS =
'css'
- JS =
'javascript'
- IMG =
'binary'
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ Assets
Returns a new instance of Assets.
29
30
31
32
33
34
35
36
37
|
# File 'lib/wake/assets.rb', line 29
def initialize(options = {})
@pwd = File.expand_path(options.fetch(:pwd, Dir.pwd))
@cache = options.fetch(:cache, DEFAULT_CACHE)
@wake = options.fetch(:wake, File.expand_path(DEFAULT_WAKE, @pwd))
@root = Pathname.new(File.expand_path(options.fetch(:root, @pwd)))
@mode = options.fetch(:mode, DEFAULT_MODE)
clear_cache
end
|
Instance Method Details
#clear_cache ⇒ Object
39
40
41
42
43
44
45
46
|
# File 'lib/wake/assets.rb', line 39
def clear_cache
system(@wake, '--cache') unless @cache
@config = nil
@index = nil
@manifest = {}
@paths = {}
end
|
#generated_file_paths ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/wake/assets.rb', line 48
def generated_file_paths
index = read_index
paths = Set.new([CACHE_FILE])
index.each do |group_name, group|
group.each do |bundle_name, bundles|
bundles['targets'].each_value do |path|
paths.add(path)
manifest = File.join(File.dirname(path), MANIFEST)
source_map = path + '.map'
[manifest, source_map].each do |file|
paths.add(file) if File.file?(file)
end
end
end
end
paths.map(&method(:resolve))
end
|
#paths_for(group, names, options = {}) ⇒ Object
66
67
68
69
70
71
72
73
74
|
# File 'lib/wake/assets.rb', line 66
def paths_for(group, names, options = {})
config = read_config
build = options.fetch(:build, DEFAULT_BUILD)
unless config.fetch(group).fetch('builds', {}).has_key?(build)
build = DEFAULT_BUILD
end
names.map { |name| read_paths(group, name, build) }.flatten
end
|
#relative(path) ⇒ Object
76
77
78
|
# File 'lib/wake/assets.rb', line 76
def relative(path)
'/' + Pathname.new(path).relative_path_from(@root).to_s
end
|
#renderer(options = {}) ⇒ Object
80
81
82
83
|
# File 'lib/wake/assets.rb', line 80
def renderer(options = {})
clear_cache unless @cache
Renderer.new(self, options)
end
|