Sha256: 1ea24861d2b195be026689edd8cfd024b63476529a1f61262a0443480bbd5ccd

Contents?: true

Size: 779 Bytes

Versions: 2

Compression:

Stored size: 779 Bytes

Contents

module Munge
  module Router
    class RemoveIndexBasename
      def initialize(html_extensions:, index:)
        @html_extensions = html_extensions
        @index           = index
        @index_basename  = Munge::Util::Path.basename_no_extension(@index)
      end

      def type
        :route
      end

      def match?(initial_route, item)
        item_is_html?(item) && basename_is_index?(initial_route)
      end

      def call(initial_route, _item)
        Munge::Util::Path.dirname(initial_route)
      end

      private

      def item_is_html?(item)
        intersection = item.extensions & @html_extensions

        intersection.length > 0
      end

      def basename_is_index?(route)
        File.basename(route) == @index_basename
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
munge-0.5.0 lib/munge/routers/remove_index_basename.rb
munge-0.5.0.beta1 lib/munge/routers/remove_index_basename.rb