Class: Jekyll::LastModifiedAt::Determinator
- Inherits:
-
Object
- Object
- Jekyll::LastModifiedAt::Determinator
- Defined in:
- lib/jekyll-last-modified-at/determinator.rb
Instance Attribute Summary collapse
-
#format ⇒ Object
Returns the value of attribute format.
-
#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
- #formatted_last_modified_date ⇒ Object
- #git ⇒ Object
-
#initialize(site_source, page_path, format = nil) ⇒ 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, format = nil) ⇒ Determinator
Returns a new instance of Determinator.
9 10 11 12 13 |
# File 'lib/jekyll-last-modified-at/determinator.rb', line 9 def initialize(site_source, page_path, format = nil) @site_source = site_source @page_path = page_path @format = format || "%d-%b-%y" end |
Instance Attribute Details
#format ⇒ Object
Returns the value of attribute format.
7 8 9 |
# File 'lib/jekyll-last-modified-at/determinator.rb', line 7 def format @format 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
#formatted_last_modified_date ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/jekyll-last-modified-at/determinator.rb', line 22 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
15 16 17 18 19 20 |
# File 'lib/jekyll-last-modified-at/determinator.rb', line 15 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
30 31 32 33 34 |
# File 'lib/jekyll-last-modified-at/determinator.rb', line 30 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
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/jekyll-last-modified-at/determinator.rb', line 36 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
60 61 62 |
# File 'lib/jekyll-last-modified-at/determinator.rb', line 60 def to_liquid @to_liquid ||= last_modified_at_time end |
#to_s ⇒ Object
56 57 58 |
# File 'lib/jekyll-last-modified-at/determinator.rb', line 56 def to_s @to_s ||= formatted_last_modified_date end |