Sha256: db513ed2fee403952f0760635110cfb513af4201e23d6a3b494144953648c220

Contents?: true

Size: 780 Bytes

Versions: 1

Compression:

Stored size: 780 Bytes

Contents

module Munge
  module Routers
    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

1 entries across 1 versions & 1 rubygems

Version Path
munge-0.6.0 lib/munge/routers/remove_index_basename.rb