Class: Gitgo::Helper::Format
- Inherits:
-
Object
- Object
- Gitgo::Helper::Format
show all
- Includes:
- Utils, Rack::Utils
- Defined in:
- lib/gitgo/helper/format.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#at(at) ⇒ Object
-
#author(author) ⇒ Object
-
#blob_a(treeish, *path) ⇒ Object
-
#branch(branch) ⇒ Object
-
#commit_a(treeish) ⇒ Object
-
#content(str) ⇒ Object
-
#date(date) ⇒ Object
-
#doc_a(doc) ⇒ Object
-
#each_diff_a(status) ⇒ Object
-
#each_path(treeish, path) {|base| ... } ⇒ Object
-
#full_path_a(type, treeish, path) ⇒ Object
-
#graph(graph) ⇒ Object
-
#history_a(treeish) ⇒ Object
-
#index_key_a(key) ⇒ Object
-
#index_value_a(key, value) ⇒ Object
-
#initialize(controller) ⇒ Format
constructor
A new instance of Format.
-
#issue_a(doc) ⇒ Object
-
#origin(origin) ⇒ Object
-
#path(path) ⇒ Object
-
#path_a(type, treeish, path) ⇒ Object
-
#ref_name(sha) ⇒ Object
-
#refs ⇒ Object
-
#sha(sha) ⇒ Object
-
#sha_a(sha) ⇒ Object
-
#tags(tags) ⇒ Object
-
#text(str) ⇒ Object
-
#textile(str) ⇒ Object
-
#title(title) ⇒ Object
-
#titles(titles) ⇒ Object
-
#tree(hash, io = [], &block) ⇒ Object
-
#tree!(hash, io = [], &block) ⇒ Object
-
#tree_a(treeish, *path) ⇒ Object
-
#url(*paths) ⇒ Object
Methods included from Utils
collapse, flatten, render
Constructor Details
#initialize(controller) ⇒ Format
Returns a new instance of Format.
13
14
15
|
# File 'lib/gitgo/helper/format.rb', line 13
def initialize(controller)
@controller = controller
end
|
Instance Attribute Details
#controller ⇒ Object
Returns the value of attribute controller.
11
12
13
|
# File 'lib/gitgo/helper/format.rb', line 11
def controller
@controller
end
|
Instance Method Details
#at(at) ⇒ Object
157
158
159
|
# File 'lib/gitgo/helper/format.rb', line 157
def at(at)
at.nil? || at.empty? ? '(none)' : sha_a(at)
end
|
#author(author) ⇒ Object
147
148
149
150
|
# File 'lib/gitgo/helper/format.rb', line 147
def author(author)
return nil if author.nil?
"#{escape_html(author.name)} (<a href=\"#{url('timeline')}?#{build_query(:author => author.email)}\">#{escape_html author.email}</a>)"
end
|
#blob_a(treeish, *path) ⇒ Object
72
73
74
|
# File 'lib/gitgo/helper/format.rb', line 72
def blob_a(treeish, *path)
path_a('blob', treeish, path)
end
|
#branch(branch) ⇒ Object
185
186
187
|
# File 'lib/gitgo/helper/format.rb', line 185
def branch(branch)
escape_html(branch)
end
|
#commit_a(treeish) ⇒ Object
64
65
66
|
# File 'lib/gitgo/helper/format.rb', line 64
def commit_a(treeish)
"<a class=\"commit\" href=\"#{url('commit', treeish)}\">#{escape_html treeish}</a>"
end
|
#content(str) ⇒ Object
143
144
145
|
# File 'lib/gitgo/helper/format.rb', line 143
def content(str)
textile text(str)
end
|
#date(date) ⇒ Object
152
153
154
155
|
# File 'lib/gitgo/helper/format.rb', line 152
def date(date)
return nil if date.nil?
"<abbr title=\"#{date.iso8601}\">#{date.strftime('%Y/%m/%d %H:%M %p')}</abbr>"
end
|
#doc_a(doc) ⇒ Object
85
86
87
88
|
# File 'lib/gitgo/helper/format.rb', line 85
def doc_a(doc)
target = doc.graph_head? ? doc.graph_head : "#{doc.graph_head}##{doc.sha}"
"<a id=\"#{doc.sha}\" href=\"#{url(doc.type, target)}\">#{escape_html doc.summary}</a>"
end
|
#each_diff_a(status) ⇒ Object
189
190
191
192
193
194
195
196
197
|
# File 'lib/gitgo/helper/format.rb', line 189
def each_diff_a(status)
status.keys.sort.each do |path|
change, a, b = status[path]
a_mode, a_sha = a
b_mode, b_sha = b
yield "<a class=\"#{change}\" href=\"#{url('obj', b_sha.to_s)}\" title=\"#{a_sha || '-'} to #{b_sha || '-'}\">#{path}</a>"
end
end
|
#each_path(treeish, path) {|base| ... } ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/gitgo/helper/format.rb', line 98
def each_path(treeish, path)
paths = path.split("/")
base = paths.pop
paths.unshift(treeish)
object_path = ['tree']
paths.collect! do |path|
object_path << path
yield "<a href=\"#{url(*object_path)}\">#{escape_html path}</a>"
end
yield(base) if base
paths
end
|
#full_path_a(type, treeish, path) ⇒ Object
60
61
62
|
# File 'lib/gitgo/helper/format.rb', line 60
def full_path_a(type, treeish, path)
"<a class=\"#{type}\" href=\"#{url(type, treeish, *path)}\">#{escape_html File.join(path)}</a>"
end
|
#graph(graph) ⇒ Object
170
171
172
173
174
175
|
# File 'lib/gitgo/helper/format.rb', line 170
def graph(graph)
graph.each do |sha, slot, index, current_slots, transitions|
next unless sha
yield(sha, "#{slot}:#{index}:#{current_slots.join(',')}:#{transitions.join(',')}")
end
end
|
#history_a(treeish) ⇒ Object
76
77
78
|
# File 'lib/gitgo/helper/format.rb', line 76
def history_a(treeish)
"<a class=\"history\" href=\"#{url('commits', treeish)}\" title=\"#{escape_html treeish}\">history</a>"
end
|
#index_key_a(key) ⇒ Object
90
91
92
|
# File 'lib/gitgo/helper/format.rb', line 90
def index_key_a(key)
"<a href=\"#{url('repo', 'index', key)}\">#{escape_html key}</a>"
end
|
#index_value_a(key, value) ⇒ Object
94
95
96
|
# File 'lib/gitgo/helper/format.rb', line 94
def index_value_a(key, value)
"<a href=\"#{url('repo', 'index', key, value)}\">#{escape_html value}</a>"
end
|
#issue_a(doc) ⇒ Object
80
81
82
83
|
# File 'lib/gitgo/helper/format.rb', line 80
def issue_a(doc)
target = doc.graph_head? ? doc.graph_head : "#{doc.graph_head}##{doc.sha}"
"<a id=\"#{doc.sha}\" href=\"#{url('issue', target)}\">#{titles(doc.graph_titles)}</a>"
end
|
#origin(origin) ⇒ Object
161
162
163
|
# File 'lib/gitgo/helper/format.rb', line 161
def origin(origin)
sha(origin)
end
|
#path(path) ⇒ Object
181
182
183
|
# File 'lib/gitgo/helper/format.rb', line 181
def path(path)
escape_html(path)
end
|
#path_a(type, treeish, path) ⇒ Object
56
57
58
|
# File 'lib/gitgo/helper/format.rb', line 56
def path_a(type, treeish, path)
"<a class=\"#{type}\" href=\"#{url(type, treeish, *path)}\">#{escape_html(path.pop || treeish)}</a>"
end
|
#ref_name(sha) ⇒ Object
25
26
27
28
|
# File 'lib/gitgo/helper/format.rb', line 25
def ref_name(sha)
reference = refs.find {|ref| ref.commit.id == sha}
reference ? reference.name : sha
end
|
#refs ⇒ Object
21
22
23
|
# File 'lib/gitgo/helper/format.rb', line 21
def refs
@refs ||= controller.repo.git.grit.refs
end
|
#sha(sha) ⇒ Object
40
41
42
|
# File 'lib/gitgo/helper/format.rb', line 40
def sha(sha)
escape_html(sha)
end
|
#sha_a(sha) ⇒ Object
52
53
54
|
# File 'lib/gitgo/helper/format.rb', line 52
def sha_a(sha)
"<a class=\"sha\" href=\"#{url('obj', sha)}\" title=\"#{sha}\">#{sha}</a>"
end
|
165
166
167
168
|
# File 'lib/gitgo/helper/format.rb', line 165
def tags(tags)
tags << '(unclassified)' if tags.empty?
escape_html tags.join(', ')
end
|
#text(str) ⇒ Object
34
35
36
37
38
|
# File 'lib/gitgo/helper/format.rb', line 34
def text(str)
str = escape_html(str)
str.gsub!(/[A-Fa-f\d]{40}/) {|sha| sha_a(sha) }
str
end
|
#textile(str) ⇒ Object
44
45
46
|
# File 'lib/gitgo/helper/format.rb', line 44
def textile(str)
::RedCloth.new(str).to_html
end
|
#title(title) ⇒ Object
134
135
136
|
# File 'lib/gitgo/helper/format.rb', line 134
def title(title)
escape_html(title)
end
|
#titles(titles) ⇒ Object
138
139
140
141
|
# File 'lib/gitgo/helper/format.rb', line 138
def titles(titles)
titles << "(nameless)" if titles.empty?
escape_html titles.join(', ')
end
|
#tree(hash, io = [], &block) ⇒ Object
117
118
119
120
121
122
123
124
|
# File 'lib/gitgo/helper/format.rb', line 117
def tree(hash, io=[], &block)
dup = {}
hash.each_pair do |key, value|
dup[key] = value.dup
end
tree!(dup, io, &block)
end
|
#tree!(hash, io = [], &block) ⇒ Object
126
127
128
129
130
131
132
|
# File 'lib/gitgo/helper/format.rb', line 126
def tree!(hash, io=[], &block)
nodes = flatten(hash)[nil]
nodes = collapse(nodes)
nodes.shift
render(nodes, io, &block)
end
|
#tree_a(treeish, *path) ⇒ Object
68
69
70
|
# File 'lib/gitgo/helper/format.rb', line 68
def tree_a(treeish, *path)
path_a('tree', treeish, path)
end
|
#url(*paths) ⇒ Object
17
18
19
|
# File 'lib/gitgo/helper/format.rb', line 17
def url(*paths)
controller.url(paths)
end
|