Method: YARD::Templates::Helpers::MarkupHelper#load_markup_provider

Defined in:
lib/yard/templates/helpers/markup_helper.rb

#load_markup_provider(type = options.markup) ⇒ Boolean

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 provider.

On failure this method will inform the user that no provider could be found and exit the program.

Returns:

  • (Boolean)

    whether the markup provider was successfully loaded.


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/yard/templates/helpers/markup_helper.rb', line 76

def load_markup_provider(type = options.markup)
  return true if MarkupHelper.markup_cache[type]
  MarkupHelper.markup_cache[type] ||= {}

  providers = MARKUP_PROVIDERS[type.to_sym]
  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?
    log.error "Invalid markup type '#{type}' or markup provider " +
      "(#{options.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 if provider[:lib]
    begin klass = eval("::" + provider[:const]); rescue NameError; next end
    MarkupHelper.markup_cache[type][:provider] = provider[:lib] # Cache the provider
    MarkupHelper.markup_cache[type][:class] = klass
    return true
  end

  # Show error message telling user to install first potential provider
  name, lib = *[providers.first[:const], providers.first[:lib] || type]
  log.error "Missing '#{lib}' gem for #{type.to_s.capitalize} formatting. Install it with `gem install #{lib}`"
  false
end