Class: Jekyll::Minibundle::BundleFile

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AssetFileOperations

#static_file!, #write_destination

Constructor Details

#initialize(config) ⇒ BundleFile

Returns a new instance of BundleFile.



18
19
20
21
22
23
24
25
# File 'lib/jekyll/minibundle/bundle_file.rb', line 18

def initialize(config)
  @type = config['type']
  @site_source_dir = config['site_dir']
  asset_source_dir = File.join @site_source_dir, config['source_dir']
  @assets = config['assets'].map { |asset_path| File.join asset_source_dir, "#{asset_path}.#{@type}" }
  @destination_path = config['destination_path']
  @attributes = config['attributes']
end

Class Method Details

.clear_cacheObject



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

def self.clear_cache
  @@mtimes = {}
  @@writes_after_mtime_updates = Hash.new false
  @@asset_bundles = {}
end

Instance Method Details

#asset_destination_pathObject



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

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

#destination(site_destination_dir) ⇒ Object



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

def destination(site_destination_dir)
  File.join site_destination_dir, asset_destination_path
end

#destination_written_after_mtime_update?Boolean

Returns:

  • (Boolean)


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

def destination_written_after_mtime_update?
  @@writes_after_mtime_updates[asset_destination_canonical_path]
end

#markupObject



27
28
29
30
31
32
# File 'lib/jekyll/minibundle/bundle_file.rb', line 27

def markup
  # we must rebundle here, if at all, in order to make sure the
  # markup and generated file have the same fingerprint
  rebundle_assets if modified?
  AssetTagMarkup.make_markup @type, asset_destination_path, @attributes
end

#modified?Boolean

Returns:

  • (Boolean)


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

def modified?
  @@mtimes[asset_destination_canonical_path] != mtime
end

#mtimeObject



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

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

#pathObject



34
35
36
# File 'lib/jekyll/minibundle/bundle_file.rb', line 34

def path
  asset_bundle.path
end

#write(site_destination_dir) ⇒ Object



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

def write(site_destination_dir)
  if File.exists?(destination(site_destination_dir)) && destination_written_after_mtime_update?
    false
  else
    write_destination site_destination_dir
    @@writes_after_mtime_updates[asset_destination_canonical_path] = true
    true
  end
end