Class: Markdown::Config
- Inherits:
-
Object
- Object
- Markdown::Config
- Defined in:
- lib/markdown/config.rb
Constant Summary collapse
- DEFAULTS =
note: make kramdown default engine
{ 'libs' => [ 'kramdown' ], 'extnames' => [ '.markdown', '.m', '.mark', '.mkdn', '.md', '.mdown', '.markdn', '.txt', '.text' ], # todo: check - add .wiki??? ext 'redcarpet' => { 'extensions' => [ 'no_intra_emphasis', 'fenced_code_blocks', 'tables', 'strikethrough' ] # todo/fix: merge nested hash?? }, }
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #known_markdown_libs ⇒ Object
- #markdown_extnames ⇒ Object
- #markdown_lib ⇒ Object
- #markdown_lib_defaults ⇒ Object
- #markdown_to_html_method ⇒ Object
- #require_markdown_libs ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/markdown/config.rb', line 44 def initialize @props = @props_default = Props.new( DEFAULTS, 'DEFAULTS' ) # check for user settings (markdown.yml) in home folder ## todo: use .markdown.yml?? or differnt name ?? props_home_file = File.join( Env.home, 'markdown.yml' ) if File.exists?( props_home_file ) puts "Loading settings from '#{props_home_file}'..." @props = @props_home = Props.load_file( props_home_file, @props ) end # check for user settings (markdown.yml) in working folder props_work_file = File.join( '.', 'markdown.yml' ) if File.exists?( props_work_file ) puts "Loading settings from '#{props_work_file}'..." @props = @props_work = Props.load_file( props_work_file, @props ) end @libs = [] require_markdown_libs() end |
Instance Method Details
#known_markdown_libs ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/markdown/config.rb', line 73 def known_markdown_libs # returns an array of known markdown engines e.g. # [ 'pandoc-ruby', 'rdiscount', 'rpeg-markdown', 'maruku', 'bluecloth', 'kramdown' ] ## todo: allow single lib para instead of libs ## todo: allow ENV setting markdown_[select]_lib=xxxx ## todo/fix: use lookup with config parent cascade ## lookup order ## 1) env variable MARKDOWN_LIB ## 2) lib property (single markdown engine) ## 3) libs property (first-come first-serve markdown engine list) user_lib = Env.markdown_lib || @props.fetch( 'lib', nil ) if user_lib.nil? user_libs = @props.fetch( 'libs', nil ) else [ user_lib ] # return as array (wrap single lib entry) end end |
#markdown_extnames ⇒ Object
69 70 71 |
# File 'lib/markdown/config.rb', line 69 def markdown_extnames @props.fetch( 'extnames', nil ) end |
#markdown_lib ⇒ Object
116 117 118 |
# File 'lib/markdown/config.rb', line 116 def markdown_lib @libs.first end |
#markdown_lib_defaults ⇒ Object
120 121 122 |
# File 'lib/markdown/config.rb', line 120 def markdown_lib_defaults opts = @props.fetch( @libs.first, {} ) end |
#markdown_to_html_method ⇒ Object
124 125 126 127 128 129 |
# File 'lib/markdown/config.rb', line 124 def markdown_to_html_method lib = @libs.first opts = @props.fetch( lib, {} ) method = opts.fetch( 'converter', "#{lib.downcase}_to_html" ) # default to <lib>_to_html if converter prop not found method.tr('-','_').to_sym end |
#require_markdown_libs ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/markdown/config.rb', line 98 def require_markdown_libs # check for available markdown libs/gems # try to require each lib and remove any not installed known_markdown_libs.each do |lib| begin require lib @libs << lib rescue LoadError => ex ## todo: use logger.debug instead of puts puts "Markdown library #{lib} not found. Use gem install #{lib} to install." end end puts " Found #{@libs.length} Markdown #{(@libs.length == 1) ? 'library' : 'libraries'}: #{@libs.join(', ')}" end |