Module: Bloggit::TextFormatter

Defined in:
lib/bloggit/text_formatter.rb

Overview

TextFormatter

Default text formatters are: :textile, :markdown, and :simple

Class Method Summary collapse

Class Method Details

.register(name, &block) ⇒ Object

Registers a formatter block with a given name.

In pages or posts, you can specify the text format in the header using:

format: Textile+.

Bloggit will look for a TextFormatter that’s been registered as :textile



21
22
23
24
25
# File 'lib/bloggit/text_formatter.rb', line 21

def register(name, &block)
  name = name.to_s.downcase.to_sym
  @formatters ||= {}
  @formatters[name] = block
end

.render(text, format) ⇒ Object

Returns the processed text using the specified format, or the original text if the format isn’t recognized.



29
30
31
32
33
# File 'lib/bloggit/text_formatter.rb', line 29

def render(text, format)
  format = format.to_s.downcase.to_sym #unless format.is_a?(Symbol)
  formatter = @formatters.fetch(format, Proc.new {|text| raise "Could not format text as '#{format}'"  })
  formatter.call( text )
end