Class: Albeano

Inherits:
Object
  • Object
show all
Defined in:
lib/albeano.rb

Constant Summary collapse

VERSION =
'1.1.0'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Albeano

Returns a new instance of Albeano.



10
11
12
13
14
15
16
17
# File 'lib/albeano.rb', line 10

def initialize(text)
  if text.respond_to?(:read)
    @text = text.read
  else
    @text = text
  end
  @markdown = nil
end

Class Method Details

.generate(text) ⇒ Object



6
7
8
# File 'lib/albeano.rb', line 6

def self.generate(text)
  new(text).generate
end

Instance Method Details

#generateString Also known as: to_s

Returns Newly generated Albino markup.

Returns:

  • (String)

    Newly generated Albino markup



20
21
22
23
24
# File 'lib/albeano.rb', line 20

def generate
  @text.gsub(/\[code(?:=(.+?))?\]\s*(.+?)\s*\[\/code\]/m) do
    Albino.colorize($2, $1 || :text)
  end
end

#to_markdown(*extensions) ⇒ String Also known as: to_md

Returns The newly generated markup.

Returns:

  • (String)

    The newly generated markup

Raises:

  • (LoadError)

    Raised when unable to load RDiscount



30
31
32
33
34
35
36
37
38
# File 'lib/albeano.rb', line 30

def to_markdown(*extensions)
  begin
    require 'rdiscount'
  rescue LoadError
    raise "Albeano requires RDiscount to render markdown"
  end

  @markdown ||= RDiscount.new(generate).to_html
end