Module: Doublesing

Defined in:
lib/doublesing.rb,
lib/doublesing/parser.rb,
lib/doublesing/version.rb,
lib/doublesing/builtins.rb,
lib/doublesing/transformer.rb,
lib/doublesing/builtins/bold.rb,
lib/doublesing/builtins/link.rb,
lib/doublesing/builtins/header.rb,
lib/doublesing/builtins/italic.rb

Defined Under Namespace

Modules: Builtins Classes: Parser, Transformer

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.assign(name, klass) ⇒ Object

Assign a handler for a custom block class. name: Name the block should respond to klass: class the block should be generated from Note:



20
21
22
# File 'lib/doublesing.rb', line 20

def self.assign(name, klass)
  @@handlers[name] = klass
end

.parse(str) ⇒ Object



9
10
11
12
13
14
# File 'lib/doublesing.rb', line 9

def self.parse(str)
  sanitized = Sanitize.fragment(str)
  tree = Parser.new.parse(sanitized)
  res = Transformer.new.apply(tree)
  res.join("")
end

.process(id, args) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/doublesing.rb', line 24

def self.process(id, args)
  if handler = @@handlers[id.to_s]
    handler.new(args).to_s
  else
    ""
  end
end

.setup!Object



31
32
33
34
# File 'lib/doublesing.rb', line 31

def self.setup!
  @@handlers = {}
  @@handlers.merge! Builtins.handlers
end