model_formatting 0.2.3.2 → 0.2.3.4

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 ADDED
@@ -0,0 +1,14 @@
1
+ source :gemcutter
2
+ source "http://gem.entp.com"
3
+
4
+ gem 'rake'
5
+ gem 'rdiscount', '~> 1.6.5'
6
+ gem 'actionpack', '~> 2.3.9'
7
+ gem 'activerecord', '~> 2.3.9'
8
+ gem 'activesupport', '~> 2.3.9'
9
+ gem 'tidy_ffi', '~> 0.1.2'
10
+
11
+ group :development, :test do
12
+ gem 'context', '0.5.5'
13
+ gem 'matchy', '~>0.4.0'
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,31 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ remote: http://gem.entp.com/
4
+ specs:
5
+ actionpack (2.3.14)
6
+ activesupport (= 2.3.14)
7
+ rack (~> 1.1.0)
8
+ activerecord (2.3.14)
9
+ activesupport (= 2.3.14)
10
+ activesupport (2.3.14)
11
+ context (0.5.5)
12
+ ffi (1.0.10)
13
+ matchy (0.4.0)
14
+ rack (1.1.2)
15
+ rake (0.9.2)
16
+ rdiscount (1.6.8)
17
+ tidy_ffi (0.1.3)
18
+ ffi (>= 0.3.5)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ actionpack (~> 2.3.9)
25
+ activerecord (~> 2.3.9)
26
+ activesupport (~> 2.3.9)
27
+ context (= 0.5.5)
28
+ matchy (~> 0.4.0)
29
+ rake
30
+ rdiscount (~> 1.6.5)
31
+ tidy_ffi (~> 0.1.2)
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'rake/testtask'
3
3
 
4
4
  spec = Gem::Specification.new do |s|
5
5
  s.name = "model_formatting"
6
- s.version = "0.2.3.2"
6
+ s.version = "0.2.3.4"
7
7
  s.author = "ENTP"
8
8
  s.email = "company@entp.com"
9
9
  s.homepage = "http://github.com/entp"
@@ -16,8 +16,8 @@ spec = Gem::Specification.new do |s|
16
16
  s.add_dependency("actionpack", "~>2.3.9")
17
17
  s.add_dependency("activerecord", "~>2.3.9")
18
18
  s.add_dependency("activesupport", "~>2.3.9")
19
- s.add_dependency("tidy", "~>1.1.2")
20
- s.add_development_dependency("jeremymcanally-context", "~>0.5.5")
19
+ s.add_dependency("tidy_ffi", "~>0.1.2")
20
+ s.add_development_dependency("jeremymcanally-context", "0.5.5")
21
21
  s.add_development_dependency("jeremymcanally-matchy", "~>0.1.0")
22
22
  end
23
23
 
@@ -170,7 +170,7 @@ module ModelFormatting
170
170
  extract_tag(text, :pre) do |txt|
171
171
  # prevent foo_bar_baz from ending up with an italic word in the middle
172
172
  text.gsub!(/(^(?! {4}|\t)[A-Za-z0-9]+_[A-Za-z0-9]+_[A-Za-z0-9]\w*)/) do |x|
173
- x.gsub('_', '\_') if x.split('').sort.to_s[0..1] == '__'
173
+ x.gsub('_', '\_') if x.split('').sort.join[0..1] == '__'
174
174
  end
175
175
 
176
176
  # in very clear cases, let newlines become <br /> tags
@@ -195,17 +195,16 @@ module ModelFormatting
195
195
  end
196
196
 
197
197
  begin
198
- require 'tidy'
199
- Tidy.path = ENV['TIDY_PATH'] unless ENV['TIDY_PATH'].blank?
198
+ require 'tidy_ffi'
200
199
  def self.process_tidy(text)
201
- return text unless Tidy.path
202
- Tidy.open(:show_body_only => true, :input_encoding => :utf8) do |tidy|
203
- tidy.options.new_inline_tags = "video"
204
- tidy.clean(text)
205
- end
200
+ tidy = TidyFFI::Tidy.new(text)
201
+ tidy.options.input_encoding = 'utf8'
202
+ tidy.options.show_body_only = true
203
+ tidy.options.new_inline_tags = "video"
204
+ tidy.clean.strip
206
205
  end
207
206
  rescue LoadError
208
- puts "No Tidy gem found. `gem install tidy`. Don't forget to set Tidy.path."
207
+ puts "No TidyFFI gem found. `gem install tidy_ffi`."
209
208
  def self.process_tidy(text)
210
209
  text
211
210
  end
@@ -1,4 +1,5 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ # encoding: utf-8
2
+ require File.expand_path('../test_helper', __FILE__)
2
3
 
