Class: Albeano
- Inherits:
-
Object
- Object
- Albeano
- Defined in:
- lib/albeano.rb
Constant Summary collapse
- VERSION =
'1.0.0'
Class Method Summary collapse
Instance Method Summary collapse
- #generate ⇒ Object (also: #to_s)
-
#initialize(text) ⇒ Albeano
constructor
A new instance of Albeano.
- #to_markdown(*extensions) ⇒ Object (also: #to_md)
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
#generate ⇒ Object Also known as: to_s
19 20 21 22 23 |
# File 'lib/albeano.rb', line 19 def generate @text.gsub(/\[code(?:=(.+?))?\]\s*(.+?)\s*\[\/code\]/m) do Albino.colorize($2, $1 || :text) end end |
#to_markdown(*extensions) ⇒ Object Also known as: to_md
27 28 29 30 31 32 33 34 35 |
# File 'lib/albeano.rb', line 27 def to_markdown(*extensions) begin require 'rdiscount' rescue LoadError raise "Albeano requires RDiscount to render markdown" end @markdown ||= RDiscount.new(generate).to_html end |