Class: CodelessCode::Formats::Term

Inherits:
Base
  • Object
show all
Defined in:
lib/codeless_code/formats/term.rb

Overview

Renders the CodelessCode::Fable using ANSI control characters for bold, italics, colors, etc.

Instance Attribute Summary

Attributes inherited from Base

#raw

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from CodelessCode::Formats::Base

Instance Method Details

#c(str) ⇒ Object



44
45
46
# File 'lib/codeless_code/formats/term.rb', line 44

def c(str)
  ColorizedString.new(str)
end

#callObject



25
26
27
# File 'lib/codeless_code/formats/term.rb', line 25

def call
  from_wiki(to_xhtml(regex(raw)))
end

#from_wiki(str) ⇒ Object



40
41
42
# File 'lib/codeless_code/formats/term.rb', line 40

def from_wiki(str)
  super(str, TermGenerator.new(self))
end

#regex(str) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/codeless_code/formats/term.rb', line 29

def regex(str)
  [
    [/\/\/\w*$/, ''],
    [/^\|   .*/, c('\\0').green],
    [/<i>([^<]+)<\/i>/mi, "''\\1''"],
    [/<b>([^<]+)<\/b>/mi, "'''\\1'''"],
    [/<a[^>]+>([^<]+)<\/a>/mi, '[[\1]]'],
    [/\/(\w+)\//, "''\\1''"],
  ].inject(str) { |str, args| str = str.gsub(*args) }
end