Class: Jekyll::Minibundle::StampFile

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AssetFileProperties

#asset_destination_path, #defaults, #destination, #destination_rel_dir, #modified?, #modified_time, #mtime, #name, #path, #placeholders, #relative_path, #to_liquid, #type, #url, #write?

Methods included from AssetFileOperations

#cleanup, #write_destination

Constructor Details

#initialize(site, asset_source_path, asset_destination_path) ⇒ StampFile

Returns a new instance of StampFile.



12
13
14
15
16
17
18
19
20
# File 'lib/jekyll/minibundle/stamp_file.rb', line 12

def initialize(site, asset_source_path, asset_destination_path)
  @site = site
  @asset_source_path = File.join(@site.source, asset_source_path)
  @asset_destination_dir = File.dirname(asset_destination_path)
  @asset_destination_extension = File.extname(asset_destination_path)
  @asset_destination_filename_prefix = File.basename(asset_destination_path)[0..-(@asset_destination_extension.size + 1)]
  @stamped_at = nil
  @is_modified = false
end

Instance Attribute Details

#asset_destination_dirObject (readonly)

Returns the value of attribute asset_destination_dir.



10
11
12
# File 'lib/jekyll/minibundle/stamp_file.rb', line 10

def asset_destination_dir
  @asset_destination_dir
end

#asset_source_pathObject (readonly)

Returns the value of attribute asset_source_path.



10
11
12
# File 'lib/jekyll/minibundle/stamp_file.rb', line 10

def asset_source_path
  @asset_source_path
end

#stamped_atObject (readonly)

Returns the value of attribute stamped_at.



10
11
12
# File 'lib/jekyll/minibundle/stamp_file.rb', line 10

def stamped_at
  @stamped_at
end

Instance Method Details

#asset_destination_filenameObject



35
36
37
# File 'lib/jekyll/minibundle/stamp_file.rb', line 35

def asset_destination_filename
  "#{@asset_destination_filename_prefix}-#{asset_stamp}#{extname}"
end

#destination_path_for_markupObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/jekyll/minibundle/stamp_file.rb', line 22

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

  asset_destination_path
end

#extnameObject



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

def extname
  @asset_destination_extension
end

#write(site_destination_dir) ⇒ Object

allows writing destination only after ‘destination_path_for_markup` has been called



45
46
47
48
49
50
51
52
53
# File 'lib/jekyll/minibundle/stamp_file.rb', line 45

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