Class: Jekyll::StaticFile
- Inherits:
-
Object
- Object
- Jekyll::StaticFile
- Defined in:
- lib/jekyll/static_file.rb
Constant Summary collapse
- @@mtimes =
the cache of last modification times [path] -> mtime
Hash.new
Class Method Summary collapse
-
.reset_cache ⇒ Object
Reset the mtimes cache (for testing purposes).
Instance Method Summary collapse
-
#destination(dest) ⇒ Object
Obtain destination path.
-
#initialize(site, base, dir, name) ⇒ StaticFile
constructor
Initialize a new StaticFile.
-
#modified? ⇒ Boolean
Is source path modified?.
-
#mtime ⇒ Object
Obtain mtime of the source path.
-
#path ⇒ Object
Obtains source file path.
-
#write(dest) ⇒ Object
Write the static file to the destination directory (if modified).
Constructor Details
#initialize(site, base, dir, name) ⇒ StaticFile
Initialize a new StaticFile.
site is the Site
base is the String path to the dir is the String path between name is the String filename of the file
Returns
13 14 15 16 17 18 |
# File 'lib/jekyll/static_file.rb', line 13 def initialize(site, base, dir, name) @site = site @base = base @dir = dir @name = name end |
Class Method Details
.reset_cache ⇒ Object
Reset the mtimes cache (for testing purposes).
Returns nothing.
68 69 70 71 72 |
# File 'lib/jekyll/static_file.rb', line 68 def self.reset_cache @@mtimes = Hash.new nil end |
Instance Method Details
#destination(dest) ⇒ Object
Obtain destination path.
dest is the String path to the destination dir
Returns destination file path.
31 32 33 |
# File 'lib/jekyll/static_file.rb', line 31 def destination(dest) File.join(dest, @dir, @name) end |
#modified? ⇒ Boolean
Is source path modified?
Returns true if modified since last write.
45 46 47 |
# File 'lib/jekyll/static_file.rb', line 45 def modified? @@mtimes[path] != mtime end |
#mtime ⇒ Object
Obtain mtime of the source path.
Returns last modifiaction time for this file.
38 39 40 |
# File 'lib/jekyll/static_file.rb', line 38 def mtime File.stat(path).mtime.to_i end |
#path ⇒ Object
Obtains source file path.
Returns source file path.
23 24 25 |
# File 'lib/jekyll/static_file.rb', line 23 def path File.join(@base, @dir, @name) end |
#write(dest) ⇒ Object
Write the static file to the destination directory (if modified).
dest is the String path to the destination dir
Returns false if the file was not modified since last time (no-op).
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/jekyll/static_file.rb', line 53 def write(dest) dest_path = destination(dest) return false if File.exist? dest_path and !modified? @@mtimes[path] = mtime FileUtils.mkdir_p(File.dirname(dest_path)) FileUtils.cp(path, dest_path) true end |