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_MODE =
:targets
- DEFAULT_WAKE =
'./node_modules/wake/bin/wake'
- CACHE_FILE =
'.wake.json'
- MANIFEST =
'.manifest.json'
- PACKAGE_FILE =
'package.json'
- WAKE_FILE =
'wake.json'
- CONFIG_FILES =
Set.new([CACHE_FILE, MANIFEST, PACKAGE_FILE, WAKE_FILE])
- CSS =
'css'
- JS =
'javascript'
- IMG =
'binary'
Instance Method Summary
collapse
Constructor Details
#initialize(options) ⇒ Assets
Returns a new instance of Assets.
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/wake/assets.rb', line 30
def initialize(options)
@pwd = File.expand_path(options.fetch(:pwd, Dir.pwd))
@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)
@manifest = new_manifest_cache
@paths = new_path_cache
system(@wake, '--cache')
read_config
return unless options[:monitor]
listener = Listen.to(@pwd).change do |modified, added, removed|
all = (modified + added + removed).map &File.method(:basename)
system(@wake, '--cache') if (added.any? or removed.any?) and not all.include?(CACHE_FILE)
update! if (CONFIG_FILES & all).any?
end
listener.force_polling(true)
listener.start
end
|
Instance Method Details
#deployment? ⇒ Boolean
52
53
54
|
# File 'lib/wake/assets.rb', line 52
def deployment?
@mode == :targets
end
|
#paths_for(group, names, options = {}) ⇒ Object
56
57
58
59
60
61
62
|
# File 'lib/wake/assets.rb', line 56
def paths_for(group, names, options = {})
build = options.fetch(:build, DEFAULT_BUILD)
unless @config[group].fetch('builds', {}).has_key?(build)
build = DEFAULT_BUILD
end
names.map { |name| @paths[group][name][build] }.flatten
end
|
#relative(path) ⇒ Object
64
65
66
|
# File 'lib/wake/assets.rb', line 64
def relative(path)
'/' + Pathname.new(path).relative_path_from(@root).to_s
end
|
#renderer(options = {}) ⇒ Object
68
69
70
|
# File 'lib/wake/assets.rb', line 68
def renderer(options = {})
Renderer.new(self, options)
end
|