acts_as_markup_on 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 537f5301e93f259371c545cdac8f80777af42de3
4
+ data.tar.gz: 9950cc1868d5257144839ff14886a654554afa52
5
+ SHA512:
6
+ metadata.gz: 629ce44c5855fc462caf99ed4a5a41b35a64d84843862a8482f6cc8054782acbddbe81d38994bb79795341a0155de99cca71c90ddbf3855c4bc0b7489dcd4627
7
+ data.tar.gz: 1ead0df1330c8ae808230949c311823127c0aec5f93a92524730de8f09d04b5b45edad58d8f5dd3ed5c7e6107883831a9a5b83d7e78ec04ebb4d677c50bf860a
@@ -0,0 +1,2 @@
1
+ == 1.0.0
2
+ * Start migrating acts_as_markup to newer Ruby and Rails
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,70 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ acts_as_markup_on (1.0.0)
5
+ RedCloth (~> 4.2)
6
+ activerecord (~> 4.0.0)
7
+ activesupport (~> 4.0.0)
8
+ rdiscount (~> 2.1.7)
9
+ wikicloth
10
+ wikitext (~> 4.0.2)
11
+
12
+ GEM
13
+ remote: http://rubygems.org/
14
+ specs:
15
+ RedCloth (4.2.9)
16
+ activemodel (4.0.0)
17
+ activesupport (= 4.0.0)
18
+ builder (~> 3.1.0)
19
+ activerecord (4.0.0)
20
+ activemodel (= 4.0.0)
21
+ activerecord-deprecated_finders (~> 1.0.2)
22
+ activesupport (= 4.0.0)
23
+ arel (~> 4.0.0)
24
+ activerecord-deprecated_finders (1.0.3)
25
+ activesupport (4.0.0)
26
+ i18n (~> 0.6, >= 0.6.4)
27
+ minitest (~> 4.2)
28
+ multi_json (~> 1.3)
29
+ thread_safe (~> 0.1)
30
+ tzinfo (~> 0.3.37)
31
+ arel (4.0.0)
32
+ atomic (1.1.14)
33
+ bluecloth (2.2.0)
34
+ builder (3.1.4)
35
+ expression_parser (0.9.0)
36
+ i18n (0.6.5)
37
+ maruku (0.7.0)
38
+ minitest (4.7.5)
39
+ multi_json (1.8.2)
40
+ rake (10.1.0)
41
+ rdiscount (2.1.7)
42
+ redcarpet (3.0.0)
43
+ rpeg-markdown (1.4.6)
44
+ shoulda (3.5.0)
45
+ shoulda-context (~> 1.0, >= 1.0.1)
46
+ shoulda-matchers (>= 1.4.1, < 3.0)
47
+ shoulda-context (1.1.5)
48
+ shoulda-matchers (2.4.0)
49
+ activesupport (>= 3.0.0)
50
+ sqlite3 (1.3.8)
51
+ thread_safe (0.1.3)
52
+ atomic
53
+ tzinfo (0.3.38)
54
+ wikicloth (0.8.0)
55
+ builder
56
+ expression_parser
57
+ wikitext (4.0.2)
58
+
59
+ PLATFORMS
60
+ ruby
61
+
62
+ DEPENDENCIES
63
+ acts_as_markup_on!
64
+ bluecloth
65
+ maruku
66
+ rake (= 10.1.0)
67
+ redcarpet
68
+ rpeg-markdown
69
+ shoulda
70
+ sqlite3
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.
@@ -0,0 +1,186 @@
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://gitrdoc.com/vigetlabs/acts_as_markup/tree/master
9
+ * http://vigetlabs.github.com/acts_as_markup
10
+
11
+
12
+ == DESCRIPTION:
13
+
14
+ Allows you to specify columns of an ActiveRecord model that contain Markdown,
15
+ Textile, Wiki text and RDoc. You may then use +to_s+ to get the original markup
16
+ text or +to_html+ to get the formated HTML.
17
+
18
+ Additionally you can have a model that contains a column that has a column with
19
+ markup text, and another that defines what language to process it as. If the field
20
+ is listed as "markdown" "textile", "mediawiki" or "rdoc" (case insensitive) it will
21
+ treat it as such, any other value for markup language will have the value pass
22
+ through as a normal string.
23
+
24
+ This AR extension can use 5 different types of Markdown processing backends:
25
+ BlueCloth, RDiscount, Ruby PEG, Redcarpet or Maruku. You specify which one you want to use by setting
26
+ a config value in your environment.rb file:
27
+
28
+ ActsAsMarkupOn.markdown_library = :bluecloth
29
+
30
+ By default RDiscount will be used.
31
+
32
+ You can specify additional options to pass to the markup library by using
33
+ <tt>:markdown_options</tt>, <tt>:textile_options</tt> or <tt>:mediawiki_options</tt>.
34
+ RDoc does not support any useful options. The options should be given as an
35
+ array of arguments. You can specify options for multiple languages when
36
+ allowing more than one. See each library's documentation for more details on
37
+ what options are available.
38
+
39
+ == EXAMPLES:
40
+
41
+ ==== Using +acts_as_markdown_on+:
42
+
43
+ class Post < ActiveRecord
44
+ acts_as_markdown_on :body
45
+ end
46
+
47
+ @post = Post.find(:first)
48
+ @post.body.to_s #=> "## Markdown Headline"
49
+ @post.body.to_html #=> "<h2> Markdown Headline</h2>"
50
+
51
+
52
+ ==== Using +acts_as_textile_on+:
53
+
54
+ class Post < ActiveRecord
55
+ acts_as_textile_on :body
56
+ end
57
+
58
+ @post = Post.find(:first)
59
+ @post.body.to_s #=> "h2. Textile Headline"
60
+ @post.body.to_html #=> "<h2>Textile Headline</h2>"
61
+
62
+
63
+ ==== Using +acts_as_mediawiki_on+:
64
+
65
+ class Post < ActiveRecord
66
+ acts_as_mediawiki_on :body
67
+ end
68
+
69
+ @post = Post.find(:first)
70
+ @post.body.to_s #=> "== Wikitext Headline =="
71
+ @post.body.to_html #=> "<h2>Wikitext Headline</h2>"
72
+
73
+
74
+ ==== Using +acts_as_rdoc_on+:
75
+
76
+ class Post < ActiveRecord
77
+ acts_as_rdoc_on :body
78
+ end
79
+
80
+ @post = Post.find(:first)
81
+ @post.body.to_s #=> "== RDoc Headline"
82
+ @post.body.to_html #=> "<h2>RDoc Headline</h2>"
83
+
84
+
85
+ ==== Using +acts_as_markup_on+:
86
+
87
+ class Post < ActiveRecord
88
+ acts_as_markup_on :language => :markdown, :columns => [:body]
89
+ end
90
+
91
+ @post = Post.find(:first)
92
+ @post.body.to_s #=> "## Markdown Headline"
93
+ @post.body.to_html #=> "<h2> Markdown Headline</h2>"
94
+
95
+
96
+ ==== Using +acts_as_markup+ with <tt>:variable</tt> language:
97
+
98
+ class Post < ActiveRecord
99
+ acts_as_markup_on :language => :variable, :columns => [:body]
100
+ end
101
+
102
+ @post = Post.find(:first)
103
+ @post.markup_language # => "markdown"
104
+ @post.body.to_s # => "## Markdown Headline"
105
+ @post.body.to_html # => "<h2> Markdown Headline</h2>"
106
+
107
+
108
+ ==== Using options
109
+
110
+ class Post < ActiveRecord
111
+ acts_as_markdown_on :body, :markdown_options => [ :filter_html ]
112
+ end
113
+
114
+ class Post < ActiveRecord
115
+ acts_as_textile_on :body, :textile_options => [ [ :filter_html ] ]
116
+ end
117
+
118
+ class Post < ActiveRecord
119
+ acts_as_mediawiki_on :body, :mediawiki_options => [ { :space_to_underscore => true } ]
120
+ end
121
+
122
+
123
+ == REQUIREMENTS:
124
+
125
+ You will need the RedCloth[http://whytheluckystiff.net/ruby/redcloth/] library
126
+ for processing the Textile text, and the WikiCloth[https://github.com/nricciar/wikicloth]
127
+ library for processing mediawiki text.
128
+
129
+ You will also need to install some type of Markdown processor.
130
+ The four options currently supported are:
131
+
132
+ * BlueCloth
133
+ * RDiscount[http://github.com/rtomayko/rdiscount]
134
+ * {Ruby PEG}[http://github.com/rtomayko/rpeg-markdown]
135
+ * Maruku[http://maruku.rubyforge.org/]
136
+ * Redcarpet[https://github.com/tanoku/redcarpet]
137
+
138
+ == INSTALL:
139
+
140
+ ==== Rails 2
141
+
142
+ <tt>(sudo) gem install acts_as_markup</tt>
143
+
144
+ Add "+acts_as_markup+" to your environment.rb:
145
+
146
+ config.gem "acts_as_markup"
147
+
148
+ ==== Rails 3
149
+
150
+ Simply add "+acts_as_markup+" to your Gemfile:
151
+
152
+ gem "acts_as_markup"
153
+
154
+ ==== Rails 4
155
+
156
+ Simply add "+acts_as_markup_on+" to your Gemfile:
157
+
158
+ gem "acts_as_markup_on"
159
+
160
+ And run "+bundle+ +install+"
161
+
162
+ == CONTRIBUTING:
163
+
164
+ 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:
165
+
166
+ === Instructions for how to add a new Markdown Library:
167
+
168
+ 1. Add another item to the <tt>ActsAsMarkupOn::MARKDOWN_LIBS</tt> hash in the form of:
169
+ :bluecloth => {:class_name => "BlueCloth",
170
+ :lib_name => "bluecloth"}
171
+ <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.
172
+ 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.
173
+ 3. Add appropriate tests (see current tests).
174
+
175
+ === Instructions for how to add a new Markup Language:
176
+
177
+ 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>").
178
+ 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).
179
+ 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>").
180
+ 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:
181
+ when /markdown/i
182
+ markup_klasses[:markdown].new self[col].to_s
183
+ 5. Add a convenience method (e.g. "<tt>acts_as_markdown</tt>")
184
+ 6. Add an extension file to the "lib/acts_as_markup/exts/" directory if you need to modify the object in anyway.
185
+ 7. Add appropriate tests (see current tests).
186
+
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
8
+ Bundler::GemHelper.install_tasks
9
+
10
+ require 'rake/testtask'
11
+
12
+ Rake::TestTask.new(:test) do |t|
13
+ t.libs << 'lib'
14
+ t.libs << 'test'
15
+ t.pattern = 'test/**/*_test.rb'
16
+ t.verbose = false
17
+ end
18
+
19
+ task :default => :test
@@ -0,0 +1,65 @@
1
+ # Generated by jeweler
2
+ # -*- encoding: utf-8 -*-
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "acts_as_markup_on"
6
+ s.version = "1.0.0"
7
+ s.authors = ["Brian Landau", "Iskander Haziev"]
8
+ s.date = "2012-03-09"
9
+ s.description = "Represent ActiveRecord Markdown, Textile, Wiki text, RDoc columns as Markdown, Textile Wikitext, RDoc objects using various external libraries to convert to HTML."
10
+ s.email = "0@droidlabs.pro"
11
+ s.extra_rdoc_files = [
12
+ "LICENSE",
13
+ "README.rdoc"
14
+ ]
15
+ s.files = [
16
+ "CHANGELOG",
17
+ "Gemfile",
18
+ "Gemfile.lock",
19
+ "LICENSE",
20
+ "README.rdoc",
21
+ "Rakefile",
22
+ "acts_as_markup_on.gemspec",
23
+ "lib/acts_as_markup_on.rb",
24
+ "lib/acts_as_markup_on/active_record_extension.rb",
25
+ "lib/acts_as_markup_on/exts/bluecloth.rb",
26
+ "lib/acts_as_markup_on/exts/maruku.rb",
27
+ "lib/acts_as_markup_on/exts/object.rb",
28
+ "lib/acts_as_markup_on/exts/peg_markdown.rb",
29
+ "lib/acts_as_markup_on/exts/rdiscount.rb",
30
+ "lib/acts_as_markup_on/exts/rdoc.rb",
31
+ "lib/acts_as_markup_on/exts/redcarpet.rb",
32
+ "lib/acts_as_markup_on/exts/wikicloth.rb",
33
+ "lib/acts_as_markup_on/exts/wikitext.rb",
34
+ "lib/acts_as_markup_on/railtie.rb",
35
+ "lib/acts_as_markup_on/stringlike.rb",
36
+ "lib/acts_as_markup_on/version.rb",
37
+ "test/acts_as_markdown_test.rb",
38
+ "test/acts_as_markup_test.rb",
39
+ "test/acts_as_mediawiki_test.rb",
40
+ "test/acts_as_rdoc_test.rb",
41
+ "test/acts_as_textile_test.rb",
42
+ "test/test_helper.rb"
43
+ ]
44
+ s.homepage = "http://github.com/gvalmon/acts_as_markup_on/"
45
+ s.licenses = ["MIT"]
46
+ s.require_paths = ["lib"]
47
+ s.rubygems_version = "1.8.15"
48
+ s.summary = "Represent ActiveRecord Markdown, Textile, Wiki text, RDoc columns as Markdown, Textile Wikitext, RDoc objects using various external libraries to convert to HTML."
49
+
50
+ s.add_runtime_dependency(%q<activerecord>, ["~> 4.0.0"])
51
+ s.add_runtime_dependency(%q<activesupport>, ["~> 4.0.0"])
52
+ s.add_runtime_dependency(%q<wikicloth>, [">= 0"])
53
+ s.add_runtime_dependency(%q<rdiscount>, ["~> 2.1.7"])
54
+ s.add_runtime_dependency(%q<wikitext>, ["~> 4.0.2"])
55
+ s.add_runtime_dependency(%q<RedCloth>, ["~> 4.2"])
56
+
57
+ s.add_development_dependency(%q<rake>, ["10.1.0"])
58
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
59
+ s.add_development_dependency(%q<sqlite3>, [">= 0"])
60
+ s.add_development_dependency(%q<rpeg-markdown>, [">= 0"])
61
+ s.add_development_dependency(%q<bluecloth>, [">= 0"])
62
+ s.add_development_dependency(%q<maruku>, [">= 0"])
63
+ s.add_development_dependency(%q<redcarpet>, [">= 0"])
64
+ end
65
+
@@ -0,0 +1,47 @@
1
+ require 'set'
2
+ require 'active_support/concern'
3
+ require 'active_support/core_ext/module/attribute_accessors'
4
+
5
+ require 'acts_as_markup_on/version'
6
+ require 'acts_as_markup_on/railtie' if defined?(Rails)
7
+
8
+ module ActsAsMarkupOn
9
+ # This exception is raised when an unsupported markup language is supplied to acts_as_markup_on.
10
+ class UnsupportedMarkupLanguage < ArgumentError
11
+ end
12
+
13
+ # This exception is raised when an unsupported Markdown library is set to the config value.
14
+ class UnsportedMarkdownLibrary < ArgumentError
15
+ end
16
+
17
+ # This exception is raised when an unsupported Mediawiki library is set to the config value.
18
+ class UnsportedMediawikiLibrary < ArgumentError
19
+ end
20
+
21
+ MARKDOWN_LIBS = { :rdiscount => {:class_name => "RDiscount",
22
+ :lib_name => "rdiscount"},
23
+ :bluecloth => {:class_name => "BlueClothText",
24
+ :lib_name => "bluecloth"},
25
+ :rpeg => {:class_name => "PEGMarkdown",
26
+ :lib_name => "peg_markdown"},
27
+ :maruku => {:class_name => "Maruku",
28
+ :lib_name => "maruku"},
29
+ :redcarpet => {:class_name => "RedcarpetText",
30
+ :lib_name => 'redcarpet'} }
31
+
32
+ MEDIAWIKI_LIBS = { :wikitext => {:class_name => "WikitextString",
33
+ :lib_name => "wikitext"},
34
+ :wikicloth => {:class_name => "WikiClothText",
35
+ :lib_name => 'wikicloth'} }
36
+
37
+ LIBRARY_EXTENSIONS = ::Set.new(Dir[File.join(File.expand_path(File.dirname(__FILE__)), 'acts_as_markup_on/exts/*.rb')].map {|file| File.basename(file, '.rb')}).delete('string')
38
+
39
+ mattr_accessor :markdown_library
40
+ mattr_accessor :mediawiki_library
41
+
42
+ # Returns the version string for the library.
43
+ def self.version
44
+ VERSION
45
+ end
46
+
47
+ end
@@ -0,0 +1,217 @@
1
+ module ActsAsMarkupOn
2
+ module ActiveRecordExtension
3
+ extend ActiveSupport::Concern
4
+
5
+ module ClassMethods
6
+
7
+ # This allows you to specify columns you want to define as containing
8
+ # Markdown, Textile, Wikitext or RDoc content.
9
+ # Then you can simply call <tt>.to_html</tt> method on the attribute.
10
+ #
11
+ # You can also specify the language as <tt>:variable</tt>. The language used
12
+ # to process the column will be based on another column. By default a column
13
+ # named "<tt>markup_language</tt>" is used, but this can be changed by providing
14
+ # a <tt>:language_column</tt> option. When a value is accessed it will create
15
+ # the correct object (Markdown, Textile, Wikitext or RDoc) based on the value
16
+ # of the language column. If any value besides markdown, textile, mediawiki, or
17
+ # RDoc is supplied for the markup language the text will pass through as a string.
18
+ #
19
+ # You can specify additional options to pass to the markup library by using
20
+ # <tt>:markdown_options</tt>, <tt>:textile_options</tt> or <tt>:mediawiki_options</tt>.
21
+ # RDoc does not support any useful options. The options should be given as an array
22
+ # of arguments. You can specify options for more than one language when using
23
+ # <tt>:variable</tt>. See each library's documentation for more details on what
24
+ # options are available.
25
+ #
26
+ #
27
+ # ==== Examples
28
+ #
29
+ # ===== Using Markdown language
30
+ #
31
+ # class Post < ActiveRecord
32
+ # acts_as_markup_on :language => :markdown, :columns => [:body]
33
+ # end
34
+ #
35
+ # @post = Post.find(:first)
36
+ # @post.body.to_s # => "## Markdown Headline"
37
+ # @post.body.to_html # => "<h2> Markdown Headline</h2>"
38
+ #
39
+ #
40
+ # ===== Using variable language
41
+ #
42
+ # class Post < ActiveRecord
43
+ # acts_as_markup_on :language => :variable, :columns => [:body], :language_column => 'language_name'
44
+ # end
45
+ #
46
+ # @post = Post.find(:first)
47
+ # @post.language_name # => "markdown"
48
+ # @post.body.to_s # => "## Markdown Headline"
49
+ # @post.body.to_html # => "<h2> Markdown Headline</h2>"
50
+ #
51
+ #
52
+ # ===== Using options
53
+ #
54
+ # class Post < ActiveRecord
55
+ # acts_as_markup_on :language => :markdown, :columns => [:body], :markdown_options => [ :filter_html ]
56
+ # end
57
+ #
58
+ # class Post < ActiveRecord
59
+ # acts_as_markup_on :language => :textile, :columns => [:body], :textile_options => [ [ :filter_html ] ]
60
+ # end
61
+ #
62
+ # class Post < ActiveRecord
63
+ # acts_as_markup_on :language => :mediawiki, :columns => [:body], :mediawiki_options => [ { :space_to_underscore => true } ]
64
+ # end
65
+ #
66
+ #
67
+ def acts_as_markup_on(options)
68
+ options.reverse_merge!(:language_column => :markup_language)
69
+ markup_class = load_markup_class(options)
70
+
71
+ unless options[:language].to_sym == :variable
72
+ define_markup_columns_reader_methods(markup_class, options)
73
+ else
74
+ define_variable_markup_columns_reader_methods(markup_class, options)
75
+ end
76
+ end
77
+
78
+ # This is a convenience method for
79
+ # `<tt>acts_as_markup_on :language => :markdown, :columns => [:body]</tt>`
80
+ # Additional options can be given at the end, if necessary.
81
+ #
82
+ def acts_as_markdown_on(*columns)
83
+ options = columns.extract_options!
84
+ acts_as_markup_on options.merge(:language => :markdown, :columns => columns)
85
+ end
86
+
87
+ # This is a convenience method for
88
+ # `<tt>acts_as_markup_on :language => :textile, :columns => [:body]</tt>`
89
+ # Additional options can be given at the end, if necessary.
90
+ #
91
+ def acts_as_textile_on(*columns)
92
+ options = columns.extract_options!
93
+ acts_as_markup_on options.merge(:language => :textile, :columns => columns)
94
+ end
95
+
96
+ # This is a convenience method for
97
+ # `<tt>acts_as_markup_on :language => :mediawiki, :columns => [:body]</tt>`
98
+ # Additional options can be given at the end, if necessary.
99
+ #
100
+ def acts_as_mediawiki_on(*columns)
101
+ options = columns.extract_options!
102
+ acts_as_markup_on options.merge(:language => :mediawiki, :columns => columns)
103
+ end
104
+
105
+ # This is a convenience method for
106
+ # `<tt>acts_as_markup_on :language => :rdoc, :columns => [:body]</tt>`
107
+ # Additional options can be given at the end, if necessary.
108
+ #
109
+ def acts_as_rdoc_on(*columns)
110
+ options = columns.extract_options!
111
+ acts_as_markup_on options.merge(:language => :rdoc, :columns => columns)
112
+ end
113
+
114
+
115
+ private
116
+ def get_markdown_class
117
+ if ActsAsMarkupOn::MARKDOWN_LIBS.keys.include? ActsAsMarkupOn.markdown_library
118
+ markdown_library_names = ActsAsMarkupOn::MARKDOWN_LIBS[ActsAsMarkupOn.markdown_library]
119
+ require markdown_library_names[:lib_name]
120
+ require_extensions(markdown_library_names[:lib_name])
121
+ return markdown_library_names[:class_name].constantize
122
+ else
123
+ raise ActsAsMarkupOn::UnsportedMarkdownLibrary, "#{ActsAsMarkupOn.markdown_library} is not currently supported."
124
+ end
125
+ end
126
+
127
+ def get_mediawiki_class
128
+ if ActsAsMarkupOn::MEDIAWIKI_LIBS.keys.include? ActsAsMarkupOn.mediawiki_library
129
+ mediawiki_library_names = ActsAsMarkupOn::MEDIAWIKI_LIBS[ActsAsMarkupOn.mediawiki_library]
130
+ require mediawiki_library_names[:lib_name]
131
+ require_extensions(mediawiki_library_names[:lib_name])
132
+ return mediawiki_library_names[:class_name].constantize
133
+ else
134
+ raise ActsAsMarkupOn::UnsportedMediawikiLibrary, "#{ActsAsMarkupOn.mediawiki_library} is not currently supported."
135
+ end
136
+ end
137
+
138
+ def require_extensions(library)# :nodoc:
139
+ if ActsAsMarkupOn::LIBRARY_EXTENSIONS.include? library.to_s
140
+ require "acts_as_markup_on/exts/#{library}"
141
+ end
142
+ end
143
+
144
+ def require_library_and_get_class(language)
145
+ case language
146
+ when :markdown
147
+ return get_markdown_class
148
+ when :textile
149
+ require 'redcloth'
150
+ return RedCloth
151
+ when :mediawiki
152
+ return get_mediawiki_class
153
+ when :rdoc
154
+ require 'rdoc'
155
+ require_extensions 'rdoc'
156
+ return RDocText
157
+ else
158
+ return String
159
+ end
160
+ end
161
+
162
+ def load_markup_class(options)
163
+ case options[:language].to_sym
164
+ when :markdown, :textile, :mediawiki, :rdoc
165
+ require_library_and_get_class(options[:language].to_sym)
166
+ when :variable
167
+ markup_classes = {}
168
+ [:textile, :mediawiki, :rdoc, :markdown].each do |language|
169
+ markup_classes[language] = require_library_and_get_class(language)
170
+ end
171
+ markup_classes
172
+ else
173
+ raise ActsAsMarkupOn::UnsupportedMarkupLanguage, "#{options[:langauge]} is not a currently supported markup language."
174
+ end
175
+ end
176
+
177
+ def define_markup_columns_reader_methods(markup_class, options)
178
+ markup_options = options["#{options[:language]}_options".to_sym] || []
179
+
180
+ options[:columns].each do |col|
181
+ define_method col do
182
+ if instance_variable_defined?("@#{col}") && !send("#{col}_changed?")
183
+ instance_variable_get("@#{col}")
184
+ else
185
+ instance_variable_set("@#{col}", markup_class.new(self[col].to_s, *markup_options))
186
+ end
187
+ end
188
+ end
189
+ end
190
+
191
+ def define_variable_markup_columns_reader_methods(markup_classes, options)
192
+ options[:columns].each do |col|
193
+ define_method col do
194
+ if instance_variable_defined?("@#{col}")
195
+ unless send("#{col}_changed?") || send("#{options[:language_column]}_changed?")
196
+ return instance_variable_get("@#{col}")
197
+ end
198
+ end
199
+ instance_variable_set("@#{col}", case send(options[:language_column])
200
+ when /markdown/i
201
+ markup_classes[:markdown].new self[col].to_s, *(options[:markdown_options] || [])
202
+ when /textile/i
203
+ markup_classes[:textile].new self[col].to_s, *(options[:textile_options] || [])
204
+ when /mediawiki/i
205
+ markup_classes[:mediawiki].new self[col].to_s, *(options[:mediawiki_options] || [])
206
+ when /rdoc/i
207
+ markup_classes[:rdoc].new self[col].to_s
208
+ else
209
+ self[col]
210
+ end)
211
+ end
212
+ end
213
+ end
214
+
215
+ end
216
+ end
217
+ end