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

#destination, #destination_rel_dir, #extname, #modified?, #relative_path, #to_liquid, #write?

Methods included from AssetFileOperations

#add_as_static_file_to, #write_destination

Constructor Details

#initialize(site, config) ⇒ BundleFile

Returns a new instance of BundleFile.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/jekyll/minibundle/bundle_file.rb', line 14

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

Instance Attribute Details

#stamped_atObject (readonly)

Returns the value of attribute stamped_at.



12
13
14
# File 'lib/jekyll/minibundle/bundle_file.rb', line 12

def stamped_at
  @stamped_at
end

Instance Method Details

#asset_destination_dirObject



43
44
45
# File 'lib/jekyll/minibundle/bundle_file.rb', line 43

def asset_destination_dir
  File.dirname(@destination_path)
end

#asset_destination_pathObject



47
48
49
# File 'lib/jekyll/minibundle/bundle_file.rb', line 47

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

#destination_path_for_markupObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/jekyll/minibundle/bundle_file.rb', line 26

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

  AssetTagMarkup.make_markup(@type, asset_destination_path, @attributes)
end

#mtimeObject



51
52
53
# File 'lib/jekyll/minibundle/bundle_file.rb', line 51

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

#pathObject



39
40
41
# File 'lib/jekyll/minibundle/bundle_file.rb', line 39

def path
  asset_bundle.path
end

#write(site_destination_dir) ⇒ Object

writes destination only after ‘destination_path_for_markup` has been called



57
58
59
60
61
62
63
64
65
# File 'lib/jekyll/minibundle/bundle_file.rb', line 57

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