Module: Blogger::Formattable
Overview
Formattable
This mixin provides a number of formatters to any object with a content method. A large number of formatters are provided to acommodate those who are hosting on servers that limit their gem usage.
The available formatters are:
- :raw
-
content is passed directly into the post, with no formatting.
- :redcloth
-
content is parsed as textile (using RedCloth gem)
- :bluecloth
-
content is parsed as textile (using BlueCloth gem)
- :rdiscount
-
content is parsed as markdown (using rdiscount gem)
- :peg_markdown
-
content is parsed as markdown (using peg_markdown gem)
- :maruku
-
content is parsed as markdown (using maruku gem)
- :haml
-
content is parsed as haml
Constant Summary collapse
- ACCEPTABLE_FORMATTERS =
[:raw, :rdiscount, :redcloth, :bluecloth, :peg_markdown, :maruku, :haml]
Instance Attribute Summary collapse
-
#formatter ⇒ Object
Specifies how the content will be formatted.
Instance Method Summary collapse
-
#format_bluecloth ⇒ Object
:nodoc:.
-
#format_content ⇒ Object
:nodoc:.
-
#format_haml ⇒ Object
:nodoc:.
-
#format_maruku ⇒ Object
:nodoc:.
-
#format_peg_markdown ⇒ Object
:nodoc:.
-
#format_raw ⇒ Object
:nodoc:.
-
#format_rdiscount ⇒ Object
:nodoc:.
-
#format_redcloth ⇒ Object
:nodoc:.
Instance Attribute Details
#formatter ⇒ Object
Specifies how the content will be formatted. Can be any of the following:
- :raw
-
content is passed directly into the post
- :redcloth
-
content is parsed as textile (using RedCloth gem)
- :bluecloth
-
content is parsed as textile (using BlueCloth gem)
- :rdiscount
-
content is parsed as markdown (using rdiscount gem)
- :peg_markdown
-
content is parsed as markdown (using peg_markdown gem)
- :maruku
-
content is parsed as markdown (using maruku gem)
- :haml
-
content is parsed as haml
Note that these aren’t all offered for the hell of it - some people have access to compiled gems, and some don’t - some don’t even get easy access to new pure Ruby gems on their server
37 38 39 |
# File 'lib/blogger.rb', line 37 def formatter @formatter end |
Instance Method Details
#format_bluecloth ⇒ Object
:nodoc:
52 53 54 55 |
# File 'lib/blogger.rb', line 52 def format_bluecloth #:nodoc: require 'bluecloth' BlueCloth.new(@content).to_html end |
#format_content ⇒ Object
:nodoc:
39 40 41 |
# File 'lib/blogger.rb', line 39 def format_content #:nodoc: send("format_#{@formatter}".to_sym) end |
#format_haml ⇒ Object
:nodoc:
72 73 74 75 |
# File 'lib/blogger.rb', line 72 def format_haml #:nodoc: require 'haml' Haml::Engine.new(@content).render end |
#format_maruku ⇒ Object
:nodoc:
67 68 69 70 |
# File 'lib/blogger.rb', line 67 def format_maruku #:nodoc: require 'maruku' Maruku.new(@content).to_html end |
#format_peg_markdown ⇒ Object
:nodoc:
62 63 64 65 |
# File 'lib/blogger.rb', line 62 def format_peg_markdown #:nodoc: require 'peg_markdown' PEGMarkdown.new(@content).to_html end |
#format_raw ⇒ Object
:nodoc:
43 44 45 |
# File 'lib/blogger.rb', line 43 def format_raw #:nodoc: @content end |
#format_rdiscount ⇒ Object
:nodoc:
57 58 59 60 |
# File 'lib/blogger.rb', line 57 def format_rdiscount #:nodoc: require 'rdiscount' RDiscount.new(@content).to_html end |
#format_redcloth ⇒ Object
:nodoc:
47 48 49 50 |
# File 'lib/blogger.rb', line 47 def format_redcloth #:nodoc: require 'redcloth' RedCloth.new(@content).to_html end |