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 CHANGED
@@ -2,7 +2,7 @@ source :gemcutter
2
2
  source "http://gem.entp.com"
3
3
 
4
4
  gem 'rake'
5
- gem 'rdiscount', '~> 1.6.5'
5
+ gem 'redcarpet', '~> 2.2'
6
6
  gem 'actionpack', '~> 3.0.0'
7
7
  gem 'activerecord', '~> 3.0.0'
8
8
  gem 'activesupport', '~> 3.0.0'
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
- rdiscount (1.6.8)
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
- rdiscount (~> 1.6.5)
55
+ redcarpet
56
56
  tidy_ffi (~> 0.1.2)
data/Rakefile CHANGED
@@ -1,18 +1,18 @@
1
- require 'rake/gempackagetask'
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.3.2"
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 rdiscount and Tender/Lighthouse extensions."
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("rdiscount", "~>1.6.5")
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
- Rake::GemPackageTask.new(spec) do |pkg|
26
+ Gem::PackageTask.new(spec) do |pkg|
27
27
  pkg.gem_spec = spec
28
28
  end
29
29
 
@@ -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 'rdiscount'
196
+ require 'redcarpet'
190
197
  def self.process_markdown(text)
191
- RDiscount.new(text).to_html
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 RDiscount gem found. `gem install rdiscount`."
208
+ puts "No Redcarpet gem found. `gem install redcarpet`."
195
209
  def self.process_markdown(text)
196
210
  text
197
211
  end
@@ -24,7 +24,7 @@ module ModelFormatting
24
24
  formats :body
25
25
  end
26
26
 
27
- describe "Simple with formatting" do
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
- describe "base with after callback" do
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
- describe "Post with formatting" do
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
- describe "being saved" do
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
- describe "ChildPost with formatting" do
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
- describe "being saved" do
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</p>\n<pre>\n<code class=\"ninja\">bar</code>\n</pre>\n<pre>\n<code>baz</code>\n</pre>\n<p>@@@ wah wah</p></div>"
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</p>\n<pre>\n<code>bar</code>\n</pre>\n<pre>\n<code>baz</code>\n</pre>\n<p>@@@ wah wah</p>\n<pre>\n\n</pre></div>"
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 new paragraphs. They are\nnot paragraphs.</p>\n<p>However, when a line is skipped, that is a paragraph. GMail, and\nbasically every comment or submission form on the web work this\nway.</p></div>"
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
- describe "GFM" do
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: 23
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 2
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: 2012-03-21 00:00:00 -07:00
19
- default_executable:
17
+ date: 2013-01-19 00:00:00 Z
20
18
  dependencies:
21
19
  - !ruby/object:Gem::Dependency
22
- name: rdiscount
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: 5
27
+ hash: 7
30
28
  segments:
31
- - 1
32
- - 6
33
- - 5
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.6.2
182
+ rubygems_version: 1.8.24
187
183
  signing_key:
188
184
  specification_version: 3
189
- summary: Automatically format model attributes using rdiscount and Tender/Lighthouse extensions.
185
+ summary: Automatically format model attributes using redcarpet (markdown) and Tender/Lighthouse extensions.
190
186
  test_files: []
191
187