acts_as_markup 0.4.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,4 +1,8 @@
1
- == 0.4.0 / 2008-08-08
1
+ == 1.0.0 / 2008-08-11
2
+
3
+ * Add support for Maruku Markdown Library.
4
+
5
+ == 0.4.0 / 2008-08-11
2
6
 
3
7
  * Add support for RDoc.
4
8
 
@@ -15,4 +19,4 @@
15
19
  * Initial Release
16
20
  * Support for Markdown and Textile markup languages.
17
21
  * `acts_as_markdown` and `acts_as_textile` convenience methods
18
- * Support for BlueCloth, RDiscount and Ruyb PEG markdown processors.
22
+ * Support for BlueCloth, RDiscount and Ruby PEG markdown processors.
data/Manifest.txt CHANGED
@@ -6,6 +6,7 @@ Rakefile
6
6
  acts_as_markup.gemspec
7
7
  lib/acts/as_markup.rb
8
8
  lib/acts_as_markup.rb
9
+ lib/acts_as_markup/exts/maruku.rb
9
10
  lib/acts_as_markup/exts/rdiscount.rb
10
11
  lib/acts_as_markup/exts/rdoc.rb
11
12
  lib/acts_as_markup/exts/string.rb
data/README.rdoc CHANGED
@@ -1,4 +1,4 @@
1
- = acts_as_markup
1
+ = Acts as Markup
2
2
 
3
3
  by Brian Landau of Viget Labs <brian.landau@viget.com>
4
4
 
@@ -20,7 +20,7 @@ treat it as such, any other value for markup language will have the value pass
20
20
  through as a normal string.
21
21
 
22
22
  This AR extension can use 3 different types of Markdown processing backends:
23
- BlueCloth, RDiscount, or Ruby PEG. You specify which one you want to use by setting
23
+ BlueCloth, RDiscount, Ruby PEG or Maruku. You specify which one you want to use by setting
24
24
  a config value in your environment.rb file:
25
25
 
26
26
  ActsAsMarkup.markdown_library = :bluecloth
@@ -108,6 +108,7 @@ The three options currently supported are:
108
108
  * BlueCloth
