Class: Jekyll::LastModifiedAt::Determinator
- Inherits:
-
Object
- Object
- Jekyll::LastModifiedAt::Determinator
- Defined in:
- lib/jekyll-last-modified-at/determinator.rb
Instance Attribute Summary collapse
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#page_path ⇒ Object
readonly
Returns the value of attribute page_path.
-
#site_source ⇒ Object
readonly
Returns the value of attribute site_source.
Instance Method Summary collapse
- #format ⇒ Object
- #format=(new_format) ⇒ Object
- #formatted_last_modified_date ⇒ Object
- #git ⇒ Object
-
#initialize(site_source, page_path, opts = {}) ⇒ Determinator
constructor
A new instance of Determinator.
- #last_modified_at_time ⇒ Object
- #last_modified_at_unix ⇒ Object
- #to_liquid ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(site_source, page_path, opts = {}) ⇒ Determinator
Returns a new instance of Determinator.
8 9 10 11 12 |
# File 'lib/jekyll-last-modified-at/determinator.rb', line 8 def initialize(site_source, page_path, opts = {}) @site_source = site_source @page_path = page_path @opts = opts end |
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts
6 7 8 |
# File 'lib/jekyll-last-modified-at/determinator.rb', line 6 def opts @opts end |
#page_path ⇒ Object (readonly)
Returns the value of attribute page_path
6 7 8 |
# File 'lib/jekyll-last-modified-at/determinator.rb', line 6 def page_path @page_path end |
#site_source ⇒ Object (readonly)
Returns the value of attribute site_source
6 7 8 |
# File 'lib/jekyll-last-modified-at/determinator.rb', line 6 def site_source @site_source end |
Instance Method Details
#format ⇒ Object
63 64 65 |
# File 'lib/jekyll-last-modified-at/determinator.rb', line 63 def format opts['format'] ||= '%d-%b-%y' end |
#format=(new_format) ⇒ Object
67 68 69 |
# File 'lib/jekyll-last-modified-at/determinator.rb', line 67 def format=(new_format) opts['format'] = new_format end |
#formatted_last_modified_date ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/jekyll-last-modified-at/determinator.rb', line 21 def formatted_last_modified_date return PATH_CACHE[page_path] unless PATH_CACHE[page_path].nil? last_modified = last_modified_at_time.strftime(format) PATH_CACHE[page_path] = last_modified last_modified end |
#git ⇒ Object
14 15 16 17 18 19 |
# File 'lib/jekyll-last-modified-at/determinator.rb', line 14 def git return REPO_CACHE[site_source] unless REPO_CACHE[site_source].nil? REPO_CACHE[site_source] = Git.new(site_source) REPO_CACHE[site_source] end |
#last_modified_at_time ⇒ Object
29 30 31 32 33 |
# File 'lib/jekyll-last-modified-at/determinator.rb', line 29 def last_modified_at_time raise Errno::ENOENT, "#{absolute_path_to_article} does not exist!" unless File.exist? absolute_path_to_article Time.at(last_modified_at_unix.to_i) end |
#last_modified_at_unix ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/jekyll-last-modified-at/determinator.rb', line 35 def last_modified_at_unix if git.git_repo? last_commit_date = Executor.sh( 'git', '--git-dir', git.top_level_directory, 'log', '-n', '1', '--format="%ct"', '--', relative_path_from_git_dir )[/\d+/] # last_commit_date can be nil iff the file was not committed. last_commit_date.nil? || last_commit_date.empty? ? mtime(absolute_path_to_article) : last_commit_date else mtime(absolute_path_to_article) end end |
#to_liquid ⇒ Object
59 60 61 |
# File 'lib/jekyll-last-modified-at/determinator.rb', line 59 def to_liquid @to_liquid ||= last_modified_at_time end |
#to_s ⇒ Object
55 56 57 |
# File 'lib/jekyll-last-modified-at/determinator.rb', line 55 def to_s @to_s ||= formatted_last_modified_date end |