Sha256: 2d14f1957809af8ca4b102fa112a903b3f79f1bafb97e0ef362ce9f9ee1906db

Contents?: true

Size: 726 Bytes

Versions: 1

Compression:

Stored size: 726 Bytes

Contents

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

1 entries across 1 versions & 1 rubygems

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