Sha256: af997f5bad5f43fc73a2059fe660dd67a1089307f25cee4fe2e3a21ad7e59c5d

Contents?: true

Size: 1.77 KB

Versions: 11

Compression:

Stored size: 1.77 KB

Contents

# frozen_string_literal: true

require 'cgi'

module PlatformosCheck
  module PlatformosLiquid
    class SourceIndex
      class FilterEntry < BaseEntry
        def parameters
          @parameters ||= (hash['parameters'] || []).map { |hash| ParameterEntry.new(hash) }
        end

        def summary
          hash['summary']&.strip == 'returns' ? nil : hash['summary']
        end

        def description
          @descritpion = begin
            desc = hash['description']&.strip || ''
            desc = '' if desc == 'returns'
            if parameters.any?
              desc += "Parameters:"
              parameters.each { |p| desc += "\n- #{p.full_summary}" }
            end
            if hash['return_type']&.any?
              rt = hash['return_type'].first
              rt['description'] = nil if rt['description']&.strip == ''
              desc += "\n\nReturns:"
              desc += "\n- #{[rt['type'], rt['description']].compact.join(': ')}\n"
            end
            if hash['examples']
              desc += "\n\n---\n\n"
              hash['examples'].each_with_index do |e, i|
                example = e['raw_liquid'].gsub(/[\n]+/, "\n").strip.split('=>')
                input = example[0].strip
                output = example[1]&.strip
                desc += "\n  - Example #{i}:\n\n```liquid\n#{input}\n```"
                desc += "\n##\nOutput: #{output}" if output
              end
            end
          end
          desc
        end

        def aliases
          hash['aliases'] || []
        end

        def input_type
          @input_type ||= hash['syntax'].split(' | ')[0]
        end

        def platformos_documentation_url
          "#{PLATFORMOS_DOCUMENTATION_URL}/api-reference/liquid/filters/#{hash['name']}"
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
platformos-check-0.4.3 lib/platformos_check/platformos_liquid/source_index/filter_entry.rb
platformos-check-0.4.2 lib/platformos_check/platformos_liquid/source_index/filter_entry.rb
platformos-check-0.4.1 lib/platformos_check/platformos_liquid/source_index/filter_entry.rb
platformos-check-0.4.0 lib/platformos_check/platformos_liquid/source_index/filter_entry.rb
platformos-check-0.3.3 lib/platformos_check/platformos_liquid/source_index/filter_entry.rb
platformos-check-0.3.1 lib/platformos_check/platformos_liquid/source_index/filter_entry.rb
platformos-check-0.3.0 lib/platformos_check/platformos_liquid/source_index/filter_entry.rb
platformos-check-0.2.2 lib/platformos_check/platformos_liquid/source_index/filter_entry.rb
platformos-check-0.2.1 lib/platformos_check/platformos_liquid/source_index/filter_entry.rb
platformos-check-0.2.0 lib/platformos_check/platformos_liquid/source_index/filter_entry.rb
platformos-check-0.1.0 lib/platformos_check/platformos_liquid/source_index/filter_entry.rb