Class: Jekyll::Minibundle::BundleFile

Inherits:
Object
  • Object
show all
Includes:
AssetFileOperations, AssetFileProperties
Defined in:
lib/jekyll/minibundle/bundle_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AssetFileProperties

#defaults, #destination, #destination_rel_dir, #modified?, #mtime, #placeholders, #relative_path, #to_liquid, #type, #url, #write?

Methods included from AssetFileOperations

#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
# 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')
  @minifier_cmd = config.fetch('minifier_cmd')
  @stamped_at = nil
  @is_modified = false
  @_asset_bundle = nil
end

Instance Attribute Details

#stamped_atObject (readonly)

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_dirObject



49
50
51
# File 'lib/jekyll/minibundle/bundle_file.rb', line 49

def asset_destination_dir
  File.dirname(@destination_path)
end

#asset_destination_pathObject



53
54
55
# File 'lib/jekyll/minibundle/bundle_file.rb', line 53

def asset_destination_path
  "#{@destination_path}-#{asset_stamp}.#{@type}"
end

#cleanupObject



25
26
27
28
29
# File 'lib/jekyll/minibundle/bundle_file.rb', line 25

def cleanup
  return unless @_asset_bundle
  @_asset_bundle.close
  @_asset_bundle = nil
end

#destination_path_for_markupObject



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/jekyll/minibundle/bundle_file.rb', line 31

def destination_path_for_markup
  # we must rebundle here, if at all, in order to make sure the
  # markup destination and generated file paths have the same
  # fingerprint
  if modified?
    @stamped_at = mtime
    @is_modified = true
    @_asset_stamp = nil
    asset_bundle.make_bundle
  end

  asset_destination_path
end

#extnameObject



57
58
59
# File 'lib/jekyll/minibundle/bundle_file.rb', line 57

def extname
  ".#{@type}"
end

#modified_timeObject



61
62
63
# File 'lib/jekyll/minibundle/bundle_file.rb', line 61

def modified_time
  @asset_paths.map { |f| File.stat(f).mtime }.max
end

#pathObject



45
46
47
# File 'lib/jekyll/minibundle/bundle_file.rb', line 45

def path
  asset_bundle.path
end

#write(site_destination_dir) ⇒ Object

writes destination only after ‘destination_path_for_markup` has been called



67
68
69
70
71
72
73
74
75
# File 'lib/jekyll/minibundle/bundle_file.rb', line 67

def write(site_destination_dir)
  if @is_modified
    write_destination(site_destination_dir)
    @is_modified = false
    true
  else
    false
  end
end