Module: Markabb

Defined in:
lib/markabb.rb,
lib/markabb/parse.rb,
lib/markabb/config.rb,
lib/markabb/version.rb,
lib/markabb/tags/nobbc.rb,
lib/markabb/classes/tag.rb,
lib/markabb/classes/parser.rb,
lib/markabb/classes/callback.rb,
lib/markabb/highlighters/raw.rb,
lib/markabb/highlighters/coderay.rb,
lib/markabb/classes/syntax_highlighter.rb

Overview

Main Markabb Module, all code is a sub of this

Defined Under Namespace

Modules: Highlighters Classes: Callback, Config, NobbcTag, Parser, SyntaxHighlighter, Tag

Constant Summary collapse

VERSION =

Markabbs Version Number

"1.0.1"
Tags =

The hash which markabb stores all the avaliable tags in

{}
SyntaxHighlighters =

The hash which markabb stores all available syntax highlighters in

{}

Class Method Summary collapse

Class Method Details

.configObject

Exposes the config object for use in your code



38
39
40
# File 'lib/markabb.rb', line 38

def self.config
    @config
end

.configure {|@config| ... } ⇒ Object

Exposes a new config object to a block Called with:

Markabb.configure do |c|
    c.foo = 'bar'
end

Yields:



32
33
34
35
# File 'lib/markabb.rb', line 32

def self.configure
    @config = Config.new
    yield @config
end

.needs_html_safe?Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
# File 'lib/markabb/parse.rb', line 22

def self.needs_html_safe?
    if defined? Rails
        return Rails.version =~ /^3\./
    else
        return false
    end
end

.parse(s) ⇒ Object

Passes the string to an instance of Markabb::Parser

Can be passed a block to change the config



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/markabb/parse.rb', line 5

def self.parse(s)
    # Set the config
    config = @config
    if block_given?
        config = Config.new unless @config
        yield(config)
    else
        raise "Please configure Markabb before using it" unless @config
    end
    output = Parser.new(config, s).output
    if needs_html_safe?
        return output.html_safe
    else
        return output
    end
end

.register_highlighter(name, highlighter) ⇒ Object

Adds a syntac highlighter to the hash



6
7
8
# File 'lib/markabb/classes/syntax_highlighter.rb', line 6

def self.register_highlighter(name, highlighter)
    SyntaxHighlighters[name] = highlighter
end

.register_tag(name, tag, group = nil) ⇒ Object

Inserts a tag into Markabb::Tags

Takes 3 inputs:

name - a symbol which is used as its key
tag - a Markabb::Tag object
group - a way to group similar tags so they can all be disabled

register_tag(:foo, Markabb::Tag, :bar)

would produce a tags hash of

=> {:foo => Markabb::Tag}



17
18
19
20
21
22
23
24
25
26
# File 'lib/markabb/classes/tag.rb', line 17

def self.register_tag(name, tag, group = nil)
    tag.name = name
    if group
        tag.group = group
        Tags[group] ||= {}
        Tags[group][name] = tag
    else
        Tags[name] = tag
    end
end

.remove_highlighter(name) ⇒ Object

Removes a syntax highlighter from the hash



11
12
13
# File 'lib/markabb/classes/syntax_highlighter.rb', line 11

def self.remove_highlighter(name)
    SyntaxHighlighters.delete(name)
end

.remove_tag(name) ⇒ Object

Removes a tag from Markabb::Tags takes the symbol for the key to delete



30
31
32
# File 'lib/markabb/classes/tag.rb', line 30

def self.remove_tag(name)
    Tags.delete(name)
end