Module: Blogger::Formattable

Included in:
Comment, Post
Defined in:
lib/blogger.rb

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

Instance Method Summary collapse

Instance Attribute Details

#formatterObject

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_blueclothObject

:nodoc:



52
53
54
55
# File 'lib/blogger.rb', line 52

def format_bluecloth #:nodoc:
  require 'bluecloth'
  BlueCloth.new(@content).to_html
end

#format_contentObject

:nodoc:



39
40
41
# File 'lib/blogger.rb', line 39

def format_content #:nodoc:
  send("format_#{@formatter}".to_sym)
end

#format_hamlObject

:nodoc:



72
73
74
75
# File 'lib/blogger.rb', line 72

def format_haml #:nodoc:
  require 'haml'
  Haml::Engine.new(@content).render
end

#format_marukuObject

: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_markdownObject

: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_rawObject

:nodoc:



43
44
45
# File 'lib/blogger.rb', line 43

def format_raw #:nodoc:
  @content
end

#format_rdiscountObject

:nodoc:



57
58
59
60
# File 'lib/blogger.rb', line 57

def format_rdiscount #:nodoc:
  require 'rdiscount'
  RDiscount.new(@content).to_html
end

#format_redclothObject

:nodoc:



47
48
49
50
# File 'lib/blogger.rb', line 47

def format_redcloth #:nodoc:
  require 'redcloth'
  RedCloth.new(@content).to_html
end