class Jekyll::Minibundle::BundleFile
Attributes
asset_destination_dir[R]
stamped_at[R]
Public Class Methods
new(site, config)
click to toggle source
# File lib/jekyll/minibundle/bundle_file.rb 15 def initialize(site, config) 16 @site = site 17 @type = config.fetch('type') 18 asset_source_dir = File.join(@site.source, config.fetch('source_dir')) 19 20 raise ArgumentError, "Bundle source directory does not exist: #{asset_source_dir}" unless File.directory?(asset_source_dir) 21 22 @asset_paths = config.fetch('assets').map do |asset_path| 23 path = File.join(asset_source_dir, "#{asset_path}.#{@type}") 24 25 raise ArgumentError, "Bundle asset source file does not exist: #{path}" unless File.file?(path) 26 27 path 28 end 29 30 @destination_path = config.fetch('destination_path') 31 @asset_destination_dir = File.dirname(@destination_path) 32 @asset_destination_filename_prefix = File.basename(@destination_path) 33 @minifier_cmd = config.fetch('minifier_cmd') 34 @stamped_at = nil 35 @is_modified = false 36 @_asset_bundle = nil 37 end
Public Instance Methods
asset_destination_filename()
click to toggle source
# File lib/jekyll/minibundle/bundle_file.rb 67 def asset_destination_filename 68 "#{@asset_destination_filename_prefix}-#{asset_stamp}#{extname}" 69 end
asset_source_path()
click to toggle source
# File lib/jekyll/minibundle/bundle_file.rb 63 def asset_source_path 64 asset_bundle.path 65 end
cleanup()
click to toggle source
# File lib/jekyll/minibundle/bundle_file.rb 39 def cleanup 40 return unless @_asset_bundle 41 42 @_asset_bundle.close 43 @_asset_bundle = nil 44 end
destination_path_for_markup()
click to toggle source
# File lib/jekyll/minibundle/bundle_file.rb 46 def destination_path_for_markup 47 # we must rebundle here, if at all, in order to make sure the 48 # destination path in the markup and the generated file path have 49 # the same fingerprint 50 51 source_mtime = mtime 52 53 if @stamped_at != source_mtime 54 @stamped_at = source_mtime 55 @is_modified = true 56 @_asset_stamp = nil 57 asset_bundle.make_bundle 58 end 59 60 asset_destination_path 61 end
extname()
click to toggle source
# File lib/jekyll/minibundle/bundle_file.rb 71 def extname 72 ".#{@type}" 73 end
modified?()
click to toggle source
# File lib/jekyll/minibundle/bundle_file.rb 79 def modified? 80 @is_modified 81 end
modified_time()
click to toggle source
# File lib/jekyll/minibundle/bundle_file.rb 75 def modified_time 76 @asset_paths.map { |f| File.stat(f).mtime }.max 77 end
write(site_destination_dir)
click to toggle source
allows writing destination only after `destination_path_for_markup` has been called
# File lib/jekyll/minibundle/bundle_file.rb 85 def write(site_destination_dir) 86 if modified? 87 dst_path = destination(site_destination_dir) 88 Files.copy_p(path, dst_path) 89 90 # respect user's umask; Ruby's tempfile has mode 0o600 91 File.chmod(0o666 & ~File.umask, dst_path) 92 93 @is_modified = false 94 true 95 else 96 false 97 end 98 end
Private Instance Methods
asset_bundle()
click to toggle source
# File lib/jekyll/minibundle/bundle_file.rb 106 def asset_bundle 107 @_asset_bundle ||= AssetBundle.new( 108 type: @type, 109 asset_paths: @asset_paths, 110 destination_path: @destination_path, 111 site_dir: @site.source, 112 minifier_cmd: @minifier_cmd 113 ) 114 end
asset_stamp()
click to toggle source
# File lib/jekyll/minibundle/bundle_file.rb 102 def asset_stamp 103 @_asset_stamp ||= AssetStamp.from_file(asset_source_path) 104 end