Sha256: 44183538beafdce8fe4ba6ed45217d6de4eea80b2457c750b444c4472aa54739

Contents?: true

Size: 725 Bytes

Versions: 2

Compression:

Stored size: 725 Bytes

Contents

module Munge
  module Router
    class AddIndexHtml
      def initialize(html_extensions:, index:)
        @html_extensions = html_extensions
        @index           = index
      end

      def type
        :filepath
      end

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

      def call(initial_route, _item)
        File.join(initial_route, @index)
      end

      private

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

        intersection.length > 0
      end

      def route_needs_extension?(route)
        basename = File.basename(route)

        !basename.include?(".")
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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