vigetlabs-acts_as_markup 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,12 @@
1
- == 0.1.0 / 2008-08-04
1
+ == 0.3.0 / 2008-08-08
2
+
3
+ * Add support for wikitext.
4
+
5
+ == 0.2.0 / 2008-08-07
6
+
7
+ * Add support for a variable markup language option.
8
+
9
+ == 0.1.0 / 2008-08-05
2
10
 
3
11
  * Initial Release
4
12
  * Support for Markdown and Textile markup languages.
File without changes
data/Manifest.txt CHANGED
@@ -1,5 +1,5 @@
1
- History.txt
2
- LICENSE.txt
1
+ CHANGELOG
2
+ LICENSE
3
3
  Manifest.txt
4
4
  README.rdoc
5
5
  Rakefile
@@ -8,6 +8,7 @@ lib/acts/as_markup.rb
8
8
  lib/acts_as_markup.rb
9
9
  lib/acts_as_markup/exts/rdiscount.rb
10
10
  lib/acts_as_markup/exts/string.rb
11
+ lib/acts_as_markup/exts/wikitext.rb
11
12
  tasks/bones.rake
12
13
  tasks/gem.rake
13
14
  tasks/git.rake
@@ -17,5 +18,8 @@ tasks/rdoc.rake
17
18
  tasks/rubyforge.rake
18
19
  tasks/setup.rb
19
20
  tasks/test.rake
21
+ test/acts_as_markdown_test.rb
20
22
  test/acts_as_markup_test.rb
23
+ test/acts_as_textile_test.rb
24
+ test/acts_as_wikitext_test.rb
21
25
  test/test_helper.rb
data/README.rdoc CHANGED
@@ -9,13 +9,13 @@ RDoc: http://viget.rubyforge.org/acts_as_markup
9
9
 
10
10
  == DESCRIPTION:
11
11
 
12
- Allows you to specify columns of an ActiveRecord model that contain Markdown or
13
- Textile text. You may then use +to_s+ to get the original markdown or textile
12
+ Allows you to specify columns of an ActiveRecord model that contain Markdown,
13
+ Textile, and Wiki text. 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" or "textile" (case insensitive) it will treat it as such,
18
+ is listed as "markdown" "textile", or "wikitext" (case insensitive) it will treat it as such,
19
19
  any other value for markup language will have the value pass through as a normal string.
20
20
 
21
21
  This AR extension can use 3 different types of Markdown processing backends:
@@ -46,8 +46,19 @@ By default RDiscount will be used.
46
46
  end
47
47
 
48
48
  @post = Post.find(:first)
49
- @post.body.to_s #=> "h2. Markdown Headline"
50
- @post.body.to_html #=> "<h2>Markdown Headline</h2>"
49
+ @post.body.to_s #=> "h2. Textile Headline"
50
+ @post.body.to_html #=> "<h2>Textile Headline</h2>"
51
+
52
+
53
+ ==== Using +acts_as_wikitext+:
54
+
55
+ class Post < ActiveRecrod
56
+ acts_as_wikitext :body
57
+ end
58
+
59
+ @post = Post.find(:first)
60
+ @post.body.to_s #=> "== Wikitext Headline =="
61
+ @post.body.to_html #=> "<h2>Wikitext Headline</h2>"
51
62
 
52
63
 
53
64
  ==== Using +acts_as_markup+:
@@ -75,7 +86,9 @@ By default RDiscount will be used.
75
86
 
76
87
  == REQUIREMENTS:
77
88
 
