lib/yard/templates/helpers/markup_helper.rb in yard-0.9.5 vs lib/yard/templates/helpers/markup_helper.rb in yard-0.9.6

- old
+ new

@@ -1,5 +1,6 @@ +# frozen_string_literal: true require 'rubygems' module YARD module Templates::Helpers # Helper methods for loading and managing markup types. @@ -26,29 +27,29 @@ {:lib => :rdiscount, :const => 'RDiscount'}, {:lib => :kramdown, :const => 'Kramdown::Document'}, {:lib => :bluecloth, :const => 'BlueCloth'}, {:lib => :maruku, :const => 'Maruku'}, {:lib => :'rpeg-markdown', :const => 'PEGMarkdown'}, - {:lib => :rdoc, :const => 'YARD::Templates::Helpers::Markup::RDocMarkdown'}, + {:lib => :rdoc, :const => 'YARD::Templates::Helpers::Markup::RDocMarkdown'} ], :textile => [ - {:lib => :redcloth, :const => 'RedCloth'}, + {:lib => :redcloth, :const => 'RedCloth'} ], :textile_strict => [ - {:lib => :redcloth, :const => 'RedCloth'}, + {:lib => :redcloth, :const => 'RedCloth'} ], :rdoc => [ - {:lib => nil, :const => 'YARD::Templates::Helpers::Markup::RDocMarkup'}, + {:lib => nil, :const => 'YARD::Templates::Helpers::Markup::RDocMarkup'} ], :asciidoc => [ {:lib => :asciidoctor, :const => 'Asciidoctor'} ], :ruby => [], :text => [], :pre => [], :html => [], - :none => [], + :none => [] } # Returns a list of extensions for various markup types. To register # extensions for a type, add them to the array of extensions for the # type. @@ -86,27 +87,27 @@ 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." + 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 + begin klass = eval("::" + provider[:const]); rescue NameError; next end # rubocop:disable Lint/Eval 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] + lib = providers.first[:lib] || type log.error "Missing '#{lib}' gem for #{type.to_s.capitalize} formatting. Install it with `gem install #{lib}`" false end # Checks for a shebang or looks at the file extension to determine @@ -123,12 +124,10 @@ # Newer versions of YARD use {CodeObjects::ExtraFileObject#contents} # @return [Symbol] the markup type recognized for the file # @see MARKUP_EXTENSIONS # @since 0.6.0 def markup_for_file(contents, filename) - if contents && contents =~ MARKUP_FILE_SHEBANG # Shebang support - return $1.to_sym - end + return $1.to_sym if contents && contents =~ MARKUP_FILE_SHEBANG # Shebang support ext = (File.extname(filename)[1..-1] || '').downcase MARKUP_EXTENSIONS.each do |type, exts| return type if exts.include?(ext) end