vigetlabs-acts_as_markup 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/Manifest.txt +2 -0
- data/README.rdoc +16 -4
- data/acts_as_markup.gemspec +7 -7
- data/lib/acts/as_markup.rb +25 -6
- data/lib/acts_as_markup.rb +1 -1
- data/lib/acts_as_markup/exts/rdoc.rb +102 -0
- data/test/acts_as_markup_test.rb +86 -1
- data/test/acts_as_rdoc_test.rb +54 -0
- metadata +6 -3
data/CHANGELOG
CHANGED
data/Manifest.txt
CHANGED
@@ -7,6 +7,7 @@ acts_as_markup.gemspec
|
|
7
7
|
lib/acts/as_markup.rb
|
8
8
|
lib/acts_as_markup.rb
|
9
9
|
lib/acts_as_markup/exts/rdiscount.rb
|
10
|
+
lib/acts_as_markup/exts/rdoc.rb
|
10
11
|
lib/acts_as_markup/exts/string.rb
|
11
12
|
lib/acts_as_markup/exts/wikitext.rb
|
12
13
|
tasks/bones.rake
|
@@ -20,6 +21,7 @@ tasks/setup.rb
|
|
20
21
|
tasks/test.rake
|
21
22
|
test/acts_as_markdown_test.rb
|
22
23
|
test/acts_as_markup_test.rb
|
24
|
+
test/acts_as_rdoc_test.rb
|
23
25
|
test/acts_as_textile_test.rb
|
24
26
|
test/acts_as_wikitext_test.rb
|
25
27
|
test/test_helper.rb
|
data/README.rdoc
CHANGED
@@ -10,13 +10,14 @@ RDoc: http://viget.rubyforge.org/acts_as_markup
|
|
10
10
|
== DESCRIPTION:
|
11
11
|
|
12
12
|
Allows you to specify columns of an ActiveRecord model that contain Markdown,
|
13
|
-
Textile,
|
13
|
+
Textile, Wiki text and RDoc. You may then use +to_s+ to get the original markup
|
14
14
|
text or +to_html+ to get the formated HTML.
|
15
15
|
|
16
16
|
Additionally you can have a model that contains a column that has a column with
|
17
17
|
markup text, and another that defines what language to process it as. If the field
|
18
|
-
is listed as "markdown" "textile", or "
|
19
|
-
any other value for markup language will have the value pass
|
18
|
+
is listed as "markdown" "textile", "wikitext" or "rdoc" (case insensitive) it will
|
19
|
+
treat it as such, any other value for markup language will have the value pass
|
20
|
+
through as a normal string.
|
20
21
|
|
21
22
|
This AR extension can use 3 different types of Markdown processing backends:
|
22
23
|
BlueCloth, RDiscount, or Ruby PEG. You specify which one you want to use by setting
|
@@ -61,6 +62,17 @@ By default RDiscount will be used.
|
|
61
62
|
@post.body.to_html #=> "<h2>Wikitext Headline</h2>"
|
62
63
|
|
63
64
|
|
65
|
+
==== Using +acts_as_rdoc+:
|
66
|
+
|
67
|
+
class Post < ActiveRecrod
|
68
|
+
acts_as_rdoc :body
|
69
|
+
end
|
70
|
+
|
71
|
+
@post = Post.find(:first)
|
72
|
+
@post.body.to_s #=> "== RDoc Headline"
|
73
|
+
@post.body.to_html #=> "<h2>RDoc Headline</h2>"
|
74
|
+
|
75
|
+
|
64
76
|
==== Using +acts_as_markup+:
|
65
77
|
|
66
78
|
class Post < ActiveRecrod
|
@@ -72,7 +84,7 @@ By default RDiscount will be used.
|
|
72
84
|
@post.body.to_html #=> "<h2> Markdown Headline</h2>"
|
73
85
|
|
74
86
|
|
75
|
-
==== Using +acts_as_markup+ with
|
87
|
+
==== Using +acts_as_markup+ with <tt>:variable</tt> language:
|
76
88
|
|
77
89
|
class Post < ActiveRecrod
|
78
90
|
acts_as_markup :language => :variable, :columns => [:body], :language_column => 'markup_language'
|
data/acts_as_markup.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = %q{acts_as_markup}
|
3
|
-
s.version = "0.
|
3
|
+
s.version = "0.4.0"
|
4
4
|
|
5
5
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
6
|
s.authors = ["Brian Landau"]
|
7
|
-
s.date = %q{2008-08-
|
7
|
+
s.date = %q{2008-08-11}
|
8
8
|
s.description = %q{Represent ActiveRecord Markdown, Textile, or Wiki text columns as Markdown, Textile or Wikitext objects using various external libraries to convert to HTML.}
|
9
9
|
s.email = %q{brian.landau@viget.com}
|
10
10
|
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.rdoc"]
|
11
|
-
s.files = ["CHANGELOG", "LICENSE", "Manifest.txt", "README.rdoc", "Rakefile", "acts_as_markup.gemspec", "lib/acts/as_markup.rb", "lib/acts_as_markup.rb", "lib/acts_as_markup/exts/rdiscount.rb", "lib/acts_as_markup/exts/string.rb", "lib/acts_as_markup/exts/wikitext.rb", "tasks/bones.rake", "tasks/gem.rake", "tasks/git.rake", "tasks/manifest.rake", "tasks/post_load.rake", "tasks/rdoc.rake", "tasks/rubyforge.rake", "tasks/setup.rb", "tasks/test.rake", "test/acts_as_markdown_test.rb", "test/acts_as_markup_test.rb", "test/acts_as_textile_test.rb", "test/acts_as_wikitext_test.rb", "test/test_helper.rb"]
|
11
|
+
s.files = ["CHANGELOG", "LICENSE", "Manifest.txt", "README.rdoc", "Rakefile", "acts_as_markup.gemspec", "lib/acts/as_markup.rb", "lib/acts_as_markup.rb", "lib/acts_as_markup/exts/rdiscount.rb", "lib/acts_as_markup/exts/rdoc.rb", "lib/acts_as_markup/exts/string.rb", "lib/acts_as_markup/exts/wikitext.rb", "tasks/bones.rake", "tasks/gem.rake", "tasks/git.rake", "tasks/manifest.rake", "tasks/post_load.rake", "tasks/rdoc.rake", "tasks/rubyforge.rake", "tasks/setup.rb", "tasks/test.rake", "test/acts_as_markdown_test.rb", "test/acts_as_markup_test.rb", "test/acts_as_rdoc_test.rb", "test/acts_as_textile_test.rb", "test/acts_as_wikitext_test.rb", "test/test_helper.rb"]
|
12
12
|
s.has_rdoc = true
|
13
13
|
s.homepage = %q{http://viget.rubyforge.com/acts_as_markup}
|
14
14
|
s.rdoc_options = ["--main", "README.rdoc"]
|
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.rubyforge_project = %q{viget}
|
17
17
|
s.rubygems_version = %q{1.2.0}
|
18
18
|
s.summary = %q{Represent ActiveRecord Markdown, Textile, or Wiki text columns as Markdown, Textile or Wikitext objects using various external libraries to convert to HTML}
|
19
|
-
s.test_files = ["test/acts_as_markdown_test.rb", "test/acts_as_markup_test.rb", "test/acts_as_textile_test.rb", "test/acts_as_wikitext_test.rb"]
|
19
|
+
s.test_files = ["test/acts_as_markdown_test.rb", "test/acts_as_markup_test.rb", "test/acts_as_rdoc_test.rb", "test/acts_as_textile_test.rb", "test/acts_as_wikitext_test.rb"]
|
20
20
|
|
21
21
|
if s.respond_to? :specification_version then
|
22
22
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
@@ -25,20 +25,20 @@ Gem::Specification.new do |s|
|
|
25
25
|
if current_version >= 3 then
|
26
26
|
s.add_runtime_dependency(%q<activesupport>, [">= 2.1.0"])
|
27
27
|
s.add_runtime_dependency(%q<activerecord>, [">= 2.1.0"])
|
28
|
-
s.add_runtime_dependency(%q<rdiscount>, [">= 1.2.7"])
|
28
|
+
s.add_runtime_dependency(%q<rdiscount>, [">= 1.2.7.1"])
|
29
29
|
s.add_runtime_dependency(%q<RedCloth>, [">= 4.0.1"])
|
30
30
|
s.add_runtime_dependency(%q<wikitext>, [">= 1.1.1"])
|
31
31
|
else
|
32
32
|
s.add_dependency(%q<activesupport>, [">= 2.1.0"])
|
33
33
|
s.add_dependency(%q<activerecord>, [">= 2.1.0"])
|
34
|
-
s.add_dependency(%q<rdiscount>, [">= 1.2.7"])
|
34
|
+
s.add_dependency(%q<rdiscount>, [">= 1.2.7.1"])
|
35
35
|
s.add_dependency(%q<RedCloth>, [">= 4.0.1"])
|
36
36
|
s.add_dependency(%q<wikitext>, [">= 1.1.1"])
|
37
37
|
end
|
38
38
|
else
|
39
39
|
s.add_dependency(%q<activesupport>, [">= 2.1.0"])
|
40
40
|
s.add_dependency(%q<activerecord>, [">= 2.1.0"])
|
41
|
-
s.add_dependency(%q<rdiscount>, [">= 1.2.7"])
|
41
|
+
s.add_dependency(%q<rdiscount>, [">= 1.2.7.1"])
|
42
42
|
s.add_dependency(%q<RedCloth>, [">= 4.0.1"])
|
43
43
|
s.add_dependency(%q<wikitext>, [">= 1.1.1"])
|
44
44
|
end
|
data/lib/acts/as_markup.rb
CHANGED
@@ -11,15 +11,15 @@ module ActiveRecord # :nodoc:
|
|
11
11
|
|
12
12
|
##
|
13
13
|
# This allows you to specify columns you want to define as containing
|
14
|
-
# Markdown, Textile or
|
14
|
+
# Markdown, Textile, Wikitext or RDoc content.
|
15
15
|
# Then you can simply call <tt>.to_html</tt> method on the attribute.
|
16
16
|
#
|
17
17
|
# You can also specify the language as <tt>:variable</tt> you will then
|
18
18
|
# need to add an additional option of <tt>:language_column</tt>. When
|
19
19
|
# a value is accessed it will create the correct object (Markdown, Textile,
|
20
|
-
# or
|
21
|
-
# besides markdown, textile, or
|
22
|
-
# the text will pass through as a string.
|
20
|
+
# Wikitext or RDoc) based on the value of the language column. If any value
|
21
|
+
# besides markdown, textile, wikitext, or RDoc is supplied for the markup
|
22
|
+
# language the text will pass through as a string.
|
23
23
|
#
|
24
24
|
#
|
25
25
|
# ==== Examples
|
@@ -58,13 +58,22 @@ module ActiveRecord # :nodoc:
|
|
58
58
|
require 'wikitext'
|
59
59
|
require_extensions 'wikitext'
|
60
60
|
klass = 'WikitextString'
|
61
|
+
when :rdoc
|
62
|
+
require 'rdoc/markup/simple_markup'
|
63
|
+
require 'rdoc/markup/simple_markup/to_html'
|
64
|
+
require_extensions 'rdoc'
|
65
|
+
klass = 'RDocText'
|
61
66
|
when :variable
|
62
67
|
markdown_klass = get_markdown_class
|
63
68
|
require 'redcloth'
|
64
69
|
require 'wikitext'
|
70
|
+
require 'rdoc/markup/simple_markup'
|
71
|
+
require 'rdoc/markup/simple_markup/to_html'
|
65
72
|
require_extensions 'wikitext'
|
73
|
+
require_extensions 'rdoc'
|
66
74
|
textile_klass = 'RedCloth'
|
67
75
|
wiki_klass = 'WikitextString'
|
76
|
+
rdoc_klass = 'RDocText'
|
68
77
|
else
|
69
78
|
raise ActsAsMarkup::UnsportedMarkupLanguage, "#{options[:langauge]} is not a currently supported markup language."
|
70
79
|
end
|
@@ -74,7 +83,7 @@ module ActiveRecord # :nodoc:
|
|
74
83
|
class_eval <<-EOV
|
75
84
|
def #{col.to_s}
|
76
85
|
if @#{col.to_s}
|
77
|
-
|
86
|
+
unless self.#{col.to_s}_changed?
|
78
87
|
return @#{col.to_s}
|
79
88
|
end
|
80
89
|
end
|
@@ -96,6 +105,8 @@ module ActiveRecord # :nodoc:
|
|
96
105
|
@#{col.to_s} = #{textile_klass}.new(self['#{col.to_s}'].to_s)
|
97
106
|
when /wikitext/i
|
98
107
|
@#{col.to_s} = #{wiki_klass}.new(self['#{col.to_s}'].to_s)
|
108
|
+
when /rdoc/i
|
109
|
+
@#{col.to_s} = #{rdoc_klass}.new(self['#{col.to_s}'].to_s)
|
99
110
|
else
|
100
111
|
@#{col.to_s} = self['#{col.to_s}']
|
101
112
|
end
|
@@ -129,6 +140,14 @@ module ActiveRecord # :nodoc:
|
|
129
140
|
acts_as_markup :language => :wikitext, :columns => columns
|
130
141
|
end
|
131
142
|
|
143
|
+
##
|
144
|
+
# This is a convenience method for
|
145
|
+
# `<tt>acts_as_markup :language => :rdoc, :columns => [:body]</tt>`
|
146
|
+
#
|
147
|
+
def acts_as_rdoc(*columns)
|
148
|
+
acts_as_markup :language => :rdoc, :columns => columns
|
149
|
+
end
|
150
|
+
|
132
151
|
|
133
152
|
private
|
134
153
|
def get_markdown_class
|
@@ -142,7 +161,7 @@ module ActiveRecord # :nodoc:
|
|
142
161
|
end
|
143
162
|
end
|
144
163
|
def require_extensions(library)# :nodoc:
|
145
|
-
if %w(rdiscount
|
164
|
+
if %w(rdiscount wikitext rdoc).include? library.to_s
|
146
165
|
require "acts_as_markup/exts/#{library.to_s}"
|
147
166
|
end
|
148
167
|
end
|
data/lib/acts_as_markup.rb
CHANGED
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'rdoc/markup/simple_markup'
|
2
|
+
require 'rdoc/markup/simple_markup/to_html'
|
3
|
+
|
4
|
+
class RDocWithHyperlinkToHtml < SM::ToHtml
|
5
|
+
|
6
|
+
##
|
7
|
+
# Generate a hyperlink for url, labeled with text. Handle the
|
8
|
+
# special cases for img: and link: described under handle_special_HYPEDLINK
|
9
|
+
def gen_url(url, text)
|
10
|
+
if url =~ /([A-Za-z]+):(.*)/
|
11
|
+
type = $1
|
12
|
+
path = $2
|
13
|
+
else
|
14
|
+
type = "http"
|
15
|
+
path = url
|
16
|
+
url = "http://#{url}"
|
17
|
+
end
|
18
|
+
|
19
|
+
if type == "link"
|
20
|
+
if path[0,1] == '#' # is this meaningful?
|
21
|
+
url = path
|
22
|
+
else
|
23
|
+
url = HTMLGenerator.gen_url(@from_path, path)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
if (type == "http" || type == "link") && url =~ /\.(gif|png|jpg|jpeg|bmp)$/
|
28
|
+
"<img src=\"#{url}\" />"
|
29
|
+
else
|
30
|
+
"<a href=\"#{url}\">#{text.sub(%r{^#{type}:/*}, '')}</a>"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# And we're invoked with a potential external hyperlink mailto:
|
36
|
+
# just gets inserted. http: links are checked to see if they
|
37
|
+
# reference an image. If so, that image gets inserted using an
|
38
|
+
# <img> tag. Otherwise a conventional <a href> is used. We also
|
39
|
+
# support a special type of hyperlink, link:, which is a reference
|
40
|
+
# to a local file whose path is relative to the --op directory.
|
41
|
+
def handle_special_HYPERLINK(special)
|
42
|
+
url = special.text
|
43
|
+
gen_url(url, url)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Here's a hypedlink where the label is different to the URL
|
47
|
+
# <label>[url]
|
48
|
+
#
|
49
|
+
def handle_special_TIDYLINK(special)
|
50
|
+
text = special.text
|
51
|
+
unless text =~ /\{(.*?)\}\[(.*?)\]/ or text =~ /(\S+)\[(.*?)\]/
|
52
|
+
return text
|
53
|
+
end
|
54
|
+
label = $1
|
55
|
+
url = $2
|
56
|
+
gen_url(url, label)
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
##
|
62
|
+
# This allows a us to create a wrapper object similar to those provided by the
|
63
|
+
# Markdown and Textile libraries. It stores the original and formated HTML text
|
64
|
+
# in instance variables. It also stores the SimpleMarkup parser objects in
|
65
|
+
# instance variables.
|
66
|
+
#
|
67
|
+
class RDocText < String
|
68
|
+
attr_reader :text
|
69
|
+
attr_reader :html
|
70
|
+
attr_reader :markup
|
71
|
+
attr_reader :html_formater
|
72
|
+
|
73
|
+
def initialize(str)
|
74
|
+
super(str)
|
75
|
+
@text = str.to_s
|
76
|
+
@markup = SM::SimpleMarkup.new
|
77
|
+
|
78
|
+
# external hyperlinks
|
79
|
+
@markup.add_special(/((link:|https?:|mailto:|ftp:|www\.)\S+\w)/, :HYPERLINK)
|
80
|
+
|
81
|
+
# and links of the form <text>[<url>]
|
82
|
+
@markup.add_special(/(((\{.*?\})|\b\S+?)\[\S+?\.\S+?\])/, :TIDYLINK)
|
83
|
+
|
84
|
+
# Convert leading comment markers to spaces, but only
|
85
|
+
# if all non-blank lines have them
|
86
|
+
|
87
|
+
if str =~ /^(?>\s*)[^\#]/
|
88
|
+
content = str
|
89
|
+
else
|
90
|
+
content = str.gsub(/^\s*(#+)/) { $1.tr('#',' ') }
|
91
|
+
end
|
92
|
+
|
93
|
+
@html_formatter = RDocWithHyperlinkToHtml.new
|
94
|
+
|
95
|
+
@html = @markup.convert(@text, @html_formatter)
|
96
|
+
end
|
97
|
+
|
98
|
+
def to_html
|
99
|
+
@html
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
data/test/acts_as_markup_test.rb
CHANGED
@@ -224,6 +224,54 @@ class ActsAsMarkupTest < ActsAsMarkupTestCase
|
|
224
224
|
end
|
225
225
|
end
|
226
226
|
|
227
|
+
context 'with a RDoc post' do
|
228
|
+
setup do
|
229
|
+
@rdoctext = "== RDoc Test Text"
|
230
|
+
@rdoc_post = VariablePost.create!(:title => 'Blah', :body => @rdoctext, :markup_language => 'RDoc')
|
231
|
+
end
|
232
|
+
|
233
|
+
should "have a RDocText object returned for the column value" do
|
234
|
+
assert_kind_of RDocText, @rdoc_post.body
|
235
|
+
end
|
236
|
+
|
237
|
+
should "return original RDoc text for a `to_s` method call on the column value" do
|
238
|
+
assert_equal @rdoctext, @rdoc_post.body.to_s
|
239
|
+
end
|
240
|
+
|
241
|
+
should "return formated html for a `to_html` method call on the column value" do
|
242
|
+
assert_match(/<h2>\s*RDoc Test Text\s*<\/h2>/, @rdoc_post.body.to_html)
|
243
|
+
end
|
244
|
+
|
245
|
+
context "changing value of RDoc field should return new RDoc object" do
|
246
|
+
setup do
|
247
|
+
@old_body = @rdoc_post.body
|
248
|
+
@rdoc_post.body = "http://www.example.com/"
|
249
|
+
end
|
250
|
+
|
251
|
+
should "still have an RDocText object but not the same object" do
|
252
|
+
assert_kind_of RDocText, @rdoc_post.body
|
253
|
+
assert_not_same @rdoc_post.body, @old_body
|
254
|
+
end
|
255
|
+
|
256
|
+
should "return correct text for `to_s`" do
|
257
|
+
assert_equal "http://www.example.com/", @rdoc_post.body.to_s
|
258
|
+
end
|
259
|
+
|
260
|
+
should "return correct HTML for the `to_html` method" do
|
261
|
+
assert_match(/<a href="http:\/\/www.example.com">www.example.com<\/a>/, @rdoc_post.body.to_html)
|
262
|
+
end
|
263
|
+
|
264
|
+
teardown do
|
265
|
+
@old_body = nil
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
teardown do
|
270
|
+
@rdoctext, @rdoc_post = nil
|
271
|
+
Post.delete_all
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
227
275
|
context "with a plain text post" do
|
228
276
|
setup do
|
229
277
|
@plain_text = "Hahaha!!!"
|
@@ -322,7 +370,7 @@ class ActsAsMarkupTest < ActsAsMarkupTestCase
|
|
322
370
|
assert_match(/[\n\s]*/, @post.body.to_html)
|
323
371
|
end
|
324
372
|
|
325
|
-
should "have a
|
373
|
+
should "have a WikitextString object returned for the column value" do
|
326
374
|
assert_kind_of WikitextString, @post.body
|
327
375
|
end
|
328
376
|
|
@@ -332,6 +380,32 @@ class ActsAsMarkupTest < ActsAsMarkupTestCase
|
|
332
380
|
end
|
333
381
|
end
|
334
382
|
|
383
|
+
context 'with RDoc' do
|
384
|
+
setup do
|
385
|
+
class ::Post < ActiveRecord::Base
|
386
|
+
acts_as_rdoc :body
|
387
|
+
end
|
388
|
+
@post = Post.create!(:title => 'Blah', :body => @text)
|
389
|
+
end
|
390
|
+
|
391
|
+
should 'return a blank string for `to_s` method' do
|
392
|
+
assert_equal @post.body.to_s, ''
|
393
|
+
end
|
394
|
+
|
395
|
+
should 'return a blank string for `to_html` method' do
|
396
|
+
assert_match(/[\n\s]*/, @post.body.to_html)
|
397
|
+
end
|
398
|
+
|
399
|
+
should "have a RDocText object returned for the column value" do
|
400
|
+
assert_kind_of RDocText, @post.body
|
401
|
+
end
|
402
|
+
|
403
|
+
teardown do
|
404
|
+
@post = nil
|
405
|
+
Post.delete_all
|
406
|
+
end
|
407
|
+
end
|
408
|
+
|
335
409
|
context 'with RDiscount Markdown' do
|
336
410
|
setup do
|
337
411
|
ActsAsMarkup.markdown_library = :rdiscount
|
@@ -424,6 +498,17 @@ class ActsAsMarkupTest < ActsAsMarkupTestCase
|
|
424
498
|
end
|
425
499
|
end
|
426
500
|
|
501
|
+
context 'acts_as_markup with bad markdown library' do
|
502
|
+
should 'raise exception when a non-supported library is set as the markdown library attribute on ActsAsMarkup' do
|
503
|
+
assert_raise ActsAsMarkup::UnsportedMarkdownLibrary do
|
504
|
+
ActsAsMarkup.markdown_library = :fake
|
505
|
+
class ::Post < ActiveRecord::Base
|
506
|
+
acts_as_markup :language => :markdown, :columns => [:body]
|
507
|
+
end
|
508
|
+
end
|
509
|
+
end
|
510
|
+
end
|
511
|
+
|
427
512
|
def teardown
|
428
513
|
teardown_db
|
429
514
|
end
|
@@ -0,0 +1,54 @@
|
|
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 formated html for a `to_html` method call on the column value" do
|
22
|
+
assert_match(/<h2>\s*RDoc Test Text\s*<\/h2>/, @post.body.to_html)
|
23
|
+
end
|
24
|
+
|
25
|
+
context "changing value of RDoc field should return new RDoc object" do
|
26
|
+
setup do
|
27
|
+
@old_body = @post.body
|
28
|
+
@post.body = "http://www.example.com/"
|
29
|
+
end
|
30
|
+
|
31
|
+
should "still have an RDocText object but not the same object" do
|
32
|
+
assert_kind_of RDocText, @post.body
|
33
|
+
assert_not_same @post.body, @old_body
|
34
|
+
end
|
35
|
+
|
36
|
+
should "return correct text for `to_s`" do
|
37
|
+
assert_equal "http://www.example.com/", @post.body.to_s
|
38
|
+
end
|
39
|
+
|
40
|
+
should "return correct HTML for the `to_html` method" do
|
41
|
+
assert_match(/<a href="http:\/\/www.example.com">www.example.com<\/a>/, @post.body.to_html)
|
42
|
+
end
|
43
|
+
|
44
|
+
teardown do
|
45
|
+
@old_body = nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
teardown do
|
50
|
+
@rdoctext, @post = nil
|
51
|
+
Post.delete_all
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vigetlabs-acts_as_markup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Landau
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-08-
|
12
|
+
date: 2008-08-11 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -37,7 +37,7 @@ dependencies:
|
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.2.7
|
40
|
+
version: 1.2.7.1
|
41
41
|
version:
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: RedCloth
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- lib/acts/as_markup.rb
|
78
78
|
- lib/acts_as_markup.rb
|
79
79
|
- lib/acts_as_markup/exts/rdiscount.rb
|
80
|
+
- lib/acts_as_markup/exts/rdoc.rb
|
80
81
|
- lib/acts_as_markup/exts/string.rb
|
81
82
|
- lib/acts_as_markup/exts/wikitext.rb
|
82
83
|
- tasks/bones.rake
|
@@ -90,6 +91,7 @@ files:
|
|
90
91
|
- tasks/test.rake
|
91
92
|
- test/acts_as_markdown_test.rb
|
92
93
|
- test/acts_as_markup_test.rb
|
94
|
+
- test/acts_as_rdoc_test.rb
|
93
95
|
- test/acts_as_textile_test.rb
|
94
96
|
- test/acts_as_wikitext_test.rb
|
95
97
|
- test/test_helper.rb
|
@@ -123,5 +125,6 @@ summary: Represent ActiveRecord Markdown, Textile, or Wiki text columns as Markd
|
|
123
125
|
test_files:
|
124
126
|
- test/acts_as_markdown_test.rb
|
125
127
|
- test/acts_as_markup_test.rb
|
128
|
+
- test/acts_as_rdoc_test.rb
|
126
129
|
- test/acts_as_textile_test.rb
|
127
130
|
- test/acts_as_wikitext_test.rb
|