Class: Milestoner::Views::Parts::Commit

Inherits:
Hanami::View::Part
  • Object
show all
Defined in:
lib/milestoner/views/parts/commit.rb

Overview

The commit presentation logic.

Instance Method Summary collapse

Constructor Details

#initializeCommit

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 colored_author(*custom)
  custom.push :bold, :blue if custom.empty?
  color[author.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[authored_relative_at, *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_humanObject



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_machineObject



46
# File 'lib/milestoner/views/parts/commit.rb', line 46

def created_at_machine = created_at.strftime "%Y-%m-%dT%H:%M:%S%z"

#emojiObject



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

#iconObject



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

#kindObject



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_emojiObject



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_idObject



94
# File 'lib/milestoner/views/parts/commit.rb', line 94

def popover_id = "po-#{sha}"

#safe_bodyObject



77
# File 'lib/milestoner/views/parts/commit.rb', line 77

def safe_body = sanitizer.call(body_html).html_safe

#safe_notesObject



79
# File 'lib/milestoner/views/parts/commit.rb', line 79

def safe_notes = sanitizer.call(notes_html).html_safe

#securityObject



96
# File 'lib/milestoner/views/parts/commit.rb', line 96

def security = signature == "Good" ? "secure" : "insecure"

#signature_emojiObject



98
# File 'lib/milestoner/views/parts/commit.rb', line 98

def signature_emoji = signature.then { |kind| kind == "Good" ? "🔒" : "🔓" }

#signature_idObject



100
# File 'lib/milestoner/views/parts/commit.rb', line 100

def signature_id = value.fingerprint.then { |text| text.empty? ? "N/A" : text }

#signature_keyObject



102
# File 'lib/milestoner/views/parts/commit.rb', line 102

def signature_key = value.fingerprint_key.then { |text| text.empty? ? "N/A" : text }

#signature_labelObject



104
105
106
# File 'lib/milestoner/views/parts/commit.rb', line 104

def signature_label
  signature.then { |kind| kind == "Good" ? "🔒 #{kind}" : "🔓 #{kind}" }
end

#tagObject



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_deletionsObject



81
# File 'lib/milestoner/views/parts/commit.rb', line 81

def total_deletions = format "%d", -deletions

#total_insertionsObject



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_humanObject



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_machineObject



110
# File 'lib/milestoner/views/parts/commit.rb', line 110

def updated_at_machine = updated_at.strftime "%Y-%m-%dT%H:%M:%S%z"