model_formatting 0.3.2 → 0.5
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/Gemfile +1 -1
- data/Gemfile.lock +2 -2
- data/Rakefile +5 -5
- data/lib/model_formatting.rb +17 -3
- data/test/formatting_test.rb +6 -6
- data/test/model_formatting_test.rb +15 -5
- metadata +13 -17
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -37,7 +37,7 @@ GEM
|
|
37
37
|
rack-test (0.5.7)
|
38
38
|
rack (>= 1.0)
|
39
39
|
rake (0.9.2)
|
40
|
-
|
40
|
+
redcarpet (2.2.2)
|
41
41
|
tidy_ffi (0.1.3)
|
42
42
|
ffi (>= 0.3.5)
|
43
43
|
tzinfo (0.3.32)
|
@@ -52,5 +52,5 @@ DEPENDENCIES
|
|
52
52
|
context (= 0.5.5)
|
53
53
|
matchy (~> 0.4.0)
|
54
54
|
rake
|
55
|
-
|
55
|
+
redcarpet
|
56
56
|
tidy_ffi (~> 0.1.2)
|
data/Rakefile
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
require '
|
1
|
+
require 'rubygems/package_task'
|
2
2
|
require 'rake/testtask'
|
3
3
|
|
4
4
|
spec = Gem::Specification.new do |s|
|
5
5
|
s.name = "model_formatting"
|
6
|
-
s.version = "0.
|
6
|
+
s.version = "0.5"
|
7
7
|
s.author = "ENTP"
|
8
8
|
s.email = "company@entp.com"
|
9
9
|
s.homepage = "http://github.com/entp"
|
10
10
|
s.platform = Gem::Platform::RUBY
|
11
|
-
s.summary = "Automatically format model attributes using
|
11
|
+
s.summary = "Automatically format model attributes using redcarpet (markdown) and Tender/Lighthouse extensions."
|
12
12
|
s.files = FileList['[a-zA-Z]*', 'bin/*', 'lib/**/*', 'rails/**/*', 'test/**/*']
|
13
13
|
s.has_rdoc = false
|
14
14
|
s.extra_rdoc_files = ["README"]
|
15
|
-
s.add_dependency("
|
15
|
+
s.add_dependency("redcarpet", "~>2.2")
|
16
16
|
s.add_dependency("actionpack", "~>3.0.0")
|
17
17
|
s.add_dependency("activerecord", "~>3.0.0")
|
18
18
|
s.add_dependency("activesupport", "~>3.0.0")
|
@@ -23,7 +23,7 @@ end
|
|
23
23
|
|
24
24
|
|
25
25
|
desc 'Build the gem.'
|
26
|
-
|
26
|
+
Gem::PackageTask.new(spec) do |pkg|
|
27
27
|
pkg.gem_spec = spec
|
28
28
|
end
|
29
29
|
|
data/lib/model_formatting.rb
CHANGED
@@ -182,16 +182,30 @@ module ModelFormatting
|
|
182
182
|
text.gsub!(/(^(?! {4}|\t)\w+_\w+_\w[\w_]*)/) do |x|
|
183
183
|
x.gsub('_', '\_') if x.split('').sort.to_s[0..1] == '__'
|
184
184
|
end
|
185
|
+
|
186
|
+
# in very clear cases, let newlines become <br /> tags
|
187
|
+
#text.gsub!(/(\A|^$\n)(^\w[^\n]*\n)(^\w[^\n]*$)+/m) do |x|
|
188
|
+
# x.gsub(/^(.+)$/, "\\1 ")
|
189
|
+
text.gsub!(/^[\w\<][^\n]*\n+/) do |x|
|
190
|
+
x =~ /\n{2}/ ? x : (x.strip!; x << " \n")
|
191
|
+
end
|
185
192
|
end
|
186
193
|
end
|
187
194
|
|
188
195
|
begin
|
189
|
-
require '
|
196
|
+
require 'redcarpet'
|
190
197
|
def self.process_markdown(text)
|
191
|
-
|
198
|
+
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,
|
199
|
+
:no_intra_emphasis => true,
|
200
|
+
:tables => true,
|
201
|
+
:fenced_code_blocks => true,
|
202
|
+
:space_after_headers => true,
|
203
|
+
# :hard_wrap => true,
|
204
|
+
# :with_toc_data => true,
|
205
|
+
:autolink => true).render(text)
|
192
206
|
end
|
193
207
|
rescue LoadError
|
194
|
-
puts "No
|
208
|
+
puts "No Redcarpet gem found. `gem install redcarpet`."
|
195
209
|
def self.process_markdown(text)
|
196
210
|
text
|
197
211
|
end
|
data/test/formatting_test.rb
CHANGED
@@ -24,7 +24,7 @@ module ModelFormatting
|
|
24
24
|
formats :body
|
25
25
|
end
|
26
26
|
|
27
|
-
|
27
|
+
context "Simple with formatting" do
|
28
28
|
it "has attribute from #formats arguments" do
|
29
29
|
Simple.model_formatting_attributes[:body].should == "formatted_body"
|
30
30
|
end
|
@@ -68,7 +68,7 @@ module ModelFormatting
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
-
|
71
|
+
context "base with after callback" do
|
72
72
|
it "does not leave mkd-extraction artifacts" do
|
73
73
|
record = BaseWithAfter.new
|
74
74
|
record.body = File.read(File.dirname(__FILE__) + '/fixtures/mkd-extraction.txt')
|
@@ -94,7 +94,7 @@ module ModelFormatting
|
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
|
-
|
97
|
+
context "Post with formatting" do
|
98
98
|
it "has attribute from #formats arguments" do
|
99
99
|
Post.model_formatting_attributes[:body].should == "formatted_body"
|
100
100
|
end
|
@@ -115,7 +115,7 @@ module ModelFormatting
|
|
115
115
|
Post.before_save.should == :format_content_with_model_formatting
|
116
116
|
end
|
117
117
|
|
118
|
-
|
118
|
+
context "being saved" do
|
119
119
|
before do
|
120
120
|
@record = Post.new
|
121
121
|
@record.body = 'booya'
|
@@ -152,7 +152,7 @@ module ModelFormatting
|
|
152
152
|
end
|
153
153
|
end
|
154
154
|
|
155
|
-
|
155
|
+
context "ChildPost with formatting" do
|
156
156
|
it "has attribute from #formats arguments" do
|
157
157
|
ChildPost.model_formatting_attributes[:body].should == "formatted_body"
|
158
158
|
end
|
@@ -169,7 +169,7 @@ module ModelFormatting
|
|
169
169
|
ChildPost.before_save.should == :format_content_with_model_formatting
|
170
170
|
end
|
171
171
|
|
172
|
-
|
172
|
+
context "being saved" do
|
173
173
|
before do
|
174
174
|
@record = ChildPost.new
|
175
175
|
@record.body = 'booya'
|
@@ -71,11 +71,11 @@ class ModelFormattingTest < Test::Unit::TestCase
|
|
71
71
|
end
|
72
72
|
|
73
73
|
it "converts @@@ with params to code blocks" do
|
74
|
-
ModelFormatting.process(:html, "foo\n@@@ ninja\nbar\n@@@\n@@@\nbaz\n@@@\n@@@ wah wah \n \n").should == "<div><p>foo
|
74
|
+
ModelFormatting.process(:html, "foo\n@@@ ninja\nbar\n@@@\n@@@\nbaz\n@@@\n@@@ wah wah \n \n").should == "<div><p>foo<br></p>\n<pre>\n<code class=\"ninja\">bar</code>\n</pre>\n<pre>\n<code>baz</code>\n</pre>\n@@@ wah wah</div>"
|
75
75
|
end
|
76
76
|
|
77
77
|
it "fixes irregular number of @@@'s" do
|
78
|
-
ModelFormatting.process(:html, "foo\n@@@\nbar\n@@@\n@@@\nbaz\n@@@\n@@@ wah wah \n \n@@@").should == "<div><p>foo
|
78
|
+
ModelFormatting.process(:html, "foo\n@@@\nbar\n@@@\n@@@\nbaz\n@@@\n@@@ wah wah \n \n@@@").should == "<div><p>foo<br></p>\n<pre>\n<code>bar</code>\n</pre>\n<pre>\n<code>baz</code>\n</pre>\n@@@ wah wah\n<pre>\n\n</pre></div>"
|
79
79
|
end
|
80
80
|
|
81
81
|
it "converts @@@ with params to code blocks with text format" do
|
@@ -88,10 +88,11 @@ class ModelFormattingTest < Test::Unit::TestCase
|
|
88
88
|
|
89
89
|
it "treats linebreaks correctly" do
|
90
90
|
ModelFormatting.process(:html, "Line breaks should not be treated as\nnew paragraphs. They are not paragraphs.\n\nHowever, when a line is skipped, that is a paragraph.\nGMail, and basically every comment or submission form on the \nweb work this way.").should == \
|
91
|
-
"<div><p>Line breaks should not be treated as
|
91
|
+
"<div><p>Line breaks should not be treated as<br>\nnew paragraphs. They are not paragraphs.</p>\n<p>However, when a line is skipped, that is a paragraph.<br>\nGMail, and basically every comment or submission form on the<br>\nweb work this way.</p></div>"
|
92
|
+
|
92
93
|
end
|
93
94
|
|
94
|
-
|
95
|
+
context "GFM" do
|
95
96
|
it "does not touch single underscores inside words" do
|
96
97
|
assert_equal "foo_bar", ModelFormatting.gfm("foo_bar")
|
97
98
|
end
|
@@ -107,7 +108,16 @@ class ModelFormattingTest < Test::Unit::TestCase
|
|
107
108
|
it "escapes two or more underscores inside words" do
|
108
109
|
assert_equal "foo\\_bar\\_baz", ModelFormatting.gfm("foo_bar_baz")
|
109
110
|
end
|
110
|
-
|
111
|
+
|
112
|
+
it "turns newlines into br tags in simple cases" do
|
113
|
+
assert_equal "foo \nbar", ModelFormatting.gfm("foo\nbar")
|
114
|
+
end
|
115
|
+
|
116
|
+
it "converts newlines in all groups" do
|
117
|
+
assert_equal "apple \npear \norange \nbanana\n\nruby \npython \nerlang \njavascript",
|
118
|
+
ModelFormatting.gfm("apple\npear\norange\nbanana\n\nruby\npython\nerlang\njavascript")
|
119
|
+
end
|
120
|
+
|
111
121
|
it "does not not convert newlines in lists" do
|
112
122
|
assert_equal "# foo\n# bar", ModelFormatting.gfm("# foo\n# bar")
|
113
123
|
assert_equal "* foo\n* bar", ModelFormatting.gfm("* foo\n* bar")
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: model_formatting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
|
10
|
-
version: 0.3.2
|
8
|
+
- 5
|
9
|
+
version: "0.5"
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- ENTP
|
@@ -15,23 +14,21 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date:
|
19
|
-
default_executable:
|
17
|
+
date: 2013-01-19 00:00:00 Z
|
20
18
|
dependencies:
|
21
19
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
20
|
+
name: redcarpet
|
23
21
|
prerelease: false
|
24
22
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
23
|
none: false
|
26
24
|
requirements:
|
27
25
|
- - ~>
|
28
26
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
27
|
+
hash: 7
|
30
28
|
segments:
|
31
|
-
-
|
32
|
-
-
|
33
|
-
|
34
|
-
version: 1.6.5
|
29
|
+
- 2
|
30
|
+
- 2
|
31
|
+
version: "2.2"
|
35
32
|
type: :runtime
|
36
33
|
version_requirements: *id001
|
37
34
|
- !ruby/object:Gem::Dependency
|
@@ -141,19 +138,18 @@ extra_rdoc_files:
|
|
141
138
|
files:
|
142
139
|
- Gemfile
|
143
140
|
- Gemfile.lock
|
144
|
-
- Rakefile
|
145
141
|
- README
|
142
|
+
- Rakefile
|
146
143
|
- bin/model_formatting
|
144
|
+
- lib/model_formatting.rb
|
147
145
|
- lib/model_formatting/config.rb
|
148
146
|
- lib/model_formatting/init.rb
|
149
147
|
- lib/model_formatting/instance_methods.rb
|
150
|
-
- lib/model_formatting.rb
|
151
148
|
- rails/init.rb
|
152
149
|
- test/fixtures/mkd-extraction.txt
|
153
150
|
- test/formatting_test.rb
|
154
151
|
- test/model_formatting_test.rb
|
155
152
|
- test/test_helper.rb
|
156
|
-
has_rdoc: true
|
157
153
|
homepage: http://github.com/entp
|
158
154
|
licenses: []
|
159
155
|
|
@@ -183,9 +179,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
183
179
|
requirements: []
|
184
180
|
|
185
181
|
rubyforge_project:
|
186
|
-
rubygems_version: 1.
|
182
|
+
rubygems_version: 1.8.24
|
187
183
|
signing_key:
|
188
184
|
specification_version: 3
|
189
|
-
summary: Automatically format model attributes using
|
185
|
+
summary: Automatically format model attributes using redcarpet (markdown) and Tender/Lighthouse extensions.
|
190
186
|
test_files: []
|
191
187
|
|