Sha256: d3497292f24ecf3f00da15236e3a7e02d3f44cddfc41f2ee1922ec7dfff8aedd

Contents?: true

Size: 821 Bytes

Versions: 1

Compression:

Stored size: 821 Bytes

Contents

require 'htmlentities'
require 'liquid'

module JekyllPagesApi
  # This is a hack to allow the module functions to be used
  class Filters
    include Liquid::StandardFilters

    def decode_html(str)
      html_decoder.decode(str)
    end

    # Slight tweak of
    # https://github.com/Shopify/liquid/blob/v2.6.1/lib/liquid/standardfilters.rb#L71-L74
    # to replace newlines with spaces.
    def condense(str)
      str.to_s.gsub(/\s+/m, ' '.freeze).strip
    end

    def text_only(str)
      # apply each filter in order
      [
        :strip_html,
        :condense,
        :decode_html,
        :strip_html,
        :condense
      ].reduce(str) do |result, filter|
        self.send(filter, result)
      end
    end


    private

    def html_decoder
      @html_decoder = HTMLEntities.new
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jekyll_pages_api-0.1.6 lib/jekyll_pages_api/filters.rb