Sha256: 30edf6ec192623d0db1cd4bcaa03338d2a4956eee5706c31203180163fdbd9f6

Contents?: true

Size: 1.06 KB

Versions: 54

Compression:

Stored size: 1.06 KB

Contents

require 'rdoc'
require 'reverse_markdown'

module AppMap
  module Swagger
    # Transform description fields into Markdown.
    class MarkdownDescriptions
      def initialize(swagger_yaml)
        @swagger_yaml = swagger_yaml
      end

      def converter
        method(:rdoc_to_markdown)
      end

      def perform
        to_markdown = lambda do |obj|
          return obj.each(&to_markdown) if obj.is_a?(Array)
          return unless obj.is_a?(Hash)

          description = obj['description']
          obj['description'] = converter.(description) if description

          obj.reject { |k,v| k == 'properties' }.each_value(&to_markdown)

          obj
        end

        to_markdown.(Util.deep_dup(@swagger_yaml))
      end

      protected

      def rdoc_to_markdown(comment)
        # Strip tags
        comment = comment.split("\n").reject { |line| line =~ /^\s*@/ }.join("\n")
        converter = ::RDoc::Markup::ToHtml.new(::RDoc::Options.new)
        html = converter.convert(comment).strip
        ::ReverseMarkdown.convert(html).strip
      end
    end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
appmap-0.80.1 lib/appmap/swagger/markdown_descriptions.rb
appmap-0.80.0 lib/appmap/swagger/markdown_descriptions.rb
appmap-0.79.0 lib/appmap/swagger/markdown_descriptions.rb
appmap-0.78.0 lib/appmap/swagger/markdown_descriptions.rb
appmap-0.77.4 lib/appmap/swagger/markdown_descriptions.rb
appmap-0.77.3 lib/appmap/swagger/markdown_descriptions.rb
appmap-0.77.2 lib/appmap/swagger/markdown_descriptions.rb
appmap-0.77.1 lib/appmap/swagger/markdown_descriptions.rb
appmap-0.77.0 lib/appmap/swagger/markdown_descriptions.rb
appmap-0.76.0 lib/appmap/swagger/markdown_descriptions.rb
appmap-0.75.0 lib/appmap/swagger/markdown_descriptions.rb
appmap-0.74.0 lib/appmap/swagger/markdown_descriptions.rb
appmap-0.73.0 lib/appmap/swagger/markdown_descriptions.rb
appmap-0.72.5 lib/appmap/swagger/markdown_descriptions.rb
appmap-0.72.4 lib/appmap/swagger/markdown_descriptions.rb
appmap-0.72.3 lib/appmap/swagger/markdown_descriptions.rb
appmap-0.72.2 lib/appmap/swagger/markdown_descriptions.rb
appmap-0.72.1 lib/appmap/swagger/markdown_descriptions.rb
appmap-0.72.0 lib/appmap/swagger/markdown_descriptions.rb
appmap-0.71.0 lib/appmap/swagger/markdown_descriptions.rb