Sha256: d761a25425cd63750a1c8a4b18ee3b27e1dc7f2ae22827cc9d7b720f659830d9

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module ThemeCheck
  module ShopifyLiquid
    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}"
        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://shopify.dev#{path})"
            else
              original_link
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
theme-check-1.13.0 lib/theme_check/shopify_liquid/documentation/markdown_template.rb
theme-check-1.12.1 lib/theme_check/shopify_liquid/documentation/markdown_template.rb
theme-check-1.12.0 lib/theme_check/shopify_liquid/documentation/markdown_template.rb