109
109
  * RDiscount[http://github.com/rtomayko/rdiscount]
110
110
  * {Ruby PEG}[http://github.com/rtomayko/rpeg-markdown/tree/master]
111
+ * Maruku[http://maruku.rubyforge.org/]
111
112
 
112
113
  == INSTALL:
113
114
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{acts_as_markup}
3
- s.version = "0.4.0"
3
+ s.version = "1.0.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"]
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
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/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"]
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/maruku.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"]
@@ -9,7 +9,6 @@ module ActiveRecord # :nodoc:
9
9
 
10
10
  module ClassMethods
11
11
 
12
- ##
13
12
  # This allows you to specify columns you want to define as containing
14
13
  # Markdown, Textile, Wikitext or RDoc content.
15
14
  # Then you can simply call <tt>.to_html</tt> method on the attribute.
@@ -116,7 +115,6 @@ module ActiveRecord # :nodoc:
116
115
  end
117
116
  end
118
117
 
119
- ##
120
118
  # This is a convenience method for
121
119
  # `<tt>acts_as_markup :language => :markdown, :columns => [:body]</tt>`
122
120
  #
@@ -124,7 +122,6 @@ module ActiveRecord # :nodoc:
124
122
  acts_as_markup :language => :markdown, :columns => columns
125
123
  end
126
124
 
127
- ##
128
125
  # This is a convenience method for
129
126
  # `<tt>acts_as_markup :language => :textile, :columns => [:body]</tt>`
130
127
  #
@@ -132,7 +129,6 @@ module ActiveRecord # :nodoc:
132
129
  acts_as_markup :language => :textile, :columns => columns
133
130
  end
134
131
 
135
- ##
136
132
  # This is a convenience method for
137
133
  # `<tt>acts_as_markup :language => :wikitext, :columns => [:body]</tt>`
138
134
  #
@@ -140,7 +136,6 @@ module ActiveRecord # :nodoc:
140
136
  acts_as_markup :language => :wikitext, :columns => columns
141
137
  end
142
138
 
143
- ##
144
139
  # This is a convenience method for
145
140
  # `<tt>acts_as_markup :language => :rdoc, :columns => [:body]</tt>`
146
141
  #
@@ -160,8 +155,9 @@ module ActiveRecord # :nodoc:
160
155
  raise ActsAsMarkup::UnsportedMarkdownLibrary, "#{ActsAsMarkup.markdown_library} is not currently supported."
161
156
  end
162
157
  end
158
+
163
159
  def require_extensions(library)# :nodoc:
164
- if %w(rdiscount wikitext rdoc).include? library.to_s
160
+ if %w(rdiscount maruku wikitext rdoc).include? library.to_s
165
161
  require "acts_as_markup/exts/#{library.to_s}"
166
162
  end
167
163
  end
@@ -0,0 +1,68 @@
1
+ require 'maruku'
2
+
3
+ class Maruku
4
+ attr_reader :text
5
+
6
+ def initialize(s=nil, meta={})
7
+ super(nil)
8
+ self.attributes.merge! meta
9
+ if s
10
+ @text = s
11
+ parse_doc(s)
12
+ end
13
+ end
14
+
15
+ # Used to get the original Markdown text.
16
+ def to_s
17
+ @text
18
+ end
19
+
20
+ end
21
+
22
+ class String
23
+ alias_method :to_html, :to_s
24
+
25
+ def to_xml
26
+ REXML::Text.new(self)
27
+ end
28
+ end
29
+
30
+ module MaRuKu # :nodoc:
31
+ module Out # :nodoc:
32
+ module HTML
33
+
34
+ # We patch this method to play nicely with our own modifications of String.
35
+ #
36
+ # It originally used a +to_html+ method on String we've swapped this out for a +to_xml+
37
+ # method because we need +to_html+ to return the original text on plain text fields of
38
+ # the variable language option on +acts_as_markup+
39
+ def array_to_html(array)
40
+ e = []
41
+ array.each do |c|
42
+ method = c.kind_of?(MDElement) ?
43
+ "to_html_#{c.node_type}" : "to_xml"
44
+
45
+ if not c.respond_to?(method)
46
+ #raise "Object does not answer to #{method}: #{c.class} #{c.inspect}"
47
+ next
48
+ end
49
+
50
+ h = c.send(method)
51
+
52
+ if h.nil?
53
+ raise "Nil html created by method #{method}:\n#{h.inspect}\n"+
54
+ " for object #{c.inspect[0,300]}"
55
+ end
56
+
57
+ if h.kind_of?Array
58
+ e = e + h #h.each do |hh| e << hh end
59
+ else
60
+ e << h
61
+ end
62
+ end
63
+ e
64
+ end
65
+
66
+ end
67
+ end
68
+ end
@@ -1,6 +1,7 @@
1
1
  require 'rdiscount'
2
2
 
3
3
  class RDiscount
4
+ # Used to get the original Markdown text.
4
5
  def to_s
5
6
  self.text
6
7
  end
@@ -3,9 +3,9 @@ require 'rdoc/markup/simple_markup/to_html'
3
3
 
4
4
  class RDocWithHyperlinkToHtml < SM::ToHtml
5
5
 
6
- ##
7
6
  # Generate a hyperlink for url, labeled with text. Handle the
8
7
  # special cases for img: and link: described under handle_special_HYPEDLINK
8
+ #
9
9
  def gen_url(url, text)
10
10
  if url =~ /([A-Za-z]+):(.*)/
11
11
  type = $1
@@ -31,21 +31,21 @@ class RDocWithHyperlinkToHtml < SM::ToHtml
31
31
  end
32
32
  end
33
33
 
34
- ##
35
34
  # And we're invoked with a potential external hyperlink mailto:
36
35
  # just gets inserted. http: links are checked to see if they
37
36
  # reference an image. If so, that image gets inserted using an
38
37
  # <img> tag. Otherwise a conventional <a href> is used. We also
39
38
  # support a special type of hyperlink, link:, which is a reference
40
39
  # to a local file whose path is relative to the --op directory.
40
+ #
41
41
  def handle_special_HYPERLINK(special)
42
42
  url = special.text
43
43
  gen_url(url, url)
44
44
  end
45
45
 
46
46
  # Here's a hypedlink where the label is different to the URL
47
- # <label>[url]
48
- #
47
+ # <label>[url]
48
+ #
49
49
  def handle_special_TIDYLINK(special)
50
50
  text = special.text
51
51
  unless text =~ /\{(.*?)\}\[(.*?)\]/ or text =~ /(\S+)\[(.*?)\]/
@@ -58,7 +58,6 @@ class RDocWithHyperlinkToHtml < SM::ToHtml
58
58
 
59
59
  end
60
60
 
61
- ##
62
61
  # This allows a us to create a wrapper object similar to those provided by the
63
62
  # Markdown and Textile libraries. It stores the original and formated HTML text
64
63
  # in instance variables. It also stores the SimpleMarkup parser objects in
@@ -1,6 +1,5 @@
1
1
  require 'wikitext'
2
2
 
3
- ##
4
3
  # This allows a us to create a wrapper object similar to those provided by the
5
4
  # Markdown and Textile libraries. It stores the original and formated HTML text
6
5
  # in instance variables.
@@ -2,7 +2,7 @@ require 'active_support'
2
2
 
3
3
  module ActsAsMarkup
4
4
  # :stopdoc:
5
- VERSION = '0.4.0'
5
+ VERSION = '1.0.0'
6
6
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
7
7
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
8
8
  # :startdoc:
@@ -22,7 +22,9 @@ module ActsAsMarkup
22
22
  :bluecloth => {:class_name => "BlueCloth",
23
23
  :lib_name => "bluecloth"},
24
24
  :rpeg => {:class_name => "PEGMarkdown",
25
- :lib_name => "peg_markdown"} }
25
+ :lib_name => "peg_markdown"},
26
+ :maruku => {:class_name => "Maruku",
27
+ :lib_name => "maruku"} }
26
28
 
