Class: Jekyll::Minibundle::StampFile

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AssetFileProperties

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

Constructor Details

#initialize(site, asset_source_path, asset_destination_path) ⇒ StampFile

Returns a new instance of StampFile.

Raises:

  • (ArgumentError)


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

def initialize(site, asset_source_path, asset_destination_path)
  @site = site
  @asset_source_path = File.join(@site.source, asset_source_path)
  raise ArgumentError, "Stamp source file does not exist: #{@asset_source_path}" unless File.file?(@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.



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

def asset_destination_dir
  @asset_destination_dir
end

#asset_source_pathObject (readonly)

Returns the value of attribute asset_source_path.



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

def asset_source_path
  @asset_source_path
end

#stamped_atObject (readonly)

Returns the value of attribute stamped_at.



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

def stamped_at
  @stamped_at
end

Instance Method Details

#asset_destination_filenameObject



44
45
46
# File 'lib/jekyll/minibundle/stamp_file.rb', line 44

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

#cleanupObject



24
25
26
# File 'lib/jekyll/minibundle/stamp_file.rb', line 24

def cleanup
  # no-op
end

#destination_path_for_markupObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/jekyll/minibundle/stamp_file.rb', line 28

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

  source_mtime = mtime

  if @stamped_at != source_mtime
    @stamped_at = source_mtime
    @is_modified = true
    @_asset_stamp = nil
  end

  asset_destination_path
end

#extnameObject



48
49
50
# File 'lib/jekyll/minibundle/stamp_file.rb', line 48

def extname
  @asset_destination_extension
end

#modified?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/jekyll/minibundle/stamp_file.rb', line 52

def modified?
  @is_modified
end

#write(site_destination_dir) ⇒ Object

allows writing destination only after ‘destination_path_for_markup` has been called



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

def write(site_destination_dir)
  if modified?
    Files.copy_p(path, destination(site_destination_dir))
    @is_modified = false
    true
  else
    false
  end
end