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 CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 1
3
- :patch: 2
3
+ :patch: 3
4
4
  :major: 0
@@ -1,11 +1,11 @@
1
+ .diff ins,
1
2
  .diff .ins {
2
3
  color: green;
3
- /* background-color: rgba(0, 0, 0, 0.03);*/
4
- background-color: #f0f5f1;
4
+ text-decoration: none;
5
5
  }
6
6
 
7
+ .diff del,
7
8
  .diff .del {
8
9
  color: red;
9
- /* background-color: rgba(0, 0, 0, 0.03);*/
10
- background-color: #f0f5f1;
10
+ text-decoration: none;
11
11
  }
@@ -1,8 +1,8 @@
1
1
  CodeHighlighter.addStyle("diff",{
2
2
  ins : {
3
- exp : /\+[^\n]+/
3
+ exp : /\+[^\n]*/
4
4
  },
5
5
  del : {
6
- exp : /\-[^\n]+/
6
+ exp : /\-[^\n]*/
7
7
  }
8
8
  });
@@ -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/%d/%Y %H:%M') %>)</em> |
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/%d/%Y %H:%M') %> : <%= revision.subject %> (<%= revision.author %>)</h4>
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
+ }
@@ -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
@@ -1,20 +1,60 @@
1
1
  module Markout
2
2
 
3
3
  class Revision
4
- attr_reader :sha, :date, :author, :subject, :message, :diff
5
- def initialize(commit)
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
@@ -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 .ins {
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 test_should_initialize_with_commit
8
+ def test_should_initialize_with_repo_and_commit
9
9
  assert_nothing_raised do
10
- @revision = Markout::Revision.new( fake_grit_commit )
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: karmi-markout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karel Minarik