27
29
  @@markdown_library = DEFAULT_MAKRDOWN_LIB
28
30
  mattr_accessor :markdown_library
@@ -24,7 +24,7 @@ class ActsAsMarkdownTest < ActsAsMarkupTestCase
24
24
  end
25
25
 
26
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)
27
+ assert_match(/<h2(\s\w+\=['"]\w*['"])*\s*>\s*Markdown Test Text\s*<\/h2>/, @post.body.to_html)
28
28
  end
29
29
 
30
30
  context "changing value of markdown field should return new markdown object" do
@@ -75,7 +75,7 @@ class ActsAsMarkdownTest < ActsAsMarkupTestCase
75
75
  end
76
76
 
77
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)
78
+ assert_match(/<h2(\s\w+\=['"]\w*['"])*\s*>\s*Markdown Test Text\s*<\/h2>/, @post.body.to_html)
79
79
  end
80
80
 
81
81
  context "changing value of markdown field should return new markdown object" do
@@ -126,7 +126,7 @@ class ActsAsMarkdownTest < ActsAsMarkupTestCase
126
126
  end
127
127
 
128
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)
129
+ assert_match(/<h2(\s\w+\=['"]\w*['"])*\s*>\s*Markdown Test Text\s*<\/h2>/, @post.body.to_html)
130
130
  end
131
131
 
132
132
  context "changing value of markdown field should return new markdown object" do
@@ -158,7 +158,58 @@ class ActsAsMarkdownTest < ActsAsMarkupTestCase
158
158
  Post.delete_all
159
159
  end
160
160
  end
161
+
162
+ context 'using Maruku' do
163
+ setup do
164
+ ActsAsMarkup.markdown_library = :maruku
165
+ class ::Post < ActiveRecord::Base
166
+ acts_as_markdown :body
167
+ end
168
+ @post = Post.create!(:title => 'Blah', :body => @markdown_text)
169
+ end
170
+
171
+ should "have a Maruku object returned for the column value" do
172
+ assert_kind_of Maruku, @post.body
173
+ end
174
+
175
+ should "return original markdown text for a `to_s` method call on the column value" do
176
+ assert_equal @markdown_text, @post.body.to_s
177
+ end
178
+
179
+ should "return formated html for a `to_html` method call on the column value" do
180
+ assert_match(/<h2(\s\w+\=['"]\w*['"])*\s*>\s*Markdown Test Text\s*<\/h2>/, @post.body.to_html)
181
+ end
182
+
183
+ context "changing value of markdown field should return new markdown object" do
184
+ setup do
185
+ @old_body = @post.body
186
+ @post.body = "`@count = 20`"
187
+ end
161
188
 
189
+ should "still have an Maruku object but not the same object" do
190
+ assert_kind_of Maruku, @post.body
191
+ assert_not_same @post.body, @old_body
192
+ end
193
+
194
+ should "return correct text for `to_s`" do
195
+ assert_equal "`@count = 20`", @post.body.to_s
196
+ end
197
+
198
+ should "return correct HTML for the `to_html` method" do
199
+ assert_match(/<code>\s*\@count\s\=\s20\s*<\/code>/, @post.body.to_html)
200
+ end
201
+
202
+ teardown do
203
+ @old_body = nil
204
+ end
205
+ end
206
+
207
+ teardown do
208
+ @post = nil
209
+ Post.delete_all
210
+ end
211
+ end
212
+
162
213
  teardown do
163
214
  @markdown_text = nil
164
215
  end
@@ -33,7 +33,7 @@ class ActsAsMarkupTest < ActsAsMarkupTestCase
33
33
  end
34
34
 
35
35
  should "return formated html for a `to_html` method call on the column value" do
36
- assert_match(/<h2>\s*Markdown Test Text\s*<\/h2>/, @markdown_post.body.to_html)
36
+ assert_match(/<h2(\s\w+\=['"]\w*['"])*\s*>\s*Markdown Test Text\s*<\/h2>/, @markdown_post.body.to_html)
37
37
  assert_match(/<h2>Textile Test Text<\/h2>/, @textile_post.body.to_html)
38
38
  end
39
39
 
@@ -97,7 +97,7 @@ class ActsAsMarkupTest < ActsAsMarkupTestCase
97
97
  end
98
98
 
99
99
  should "return formated html for a `to_html` method call on the column value" do
100
- assert_match(/<h2>\s*Markdown Test Text\s*<\/h2>/, @markdown_post.body.to_html)
100
+ assert_match(/<h2(\s\w+\=['"]\w*['"])*\s*>\s*Markdown Test Text\s*<\/h2>/, @markdown_post.body.to_html)
101
101
  end
102
102
 
103
103
  context "changing value of markup field should return new markup object" do
@@ -486,6 +486,33 @@ class ActsAsMarkupTest < ActsAsMarkupTestCase
486
486
  Post.delete_all
487
487
  end
488
488
  end
489
+
490
+ context 'with Maruku Markdown' do
491
+ setup do
492
+ ActsAsMarkup.markdown_library = :maruku
493
+ class ::Post < ActiveRecord::Base
494
+ acts_as_markdown :body
495
+ end
496
+ @post = Post.create!(:title => 'Blah', :body => @text)
497
+ end
498
+
499
+ should 'return a blank string for `to_s` method' do
500
+ assert_equal @post.body.to_s, ''
501
+ end
502
+
503
+ should 'return a blank string for `to_html` method' do
504
+ assert_match(/[\n\s]*/, @post.body.to_html)
505
+ end
506
+
507
+ should "have a Maruku object returned for the column value" do
508
+ assert_kind_of Maruku, @post.body
509
+ end
510
+
511
+ teardown do
512
+ @post = nil
513
+ Post.delete_all
514
+ end
515
+ end
489
516
  end
490
517
 
491
518
  context 'acts_as_markup with bad language name' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_markup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Landau
@@ -81,6 +81,7 @@ files:
81
81
  - acts_as_markup.gemspec
82
82
  - lib/acts/as_markup.rb
83
83
  - lib/acts_as_markup.rb
84
+ - lib/acts_as_markup/exts/maruku.rb
84
85
  - lib/acts_as_markup/exts/rdiscount.rb
85
86
  - lib/acts_as_markup/exts/rdoc.rb
86
87
  - lib/acts_as_markup/exts/string.rb