3
4
  module ModelFormatting
4
5
  class Test < Test::Unit::TestCase
@@ -43,14 +44,21 @@ module ModelFormatting
43
44
  record = Simple.new
44
45
  record.body = "My name is\n__Name__"
45
46
  record.save
46
- record.formatted_body.should == %(<div><p>My name is<br />\n<strong>Name</strong></p></div>)
47
+ record.formatted_body.should == %(<div><p>My name is<br>\n<strong>Name</strong></p></div>)
47
48
  end
48
49
 
49
50
  it "preserves leading spaces in code blocks" do
50
51
  record = Simple.new
51
52
  record.body = " code\n more code\n\nnot code\n\n"
52
53
  record.save
53
- record.formatted_body.should == %(<div><pre><code>code\nmore code</code></pre>\n\n<p>not code</p></div>)
54
+ record.formatted_body.should == %(<div><pre>\n<code>code\nmore code</code>\n</pre>\n<p>not code</p></div>)
55
+ end
56
+
57
+ it "converts unicode characters to html entities" do
58
+ record = Simple.new
59
+ record.body = "Encöded ɐ \\Upload \\upload"
60
+ record.save
61
+ record.formatted_body.should ==%(<div><p>Enc&ouml;ded &#592; \\Upload \\upload</p></div>)
54
62
  end
55
63
  end
56
64
 
@@ -108,7 +116,7 @@ module ModelFormatting
108
116
  end
109
117
 
110
118
  describe "being saved" do
111
- before :all do
119
+ before do
112
120
  @record = Post.new
113
121
  @record.body = 'booya'
114
122
  @record.title = 'wtf'
@@ -116,11 +124,11 @@ module ModelFormatting
116
124
  end
117
125
 
118
126
  it "formats #body" do
119
- @record.formatted_body.should == %(<div>(<p>ayoob</p>)</div>)
127
+ @record.formatted_body.should == %(<div>(\n<p>ayoob</p>\n)</div>)
120
128
  end
121
129
 
122
130
  it "formats #title" do
123
- @record.title_html.should == %(<div>(<p>ftw</p>)</div>)
131
+ @record.title_html.should == %(<div>(\n<p>ftw</p>\n)</div>)
124
132
  end
125
133
 
126
134
  it "formats #bio" do
@@ -162,7 +170,7 @@ module ModelFormatting
162
170
  end
163
171
 
164
172
  describe "being saved" do
165
- before :all do
173
+ before do
166
174
  @record = ChildPost.new
167
175
  @record.body = 'booya'
168
176
  @record.bio = 'wtf'
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require File.expand_path('../test_helper', __FILE__)
2
2
 
3
3
  class ModelFormattingTest < Test::Unit::TestCase
4
4
  it "parses simple string into array of single FormattedBlock" do
@@ -55,27 +55,27 @@ class ModelFormattingTest < Test::Unit::TestCase
55
55
  end
56
56
 
57
57
  it "doesn't remove lines with pipes" do
58
- ModelFormatting.process(:html, "Yo.\n\nhere is a | pipe\n\nfoobaz").should == %(<div><p>Yo.</p>\n\n<p>here is a | pipe</p>\n\n<p>foobaz</p></div>)
58
+ ModelFormatting.process(:html, "Yo.\n\nhere is a | pipe\n\nfoobaz").should == %(<div><p>Yo.</p>\n<p>here is a | pipe</p>\n<p>foobaz</p></div>)
59
59
  end
60
60
 
61
61
  it "doesn't remove duplicate pre blocks" do
62
- ModelFormatting.process(:html, "Yes! <pre>tacos</pre> are great.\n\nI love to eat <pre>tacos</pre> topped with <pre>tacos</pre>.\n\nYes.").should == %(<div><p>Yes! <pre>tacos</pre> are great.</p>\n\n<p>I love to eat <pre>tacos</pre> topped with <pre>tacos</pre>.</p>\n\n<p>Yes.</p></div>)
62
+ ModelFormatting.process(:html, "Yes! <pre>tacos</pre> are great.\n\nI love to eat <pre>tacos</pre> topped with <pre>tacos</pre>.\n\nYes.").should == %(<div><p>Yes!</p>\n<pre>\ntacos\n</pre>\nare great.\n<p>I love to eat</p>\n<pre>\ntacos\n</pre>\ntopped with\n<pre>\ntacos\n</pre>\n.\n<p>Yes.</p></div>)
63
63
  end
64
64
 
65
65
  it "links and encodes urls correctly" do
66
- ModelFormatting.process(:html, "a *b* \n[Whoo](http://entp.com?a=1&b=2)").should == %(<div><p>a <em>b</em><br/>\n<a href="http://entp.com?a=1&amp;b=2">Whoo</a></p></div>)
66
+ ModelFormatting.process(:html, "a *b* \n[Whoo](http://entp.com?a=1&b=2)").should == %(<div><p>a <em>b</em><br>\n<a href=\"http://entp.com?a=1&amp;b=2\">Whoo</a></p></div>)
67
67
  end
68
68
 
69
69
  it "converts @@@ to code blocks" do
70
- ModelFormatting.process(:html, "<a>foo</a>\n\n@@@\n<a>bar</a>\n@@@\n\n@@@\nbaz\n@@@\n\n@@@ wah wah \n \n").should == %(<div><p><a>foo</a></p>\n\n<pre><code>&lt;a&gt;bar&lt;/a&gt;</code>\n</pre>\n\n\n\n\n<pre><code>baz</code>\n</pre>\n\n\n<p>@@@ wah wah</p></div>)
70
+ ModelFormatting.process(:html, "<a>foo</a>\n\n@@@\n<a>bar</a>\n@@@\n\n@@@\nbaz\n@@@\n\n@@@ wah wah \n \n").should == %(<div><p><a>foo</a></p>\n<pre>\n<code>&lt;a&gt;bar&lt;/a&gt;</code>\n</pre>\n<pre>\n<code>baz</code>\n</pre>\n<p>@@@ wah wah</p></div>)
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\n<pre><code class=\"ninja\">bar</code>\n</pre>\n\n\n<pre><code>baz</code>\n</pre>\n\n\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</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>"
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\n<pre><code>bar</code>\n</pre>\n\n\n<pre><code>baz</code>\n</pre>\n\n\n<p>@@@ wah wah</p>\n\n<pre><code></code>\n</pre></div>"
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>"
79
79
  end
80
80
 
81
81
  it "converts @@@ with params to code blocks with text format" do
@@ -88,7 +88,7 @@ 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<br/>\nnew paragraphs. They are not paragraphs.</p>\n\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>"
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
  end
93
93
 
94
94
  describe "GFM" do
data/test/test_helper.rb CHANGED
@@ -1,8 +1,20 @@
1
1
  $:.unshift(File.dirname(__FILE__) + '/../lib')
2
2
 
3
+ require 'test/unit'
4
+ module Test
5
+ module Unit
6
+ class TestCase
7
+ def method_name
8
+ /`(.*)'/.match(caller.first).captures[0].to_sym rescue nil
9
+ end
10
+ end
11
+ end
12
+ end
13
+
3
14
  require 'rubygems'
4
15
  require 'action_controller'
5
16
  require 'action_view'
17
+ require 'active_support/core_ext'
6
18
  require 'model_formatting'
7
19
  require 'model_formatting/init'
8
20
  require 'model_formatting/config'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: model_formatting
3
3
  version: !ruby/object:Gem::Version
4
- hash: 87
4
+ hash: 91
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
9
  - 3
10
- - 2
11
- version: 0.2.3.2
10
+ - 4
11
+ version: 0.2.3.4
12
12
  platform: ruby
13
13
  authors:
14
14
  - ENTP
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-11-04 00:00:00 -07:00
19
+ date: 2011-11-07 00:00:00 -08:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -84,19 +84,19 @@ dependencies:
84
84
  type: :runtime
85
85
  version_requirements: *id004
86
86
  - !ruby/object:Gem::Dependency
87
- name: tidy
87
+ name: tidy_ffi
88
88
  prerelease: false
89
89
  requirement: &id005 !ruby/object:Gem::Requirement
90
90
  none: false
91
91
  requirements:
92
92
  - - ~>
93
93
  - !ruby/object:Gem::Version
94
- hash: 23
94
+ hash: 31
95
95
  segments:
96
- - 1
96
+ - 0
97
97
  - 1
98
98
  - 2
99
- version: 1.1.2
99
+ version: 0.1.2
100
100
  type: :runtime
101
101
  version_requirements: *id005
102
102
  - !ruby/object:Gem::Dependency
@@ -105,7 +105,7 @@ dependencies:
105
105
  requirement: &id006 !ruby/object:Gem::Requirement
106
106
  none: false
107
107
  requirements:
108
- - - ~>
108
+ - - "="
109
109
  - !ruby/object:Gem::Version
110
110
  hash: 1
111
111
  segments:
@@ -140,6 +140,8 @@ extensions: []
140
140
  extra_rdoc_files:
141
141
  - README
142
142
  files:
143
+ - Gemfile
144
+ - Gemfile.lock
143
145
  - Rakefile
144
146
  - README
145
147
  - bin/model_formatting