acts_as_markup_extended 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,58 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class ActsAsRDocTest < ActsAsMarkupTestCase
4
+ context 'acts_as_rdoc' do
5
+ setup do
6
+ @rdoctext = "== RDoc Test Text"
7
+ class ::Post < ActiveRecord::Base
8
+ acts_as_rdoc :body
9
+ end
10
+ @post = Post.create!(:title => 'Blah', :body => @rdoctext)
11
+ end
12
+
13
+ should "have a RDocText object returned for the column value" do
14
+ assert_kind_of RDocText, @post.body
15
+ end
16
+
17
+ should "return original RDoc text for a `to_s` method call on the column value" do
18
+ assert_equal @rdoctext, @post.body.to_s
19
+ end
20
+
21
+ should 'return false for .blank?' do
22
+ assert !@post.body.blank?
23
+ end
24
+
25
+ should "return formated html for a `to_html` method call on the column value" do
26
+ assert_match(/<h2>\s*RDoc Test Text\s*<\/h2>/, @post.body.to_html)
27
+ end
28
+
29
+ context "changing value of RDoc field should return new RDoc object" do
30
+ setup do
31
+ @old_body = @post.body
32
+ @post.body = "http://www.example.com/"
33
+ end
34
+
35
+ should "still have an RDocText object but not the same object" do
36
+ assert_kind_of RDocText, @post.body
37
+ assert_not_same @post.body, @old_body
38
+ end
39
+
40
+ should "return correct text for `to_s`" do
41
+ assert_equal "http://www.example.com/", @post.body.to_s
42
+ end
43
+
44
+ should "return correct HTML for the `to_html` method" do
45
+ assert_match(/<a href="http:\/\/www.example.com">www.example.com<\/a>/, @post.body.to_html)
46
+ end
47
+
48
+ teardown do
49
+ @old_body = nil
50
+ end
51
+ end
52
+
53
+ teardown do
54
+ @rdoctext, @post = nil
55
+ Post.delete_all
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,77 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class ActsAsTextileTest < ActsAsMarkupTestCase
4
+ context 'acts_as_textile' do
5
+ setup do
6
+ @textile_text = "h2. Textile Test Text"
7
+ class ::Post < ActiveRecord::Base
8
+ acts_as_textile :body
9
+ end
10
+ @post = Post.create!(:title => 'Blah', :body => @textile_text)
11
+ end
12
+
13
+ should "have a RedCloth object returned for the column value" do
14
+ assert_kind_of RedCloth::TextileDoc, @post.body
15
+ end
16
+
17
+ should "return original textile text for a `to_s` method call on the column value" do
18
+ assert_equal @textile_text, @post.body.to_s
19
+ end
20
+
21
+ should 'return false for .blank?' do
22
+ assert !@post.body.blank?
23
+ end
24
+
25
+ should "return formated html for a `to_html` method call on the column value" do
26
+ assert_match(/<h2>Textile Test Text<\/h2>/, @post.body.to_html)
27
+ end
28
+
29
+ should "not return escaped html" do
30
+ @post.body = "h2. Textile <i>Test</i> Text"
31
+ assert_match(/<i>Test<\/i>/, @post.body.to_html)
32
+ end
33
+
34
+ context "changing value of textile field should return new textile object" do
35
+ setup do
36
+ @old_body = @post.body
37
+ @post.body = "@@count = 20@"
38
+ end
39
+
40
+ should "still have an RedCloth object but not the same object" do
41
+ assert_kind_of RedCloth::TextileDoc, @post.body
42
+ assert_not_same @post.body, @old_body
43
+ end
44
+
45
+ should "return correct text for `to_s`" do
46
+ assert_equal "@@count = 20@", @post.body.to_s
47
+ end
48
+
49
+ should "return correct HTML for the `to_html` method" do
50
+ assert_match(/<code>\@count\s\=\s20<\/code>/, @post.body.to_html)
51
+ end
52
+
53
+ teardown do
54
+ @old_body = nil
55
+ end
56
+ end
57
+
58
+ teardown do
59
+ @textile_text, @post = nil
60
+ Post.delete_all
61
+ end
62
+ end
63
+
64
+ context 'acts_as_textile with options' do
65
+ setup do
66
+ class ::Post
67
+ acts_as_textile :body, :textile_options => [ [ :filter_html ] ]
68
+ end
69
+ @post = Post.new(:title => 'Blah')
70
+ end
71
+
72
+ should "return escaped html because of :filter_html" do
73
+ @post.body = "h2. Textile <i>Test</i> Text"
74
+ assert_match(/&lt;i&gt;Test&lt;\/i&gt;/, @post.body.to_html)
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,77 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class ActsAsWikitextTest < ActsAsMarkupTestCase
4
+ context 'acts_as_wikitext' do
5
+ setup do
6
+ @wikitext = "== Wikitext Test Text =="
7
+ class ::Post < ActiveRecord::Base
8
+ acts_as_wikitext :body
9
+ end
10
+ @post = Post.create!(:title => 'Blah', :body => @wikitext)
11
+ end
12
+
13
+ should "have a WikitextString object returned for the column value" do
14
+ assert_kind_of WikitextString, @post.body
15
+ end
16
+
17
+ should "return original wikitext text for a `to_s` method call on the column value" do
18
+ assert_equal @wikitext, @post.body.to_s
19
+ end
20
+
21
+ should 'return false for .blank?' do
22
+ assert !@post.body.blank?
23
+ end
24
+
25
+ should "return formated html for a `to_html` method call on the column value" do
26
+ assert_match(/<h2>Wikitext Test Text<\/h2>/, @post.body.to_html)
27
+ end
28
+
29
+ should "underscore spaces in URLs" do
30
+ @post.body = "[[foo bar]]"
31
+ assert_match(/<a href="\/wiki\/foo_bar">foo bar<\/a>/, @post.body.to_html)
32
+ end
33
+
34
+ context "changing value of wikitext field should return new wikitext object" do
35
+ setup do
36
+ @old_body = @post.body
37
+ @post.body = "`@count = 20`"
38
+ end
39
+
40
+ should "still have an WikitextString object but not the same object" do
41
+ assert_kind_of WikitextString, @post.body
42
+ assert_not_same @post.body, @old_body
43
+ end
44
+
45
+ should "return correct text for `to_s`" do
46
+ assert_equal "`@count = 20`", @post.body.to_s
47
+ end
48
+
49
+ should "return correct HTML for the `to_html` method" do
50
+ assert_match(/<p><code>\@count\s\=\s20<\/code><\/p>/, @post.body.to_html)
51
+ end
52
+
53
+ teardown do
54
+ @old_body = nil
55
+ end
56
+ end
57
+
58
+ teardown do
59
+ @wikitext, @post = nil
60
+ Post.delete_all
61
+ end
62
+ end
63
+
64
+ context 'acts_as_wikitext with options' do
65
+ setup do
66
+ class ::Post
67
+ acts_as_wikitext :body, :wikitext_options => [ { :space_to_underscore => false } ]
68
+ end
69
+ @post = Post.new(:title => 'Blah')
70
+ end
71
+
72
+ should "not underscore spaces in URLs because of :space_to_underscore option" do
73
+ @post.body = "[[foo bar]]"
74
+ assert_match(/<a href="\/wiki\/foo%20bar">foo bar<\/a>/, @post.body.to_html)
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,95 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ include MarkupExtensionMethods
4
+
5
+ class MarkupMethodsTest < ActsAsMarkupTestCase
6
+
7
+ context "checklist" do
8
+ setup do
9
+ @no_disposition = %Q~<li> test </li>~
10
+ @deferred_in = %Q~<li>d test</li>~
11
+ @deferred_out = %Q~<li><strong>(>) </strong>test</li>~
12
+ @completed_in = %Q~<li>x test</li>~
13
+ @completed_out = %Q~<li><strong>(X) </strong>test</li>~
14
+ @in_progress_in = %Q~<li>@ test</li>~
15
+ @in_progress_out = %Q~<li><strong>(@) </strong>test</li>~
16
+ @dropped_in = %Q~<li>0 test</li>~
17
+ @dropped_out = %Q~<li><strong>(0) </strong>test</li>~
18
+ @not_disp_char = %Q~<li>% test</li>~
19
+ end
20
+
21
+ should "leave list item without disposition character unchanged" do
22
+ assert_equal @no_disposition, @no_disposition.checklist
23
+ end
24
+
25
+ should "put parens around list item with 'd' disposition character" do
26
+ assert_equal @deferred_out, @deferred_in.checklist
27
+ end
28
+
29
+ should "put parens around list item with 'x' disposition character" do
30
+ assert_equal @completed_out, @completed_in.checklist
31
+ end
32
+
33
+ should "put parens around list item with '@' disposition character" do
34
+ assert_equal @in_progress_out, @in_progress_in.checklist
35
+ end
36
+
37
+ should "put parens around list item with '0' disposition character" do
38
+ assert_equal @dropped_out, @dropped_in.checklist
39
+ end
40
+
41
+ should "leave list item with a character other than disp character unchanged" do
42
+ assert_equal @not_disp_char, @not_disp_char.checklist
43
+ end
44
+ end
45
+
46
+ context "ahttp" do
47
+ setup do
48
+ @simple_href_in = %Q~http://www.google.com~
49
+ @simple_href_out = %Q~<a href="http://www.google.com">http://www.google.com</a>~
50
+ @href_with_spaces = %Q~<a href = " http://www.google.com ">google</a>~
51
+ @img = %Q~<img alt="alt text" title="Title"~ +
52
+ %Q~ src="http://www.textism.com/common/textist.gif">~
53
+ @code = %Q~<code>&lt;http://www.google.com </code>~
54
+ @pre = %Q~<pre>&lt;http://www.google.com </pre>~
55
+ end
56
+
57
+ should "make href from text" do
58
+ assert_equal @simple_href_out, @simple_href_in.ahttp
59
+ end
60
+
61
+ should "leave href text inside href unchanged" do
62
+ assert_equal @simple_href_out, @simple_href_out.ahttp
63
+ end
64
+
65
+ should "leave href text inside href with spaces unchanged" do
66
+ assert_equal @href_with_spaces, @href_with_spaces.ahttp
67
+ end
68
+
69
+ should "leave href text inside <img> tag unchanged" do
70
+ assert_equal @img, @img.ahttp
71
+ end
72
+
73
+ should "leave href text inside <code> tags unchanged" do
74
+ assert_equal @code, @code.ahttp
75
+ end
76
+
77
+ should "leave href text inside <pre> tags unchanged" do
78
+ assert_equal @code, @code.ahttp
79
+ end
80
+ end
81
+
82
+ context "logo" do
83
+ setup do
84
+ @logo_in = %Q~<a href="home">logo</a>~
85
+ @logo_out = %Q~<a href="http://www.google.com">\n~ +
86
+ %Q~<img id="logo" alt="Google"~ +
87
+ %Q~ src="http://www.google.com/images/logos/google_logo.gif"~ +
88
+ %Q~ style="border: 0 none;">\n</a>\n~
89
+ end
90
+
91
+ should "substitute company logo and home page link when special URL is matched"do
92
+ assert_equal @logo_out, @logo_in.logo
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,69 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ gem 'sqlite3-ruby'
4
+ require 'shoulda'
5
+ require 'active_support'
6
+ require 'active_support/test_case'
7
+ require File.expand_path( File.join(File.dirname(__FILE__), %w[.. lib acts_as_markup_extended]) )
8
+ ActiveRecord::Schema.verbose = false
9
+
10
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
11
+
12
+ def setup_db
13
+ ActiveRecord::Schema.define(:version => 1) do
14
+ create_table :posts do |t|
15
+ t.column :title, :string
16
+ t.column :body, :text
17
+ t.timestamps
18
+ end
19
+
20
+ create_table :markdown_posts do |t|
21
+ t.column :title, :string
22
+ t.column :body, :text
23
+ t.timestamps
24
+ end
25
+
26
+ create_table :textile_posts do |t|
27
+ t.column :title, :string
28
+ t.column :body, :text
29
+ t.timestamps
30
+ end
31
+
32
+ create_table :variable_posts do |t|
33
+ t.column :title, :string
34
+ t.column :body, :text
35
+ t.column :markup_language, :string
36
+ t.timestamps
37
+ end
38
+
39
+ create_table :variable_language_posts do |t|
40
+ t.column :title, :string
41
+ t.column :body, :text
42
+ t.column :language_name, :string
43
+ t.timestamps
44
+ end
45
+ end
46
+ end
47
+
48
+ def teardown_db
49
+ ActiveRecord::Base.connection.tables.each do |table|
50
+ ActiveRecord::Base.connection.drop_table(table)
51
+ end
52
+ end
53
+
54
+ class ActsAsMarkupTestCase < ActiveSupport::TestCase
55
+ def setup
56
+ setup_db
57
+ end
58
+
59
+ def teardown
60
+ teardown_db
61
+ end
62
+
63
+ def self.should_act_like_a_string
64
+ should "act like a string" do
65
+ assert_equal @post.body.split(' '), ['##', 'Markdown', 'Test', 'Text']
66
+ assert @post.body.match(/Te[sx]t/)
67
+ end
68
+ end
69
+ end
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acts_as_markup_extended
3
+ version: !ruby/object:Gem::Version
4
+ hash: 21
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 1
10
+ version: 1.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Mitch Marx
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-07-01 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: activesupport
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 7
29
+ segments:
30
+ - 2
31
+ - 3
32
+ - 2
33
+ version: 2.3.2
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: activerecord
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 7
45
+ segments:
46
+ - 2
47
+ - 3
48
+ - 2
49
+ version: 2.3.2
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: rdiscount
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ hash: 9
61
+ segments:
62
+ - 1
63
+ - 3
64
+ version: "1.3"
65
+ type: :runtime
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: wikitext
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 2
78
+ - 0
79
+ version: "2.0"
80
+ type: :runtime
81
+ version_requirements: *id004
82
+ - !ruby/object:Gem::Dependency
83
+ name: RedCloth
84
+ prerelease: false
85
+ requirement: &id005 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ hash: 31
91
+ segments:
92
+ - 4
93
+ - 2
94
+ version: "4.2"
95
+ type: :runtime
96
+ version_requirements: *id005
97
+ description: Represent ActiveRecord Markdown, Textile, Wiki text, RDoc columns as Markdown, Textile Wikitext, RDoc objects using various external libraries to convert to HTML. Includes markup extension methods.
98
+ email: mitch.marx@mdpaladin.com
99
+ executables: []
100
+
101
+ extensions: []
102
+
103
+ extra_rdoc_files:
104
+ - LICENSE
105
+ - README.rdoc
106
+ files:
107
+ - CHANGELOG
108
+ - LICENSE
109
+ - README.rdoc
110
+ - Rakefile
111
+ - lib/acts/as_markup.rb
112
+ - lib/acts_as_markup/exts/maruku.rb
113
+ - lib/acts_as_markup/exts/object.rb
114
+ - lib/acts_as_markup/exts/peg_markdown.rb
115
+ - lib/acts_as_markup/exts/rdiscount.rb
116
+ - lib/acts_as_markup/exts/rdoc.rb
117
+ - lib/acts_as_markup/exts/wikitext.rb
118
+ - lib/acts_as_markup/stringlike.rb
119
+ - lib/acts_as_markup_extended.rb
120
+ - lib/markup_extensions.rb
121
+ - lib/markup_methods/ahttp.rb
122
+ - lib/markup_methods/checklist.rb
123
+ - lib/markup_methods/logo.rb
124
+ - test/acts_as_markdown_test.rb
125
+ - test/acts_as_markup_extended.rb
126
+ - test/acts_as_markup_test.rb
127
+ - test/acts_as_rdoc_test.rb
128
+ - test/acts_as_textile_test.rb
129
+ - test/acts_as_wikitext_test.rb
130
+ - test/markup_methods_test.rb
131
+ - test/test_helper.rb
132
+ homepage: https://github.com/mitchmarx/acts_as_markup_extended/
133
+ licenses: []
134
+
135
+ post_install_message:
136
+ rdoc_options: []
137
+
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ hash: 3
146
+ segments:
147
+ - 0
148
+ version: "0"
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ hash: 3
155
+ segments:
156
+ - 0
157
+ version: "0"
158
+ requirements: []
159
+
160
+ rubyforge_project:
161
+ rubygems_version: 1.8.5
162
+ signing_key:
163
+ specification_version: 3
164
+ summary: Represent ActiveRecord Markdown, Textile, Wiki text, RDoc columns as Markdown, Textile Wikitext, RDoc objects using various external libraries to convert to HTML. Includes markup extension methods.
165
+ test_files: []
166
+