Module: MultiMarkdown
- Defined in:
- lib/multi_markdown/version.rb,
lib/multi_markdown/multi_markdown.rb
Constant Summary collapse
- VERSION =
multi_markdown version
"0.2.0"
- LIBRARIES =
Markdown library names
{ :bluecloth => 'bluecloth', :kramdown => 'kramdown', :maruku => 'maruku', :rdiscount => 'rdiscount', :redcarpet => 'redcarpet', :rpeg_markdown => 'peg_markdown' }
- CONSTANTS =
Markdown Constants
{ :bluecloth => 'BlueCloth', :kramdown => 'Kramdown::Document', :maruku => 'Maruku', :rdiscount => 'RDiscount', :redcarpet => 'RedcarpetCompat', :rpeg_markdown => 'PEGMarkdown' }
- PRIORITY =
The loading priority
[ :redcarpet, :rdiscount, :kramdown, :bluecloth, :maruku, :rpeg_markdown ]
- @@markdown =
nil
Class Method Summary collapse
-
.find(library) ⇒ Object
Attempts to find the specific Markdown library.
-
.load ⇒ #new
Attempts to find or load the first available Markdown library.
-
.new(text, options = {}) ⇒ #to_html
Loads the first available Markdown library and creates a Markdown document.
-
.use(library) ⇒ #new
Uses a specific Markdown library.
Class Method Details
.find(library) ⇒ Object
Attempts to find the specific Markdown library.
48 49 50 51 52 53 54 |
# File 'lib/multi_markdown/multi_markdown.rb', line 48 def self.find(library) unless CONSTANTS.has_key?(library) raise(ArgumentError,"unknown Markdown library: #{library}") end eval(CONSTANTS[library]) end |
.load ⇒ #new
Attempts to find or load the first available Markdown library.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/multi_markdown/multi_markdown.rb', line 97 def self.load # attempt to find an already loaded markdown library PRIORITY.each do |library| begin return(@@markdown = find(library)) rescue NameError end end PRIORITY.each do |library| begin return use(library) rescue Gem::LoadError => e # re-raise Gem::LoadErrors, as they are a sign of dependency issues raise(e) rescue LoadError end end raise(LoadError,"could not load any of the markdown libraries") end |
.new(text, options = {}) ⇒ #to_html
Loads the first available Markdown library and creates a Markdown document.
133 134 135 136 137 |
# File 'lib/multi_markdown/multi_markdown.rb', line 133 def self.new(text,={}) load unless @@markdown @@markdown.new(text,) end |
.use(library) ⇒ #new
Uses a specific Markdown library.
76 77 78 79 80 81 82 83 84 |
# File 'lib/multi_markdown/multi_markdown.rb', line 76 def self.use(library) unless LIBRARIES.has_key?(library) raise(ArgumentError,"unknown Markdown library: #{library}") end require LIBRARIES[library] @@markdown = find(library) end |