Sha256: 9145030346ca4b6d320e157be6e1d64ceb3d0e851105f95d1d5b9595760ed86a

Contents?: true

Size: 1.16 KB

Versions: 25

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

module PlatformosCheck
  module PlatformosLiquid
    class Documentation
      class MarkdownTemplate
        MARKDOWN_RELATIVE_LINK = %r{(\[([^\[]+)\]\((/[^\)]+)\))*}

        def render(entry)
          [
            title(entry),
            body(entry)
          ].reject(&:empty?).join("\n")
        end

        private

        def title(entry)
          "### [#{entry.name}](#{entry.platformos_documentation_url})"
        end

        def body(entry)
          [entry.deprecation_reason, entry.summary, entry.description]
            .reject(&:nil?)
            .reject(&:empty?)
            .join(horizontal_rule)
            .tap { |body| break(patch_urls!(body)) }
        end

        def horizontal_rule
          "\n\n---\n\n"
        end

        def patch_urls!(body)
          body.gsub(MARKDOWN_RELATIVE_LINK) do |original_link|
            match = Regexp.last_match

            text = match[2]
            path = match[3]

            if text && path
              "[#{text}](https://documentation.platformos.com#{path})"
            else
              original_link
            end
          end
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
platformos-check-0.4.14 lib/platformos_check/platformos_liquid/documentation/markdown_template.rb
platformos-check-0.4.13 lib/platformos_check/platformos_liquid/documentation/markdown_template.rb
platformos-check-0.4.12 lib/platformos_check/platformos_liquid/documentation/markdown_template.rb
platformos-check-0.4.11 lib/platformos_check/platformos_liquid/documentation/markdown_template.rb
platformos-check-0.4.10 lib/platformos_check/platformos_liquid/documentation/markdown_template.rb
platformos-check-0.4.9 lib/platformos_check/platformos_liquid/documentation/markdown_template.rb
platformos-check-0.4.8 lib/platformos_check/platformos_liquid/documentation/markdown_template.rb
platformos-check-0.4.7 lib/platformos_check/platformos_liquid/documentation/markdown_template.rb
platformos-check-0.4.6 lib/platformos_check/platformos_liquid/documentation/markdown_template.rb
platformos-check-0.4.5 lib/platformos_check/platformos_liquid/documentation/markdown_template.rb
platformos-check-0.4.4 lib/platformos_check/platformos_liquid/documentation/markdown_template.rb
platformos-check-0.4.3 lib/platformos_check/platformos_liquid/documentation/markdown_template.rb
platformos-check-0.4.2 lib/platformos_check/platformos_liquid/documentation/markdown_template.rb
platformos-check-0.4.1 lib/platformos_check/platformos_liquid/documentation/markdown_template.rb
platformos-check-0.4.0 lib/platformos_check/platformos_liquid/documentation/markdown_template.rb
platformos-check-0.3.3 lib/platformos_check/platformos_liquid/documentation/markdown_template.rb
platformos-check-0.3.1 lib/platformos_check/platformos_liquid/documentation/markdown_template.rb
platformos-check-0.3.0 lib/platformos_check/platformos_liquid/documentation/markdown_template.rb
platformos-check-0.2.2 lib/platformos_check/platformos_liquid/documentation/markdown_template.rb
platformos-check-0.2.1 lib/platformos_check/platformos_liquid/documentation/markdown_template.rb