drafter 0.2.7 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +2 -0
- data/VERSION +1 -1
- data/drafter.gemspec +6 -1
- data/lib/drafter/diffing.rb +16 -0
- data/lib/drafter.rb +3 -0
- data/test/drafter/test_diffing.rb +38 -0
- data/test/helper.rb +5 -5
- metadata +35 -22
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -42,6 +42,7 @@ GEM
|
|
42
42
|
debugger-linecache (1.1.1)
|
43
43
|
debugger-ruby_core_source (>= 1.1.1)
|
44
44
|
debugger-ruby_core_source (1.1.2)
|
45
|
+
diffy (2.0.8)
|
45
46
|
erubis (2.7.0)
|
46
47
|
git (1.2.5)
|
47
48
|
hike (1.2.1)
|
@@ -119,6 +120,7 @@ DEPENDENCIES
|
|
119
120
|
bundler (~> 1.0.0)
|
120
121
|
carrierwave
|
121
122
|
debugger
|
123
|
+
diffy
|
122
124
|
jeweler (~> 1.6.4)
|
123
125
|
minitest
|
124
126
|
minitest-rails-shoulda
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.8
|
data/drafter.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "drafter"
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["futurechimp"]
|
@@ -28,12 +28,14 @@ Gem::Specification.new do |s|
|
|
28
28
|
"lib/drafter.rb",
|
29
29
|
"lib/drafter/apply.rb",
|
30
30
|
"lib/drafter/creation.rb",
|
31
|
+
"lib/drafter/diffing.rb",
|
31
32
|
"lib/drafter/draft.rb",
|
32
33
|
"lib/drafter/draft_upload.rb",
|
33
34
|
"lib/drafter/draft_uploader.rb",
|
34
35
|
"lib/drafter/draftable.rb",
|
35
36
|
"test/drafter/test_apply.rb",
|
36
37
|
"test/drafter/test_creation.rb",
|
38
|
+
"test/drafter/test_diffing.rb",
|
37
39
|
"test/drafter/test_draft.rb",
|
38
40
|
"test/drafter/test_draft_upload.rb",
|
39
41
|
"test/drafter/test_draftable.rb",
|
@@ -58,6 +60,7 @@ Gem::Specification.new do |s|
|
|
58
60
|
|
59
61
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
60
62
|
s.add_runtime_dependency(%q<activerecord>, [">= 0"])
|
63
|
+
s.add_runtime_dependency(%q<diffy>, [">= 0"])
|
61
64
|
s.add_development_dependency(%q<sqlite3>, [">= 0"])
|
62
65
|
s.add_development_dependency(%q<debugger>, [">= 0"])
|
63
66
|
s.add_development_dependency(%q<minitest>, [">= 0"])
|
@@ -69,6 +72,7 @@ Gem::Specification.new do |s|
|
|
69
72
|
s.add_development_dependency(%q<minitest-rails-shoulda>, [">= 0"])
|
70
73
|
else
|
71
74
|
s.add_dependency(%q<activerecord>, [">= 0"])
|
75
|
+
s.add_dependency(%q<diffy>, [">= 0"])
|
72
76
|
s.add_dependency(%q<sqlite3>, [">= 0"])
|
73
77
|
s.add_dependency(%q<debugger>, [">= 0"])
|
74
78
|
s.add_dependency(%q<minitest>, [">= 0"])
|
@@ -81,6 +85,7 @@ Gem::Specification.new do |s|
|
|
81
85
|
end
|
82
86
|
else
|
83
87
|
s.add_dependency(%q<activerecord>, [">= 0"])
|
88
|
+
s.add_dependency(%q<diffy>, [">= 0"])
|
84
89
|
s.add_dependency(%q<sqlite3>, [">= 0"])
|
85
90
|
s.add_dependency(%q<debugger>, [">= 0"])
|
86
91
|
s.add_dependency(%q<minitest>, [">= 0"])
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Diffing
|
2
|
+
|
3
|
+
# Get a diff between the current and draft status of an ActiveRecord
|
4
|
+
# object field.
|
5
|
+
#
|
6
|
+
# @param [Symbol] attr the attribute you want to diff.
|
7
|
+
# @param [Hash] options an options hash allowing you to pass a :format.
|
8
|
+
# @return [String] a diff string. If :format was nil, this could be a
|
9
|
+
# [Diffy::Diff].
|
10
|
+
def differences(attr, options={:format => :html})
|
11
|
+
if self.draft
|
12
|
+
Diffy::Diff.new(self.send(attr), self.draft(attr)).to_s(options[:format])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
data/lib/drafter.rb
CHANGED
@@ -2,6 +2,7 @@ require 'active_support/concern'
|
|
2
2
|
require 'active_support/dependencies/autoload'
|
3
3
|
require 'active_support/core_ext/module/delegation'
|
4
4
|
require 'active_record'
|
5
|
+
require 'diffy'
|
5
6
|
|
6
7
|
require File.dirname(__FILE__) + '/drafter/draft_uploader'
|
7
8
|
|
@@ -11,6 +12,7 @@ module Drafter
|
|
11
12
|
|
12
13
|
autoload :Apply
|
13
14
|
autoload :Creation
|
15
|
+
autoload :Diffing
|
14
16
|
autoload :Draft
|
15
17
|
autoload :Draftable
|
16
18
|
autoload :DraftUpload
|
@@ -23,6 +25,7 @@ module Drafter
|
|
23
25
|
included do
|
24
26
|
include Apply
|
25
27
|
include Creation
|
28
|
+
include Diffing
|
26
29
|
include Draftable
|
27
30
|
end
|
28
31
|
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestDrafter < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
describe "Diffing draft and live versions" do
|
6
|
+
describe "a draftable object" do
|
7
|
+
before do
|
8
|
+
@article = Article.new(:text => "foo")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should respond_to? :differences" do
|
12
|
+
assert @article.respond_to?(:differences)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "when there is no draft version" do
|
16
|
+
it "should return nil" do
|
17
|
+
assert_equal(nil, @article.differences(:text))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "when there is both a draft and a persisted version" do
|
22
|
+
before do
|
23
|
+
@article.save!
|
24
|
+
@article.text = "superfoo"
|
25
|
+
@article.save_draft
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "for a string attribute" do
|
29
|
+
# return an html diff string for "foo" and "superfoo"
|
30
|
+
it "should return an HTML diff between the draft and live object" do
|
31
|
+
assert (@article.reload.differences(:text)).include?(%Q(<li class=\"del\"><del>f<strong>oo</strong></del></li>))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/test/helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: drafter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-08-29 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &2164564480 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,21 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2164564480
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: diffy
|
27
|
+
requirement: &2164563780 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2164563780
|
25
36
|
- !ruby/object:Gem::Dependency
|
26
37
|
name: sqlite3
|
27
|
-
requirement: &
|
38
|
+
requirement: &2164562600 !ruby/object:Gem::Requirement
|
28
39
|
none: false
|
29
40
|
requirements:
|
30
41
|
- - ! '>='
|
@@ -32,10 +43,10 @@ dependencies:
|
|
32
43
|
version: '0'
|
33
44
|
type: :development
|
34
45
|
prerelease: false
|
35
|
-
version_requirements: *
|
46
|
+
version_requirements: *2164562600
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: debugger
|
38
|
-
requirement: &
|
49
|
+
requirement: &2164562060 !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ! '>='
|
@@ -43,10 +54,10 @@ dependencies:
|
|
43
54
|
version: '0'
|
44
55
|
type: :development
|
45
56
|
prerelease: false
|
46
|
-
version_requirements: *
|
57
|
+
version_requirements: *2164562060
|
47
58
|
- !ruby/object:Gem::Dependency
|
48
59
|
name: minitest
|
49
|
-
requirement: &
|
60
|
+
requirement: &2164561420 !ruby/object:Gem::Requirement
|
50
61
|
none: false
|
51
62
|
requirements:
|
52
63
|
- - ! '>='
|
@@ -54,10 +65,10 @@ dependencies:
|
|
54
65
|
version: '0'
|
55
66
|
type: :development
|
56
67
|
prerelease: false
|
57
|
-
version_requirements: *
|
68
|
+
version_requirements: *2164561420
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: bundler
|
60
|
-
requirement: &
|
71
|
+
requirement: &2164560500 !ruby/object:Gem::Requirement
|
61
72
|
none: false
|
62
73
|
requirements:
|
63
74
|
- - ~>
|
@@ -65,10 +76,10 @@ dependencies:
|
|
65
76
|
version: 1.0.0
|
66
77
|
type: :development
|
67
78
|
prerelease: false
|
68
|
-
version_requirements: *
|
79
|
+
version_requirements: *2164560500
|
69
80
|
- !ruby/object:Gem::Dependency
|
70
81
|
name: jeweler
|
71
|
-
requirement: &
|
82
|
+
requirement: &2164554580 !ruby/object:Gem::Requirement
|
72
83
|
none: false
|
73
84
|
requirements:
|
74
85
|
- - ~>
|
@@ -76,10 +87,10 @@ dependencies:
|
|
76
87
|
version: 1.6.4
|
77
88
|
type: :development
|
78
89
|
prerelease: false
|
79
|
-
version_requirements: *
|
90
|
+
version_requirements: *2164554580
|
80
91
|
- !ruby/object:Gem::Dependency
|
81
92
|
name: rcov
|
82
|
-
requirement: &
|
93
|
+
requirement: &2164553700 !ruby/object:Gem::Requirement
|
83
94
|
none: false
|
84
95
|
requirements:
|
85
96
|
- - ! '>='
|
@@ -87,10 +98,10 @@ dependencies:
|
|
87
98
|
version: '0'
|
88
99
|
type: :development
|
89
100
|
prerelease: false
|
90
|
-
version_requirements: *
|
101
|
+
version_requirements: *2164553700
|
91
102
|
- !ruby/object:Gem::Dependency
|
92
103
|
name: turn
|
93
|
-
requirement: &
|
104
|
+
requirement: &2164552780 !ruby/object:Gem::Requirement
|
94
105
|
none: false
|
95
106
|
requirements:
|
96
107
|
- - ! '>='
|
@@ -98,10 +109,10 @@ dependencies:
|
|
98
109
|
version: '0'
|
99
110
|
type: :development
|
100
111
|
prerelease: false
|
101
|
-
version_requirements: *
|
112
|
+
version_requirements: *2164552780
|
102
113
|
- !ruby/object:Gem::Dependency
|
103
114
|
name: carrierwave
|
104
|
-
requirement: &
|
115
|
+
requirement: &2164551960 !ruby/object:Gem::Requirement
|
105
116
|
none: false
|
106
117
|
requirements:
|
107
118
|
- - ! '>='
|
@@ -109,10 +120,10 @@ dependencies:
|
|
109
120
|
version: '0'
|
110
121
|
type: :development
|
111
122
|
prerelease: false
|
112
|
-
version_requirements: *
|
123
|
+
version_requirements: *2164551960
|
113
124
|
- !ruby/object:Gem::Dependency
|
114
125
|
name: minitest-rails-shoulda
|
115
|
-
requirement: &
|
126
|
+
requirement: &2164551280 !ruby/object:Gem::Requirement
|
116
127
|
none: false
|
117
128
|
requirements:
|
118
129
|
- - ! '>='
|
@@ -120,7 +131,7 @@ dependencies:
|
|
120
131
|
version: '0'
|
121
132
|
type: :development
|
122
133
|
prerelease: false
|
123
|
-
version_requirements: *
|
134
|
+
version_requirements: *2164551280
|
124
135
|
description: A
|
125
136
|
email: dave.hrycyszyn@headlondon.com
|
126
137
|
executables: []
|
@@ -140,12 +151,14 @@ files:
|
|
140
151
|
- lib/drafter.rb
|
141
152
|
- lib/drafter/apply.rb
|
142
153
|
- lib/drafter/creation.rb
|
154
|
+
- lib/drafter/diffing.rb
|
143
155
|
- lib/drafter/draft.rb
|
144
156
|
- lib/drafter/draft_upload.rb
|
145
157
|
- lib/drafter/draft_uploader.rb
|
146
158
|
- lib/drafter/draftable.rb
|
147
159
|
- test/drafter/test_apply.rb
|
148
160
|
- test/drafter/test_creation.rb
|
161
|
+
- test/drafter/test_diffing.rb
|
149
162
|
- test/drafter/test_draft.rb
|
150
163
|
- test/drafter/test_draft_upload.rb
|
151
164
|
- test/drafter/test_draftable.rb
|
@@ -173,7 +186,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
173
186
|
version: '0'
|
174
187
|
segments:
|
175
188
|
- 0
|
176
|
-
hash:
|
189
|
+
hash: -2897349280807350836
|
177
190
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
178
191
|
none: false
|
179
192
|
requirements:
|