karmi-markout 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION.yml +1 -1
- data/lib/markout/formatters/html/templates/common/code.css +4 -4
- data/lib/markout/formatters/html/templates/common/syntax_diff.js +2 -2
- data/lib/markout/formatters/html/templates/default/content.rhtml +3 -4
- data/lib/markout/formatters/html/templates/default/screen.css +15 -1
- data/lib/markout/history.rb +1 -1
- data/lib/markout/revision.rb +43 -3
- data/test/fixtures/markdown.html +8 -8
- data/test/markout_revision_test.rb +4 -2
- metadata +1 -1
data/VERSION.yml
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
+
.diff ins,
|
1
2
|
.diff .ins {
|
2
3
|
color: green;
|
3
|
-
|
4
|
-
background-color: #f0f5f1;
|
4
|
+
text-decoration: none;
|
5
5
|
}
|
6
6
|
|
7
|
+
.diff del,
|
7
8
|
.diff .del {
|
8
9
|
color: red;
|
9
|
-
|
10
|
-
background-color: #f0f5f1;
|
10
|
+
text-decoration: none;
|
11
11
|
}
|
@@ -10,7 +10,6 @@
|
|
10
10
|
<style type="text/css" media="screen"><%= screen_style %></style>
|
11
11
|
<style type="text/css" media="print"><%= print_style %></style>
|
12
12
|
|
13
|
-
<%= syntax_highlighter %>
|
14
13
|
<script type="text/javascript"><%= jquery %></script>
|
15
14
|
<script type="text/javascript"><%= application_js %></script>
|
16
15
|
|
@@ -22,7 +21,7 @@
|
|
22
21
|
<div id="history_header">
|
23
22
|
<p>Last revision:
|
24
23
|
<strong><%= history.revisions.first.subject %></strong>
|
25
|
-
<em>(<%= history.revisions.first.author %>, <%= history.revisions.first.date.strftime('%m/%
|
24
|
+
<em>(<%= history.revisions.first.author %>, <%= history.revisions.first.date.strftime('%d/%m/%Y %H:%M') %>)</em> |
|
26
25
|
<a href="#history">History</a>
|
27
26
|
<!-- <strong class="new_revisions">(3 new)</strong> -->
|
28
27
|
</p>
|
@@ -40,11 +39,11 @@
|
|
40
39
|
<h2>History</h2>
|
41
40
|
<% history.revisions.each do |revision| %>
|
42
41
|
<div id="revision_<%= revision.sha %>" class="revision">
|
43
|
-
<h4><%= revision.date.strftime('%m/%
|
42
|
+
<h4><%= revision.date.strftime('%d/%m/%Y %H:%M') %> : <%= revision.subject %> (<%= revision.author %>)</h4>
|
44
43
|
<div class="detail">
|
45
44
|
<pre>
|
46
45
|
<code class="diff">
|
47
|
-
<%= revision.diff %>
|
46
|
+
<%= revision.diff(:format => 'inline') %>
|
48
47
|
</code>
|
49
48
|
</pre>
|
50
49
|
</div><!-- /detail -->
|
@@ -163,12 +163,26 @@ hr { display: none; }
|
|
163
163
|
}
|
164
164
|
|
165
165
|
#history .revision pre {
|
166
|
+
background: none;
|
167
|
+
line-height: 120%;
|
166
168
|
border: none;
|
167
169
|
margin: 0;
|
168
|
-
padding: 0;
|
170
|
+
padding: 0 1em 0 1em;
|
169
171
|
}
|
170
172
|
|
171
173
|
#history .revision code {
|
172
174
|
margin: 0;
|
173
175
|
padding: 0;
|
174
176
|
}
|
177
|
+
|
178
|
+
#history .diff ins,
|
179
|
+
#history .diff .ins {
|
180
|
+
color: green;
|
181
|
+
text-decoration: none;
|
182
|
+
}
|
183
|
+
|
184
|
+
#history .diff del,
|
185
|
+
#history .diff .del {
|
186
|
+
color: red;
|
187
|
+
text-decoration: none;
|
188
|
+
}
|
data/lib/markout/history.rb
CHANGED
@@ -23,7 +23,7 @@ module Markout
|
|
23
23
|
def load_revisions
|
24
24
|
@repo ||= load_repository
|
25
25
|
commits = @repo.log 'master', @document.filename
|
26
|
-
@revisions = commits.collect { |c| Markout::Revision.new(c) }
|
26
|
+
@revisions = commits.collect { |c| Markout::Revision.new(@repo, c) }
|
27
27
|
# puts @revisions
|
28
28
|
end
|
29
29
|
end
|
data/lib/markout/revision.rb
CHANGED
@@ -1,20 +1,60 @@
|
|
1
1
|
module Markout
|
2
2
|
|
3
3
|
class Revision
|
4
|
-
|
5
|
-
|
4
|
+
|
5
|
+
attr_reader :sha, :date, :author, :subject, :message
|
6
|
+
|
7
|
+
def initialize(repo, commit)
|
8
|
+
@repo = repo
|
6
9
|
@sha = commit.sha
|
7
10
|
@date = commit.date
|
8
11
|
@author = commit.author.to_s
|
9
12
|
@subject, @message = parse_commit_message(commit)
|
10
|
-
@diff = commit.show.first.diff
|
13
|
+
@diff = commit.show.first.diff || ''
|
14
|
+
end
|
15
|
+
|
16
|
+
def diff(options={})
|
17
|
+
case options[:format]
|
18
|
+
when 'raw' then @diff
|
19
|
+
when 'short' then short_diff
|
20
|
+
when 'inline' then inline_diff
|
21
|
+
else @diff
|
22
|
+
end
|
11
23
|
end
|
12
24
|
|
13
25
|
private
|
26
|
+
|
14
27
|
def parse_commit_message(commit)
|
15
28
|
lines = commit.message.split("/n")
|
16
29
|
[ lines.first, lines[1..commit.message.size].join("\n") ]
|
17
30
|
end
|
31
|
+
|
32
|
+
def short_diff
|
33
|
+
@diff.gsub(/^\-\-\- a\/\S+\n+/, '').
|
34
|
+
gsub(/^\+\+\+ b\/\S+\n+/, '').
|
35
|
+
gsub(/^\-\-\- \/dev\/null\n+/, '').
|
36
|
+
gsub(/^\+\+\+ \/dev\/null\n+/, '').
|
37
|
+
gsub(/^@@ .+\n+/, '')
|
38
|
+
end
|
39
|
+
|
40
|
+
def inline_diff
|
41
|
+
# FIXME: Cleanup
|
42
|
+
output = %x[cd #{@repo.path} && git show --no-prefix --ignore-space-change --color-words #{@sha} 2>&1]
|
43
|
+
if $?.success?
|
44
|
+
return convert_bash_color_codes( output.gsub(/(.*)@@(.*)/m, '\2') )
|
45
|
+
else
|
46
|
+
return short_diff
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Lifted from Integrity (www.integrityapp.com), (c) foca & sr
|
51
|
+
def convert_bash_color_codes(string)
|
52
|
+
string.
|
53
|
+
gsub(/\e\[31m([^\e]*)\e\[m/, '<del>\1</del>').
|
54
|
+
gsub(/\e\[32m([^\e]*)\e\[m/, '<ins>\1</ins>').
|
55
|
+
gsub("\e[m", '')
|
56
|
+
end
|
57
|
+
|
18
58
|
end
|
19
59
|
|
20
60
|
end
|
data/test/fixtures/markdown.html
CHANGED
@@ -172,9 +172,11 @@ hr { display: none; }
|
|
172
172
|
}
|
173
173
|
|
174
174
|
#history .revision pre {
|
175
|
+
background: none;
|
176
|
+
line-height: 120%;
|
175
177
|
border: none;
|
176
178
|
margin: 0;
|
177
|
-
padding: 0;
|
179
|
+
padding: 0 1em 0 1em;
|
178
180
|
}
|
179
181
|
|
180
182
|
#history .revision code {
|
@@ -407,21 +409,19 @@ CodeHighlighter.init = function() {
|
|
407
409
|
}
|
408
410
|
}</script><script type="text/javascript">CodeHighlighter.addStyle("diff",{
|
409
411
|
ins : {
|
410
|
-
exp : /\+[^\n]
|
412
|
+
exp : /\+[^\n]*/
|
411
413
|
},
|
412
414
|
del : {
|
413
|
-
exp : /\-[^\n]
|
415
|
+
exp : /\-[^\n]*/
|
414
416
|
}
|
415
|
-
});</script><style type="text/css" media="screen">.diff
|
417
|
+
});</script><style type="text/css" media="screen">.diff ins,
|
418
|
+
.diff .ins {
|
416
419
|
color: green;
|
417
|
-
/* background-color: rgba(0, 0, 0, 0.03);*/
|
418
|
-
background-color: #f0f5f1;
|
419
420
|
}
|
420
421
|
|
422
|
+
.diff del,
|
421
423
|
.diff .del {
|
422
424
|
color: red;
|
423
|
-
/* background-color: rgba(0, 0, 0, 0.03);*/
|
424
|
-
background-color: #f0f5f1;
|
425
425
|
}</style>
|
426
426
|
<script type="text/javascript">/*
|
427
427
|
* jQuery JavaScript Library v1.3.2
|
@@ -5,9 +5,11 @@ require 'ostruct'
|
|
5
5
|
module Markout
|
6
6
|
class RevisionTest < Test::Unit::TestCase
|
7
7
|
|
8
|
-
def
|
8
|
+
def test_should_initialize_with_repo_and_commit
|
9
9
|
assert_nothing_raised do
|
10
|
-
@revision = Markout::Revision.new(
|
10
|
+
@revision = Markout::Revision.new(
|
11
|
+
Grit::Repo.new(fixtures_path.join('empty_repository__dot__git'), :is_bare => true),
|
12
|
+
fake_grit_commit )
|
11
13
|
end
|
12
14
|
assert_not_nil @revision.sha
|
13
15
|
assert_not_nil @revision.date
|