78
- You will need the RedCloth library for processing the Textile text.
89
+ You will need the RedCloth[http://whytheluckystiff.net/ruby/redcloth/] library
90
+ for processing the Textile text, and the Wikitext[http://wikitext.rubyforge.org/]
91
+ library for processing wikitext.
79
92
 
80
93
  You will also need to install some type of Markdown processor.
81
94
  The three options currently supported are:
data/Rakefile CHANGED
@@ -13,13 +13,13 @@ PROJ.name = 'acts_as_markup'
13
13
  PROJ.authors = 'Brian Landau'
14
14
  PROJ.email = 'brian.landau@viget.com'
15
15
  PROJ.url = 'http://viget.rubyforge.com/acts_as_markup'
16
- PROJ.description = "Represent ActiveRecord Markdown or Textile text columns as Markdown or Textile objects using various external libraries to convert to HTML."
16
+ PROJ.description = "Represent ActiveRecord Markdown, Textile, or Wiki text columns as Markdown, Textile or Wikitext objects using various external libraries to convert to HTML."
17
17
  PROJ.rubyforge.name = 'viget'
18
18
  PROJ.version = ActsAsMarkup::VERSION
19
- PROJ.rdoc.include = %w(^lib/ LICENSE\.txt README\.rdoc)
19
+ PROJ.rdoc.include = %w(^lib/ LICENSE CHANGELOG README\.rdoc)
20
20
  PROJ.rdoc.remote_dir = 'acts_as_markup'
21
21
  PROJ.test.files = FileList['test/**/*_test.rb']
22
22
 
23
- %W(activesupport activerecord rdiscount RedCloth).each do |gem|
23
+ %W(activesupport activerecord rdiscount RedCloth wikitext).each do |gem|
24
24
  depend_on gem
25
25
  end
@@ -1,22 +1,22 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{acts_as_markup}
3
- s.version = "0.2.0"
3
+ s.version = "0.3.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-07}
8
- s.description = %q{Represent ActiveRecord Markdown or Textile text columns as Markdown or Textile objects using various external libraries to convert to HTML.}
7
+ s.date = %q{2008-08-08}
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
- s.extra_rdoc_files = ["LICENSE.txt", "README.rdoc"]
11
- s.files = ["History.txt", "LICENSE.txt", "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", "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_markup_test.rb", "test/test_helper.rb"]
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"]
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"]
15
15
  s.require_paths = ["lib"]
16
16
  s.rubyforge_project = %q{viget}
17
17
  s.rubygems_version = %q{1.2.0}
18
- s.summary = %q{Represent ActiveRecord Markdown or Textile text columns as Markdown or Textile objects using various external libraries to convert to HTML}
19
- s.test_files = ["test/acts_as_markup_test.rb"]
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"]
20
20
 
21
21
  if s.respond_to? :specification_version then
22
22
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -27,16 +27,19 @@ Gem::Specification.new do |s|
27
27
  s.add_runtime_dependency(%q<activerecord>, [">= 2.1.0"])
28
28
  s.add_runtime_dependency(%q<rdiscount>, [">= 1.2.7"])
29
29
  s.add_runtime_dependency(%q<RedCloth>, [">= 4.0.1"])
30
+ s.add_runtime_dependency(%q<wikitext>, [">= 1.1.1"])
30
31
  else
31
32
  s.add_dependency(%q<activesupport>, [">= 2.1.0"])
32
33
  s.add_dependency(%q<activerecord>, [">= 2.1.0"])
33
34
  s.add_dependency(%q<rdiscount>, [">= 1.2.7"])
34
35
  s.add_dependency(%q<RedCloth>, [">= 4.0.1"])
36
+ s.add_dependency(%q<wikitext>, [">= 1.1.1"])
35
37
  end
36
38
  else
37
39
  s.add_dependency(%q<activesupport>, [">= 2.1.0"])
38
40
  s.add_dependency(%q<activerecord>, [">= 2.1.0"])
39
41
  s.add_dependency(%q<rdiscount>, [">= 1.2.7"])
40
42
  s.add_dependency(%q<RedCloth>, [">= 4.0.1"])
43
+ s.add_dependency(%q<wikitext>, [">= 1.1.1"])
41
44
  end
42
45
  end
@@ -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 or Textile content.
14
+ # Markdown, Textile or Wikitext 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
- # a value is accessed it will create the correct object (Markdown or Textile)
20
- # based on the value of the language column. If any value besides markdown or
21
- # textile is supplied for the markup language the text will pass through
22
- # as a string.
19
+ # a value is accessed it will create the correct object (Markdown, Textile,
20
+ # or Wikitext) based on the value of the language column. If any value
21
+ # besides markdown, textile, or wikitext is supplied for the markup language
22
+ # the text will pass through as a string.
23
23
  #
24
24
  #
25
25
  # ==== Examples
@@ -50,26 +50,21 @@ module ActiveRecord # :nodoc:
50
50
  def acts_as_markup(options)
51
51
  case options[:language].to_sym
52
52
  when :markdown
53
- if ActsAsMarkup::MARKDOWN_LIBS.keys.include? ActsAsMarkup.markdown_library
54
- markdown_library_names = ActsAsMarkup::MARKDOWN_LIBS[ActsAsMarkup.markdown_library]
55
- require markdown_library_names[:lib_name]
56
- klass = markdown_library_names[:class_name]
57
- else
58
- raise ActsAsMarkup::UnsportedMarkdownLibrary, "#{ActsAsMarkup.markdown_library} is not currently supported."
59
- end
53
+ klass = get_markdown_class
60
54
  when :textile
61
55
  require 'redcloth'
62
56
  klass = 'RedCloth'
57
+ when :wikitext
58
+ require 'wikitext'
59
+ require_extensions 'wikitext'
60
+ klass = 'WikitextString'
63
61
  when :variable
64
- if ActsAsMarkup::MARKDOWN_LIBS.keys.include? ActsAsMarkup.markdown_library
65
- markdown_library_names = ActsAsMarkup::MARKDOWN_LIBS[ActsAsMarkup.markdown_library]
66
- require markdown_library_names[:lib_name]
67
- markdown_klass = markdown_library_names[:class_name]
68
- else
69
- raise ActsAsMarkup::UnsportedMarkdownLibrary, "#{ActsAsMarkup.markdown_library} is not currently supported."
70
- end
62
+ markdown_klass = get_markdown_class
71
63
  require 'redcloth'
64
+ require 'wikitext'
65
+ require_extensions 'wikitext'
72
66
  textile_klass = 'RedCloth'
67
+ wiki_klass = 'WikitextString'
73
68
  else
74
69
  raise ActsAsMarkup::UnsportedMarkupLanguage, "#{options[:langauge]} is not a currently supported markup language."
75
70
  end
@@ -99,6 +94,8 @@ module ActiveRecord # :nodoc:
99
94
  @#{col.to_s} = #{markdown_klass}.new(self['#{col.to_s}'].to_s)
100
95
  when /textile/i
101
96
  @#{col.to_s} = #{textile_klass}.new(self['#{col.to_s}'].to_s)
97
+ when /wikitext/i
98
+ @#{col.to_s} = #{wiki_klass}.new(self['#{col.to_s}'].to_s)
102
99
  else
103
100
  @#{col.to_s} = self['#{col.to_s}']
104
101
  end
@@ -124,6 +121,32 @@ module ActiveRecord # :nodoc:
124
121
  acts_as_markup :language => :textile, :columns => columns
125
122
  end
126
123
 
124
+ ##
125
+ # This is a convenience method for
126
+ # `<tt>acts_as_markup :language => :wikitext, :columns => [:body]</tt>`
127
+ #
128
+ def acts_as_wikitext(*columns)
129
+ acts_as_markup :language => :wikitext, :columns => columns
130
+ end
131
+
132
+
133
+ private
134
+ def get_markdown_class
135
+ if ActsAsMarkup::MARKDOWN_LIBS.keys.include? ActsAsMarkup.markdown_library
136
+ markdown_library_names = ActsAsMarkup::MARKDOWN_LIBS[ActsAsMarkup.markdown_library]
137
+ require markdown_library_names[:lib_name]
138
+ require_extensions(markdown_library_names[:lib_name])
139
+ return markdown_library_names[:class_name]
140
+ else
141
+ raise ActsAsMarkup::UnsportedMarkdownLibrary, "#{ActsAsMarkup.markdown_library} is not currently supported."
142
+ end
143
+ end
144
+ def require_extensions(library)# :nodoc:
145
+ if %w(rdiscount maruku wikitext).include? library.to_s
146
+ require "acts_as_markup/exts/#{library.to_s}"
147
+ end
148
+ end
149
+
127
150
  end
128
151
  end
129
152
  end
@@ -1,3 +1,5 @@
1
+ require 'rdiscount'
2
+
1
3
  class RDiscount
2
4
  def to_s
3
5
  self.text
@@ -1,9 +1 @@
1
- module ActsAsMarkup
2
- module StringExtension
3
- def to_html
4
- self.to_s
5
- end
6
- end
7
- end
8
-
9
- String.send :include, ActsAsMarkup::StringExtension
1
+ String.send :alias_method, :to_html, :to_s
@@ -0,0 +1,21 @@
1
+ require 'wikitext'
2
+
3
+ ##
4
+ # This allows a us to create a wrapper object similar to those provided by the
5
+ # Markdown and Textile libraries. It stores the original and formated HTML text
6
+ # in instance variables.
7
+ #
8
+ class WikitextString < String
9
+ attr_reader :text
10
+ attr_reader :html
11
+
12
+ def initialize(str)
13
+ super(str)
14
+ @text = str.to_s
15
+ @html = Wikitext::Parser.new.parse(@text)
16
+ end
17
+
18
+ def to_html
19
+ @html
20
+ end
21
+ end
@@ -2,7 +2,7 @@ require 'active_support'
2
2
 
3
3
  module ActsAsMarkup
4
4
  # :stopdoc:
5
- VERSION = '0.2.0'
5
+ VERSION = '0.3.0'
6
6
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
7
7
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
8
8
  # :startdoc:
@@ -66,5 +66,5 @@ module ActsAsMarkup
66
66
 
67
67
  end # module ActsAsMarkup
68
68
 
69
- ActsAsMarkup.require_all_libs_relative_to __FILE__
69
+ require 'acts_as_markup/exts/string'
70
70
  ActsAsMarkup.require_all_libs_relative_to __FILE__, 'acts'
data/tasks/setup.rb CHANGED
@@ -24,7 +24,7 @@ PROJ = OpenStruct.new(
24
24
  # System Defaults
25
25
  :ruby_opts => %w(-w),
26
26
  :libs => [],
27
- :history_file => 'History.txt',
27
+ :history_file => 'CHANGELOG',
28
28
  :manifest_file => 'Manifest.txt',
29
29
  :readme_file => 'README.rdoc',
30
30
 
@@ -0,0 +1,166 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class ActsAsMarkdownTest < ActsAsMarkupTestCase
4
+ context 'acts_as_markdown' do
5
+ setup do
6
+ @markdown_text = '## Markdown Test Text'
7
+ end
8
+
9
+ context 'using RDiscount' do
10
+ setup do
11
+ ActsAsMarkup.markdown_library = :rdiscount
12
+ class ::Post < ActiveRecord::Base
13
+ acts_as_markdown :body
14
+ end
15
+ @post = Post.create!(:title => 'Blah', :body => @markdown_text)
16
+ end
17
+
18
+ should "have a RDiscount object returned for the column value" do
19
+ assert_kind_of RDiscount, @post.body
20
+ end
21
+
22
+ should "return original markdown text for a `to_s` method call on the column value" do
23
+ assert_equal @markdown_text, @post.body.to_s
24
+ end
25
+
26
+ should "return formated html for a `to_html` method call on the column value" do
27
+ assert_match(/<h2>\s*Markdown Test Text\s*<\/h2>/, @post.body.to_html)
28
+ end
29
+
30
+ context "changing value of markdown field should return new markdown object" do
31
+ setup do
32
+ @old_body = @post.body
33
+ @post.body = "`@count = 20`"
34
+ end
35
+
36
+ should "still have an RDiscount object but not the same object" do
37
+ assert_kind_of RDiscount, @post.body
38
+ assert_not_same @post.body, @old_body
39
+ end
40
+
41
+ should "return correct text for `to_s`" do
42
+ assert_equal "`@count = 20`", @post.body.to_s
43
+ end
44
+
45
+ should "return correct HTML for the `to_html` method" do
46
+ assert_match(/<code>\s*\@count\s\=\s20\s*<\/code>/, @post.body.to_html)
47
+ end
48
+
49
+ teardown do
50
+ @old_body = nil
51
+ end
52
+ end
53
+
54
+ teardown do
55
+ @post = nil
56
+ Post.delete_all
57
+ end
58
+ end
59
+
60
+ context 'using Ruby PEG Markdown' do
61
+ setup do
62
+ ActsAsMarkup.markdown_library = :rpeg
63
+ class ::Post < ActiveRecord::Base
64
+ acts_as_markdown :body
65
+ end
66
+ @post = Post.create!(:title => 'Blah', :body => @markdown_text)
67
+ end
68
+
69
+ should "have a Ruby PEG Markdown object returned for the column value" do
70
+ assert_kind_of PEGMarkdown, @post.body
71
+ end
72
+
73
+ should "return original markdown text for a `to_s` method call on the column value" do
74
+ assert_equal @markdown_text, @post.body.to_s
75
+ end
76
+
77
+ should "return formated html for a `to_html` method call on the column value" do
78
+ assert_match(/<h2>\s*Markdown Test Text\s*<\/h2>/, @post.body.to_html)
79
+ end
80
+
81
+ context "changing value of markdown field should return new markdown object" do
82
+ setup do
83
+ @old_body = @post.body
84
+ @post.body = "`@count = 20`"
85
+ end
86
+
87
+ should "still have an PEGMarkdown object but not the same object" do
88
+ assert_kind_of PEGMarkdown, @post.body
89
+ assert_not_same @post.body, @old_body
90
+ end
91
+
92
+ should "return correct text for `to_s`" do
93
+ assert_equal "`@count = 20`", @post.body.to_s
94
+ end
95
+
96
+ should "return correct HTML for the `to_html` method" do
97
+ assert_match(/<code>\s*\@count\s\=\s20\s*<\/code>/, @post.body.to_html)
98
+ end
99
+
100
+ teardown do
101
+ @old_body = nil
102
+ end
103
+ end
104
+
105
+ teardown do
106
+ @post = nil
107
+ Post.delete_all
108
+ end
109
+ end
110
+
111
+ context 'using BlueCloth' do
112
+ setup do
113
+ ActsAsMarkup.markdown_library = :bluecloth
114
+ class ::Post < ActiveRecord::Base
115
+ acts_as_markdown :body
116
+ end
117
+ @post = Post.create!(:title => 'Blah', :body => @markdown_text)
118
+ end
119
+
120
+ should "have a BlueCloth object returned for the column value" do
121
+ assert_kind_of BlueCloth, @post.body
122
+ end
123
+
124
+ should "return original markdown text for a `to_s` method call on the column value" do
125
+ assert_equal @markdown_text, @post.body.to_s
126
+ end
127
+
128
+ should "return formated html for a `to_html` method call on the column value" do
129
+ assert_match(/<h2>\s*Markdown Test Text\s*<\/h2>/, @post.body.to_html)
130
+ end
131
+
132
+ context "changing value of markdown field should return new markdown object" do
133
+ setup do
134
+ @old_body = @post.body
135
+ @post.body = "`@count = 20`"
136
+ end
137
+
138
+ should "still have an BlueCloth object but not the same object" do
139
+ assert_kind_of BlueCloth, @post.body
140
+ assert_not_same @post.body, @old_body
141
+ end
142
+
143
+ should "return correct text for `to_s`" do
144
+ assert_equal "`@count = 20`", @post.body.to_s
145
+ end
146
+
147
+ should "return correct HTML for the `to_html` method" do
148
+ assert_match(/<code>\s*\@count\s\=\s20\s*<\/code>/, @post.body.to_html)
149
+ end
150
+
151
+ teardown do
152
+ @old_body = nil
153
+ end
154
+ end
155
+
156
+ teardown do
157
+ @post = nil
158
+ Post.delete_all
159
+ end
160
+ end
161
+
162
+ teardown do
163
+ @markdown_text = nil
164
+ end
165
+ end
166
+ end
@@ -1,224 +1,10 @@
1
1
  require File.dirname(__FILE__) + '/test_helper'
2
2
 
3
- class ActsAsMarkupTest < Test::Unit::TestCase
3
+ class ActsAsMarkupTest < ActsAsMarkupTestCase
4
4
  def setup
5
5
  setup_db
6
6
  end
7
7
 
8
- context 'acts_as_markdown' do
9
- setup do
10
- @markdown_text = '## Markdown Test Text'
11
- end
12
-
13
- context 'using RDiscount' do
14
- setup do
15
- ActsAsMarkup.markdown_library = :rdiscount
16
- class ::Post < ActiveRecord::Base
17
- acts_as_markdown :body
18
- end
19
- @post = Post.create!(:title => 'Blah', :body => @markdown_text)
20
- end
21
-
22
- should "have a RDiscount object returned for the column value" do
23
- assert_kind_of RDiscount, @post.body
24
- end
25
-
26
- should "return original markdown text for a `to_s` method call on the column value" do
27
- assert_equal @markdown_text, @post.body.to_s
28
- end
29
-
30
- should "return formated html for a `to_html` method call on the column value" do
31
- assert_match(/<h2>\s*Markdown Test Text\s*<\/h2>/, @post.body.to_html)
32
- end
33
-
34
- context "changing value of markdown field should return new markdown object" do
35
- setup do
36
- @old_body = @post.body
37
- @post.body = "`@count = 20`"
38
- end
39
-
40
- should "still have an RDiscount object but not the same object" do
41
- assert_kind_of RDiscount, @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>\s*\@count\s\=\s20\s*<\/code>/, @post.body.to_html)
51
- end
52
-
53
- teardown do
54
- @old_body = nil
55
- end
56
- end
57
-
58
- teardown do
59
- @post = nil
60
- Post.delete_all
61
- end
62
- end
63
-
64
- context 'using Ruby PEG Markdown' do
65
- setup do
66
- ActsAsMarkup.markdown_library = :rpeg
67
- class ::Post < ActiveRecord::Base
68
- acts_as_markdown :body
69
- end
70
- @post = Post.create!(:title => 'Blah', :body => @markdown_text)
71
- end
72
-
73
- should "have a Ruby PEG Markdown object returned for the column value" do
74
- assert_kind_of PEGMarkdown, @post.body
75
- end
76
-
77
- should "return original markdown text for a `to_s` method call on the column value" do
78
- assert_equal @markdown_text, @post.body.to_s
79
- end
80
-
81
- should "return formated html for a `to_html` method call on the column value" do
82
- assert_match(/<h2>\s*Markdown Test Text\s*<\/h2>/, @post.body.to_html)
83
- end
84
-
85
- context "changing value of markdown field should return new markdown object" do
86
- setup do
87
- @old_body = @post.body
88
- @post.body = "`@count = 20`"
89
- end
90
-
91
- should "still have an PEGMarkdown object but not the same object" do
92
- assert_kind_of PEGMarkdown, @post.body
93
- assert_not_same @post.body, @old_body
94
- end
95
-
96
- should "return correct text for `to_s`" do
97
- assert_equal "`@count = 20`", @post.body.to_s
98
- end
99
-
100
- should "return correct HTML for the `to_html` method" do
101
- assert_match(/<code>\s*\@count\s\=\s20\s*<\/code>/, @post.body.to_html)
102
- end
103
-
104
- teardown do
105
- @old_body = nil
106
- end
107
- end
108
-
109
- teardown do
110
- @post = nil
111
- Post.delete_all
112
- end
113
- end
114
-
115
- context 'using BlueCloth' do
116
- setup do
117
- ActsAsMarkup.markdown_library = :bluecloth
118
- class ::Post < ActiveRecord::Base
119
- acts_as_markdown :body
120
- end
121
- @post = Post.create!(:title => 'Blah', :body => @markdown_text)
122
- end
123
-
124
- should "have a BlueCloth object returned for the column value" do
125
- assert_kind_of BlueCloth, @post.body
126
- end
127
-
128
- should "return original markdown text for a `to_s` method call on the column value" do
129
- assert_equal @markdown_text, @post.body.to_s
130
- end
131
-
132
- should "return formated html for a `to_html` method call on the column value" do
133
- assert_match(/<h2>\s*Markdown Test Text\s*<\/h2>/, @post.body.to_html)
134
- end
135
-
136
- context "changing value of markdown field should return new markdown object" do
137
- setup do
138
- @old_body = @post.body
139
- @post.body = "`@count = 20`"
140
- end
141
-
142
- should "still have an BlueCloth object but not the same object" do
143
- assert_kind_of BlueCloth, @post.body
144
- assert_not_same @post.body, @old_body
145
- end
146
-
147
- should "return correct text for `to_s`" do
148
- assert_equal "`@count = 20`", @post.body.to_s
149
- end
150
-
151
- should "return correct HTML for the `to_html` method" do
152
- assert_match(/<code>\s*\@count\s\=\s20\s*<\/code>/, @post.body.to_html)
153
- end
154
-
155
- teardown do
156
- @old_body = nil
157
- end
158
- end
159
-
160
- teardown do
161
- @post = nil
162
- Post.delete_all
163
- end
164
- end
165
-
166
- teardown do
167
- @markdown_text = nil
168
- end
169
- end
170
-
171
- context 'acts_as_textile' do
172
- setup do
173
- @textile_text = "h2. Textile Test Text"
174
- class ::Post < ActiveRecord::Base
175
- acts_as_textile :body
176
- end
177
- @post = Post.create!(:title => 'Blah', :body => @textile_text)
178
- end
179
-
180
- should "have a RedCloth object returned for the column value" do
181
- assert_kind_of RedCloth::TextileDoc, @post.body
182
- end
183
-
184
- should "return original textile text for a `to_s` method call on the column value" do
185
- assert_equal @textile_text, @post.body.to_s
186
- end
187
-
188
- should "return formated html for a `to_html` method call on the column value" do
189
- assert_match(/<h2>Textile Test Text<\/h2>/, @post.body.to_html)
190
- end
191
-
192
- context "changing value of textile field should return new textile object" do
193
- setup do
194
- @old_body = @post.body
195
- @post.body = "@@count = 20@"
196
- end
197
-
198
- should "still have an RedCloth object but not the same object" do
199
- assert_kind_of RedCloth::TextileDoc, @post.body
200
- assert_not_same @post.body, @old_body
201
- end
202
-
203
- should "return correct text for `to_s`" do
204
- assert_equal "@@count = 20@", @post.body.to_s
205
- end
206
-
207
- should "return correct HTML for the `to_html` method" do
208
- assert_match(/<code>\@count\s\=\s20<\/code>/, @post.body.to_html)
209
- end
210
-
211
- teardown do
212
- @old_body = nil
213
- end
214
- end
215
-
216
- teardown do
217
- @textile_text, @post = nil
218
- Post.delete_all
219
- end
220
- end
221
-
222
8
  context 'acts_as_markup' do
223
9
  setup do
224
10
  ActsAsMarkup.markdown_library = ActsAsMarkup::DEFAULT_MAKRDOWN_LIB
@@ -390,6 +176,54 @@ class ActsAsMarkupTest < Test::Unit::TestCase
390
176
  end
391
177
  end
392
178
 
179
+ context 'with a Wikitext post' do
180
+ setup do
181
+ @wikitext = "== Wikitext Test Text =="
182
+ @wikitext_post = VariablePost.create!(:title => 'Blah', :body => @wikitext, :markup_language => 'Wikitext')
183
+ end
184
+
185
+ should "have a WikitextString object returned for the column value" do
186
+ assert_kind_of WikitextString, @wikitext_post.body
187
+ end
188
+
189
+ should "return original wikitext text for a `to_s` method call on the column value" do
190
+ assert_equal @wikitext, @wikitext_post.body.to_s
191
+ end
192
+
193
+ should "return formated html for a `to_html` method call on the column value" do
194
+ assert_match(/<h2>Wikitext Test Text<\/h2>/, @wikitext_post.body.to_html)
195
+ end
196
+
197
+ context "changing value of wikitext field should return new wikitext object" do
198
+ setup do
199
+ @old_body = @wikitext_post.body
200
+ @wikitext_post.body = "`@count = 20`"
201
+ end
202
+
203
+ should "still have an WikitextString object but not the same object" do
204
+ assert_kind_of WikitextString, @wikitext_post.body
205
+ assert_not_same @wikitext_post.body, @old_body
206
+ end
207
+
208
+ should "return correct text for `to_s`" do
209
+ assert_equal "`@count = 20`", @wikitext_post.body.to_s
210
+ end
211
+
212
+ should "return correct HTML for the `to_html` method" do
213
+ assert_match(/<tt>\@count\s\=\s20<\/tt>/, @wikitext_post.body.to_html)
214
+ end
215
+
216
+ teardown do
217
+ @old_body = nil
218
+ end
219
+ end
220
+
221
+ teardown do
222
+ @wikitext, @wikitext_post = nil
223
+ Post.delete_all
224
+ end
225
+ end
226
+
393
227
  context "with a plain text post" do
394
228
  setup do
395
229
  @plain_text = "Hahaha!!!"
@@ -403,8 +237,10 @@ class ActsAsMarkupTest < Test::Unit::TestCase
403
237
  should "return the original string with a `to_s` method call on the column value" do
404
238
  assert_equal @plain_text, @plain_text_post.body.to_s
405
239
  end
406
-
407
- should "eturn the original string with a `to_html` method call on the column value" do
240
+
241
+ # FIXME: why is this failing??? both objects are String, both have EXACTLY the same value when output
242
+ # in failure message. assert_equal does not require same object. This is very odd!
243
+ should "return the original string with a `to_html` method call on the column value" do
408
244
  assert_equal @plain_text, @plain_text_post.body.to_html
409
245
  end
410
246
 
@@ -470,6 +306,32 @@ class ActsAsMarkupTest < Test::Unit::TestCase
470
306
  end
471
307
  end
472
308
 
309
+ context 'with wikitext' do
310
+ setup do
311
+ class ::Post < ActiveRecord::Base
312
+ acts_as_wikitext :body
313
+ end
314
+ @post = Post.create!(:title => 'Blah', :body => @text)
315
+ end
316
+
317
+ should 'return a blank string for `to_s` method' do
318
+ assert_equal @post.body.to_s, ''
319
+ end
320
+
321
+ should 'return a blank string for `to_html` method' do
322
+ assert_match(/[\n\s]*/, @post.body.to_html)
323
+ end
324
+
325
+ should "have a RedCloth object returned for the column value" do
326
+ assert_kind_of WikitextString, @post.body
327
+ end
328
+
329
+ teardown do
330
+ @post = nil
331
+ Post.delete_all
332
+ end
333
+ end
334
+
473
335
  context 'with RDiscount Markdown' do
474
336
  setup do
475
337
  ActsAsMarkup.markdown_library = :rdiscount
@@ -556,7 +418,7 @@ class ActsAsMarkupTest < Test::Unit::TestCase
556
418
  should 'raise exception when a non-supported language is passed to acts_as_markup' do
557
419
  assert_raise ActsAsMarkup::UnsportedMarkupLanguage do
558
420
  class ::Post < ActiveRecord::Base
559
- acts_as_markup :language => :wiki, :columns => [:body]
421
+ acts_as_markup :language => :fake, :columns => [:body]
560
422
  end
561
423
  end
562
424
  end
@@ -0,0 +1,54 @@
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 formated html for a `to_html` method call on the column value" do
22
+ assert_match(/<h2>Textile Test Text<\/h2>/, @post.body.to_html)
23
+ end
24
+
25
+ context "changing value of textile field should return new textile object" do
26
+ setup do
27
+ @old_body = @post.body
28
+ @post.body = "@@count = 20@"
29
+ end
30
+
31
+ should "still have an RedCloth object but not the same object" do
32
+ assert_kind_of RedCloth::TextileDoc, @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 "@@count = 20@", @post.body.to_s
38
+ end
39
+
40
+ should "return correct HTML for the `to_html` method" do
41
+ assert_match(/<code>\@count\s\=\s20<\/code>/, @post.body.to_html)
42
+ end
43
+
44
+ teardown do
45
+ @old_body = nil
46
+ end
47
+ end
48
+
49
+ teardown do
50
+ @textile_text, @post = nil
51
+ Post.delete_all
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,54 @@
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 formated html for a `to_html` method call on the column value" do
22
+ assert_match(/<h2>Wikitext Test Text<\/h2>/, @post.body.to_html)
23
+ end
24
+
25
+ context "changing value of wikitext field should return new wikitext object" do
26
+ setup do
27
+ @old_body = @post.body
28
+ @post.body = "`@count = 20`"
29
+ end
30
+
31
+ should "still have an WikitextString object but not the same object" do
32
+ assert_kind_of WikitextString, @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 "`@count = 20`", @post.body.to_s
38
+ end
39
+
40
+ should "return correct HTML for the `to_html` method" do
41
+ assert_match(/<tt>\@count\s\=\s20<\/tt>/, @post.body.to_html)
42
+ end
43
+
44
+ teardown do
45
+ @old_body = nil
46
+ end
47
+ end
48
+
49
+ teardown do
50
+ @wikitext, @post = nil
51
+ Post.delete_all
52
+ end
53
+ end
54
+ end
data/test/test_helper.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'test/unit'
2
2
  require 'shoulda'
3
+ require 'active_support'
4
+ require 'active_support/test_case'
3
5
  require File.expand_path( File.join(File.dirname(__FILE__), %w[.. lib acts_as_markup]) )
4
6
 
5
7
  ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
@@ -38,3 +40,13 @@ def teardown_db
38
40
  ActiveRecord::Base.connection.drop_table(table)
39
41
  end
40
42
  end
43
+
44
+ class ActsAsMarkupTestCase < ActiveSupport::TestCase
45
+ def setup
46
+ setup_db
47
+ end
48
+
49
+ def teardown
50
+ teardown_db
51
+ end
52
+ 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.2.0
4
+ version: 0.3.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-07 00:00:00 -07:00
12
+ date: 2008-08-08 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -48,18 +48,28 @@ dependencies:
48
48
  - !ruby/object:Gem::Version
49
49
  version: 4.0.1
50
50
  version:
51
- description: Represent ActiveRecord Markdown or Textile text columns as Markdown or Textile objects using various external libraries to convert to HTML.
51
+ - !ruby/object:Gem::Dependency
52
+ name: wikitext
53
+ version_requirement:
54
+ version_requirements: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: 1.1.1
59
+ version:
60
+ description: Represent ActiveRecord Markdown, Textile, or Wiki text columns as Markdown, Textile or Wikitext objects using various external libraries to convert to HTML.
52
61
  email: brian.landau@viget.com
53
62
  executables: []
54
63
 
55
64
  extensions: []
56
65
 
57
66
  extra_rdoc_files:
58
- - LICENSE.txt
67
+ - CHANGELOG
68
+ - LICENSE
59
69
  - README.rdoc
60
70
  files:
61
- - History.txt
62
- - LICENSE.txt
71
+ - CHANGELOG
72
+ - LICENSE
63
73
  - Manifest.txt
64
74
  - README.rdoc
65
75
  - Rakefile
@@ -68,6 +78,7 @@ files:
68
78
  - lib/acts_as_markup.rb
69
79
  - lib/acts_as_markup/exts/rdiscount.rb
70
80
  - lib/acts_as_markup/exts/string.rb
81
+ - lib/acts_as_markup/exts/wikitext.rb
71
82
  - tasks/bones.rake
72
83
  - tasks/gem.rake
73
84
  - tasks/git.rake
@@ -77,7 +88,10 @@ files:
77
88
  - tasks/rubyforge.rake
78
89
  - tasks/setup.rb
79
90
  - tasks/test.rake
91
+ - test/acts_as_markdown_test.rb
80
92
  - test/acts_as_markup_test.rb
93
+ - test/acts_as_textile_test.rb
94
+ - test/acts_as_wikitext_test.rb
81
95
  - test/test_helper.rb
82
96
  has_rdoc: true
83
97
  homepage: http://viget.rubyforge.com/acts_as_markup
@@ -105,6 +119,9 @@ rubyforge_project: viget
105
119
  rubygems_version: 1.2.0
106
120
  signing_key:
107
121
  specification_version: 2
108
- summary: Represent ActiveRecord Markdown or Textile text columns as Markdown or Textile objects using various external libraries to convert to HTML
122
+ summary: Represent ActiveRecord Markdown, Textile, or Wiki text columns as Markdown, Textile or Wikitext objects using various external libraries to convert to HTML
109
123
  test_files:
124
+ - test/acts_as_markdown_test.rb
110
125
  - test/acts_as_markup_test.rb
126
+ - test/acts_as_textile_test.rb
127
+ - test/acts_as_wikitext_test.rb