Class: Jekyll::Minibundle::BundleFile
Instance Attribute Summary collapse
Instance Method Summary
collapse
#asset_destination_path, #defaults, #destination, #destination_rel_dir, #modified?, #mtime, #name, #path, #placeholders, #relative_path, #to_liquid, #type, #url, #write?
#write_destination
Constructor Details
#initialize(site, config) ⇒ BundleFile
Returns a new instance of BundleFile.
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/jekyll/minibundle/bundle_file.rb', line 13
def initialize(site, config)
@site = site
@type = config.fetch('type')
asset_source_dir = File.join(@site.source, config.fetch('source_dir'))
@asset_paths = config.fetch('assets').map { |asset_path| File.join(asset_source_dir, "#{asset_path}.#{@type}") }
destination_path = config.fetch('destination_path')
@asset_destination_dir = File.dirname(destination_path)
@asset_destination_filename_prefix = File.basename(destination_path)
@minifier_cmd = config.fetch('minifier_cmd')
@stamped_at = nil
@is_modified = false
@_asset_bundle = nil
end
|
Instance Attribute Details
#asset_destination_dir ⇒ Object
Returns the value of attribute asset_destination_dir.
11
12
13
|
# File 'lib/jekyll/minibundle/bundle_file.rb', line 11
def asset_destination_dir
@asset_destination_dir
end
|
#stamped_at ⇒ Object
Returns the value of attribute stamped_at.
11
12
13
|
# File 'lib/jekyll/minibundle/bundle_file.rb', line 11
def stamped_at
@stamped_at
end
|
Instance Method Details
#asset_destination_filename ⇒ Object
51
52
53
|
# File 'lib/jekyll/minibundle/bundle_file.rb', line 51
def asset_destination_filename
"#{@asset_destination_filename_prefix}-#{asset_stamp}#{extname}"
end
|
#asset_source_path ⇒ Object
47
48
49
|
# File 'lib/jekyll/minibundle/bundle_file.rb', line 47
def asset_source_path
asset_bundle.path
end
|
#cleanup ⇒ Object
27
28
29
30
31
|
# File 'lib/jekyll/minibundle/bundle_file.rb', line 27
def cleanup
return unless @_asset_bundle
@_asset_bundle.close
@_asset_bundle = nil
end
|
#destination_path_for_markup ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/jekyll/minibundle/bundle_file.rb', line 33
def destination_path_for_markup
if modified?
@stamped_at = mtime
@is_modified = true
@_asset_stamp = nil
asset_bundle.make_bundle
end
asset_destination_path
end
|
#extname ⇒ Object
55
56
57
|
# File 'lib/jekyll/minibundle/bundle_file.rb', line 55
def extname
".#{@type}"
end
|
#modified_time ⇒ Object
59
60
61
|
# File 'lib/jekyll/minibundle/bundle_file.rb', line 59
def modified_time
@asset_paths.map { |f| File.stat(f).mtime }.max
end
|
#write(site_destination_dir) ⇒ Object
allows writing destination only after ‘destination_path_for_markup` has been called
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/jekyll/minibundle/bundle_file.rb', line 65
def write(site_destination_dir)
if @is_modified
dst_path = write_destination(site_destination_dir)
File.chmod(0o666 & ~File.umask, dst_path)
@is_modified = false
true
else
false
end
end
|