lib/yard/templates/helpers/markup_helper.rb in yard-0.6.1 vs lib/yard/templates/helpers/markup_helper.rb in yard-0.6.2
- old
+ new
@@ -7,11 +7,12 @@
MARKUP_PROVIDERS = {
:markdown => [
{:lib => :bluecloth, :const => 'BlueCloth'},
{:lib => :maruku, :const => 'Maruku'},
{:lib => :"rpeg-markdown", :const => "PEGMarkdown"},
- {:lib => :rdiscount, :const => "RDiscount"}
+ {:lib => :rdiscount, :const => "RDiscount"},
+ {:lib => :kramdown, :const => "Kramdown::Document"}
],
:textile => [
{:lib => :redcloth, :const => 'RedCloth'}
],
:rdoc => [],
@@ -45,49 +46,49 @@
require 'rubygems'
require 'rdoc/markup/simple_markup'
require 'rdoc/markup/simple_markup/to_html'
SimpleMarkup = SM::SimpleMarkup.new
end
-
- private
# Attempts to load the first valid markup provider in {MARKUP_PROVIDERS}.
# If a provider is specified, immediately try to load it.
#
# On success this sets `@markup_provider` and `@markup_class` to
# the provider name and library constant class/module respectively for
# the loaded proider.
#
# On failure this method will inform the user that no provider could be
# found and exit the program.
+ #
+ # @return [Boolean] whether the markup provider was successfully loaded.
def load_markup_provider(type = options[:markup])
- return if type == :rdoc || (@markup_cache && @markup_cache[type])
+ return true if type == :rdoc || (@markup_cache && @markup_cache[type])
@markup_cache ||= {}
@markup_cache[type] ||= {}
providers = MARKUP_PROVIDERS[type]
- return if providers && providers.empty?
- if options[:markup_provider]
+ return true if providers && providers.empty?
+ if providers && options[:markup_provider]
providers = providers.select {|p| p[:lib] == options[:markup_provider] }
end
if providers == nil || providers.empty?
- STDERR.puts "Invalid markup type '#{type}'"
- exit
+ log.error "Invalid markup type '#{type}' or markup provider is not registered."
+ return false
end
# Search for provider, return the library class name as const if found
providers.each do |provider|
begin require provider[:lib].to_s; rescue LoadError; next end
@markup_cache[type][:provider] = provider[:lib] # Cache the provider
- @markup_cache[type][:class] = Kernel.const_get(provider[:const])
- return
+ @markup_cache[type][:class] = eval(provider[:const])
+ return false
end
# Show error message telling user to install first potential provider
name, lib = providers.first[:const], providers.first[:lib]
- STDERR.puts "Missing #{name} gem for #{options[:markup].to_s.capitalize} formatting. Install it with `gem install #{lib}`"
- exit
+ log.error "Missing #{name} gem for #{options[:markup].to_s.capitalize} formatting. Install it with `gem install #{lib}`"
+ false
end
# Checks for a shebang or looks at the file extension to determine
# the markup type for the file contents. File extensions are registered
# for a markup type in {MARKUP_EXTENSIONS}.