Class: Milestoner::Views::Parts::Commit
- Inherits:
-
Hanami::View::Part
- Object
- Hanami::View::Part
- Milestoner::Views::Parts::Commit
- Defined in:
- lib/milestoner/views/parts/commit.rb
Overview
The commit presentation logic.
Instance Method Summary collapse
- #colored_author(*custom) ⇒ Object
- #colored_created_relative_at(*custom) ⇒ Object
- #colored_sha(*custom) ⇒ Object
- #colored_updated_relative_at(*custom) ⇒ Object
- #created_at_human ⇒ Object
- #created_at_machine ⇒ Object
- #emoji ⇒ Object
- #icon ⇒ Object
-
#initialize ⇒ Commit
constructor
A new instance of Commit.
- #kind ⇒ Object
- #milestone_emoji ⇒ Object
- #popover_id ⇒ Object
- #safe_body ⇒ Object
- #safe_notes ⇒ Object
- #security ⇒ Object
- #signature_emoji ⇒ Object
- #signature_id ⇒ Object
- #signature_key ⇒ Object
- #signature_label ⇒ Object
- #tag ⇒ Object
- #total_deletions ⇒ Object
- #total_insertions ⇒ Object
- #updated_at_human ⇒ Object
- #updated_at_machine ⇒ Object
Constructor Details
#initialize ⇒ Commit
Returns a new instance of Commit.
19 20 21 22 |
# File 'lib/milestoner/views/parts/commit.rb', line 19 def initialize(**) super @prefixes = settings.commit_categories.pluck :label end |
Instance Method Details
#colored_author(*custom) ⇒ Object
24 25 26 27 |
# File 'lib/milestoner/views/parts/commit.rb', line 24 def (*custom) custom.push :bold, :blue if custom.empty? color[.name, *custom] end |
#colored_created_relative_at(*custom) ⇒ Object
29 30 31 32 |
# File 'lib/milestoner/views/parts/commit.rb', line 29 def colored_created_relative_at(*custom) custom.push :bright_purple if custom.empty? color[, *custom] end |
#colored_sha(*custom) ⇒ Object
39 40 41 42 |
# File 'lib/milestoner/views/parts/commit.rb', line 39 def colored_sha(*custom) custom.push :yellow if custom.empty? color[sha[...12], *custom] end |
#colored_updated_relative_at(*custom) ⇒ Object
34 35 36 37 |
# File 'lib/milestoner/views/parts/commit.rb', line 34 def colored_updated_relative_at(*custom) custom.push :cyan if custom.empty? color[committed_relative_at, *custom] end |
#created_at_human ⇒ Object
44 |
# File 'lib/milestoner/views/parts/commit.rb', line 44 def created_at_human = created_at.strftime "%Y-%m-%d (%A) %I:%M %p %Z" |
#created_at_machine ⇒ Object
46 |
# File 'lib/milestoner/views/parts/commit.rb', line 46 def created_at_machine = created_at.strftime "%Y-%m-%dT%H:%M:%S%z" |
#emoji ⇒ Object
55 56 57 58 59 |
# File 'lib/milestoner/views/parts/commit.rb', line 55 def emoji settings.commit_categories .find { |category| category.fetch(:label) == prefix } .then { |category| category ? category.fetch(:emoji) : "🔶" } end |
#icon ⇒ Object
61 62 63 64 65 66 |
# File 'lib/milestoner/views/parts/commit.rb', line 61 def icon if prefixes.include? prefix then String(prefix).downcase elsif directive? then "rebase" else "invalid" end end |
#kind ⇒ Object
48 49 50 51 52 53 |
# File 'lib/milestoner/views/parts/commit.rb', line 48 def kind if prefixes.include? prefix then "normal" elsif directive? then "alert" else "error" end end |
#milestone_emoji ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/milestoner/views/parts/commit.rb', line 68 def milestone_emoji case milestone when "major" then "🔴" when "minor" then "🔵" when "patch" then "🟢" else "⚪️" end end |
#popover_id ⇒ Object
94 |
# File 'lib/milestoner/views/parts/commit.rb', line 94 def popover_id = "po-#{sha}" |
#safe_body ⇒ Object
77 |
# File 'lib/milestoner/views/parts/commit.rb', line 77 def safe_body = sanitizer.call(body_html).html_safe |
#safe_notes ⇒ Object
79 |
# File 'lib/milestoner/views/parts/commit.rb', line 79 def safe_notes = sanitizer.call(notes_html).html_safe |
#security ⇒ Object
96 |
# File 'lib/milestoner/views/parts/commit.rb', line 96 def security = signature == "Good" ? "secure" : "insecure" |
#signature_emoji ⇒ Object
98 |
# File 'lib/milestoner/views/parts/commit.rb', line 98 def signature_emoji = signature.then { |kind| kind == "Good" ? "🔒" : "🔓" } |
#signature_id ⇒ Object
100 |
# File 'lib/milestoner/views/parts/commit.rb', line 100 def signature_id = value.fingerprint.then { |text| text.empty? ? "N/A" : text } |
#signature_key ⇒ Object
102 |
# File 'lib/milestoner/views/parts/commit.rb', line 102 def signature_key = value.fingerprint_key.then { |text| text.empty? ? "N/A" : text } |
#signature_label ⇒ Object
104 105 106 |
# File 'lib/milestoner/views/parts/commit.rb', line 104 def signature_label signature.then { |kind| kind == "Good" ? "🔒 #{kind}" : "🔓 #{kind}" } end |
#tag ⇒ Object
87 88 89 90 91 92 |
# File 'lib/milestoner/views/parts/commit.rb', line 87 def tag return "rebase" if directive? return "invalid" unless prefixes.include? prefix milestone end |
#total_deletions ⇒ Object
81 |
# File 'lib/milestoner/views/parts/commit.rb', line 81 def total_deletions = format "%d", -deletions |
#total_insertions ⇒ Object
83 84 85 |
# File 'lib/milestoner/views/parts/commit.rb', line 83 def total_insertions insertions.then { |total| total.positive? ? "+#{total}" : total.to_s } end |
#updated_at_human ⇒ Object
108 |
# File 'lib/milestoner/views/parts/commit.rb', line 108 def updated_at_human = updated_at.strftime "%Y-%m-%d (%A) %I:%M %p %Z" |
#updated_at_machine ⇒ Object
110 |
# File 'lib/milestoner/views/parts/commit.rb', line 110 def updated_at_machine = updated_at.strftime "%Y-%m-%dT%H:%M:%S%z" |