Commit 1ea385625b481e405fbbffc2b2465553b20d90de
1 parent
26323046
Exists in
master
and in
4 other branches
Remove Commit & Tree decorators
Showing
2 changed files
with
0 additions
and
126 deletions
Show diff stats
app/decorators/commit_decorator.rb
@@ -1,93 +0,0 @@ | @@ -1,93 +0,0 @@ | ||
1 | -class CommitDecorator < ApplicationDecorator | ||
2 | - decorates :commit | ||
3 | - | ||
4 | - # Returns a string describing the commit for use in a link title | ||
5 | - # | ||
6 | - # Example | ||
7 | - # | ||
8 | - # "Commit: Alex Denisov - Project git clone panel" | ||
9 | - def link_title | ||
10 | - "Commit: #{author_name} - #{title}" | ||
11 | - end | ||
12 | - | ||
13 | - # Returns the commits title. | ||
14 | - # | ||
15 | - # Usually, the commit title is the first line of the commit message. | ||
16 | - # In case this first line is longer than 80 characters, it is cut off | ||
17 | - # after 70 characters and ellipses (`&hellp;`) are appended. | ||
18 | - def title | ||
19 | - title = safe_message | ||
20 | - | ||
21 | - return no_commit_message if title.blank? | ||
22 | - | ||
23 | - title_end = title.index(/\n/) | ||
24 | - if (!title_end && title.length > 80) || (title_end && title_end > 80) | ||
25 | - title[0..69] << "…".html_safe | ||
26 | - else | ||
27 | - title.split(/\n/, 2).first | ||
28 | - end | ||
29 | - end | ||
30 | - | ||
31 | - # Returns the commits description | ||
32 | - # | ||
33 | - # cut off, ellipses (`&hellp;`) are prepended to the commit message. | ||
34 | - def description | ||
35 | - description = safe_message | ||
36 | - | ||
37 | - title_end = description.index(/\n/) | ||
38 | - if (!title_end && description.length > 80) || (title_end && title_end > 80) | ||
39 | - "…".html_safe << description[70..-1] | ||
40 | - else | ||
41 | - description.split(/\n/, 2)[1].try(:chomp) | ||
42 | - end | ||
43 | - end | ||
44 | - | ||
45 | - # Returns a link to the commit author. If the author has a matching user and | ||
46 | - # is a member of the current @project it will link to the team member page. | ||
47 | - # Otherwise it will link to the author email as specified in the commit. | ||
48 | - # | ||
49 | - # options: | ||
50 | - # avatar: true will prepend the avatar image | ||
51 | - # size: size of the avatar image in px | ||
52 | - def author_link(options = {}) | ||
53 | - person_link(options.merge source: :author) | ||
54 | - end | ||
55 | - | ||
56 | - # Just like #author_link but for the committer. | ||
57 | - def committer_link(options = {}) | ||
58 | - person_link(options.merge source: :committer) | ||
59 | - end | ||
60 | - | ||
61 | - protected | ||
62 | - | ||
63 | - def no_commit_message | ||
64 | - "--no commit message" | ||
65 | - end | ||
66 | - | ||
67 | - # Private: Returns a link to a person. If the person has a matching user and | ||
68 | - # is a member of the current @project it will link to the team member page. | ||
69 | - # Otherwise it will link to the person email as specified in the commit. | ||
70 | - # | ||
71 | - # options: | ||
72 | - # source: one of :author or :committer | ||
73 | - # avatar: true will prepend the avatar image | ||
74 | - # size: size of the avatar image in px | ||
75 | - def person_link(options = {}) | ||
76 | - source_name = send "#{options[:source]}_name".to_sym | ||
77 | - source_email = send "#{options[:source]}_email".to_sym | ||
78 | - text = if options[:avatar] | ||
79 | - avatar = h.image_tag h.gravatar_icon(source_email, options[:size]), class: "avatar #{"s#{options[:size]}" if options[:size]}", width: options[:size], alt: "" | ||
80 | - %Q{#{avatar} <span class="commit-#{options[:source]}-name">#{source_name}</span>} | ||
81 | - else | ||
82 | - source_name | ||
83 | - end | ||
84 | - | ||
85 | - user = User.where('name like ? or email like ?', source_name, source_email).first | ||
86 | - | ||
87 | - if user.nil? | ||
88 | - h.mail_to(source_email, text.html_safe, class: "commit-#{options[:source]}-link") | ||
89 | - else | ||
90 | - h.link_to(text.html_safe, h.user_path(user), class: "commit-#{options[:source]}-link") | ||
91 | - end | ||
92 | - end | ||
93 | -end |
app/decorators/tree_decorator.rb
@@ -1,33 +0,0 @@ | @@ -1,33 +0,0 @@ | ||
1 | -class TreeDecorator < ApplicationDecorator | ||
2 | - decorates :tree | ||
3 | - | ||
4 | - def breadcrumbs(max_links = 2) | ||
5 | - if path | ||
6 | - part_path = "" | ||
7 | - parts = path.split("\/") | ||
8 | - | ||
9 | - yield('..', nil) if parts.count > max_links | ||
10 | - | ||
11 | - parts.each do |part| | ||
12 | - part_path = File.join(part_path, part) unless part_path.empty? | ||
13 | - part_path = part if part_path.empty? | ||
14 | - | ||
15 | - next unless parts.last(2).include?(part) if parts.count > max_links | ||
16 | - yield(part, h.tree_join(ref, part_path)) | ||
17 | - end | ||
18 | - end | ||
19 | - end | ||
20 | - | ||
21 | - def up_dir? | ||
22 | - path.present? | ||
23 | - end | ||
24 | - | ||
25 | - def up_dir_path | ||
26 | - file = File.join(path, "..") | ||
27 | - h.tree_join(ref, file) | ||
28 | - end | ||
29 | - | ||
30 | - def readme | ||
31 | - @readme ||= contents.find { |c| c.is_a?(Grit::Blob) and c.name =~ /^readme/i } | ||
32 | - end | ||
33 | -end |