Module: ActsAsMarkupOn::ActiveRecordExtension::ClassMethods
- Defined in:
- lib/acts_as_markup_on/active_record_extension.rb
Instance Method Summary collapse
-
#acts_as_markdown_on(*columns) ⇒ Object
This is a convenience method for ‘
acts_as_markup_on :language => :markdown, :columns => [:body]
` Additional options can be given at the end, if necessary. -
#acts_as_markup_on(options) ⇒ Object
This allows you to specify columns you want to define as containing Markdown, Textile, Wikitext or RDoc content.
-
#acts_as_mediawiki_on(*columns) ⇒ Object
This is a convenience method for ‘
acts_as_markup_on :language => :mediawiki, :columns => [:body]
` Additional options can be given at the end, if necessary. -
#acts_as_rdoc_on(*columns) ⇒ Object
This is a convenience method for ‘
acts_as_markup_on :language => :rdoc, :columns => [:body]
` Additional options can be given at the end, if necessary. -
#acts_as_textile_on(*columns) ⇒ Object
This is a convenience method for ‘
acts_as_markup_on :language => :textile, :columns => [:body]
` Additional options can be given at the end, if necessary.
Instance Method Details
#acts_as_markdown_on(*columns) ⇒ Object
This is a convenience method for ‘acts_as_markup_on :language => :markdown, :columns => [:body]
` Additional options can be given at the end, if necessary.
82 83 84 85 |
# File 'lib/acts_as_markup_on/active_record_extension.rb', line 82 def acts_as_markdown_on(*columns) = columns. acts_as_markup_on .merge(:language => :markdown, :columns => columns) end |
#acts_as_markup_on(options) ⇒ Object
This allows you to specify columns you want to define as containing Markdown, Textile, Wikitext or RDoc content. Then you can simply call .to_html
method on the attribute.
You can also specify the language as :variable
. The language used to process the column will be based on another column. By default a column named “markup_language
” is used, but this can be changed by providing a :language_column
option. When a value is accessed it will create the correct object (Markdown, Textile, Wikitext or RDoc) based on the value of the language column. If any value besides markdown, textile, mediawiki, or RDoc is supplied for the markup language the text will pass through as a string.
You can specify additional options to pass to the markup library by using :markdown_options
, :textile_options
or :mediawiki_options
. RDoc does not support any useful options. The options should be given as an array of arguments. You can specify options for more than one language when using :variable
. See each library’s documentation for more details on what options are available.
Examples
Using Markdown language
class Post < ActiveRecord
acts_as_markup_on :language => :markdown, :columns => [:body]
end
@post = Post.find(:first)
@post.body.to_s # => "## Markdown Headline"
@post.body.to_html # => "<h2> Markdown Headline</h2>"
Using variable language
class Post < ActiveRecord
acts_as_markup_on :language => :variable, :columns => [:body], :language_column => 'language_name'
end
@post = Post.find(:first)
@post.language_name # => "markdown"
@post.body.to_s # => "## Markdown Headline"
@post.body.to_html # => "<h2> Markdown Headline</h2>"
Using options
class Post < ActiveRecord
acts_as_markup_on :language => :markdown, :columns => [:body], :markdown_options => [ :filter_html ]
end
class Post < ActiveRecord
acts_as_markup_on :language => :textile, :columns => [:body], :textile_options => [ [ :filter_html ] ]
end
class Post < ActiveRecord
acts_as_markup_on :language => :mediawiki, :columns => [:body], :mediawiki_options => [ { :space_to_underscore => true } ]
end
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/acts_as_markup_on/active_record_extension.rb', line 67 def acts_as_markup_on() .reverse_merge!(:language_column => :markup_language) markup_class = load_markup_class() unless [:language].to_sym == :variable define_markup_columns_reader_methods(markup_class, ) else define_variable_markup_columns_reader_methods(markup_class, ) end end |
#acts_as_mediawiki_on(*columns) ⇒ Object
This is a convenience method for ‘acts_as_markup_on :language => :mediawiki, :columns => [:body]
` Additional options can be given at the end, if necessary.
100 101 102 103 |
# File 'lib/acts_as_markup_on/active_record_extension.rb', line 100 def acts_as_mediawiki_on(*columns) = columns. acts_as_markup_on .merge(:language => :mediawiki, :columns => columns) end |
#acts_as_rdoc_on(*columns) ⇒ Object
This is a convenience method for ‘acts_as_markup_on :language => :rdoc, :columns => [:body]
` Additional options can be given at the end, if necessary.
109 110 111 112 |
# File 'lib/acts_as_markup_on/active_record_extension.rb', line 109 def acts_as_rdoc_on(*columns) = columns. acts_as_markup_on .merge(:language => :rdoc, :columns => columns) end |
#acts_as_textile_on(*columns) ⇒ Object
This is a convenience method for ‘acts_as_markup_on :language => :textile, :columns => [:body]
` Additional options can be given at the end, if necessary.
91 92 93 94 |
# File 'lib/acts_as_markup_on/active_record_extension.rb', line 91 def acts_as_textile_on(*columns) = columns. acts_as_markup_on .merge(:language => :textile, :columns => columns) end |