tristandunn-acts_as_markup 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +47 -0
- data/LICENSE +22 -0
- data/README.rdoc +170 -0
- data/Rakefile +33 -0
- data/lib/acts/.as_markup.rb.swp +0 -0
- data/lib/acts/as_markup.rb +209 -0
- data/lib/acts_as_markup.rb +75 -0
- data/lib/acts_as_markup/exts/maruku.rb +70 -0
- data/lib/acts_as_markup/exts/object.rb +5 -0
- data/lib/acts_as_markup/exts/peg_markdown.rb +10 -0
- data/lib/acts_as_markup/exts/rdiscount.rb +15 -0
- data/lib/acts_as_markup/exts/rdoc.rb +100 -0
- data/lib/acts_as_markup/exts/simple_format.rb +18 -0
- data/lib/acts_as_markup/exts/wikitext.rb +20 -0
- data/lib/acts_as_markup/stringlike.rb +7 -0
- data/tasks/bones.rake +21 -0
- data/tasks/gem.rake +201 -0
- data/tasks/git.rake +41 -0
- data/tasks/post_load.rake +32 -0
- data/tasks/rdoc.rake +51 -0
- data/tasks/rubyforge.rake +55 -0
- data/tasks/setup.rb +249 -0
- data/tasks/test.rake +29 -0
- data/test/.acts_as_markup_test.rb.swp +0 -0
- data/test/acts_as_markdown_test.rb +298 -0
- data/test/acts_as_markup_test.rb +636 -0
- data/test/acts_as_rdoc_test.rb +58 -0
- data/test/acts_as_textile_test.rb +77 -0
- data/test/acts_as_wikitext_test.rb +77 -0
- data/test/test_helper.rb +69 -0
- data/tristandunn-acts_as_markup.gemspec +52 -0
- metadata +162 -0
data/CHANGELOG
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
== 1.3.3 / 2009-06-11
|
2
|
+
* Maintenance release
|
3
|
+
|
4
|
+
== 1.3.2 / 2009-04-28
|
5
|
+
* Maintenance release
|
6
|
+
|
7
|
+
== 1.3.1 / 2008-04-27
|
8
|
+
* Update rake tasks and way RDoc is generated
|
9
|
+
* Ensure works with Rails 2.3.2 and latest version of related markup gems.
|
10
|
+
|
11
|
+
== 1.3.0 / 2008-11-19
|
12
|
+
* Add ability to accept options that will be passed to supported markup parsers. (chewi[http://github.com/chewi/])
|
13
|
+
|
14
|
+
== 1.2.0 / 2008-09-10
|
15
|
+
* Allow all objects to have a to_html method that defaults as to_s instead just doing this for strings. (idea from crnixon[http://github.com/crnixon/])
|
16
|
+
* Add string methods to all markup objects via the StringLike mixin. (crnixon[http://github.com/crnixon/])
|
17
|
+
* Other Minor bug fixes
|
18
|
+
|
19
|
+
== 1.1.2 / 2008-08-22
|
20
|
+
* Make sure all markup objects properly respond to the .blank? method call.
|
21
|
+
|
22
|
+
== 1.1.0 / 2008-08-12
|
23
|
+
|
24
|
+
* Use a default for markup language column name when the variable options is used.
|
25
|
+
|
26
|
+
== 1.0.0 / 2008-08-11
|
27
|
+
|
28
|
+
* Add support for Maruku Markdown Library.
|
29
|
+
|
30
|
+
== 0.4.0 / 2008-08-11
|
31
|
+
|
32
|
+
* Add support for RDoc.
|
33
|
+
|
34
|
+
== 0.3.0 / 2008-08-08
|
35
|
+
|
36
|
+
* Add support for wikitext.
|
37
|
+
|
38
|
+
== 0.2.0 / 2008-08-07
|
39
|
+
|
40
|
+
* Add support for a variable markup language option.
|
41
|
+
|
42
|
+
== 0.1.0 / 2008-08-05
|
43
|
+
|
44
|
+
* Initial Release
|
45
|
+
* Support for Markdown and Textile markup languages.
|
46
|
+
* `acts_as_markdown` and `acts_as_textile` convenience methods
|
47
|
+
* Support for BlueCloth, RDiscount and Ruby PEG markdown processors.
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2008 Brian Landau of Viget Labs
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
= Acts as Markup
|
2
|
+
|
3
|
+
by Brian Landau of Viget Labs <brian.landau@viget.com>
|
4
|
+
|
5
|
+
GitHub Project: http://github.com/vigetlabs/acts_as_markup
|
6
|
+
|
7
|
+
RDoc:
|
8
|
+
* http://viget.rubyforge.org/acts_as_markup
|
9
|
+
* http://gitrdoc.com/vigetlabs/acts_as_markup/tree/master
|
10
|
+
* http://vigetlabs.github.com/acts_as_markup
|
11
|
+
|
12
|
+
|
13
|
+
== DESCRIPTION:
|
14
|
+
|
15
|
+
Allows you to specify columns of an ActiveRecord model that contain Markdown,
|
16
|
+
Textile, Wiki text and RDoc. You may then use +to_s+ to get the original markup
|
17
|
+
text or +to_html+ to get the formated HTML.
|
18
|
+
|
19
|
+
Additionally you can have a model that contains a column that has a column with
|
20
|
+
markup text, and another that defines what language to process it as. If the field
|
21
|
+
is listed as "markdown" "textile", "wikitext" or "rdoc" (case insensitive) it will
|
22
|
+
treat it as such, any other value for markup language will have the value pass
|
23
|
+
through as a normal string.
|
24
|
+
|
25
|
+
This AR extension can use 3 different types of Markdown processing backends:
|
26
|
+
BlueCloth, RDiscount, Ruby PEG or Maruku. You specify which one you want to use by setting
|
27
|
+
a config value in your environment.rb file:
|
28
|
+
|
29
|
+
ActsAsMarkup.markdown_library = :bluecloth
|
30
|
+
|
31
|
+
By default RDiscount will be used.
|
32
|
+
|
33
|
+
You can specify additional options to pass to the markup library by using
|
34
|
+
<tt>:markdown_options</tt>, <tt>:textile_options</tt> or <tt>:wikitext_options</tt>.
|
35
|
+
RDoc does not support any useful options. The options should be given as an
|
36
|
+
array of arguments. You can specify options for multiple languages when
|
37
|
+
allowing more than one. See each library's documentation for more details on
|
38
|
+
what options are available.
|
39
|
+
|
40
|
+
== EXAMPLES:
|
41
|
+
|
42
|
+
==== Using +acts_as_markdown+:
|
43
|
+
|
44
|
+
class Post < ActiveRecord
|
45
|
+
acts_as_markdown :body
|
46
|
+
end
|
47
|
+
|
48
|
+
@post = Post.find(:first)
|
49
|
+
@post.body.to_s #=> "## Markdown Headline"
|
50
|
+
@post.body.to_html #=> "<h2> Markdown Headline</h2>"
|
51
|
+
|
52
|
+
|
53
|
+
==== Using +acts_as_textile+:
|
54
|
+
|
55
|
+
class Post < ActiveRecord
|
56
|
+
acts_as_textile :body
|
57
|
+
end
|
58
|
+
|
59
|
+
@post = Post.find(:first)
|
60
|
+
@post.body.to_s #=> "h2. Textile Headline"
|
61
|
+
@post.body.to_html #=> "<h2>Textile Headline</h2>"
|
62
|
+
|
63
|
+
|
64
|
+
==== Using +acts_as_wikitext+:
|
65
|
+
|
66
|
+
class Post < ActiveRecord
|
67
|
+
acts_as_wikitext :body
|
68
|
+
end
|
69
|
+
|
70
|
+
@post = Post.find(:first)
|
71
|
+
@post.body.to_s #=> "== Wikitext Headline =="
|
72
|
+
@post.body.to_html #=> "<h2>Wikitext Headline</h2>"
|
73
|
+
|
74
|
+
|
75
|
+
==== Using +acts_as_rdoc+:
|
76
|
+
|
77
|
+
class Post < ActiveRecord
|
78
|
+
acts_as_rdoc :body
|
79
|
+
end
|
80
|
+
|
81
|
+
@post = Post.find(:first)
|
82
|
+
@post.body.to_s #=> "== RDoc Headline"
|
83
|
+
@post.body.to_html #=> "<h2>RDoc Headline</h2>"
|
84
|
+
|
85
|
+
|
86
|
+
==== Using +acts_as_markup+:
|
87
|
+
|
88
|
+
class Post < ActiveRecord
|
89
|
+
acts_as_markup :language => :markdown, :columns => [:body]
|
90
|
+
end
|
91
|
+
|
92
|
+
@post = Post.find(:first)
|
93
|
+
@post.body.to_s #=> "## Markdown Headline"
|
94
|
+
@post.body.to_html #=> "<h2> Markdown Headline</h2>"
|
95
|
+
|
96
|
+
|
97
|
+
==== Using +acts_as_markup+ with <tt>:variable</tt> language:
|
98
|
+
|
99
|
+
class Post < ActiveRecord
|
100
|
+
acts_as_markup :language => :variable, :columns => [:body]
|
101
|
+
end
|
102
|
+
|
103
|
+
@post = Post.find(:first)
|
104
|
+
@post.markup_language # => "markdown"
|
105
|
+
@post.body.to_s # => "## Markdown Headline"
|
106
|
+
@post.body.to_html # => "<h2> Markdown Headline</h2>"
|
107
|
+
|
108
|
+
|
109
|
+
==== Using options
|
110
|
+
|
111
|
+
class Post < ActiveRecord
|
112
|
+
acts_as_markdown :body, :markdown_options => [ :filter_html ]
|
113
|
+
end
|
114
|
+
|
115
|
+
class Post < ActiveRecord
|
116
|
+
acts_as_textile :body, :textile_options => [ [ :filter_html ] ]
|
117
|
+
end
|
118
|
+
|
119
|
+
class Post < ActiveRecord
|
120
|
+
acts_as_wikitext :body, :wikitext_options => [ { :space_to_underscore => true } ]
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
== REQUIREMENTS:
|
125
|
+
|
126
|
+
You will need the RedCloth[http://whytheluckystiff.net/ruby/redcloth/] library
|
127
|
+
for processing the Textile text, and the Wikitext[http://wikitext.rubyforge.org/]
|
128
|
+
library for processing wikitext.
|
129
|
+
|
130
|
+
You will also need to install some type of Markdown processor.
|
131
|
+
The three options currently supported are:
|
132
|
+
|
133
|
+
* BlueCloth
|
134
|
+
* RDiscount[http://github.com/rtomayko/rdiscount]
|
135
|
+
* {Ruby PEG}[http://github.com/rtomayko/rpeg-markdown/tree/master]
|
136
|
+
* Maruku[http://maruku.rubyforge.org/]
|
137
|
+
|
138
|
+
== INSTALL:
|
139
|
+
|
140
|
+
<tt>sudo gem install acts_as_markup</tt>
|
141
|
+
|
142
|
+
Add "+acts_as_markup+" to your environment.rb:
|
143
|
+
|
144
|
+
config.gem "acts_as_markup"
|
145
|
+
|
146
|
+
== CONTRIBUTING:
|
147
|
+
|
148
|
+
Make a fork on GitHub, make your changes and do a pull request. Good places to start are adding new Markdown libraries or new markup languages, here's instructions for both:
|
149
|
+
|
150
|
+
=== Instructions for how to add a new Markdown Library:
|
151
|
+
|
152
|
+
1. Add another item to the <tt>ActsAsMarkup::MARKDOWN_LIBS</tt> hash in the form of:
|
153
|
+
:bluecloth => {:class_name => "BlueCloth",
|
154
|
+
:lib_name => "bluecloth"}
|
155
|
+
<tt>:lib_name</tt> should be the name needed to require the library, while <tt>:class_name</tt> should be the class that we are making an instance of.
|
156
|
+
2. If you need to modify the object in anyway (e.g. to add a <tt>to_s</tt> or <tt>to_html</tt> method), add a file to the "lib/acts_as_markup/exts/" directory.
|
157
|
+
3. Add appropriate tests (see current tests).
|
158
|
+
|
159
|
+
=== Instructions for how to add a new Markup Language:
|
160
|
+
|
161
|
+
1. Add a "<tt>when</tt>" statement to the "<tt>case</tt>" statement in <tt>acts_as_markup</tt>. The "<tt>when</tt>" statement should match with a symbol that represents the language name in some way (e.g. "<tt>:markdown</tt>").
|
162
|
+
2. In the "<tt>when</tt>" block you need to set the "<tt>klass</tt>" local variable and require the library and the extension file if you need one (use the special <tt>require_extensions</tt> method to require extensions).
|
163
|
+
3. Add the same lines you added to the previous "<tt>when</tt>" statement to the "<tt>:variable</tt>" "<tt>when</tt>" statement. But replace "<tt>klass</tt>" with "<tt>language_klass</tt>" (e.g. "<tt>markdown_klass</tt>").
|
164
|
+
4. Add a relevant "<tt>when</tt>" statement to the <tt>class_eval</tt> block for the "<tt>:variable</tt>" language option. This should look something like:
|
165
|
+
when /markdown/i
|
166
|
+
markup_klasses[:markdown].new self[col].to_s
|
167
|
+
5. Add a convenience method (e.g. "<tt>acts_as_markdown</tt>")
|
168
|
+
6. Add an extension file to the "lib/acts_as_markup/exts/" directory if you need to modify the object in anyway.
|
169
|
+
7. Add appropriate tests (see current tests).
|
170
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Look in the tasks/setup.rb file for the various options that can be
|
2
|
+
# configured in this Rakefile. The .rake files in the tasks directory
|
3
|
+
# are where the options are used.
|
4
|
+
|
5
|
+
load 'tasks/setup.rb'
|
6
|
+
|
7
|
+
ensure_in_path 'lib'
|
8
|
+
require 'acts_as_markup'
|
9
|
+
|
10
|
+
task :default => 'test:run'
|
11
|
+
|
12
|
+
PROJ.name = 'tristandunn-acts_as_markup'
|
13
|
+
PROJ.authors = 'Brian Landau'
|
14
|
+
PROJ.email = 'brian.landau@viget.com'
|
15
|
+
PROJ.url = 'http://viget.rubyforge.com/acts_as_markup'
|
16
|
+
PROJ.description = "Represent ActiveRecord Markdown, Textile, Wiki text, RDoc columns as Markdown, Textile Wikitext, RDoc objects using various external libraries to convert to HTML."
|
17
|
+
PROJ.rubyforge.name = 'viget'
|
18
|
+
PROJ.version = ActsAsMarkup::VERSION
|
19
|
+
PROJ.rdoc.include = %w(^lib/ LICENSE CHANGELOG README\.rdoc)
|
20
|
+
PROJ.rdoc.remote_dir = 'acts_as_markup'
|
21
|
+
PROJ.rcov.opts = ['--no-html', '-T', '--sort coverage',
|
22
|
+
'-x "\/Library\/Ruby\/"',
|
23
|
+
'-x "\/opt\/local\/lib/ruby"',
|
24
|
+
'-x "\/System\/Library\/"']
|
25
|
+
PROJ.rcov.pattern = 'test/**/*_test.rb'
|
26
|
+
|
27
|
+
PROJ.gem.development_dependencies << ['thoughtbot-shoulda', '~> 2.0']
|
28
|
+
PROJ.gem.development_dependencies << ['bones', '~> 2.5']
|
29
|
+
depend_on 'activesupport', '~> 2.3.2'
|
30
|
+
depend_on 'activerecord', '~> 2.3.2'
|
31
|
+
depend_on 'rdiscount', '~> 1.3'
|
32
|
+
depend_on 'wikitext', '~> 1.5'
|
33
|
+
depend_on 'RedCloth', '~> 4.2'
|
Binary file
|
@@ -0,0 +1,209 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
module ActiveRecord # :nodoc:
|
4
|
+
module Acts # :nodoc:
|
5
|
+
module AsMarkup
|
6
|
+
def self.included(base) # :nodoc:
|
7
|
+
base.extend(ClassMethods)
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
|
12
|
+
# This allows you to specify columns you want to define as containing
|
13
|
+
# Markdown, Textile, Wikitext or RDoc content.
|
14
|
+
# Then you can simply call <tt>.to_html</tt> method on the attribute.
|
15
|
+
#
|
16
|
+
# You can also specify the language as <tt>:variable</tt>. The language used
|
17
|
+
# to process the column will be based on another column. By default a column
|
18
|
+
# named "<tt>markup_language</tt>" is used, but this can be changed by providing
|
19
|
+
# a <tt>:language_column</tt> option. When a value is accessed it will create
|
20
|
+
# the correct object (Markdown, Textile, Wikitext or RDoc) based on the value
|
21
|
+
# of the language column. If any value besides markdown, textile, wikitext, or
|
22
|
+
# RDoc is supplied for the markup language the text will pass through as a string.
|
23
|
+
#
|
24
|
+
# You can specify additional options to pass to the markup library by using
|
25
|
+
# <tt>:markdown_options</tt>, <tt>:textile_options</tt> or <tt>:wikitext_options</tt>.
|
26
|
+
# RDoc does not support any useful options. The options should be given as an array
|
27
|
+
# of arguments. You can specify options for more than one language when using
|
28
|
+
# <tt>:variable</tt>. See each library's documentation for more details on what
|
29
|
+
# options are available.
|
30
|
+
#
|
31
|
+
#
|
32
|
+
# ==== Examples
|
33
|
+
#
|
34
|
+
# ===== Using Markdown language
|
35
|
+
#
|
36
|
+
# class Post < ActiveRecord
|
37
|
+
# acts_as_markup :language => :markdown, :columns => [:body]
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# @post = Post.find(:first)
|
41
|
+
# @post.body.to_s # => "## Markdown Headline"
|
42
|
+
# @post.body.to_html # => "<h2> Markdown Headline</h2>"
|
43
|
+
#
|
44
|
+
#
|
45
|
+
# ===== Using variable language
|
46
|
+
#
|
47
|
+
# class Post < ActiveRecord
|
48
|
+
# acts_as_markup :language => :variable, :columns => [:body], :language_column => 'language_name'
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# @post = Post.find(:first)
|
52
|
+
# @post.language_name # => "markdown"
|
53
|
+
# @post.body.to_s # => "## Markdown Headline"
|
54
|
+
# @post.body.to_html # => "<h2> Markdown Headline</h2>"
|
55
|
+
#
|
56
|
+
#
|
57
|
+
# ===== Using options
|
58
|
+
#
|
59
|
+
# class Post < ActiveRecord
|
60
|
+
# acts_as_markup :language => :markdown, :columns => [:body], :markdown_options => [ :filter_html ]
|
61
|
+
# end
|
62
|
+
#
|
63
|
+
# class Post < ActiveRecord
|
64
|
+
# acts_as_markup :language => :textile, :columns => [:body], :textile_options => [ [ :filter_html ] ]
|
65
|
+
# end
|
66
|
+
#
|
67
|
+
# class Post < ActiveRecord
|
68
|
+
# acts_as_markup :language => :wikitext, :columns => [:body], :wikitext_options => [ { :space_to_underscore => true } ]
|
69
|
+
# end
|
70
|
+
#
|
71
|
+
#
|
72
|
+
def acts_as_markup(options)
|
73
|
+
case options[:language].to_sym
|
74
|
+
when :markdown, :textile, :wikitext, :rdoc, :simple_format
|
75
|
+
klass = require_library_and_get_class(options[:language].to_sym)
|
76
|
+
when :variable
|
77
|
+
markup_klasses = {}
|
78
|
+
[:textile, :wikitext, :rdoc, :markdown, :simple_format].each do |language|
|
79
|
+
markup_klasses[language] = require_library_and_get_class(language)
|
80
|
+
end
|
81
|
+
options[:language_column] ||= :markup_language
|
82
|
+
else
|
83
|
+
raise ActsAsMarkup::UnsupportedMarkupLanguage, "#{options[:langauge]} is not a currently supported markup language."
|
84
|
+
end
|
85
|
+
|
86
|
+
unless options[:language].to_sym == :variable
|
87
|
+
markup_options = options["#{options[:language]}_options".to_sym] || []
|
88
|
+
options[:columns].each do |col|
|
89
|
+
define_method col do
|
90
|
+
if instance_variable_defined?("@#{col}")
|
91
|
+
unless send("#{col}_changed?")
|
92
|
+
return instance_variable_get("@#{col}")
|
93
|
+
end
|
94
|
+
end
|
95
|
+
instance_variable_set("@#{col}", klass.new(self[col].to_s, *markup_options))
|
96
|
+
end
|
97
|
+
end
|
98
|
+
else
|
99
|
+
options[:columns].each do |col|
|
100
|
+
define_method col do
|
101
|
+
if instance_variable_defined?("@#{col}")
|
102
|
+
unless send("#{col}_changed?") || send("#{options[:language_column]}_changed?")
|
103
|
+
return instance_variable_get("@#{col}")
|
104
|
+
end
|
105
|
+
end
|
106
|
+
instance_variable_set("@#{col}", case send(options[:language_column])
|
107
|
+
when /markdown/i
|
108
|
+
markup_klasses[:markdown].new self[col].to_s, *(options[:markdown_options] || [])
|
109
|
+
when /textile/i
|
110
|
+
markup_klasses[:textile].new self[col].to_s, *(options[:textile_options] || [])
|
111
|
+
when /wikitext/i
|
112
|
+
markup_klasses[:wikitext].new self[col].to_s, *(options[:wikitext_options] || [])
|
113
|
+
when /rdoc/i
|
114
|
+
markup_klasses[:rdoc].new self[col].to_s
|
115
|
+
when /simple/i
|
116
|
+
markup_klasses[:simple_format].new self[col].to_s
|
117
|
+
else
|
118
|
+
self[col]
|
119
|
+
end)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# This is a convenience method for
|
126
|
+
# `<tt>acts_as_markup :language => :markdown, :columns => [:body]</tt>`
|
127
|
+
# Additional options can be given at the end, if necessary.
|
128
|
+
#
|
129
|
+
def acts_as_markdown(*columns)
|
130
|
+
options = columns.extract_options!
|
131
|
+
acts_as_markup options.merge(:language => :markdown, :columns => columns)
|
132
|
+
end
|
133
|
+
|
134
|
+
# This is a convenience method for
|
135
|
+
# `<tt>acts_as_markup :language => :textile, :columns => [:body]</tt>`
|
136
|
+
# Additional options can be given at the end, if necessary.
|
137
|
+
#
|
138
|
+
def acts_as_textile(*columns)
|
139
|
+
options = columns.extract_options!
|
140
|
+
acts_as_markup options.merge(:language => :textile, :columns => columns)
|
141
|
+
end
|
142
|
+
|
143
|
+
# This is a convenience method for
|
144
|
+
# `<tt>acts_as_markup :language => :wikitext, :columns => [:body]</tt>`
|
145
|
+
# Additional options can be given at the end, if necessary.
|
146
|
+
#
|
147
|
+
def acts_as_wikitext(*columns)
|
148
|
+
options = columns.extract_options!
|
149
|
+
acts_as_markup options.merge(:language => :wikitext, :columns => columns)
|
150
|
+
end
|
151
|
+
|
152
|
+
# This is a convenience method for
|
153
|
+
# `<tt>acts_as_markup :language => :rdoc, :columns => [:body]</tt>`
|
154
|
+
# Additional options can be given at the end, if necessary.
|
155
|
+
#
|
156
|
+
def acts_as_rdoc(*columns)
|
157
|
+
options = columns.extract_options!
|
158
|
+
acts_as_markup options.merge(:language => :rdoc, :columns => columns)
|
159
|
+
end
|
160
|
+
|
161
|
+
|
162
|
+
private
|
163
|
+
def get_markdown_class
|
164
|
+
if ActsAsMarkup::MARKDOWN_LIBS.keys.include? ActsAsMarkup.markdown_library
|
165
|
+
markdown_library_names = ActsAsMarkup::MARKDOWN_LIBS[ActsAsMarkup.markdown_library]
|
166
|
+
require markdown_library_names[:lib_name]
|
167
|
+
require_extensions(markdown_library_names[:lib_name])
|
168
|
+
return markdown_library_names[:class_name].constantize
|
169
|
+
else
|
170
|
+
raise ActsAsMarkup::UnsportedMarkdownLibrary, "#{ActsAsMarkup.markdown_library} is not currently supported."
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def require_extensions(library)# :nodoc:
|
175
|
+
if ActsAsMarkup::LIBRARY_EXTENSIONS.include? library.to_s
|
176
|
+
require "#{ActsAsMarkup::LIBPATH}/acts_as_markup/exts/#{library}"
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
def require_library_and_get_class(language)
|
181
|
+
case language
|
182
|
+
when :markdown
|
183
|
+
return get_markdown_class
|
184
|
+
when :textile
|
185
|
+
require 'redcloth'
|
186
|
+
return RedCloth
|
187
|
+
when :wikitext
|
188
|
+
require 'wikitext'
|
189
|
+
require_extensions 'wikitext'
|
190
|
+
return WikitextString
|
191
|
+
when :rdoc
|
192
|
+
require 'rdoc/markup/simple_markup'
|
193
|
+
require 'rdoc/markup/simple_markup/to_html'
|
194
|
+
require_extensions 'rdoc'
|
195
|
+
return RDocText
|
196
|
+
when :simple_format
|
197
|
+
require 'acts_as_markup/exts/simple_format'
|
198
|
+
return SimpleFormat
|
199
|
+
else
|
200
|
+
return String
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
ActiveRecord::Base.send :include, ActiveRecord::Acts::AsMarkup
|