Sha256: d54e5ff037d7af026bf3144caf67e712c1ff839dcd86bb18876fb1ab59b40810

Contents?: true

Size: 688 Bytes

Versions: 5

Compression:

Stored size: 688 Bytes

Contents

module HighVoltage
  module Constraints
    # Routing constraint to validate request.path has a corresponding view
    class RootRoute
      def initialize
        @lookup_context = ActionView::LookupContext.new(
          Rails.configuration.paths["app/views"],
        )
      end

      def matches?(request)
        page_id = clean_page_path(request.path)
        template = File.join(content_path, page_id)
        lookup_context.exists? template
      end

      private

      attr_reader :lookup_context

      def clean_page_path(request_path)
        request_path.sub(/\.html$/, "")
      end

      def content_path
        HighVoltage.content_path
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
high_voltage-4.0.0 lib/high_voltage/constraints/root_route.rb
high_voltage-4.0.0.rc1 lib/high_voltage/constraints/root_route.rb
high_voltage-3.1.2 lib/high_voltage/constraints/root_route.rb
high_voltage-3.1.1 lib/high_voltage/constraints/root_route.rb
high_voltage-3.1.0 lib/high_voltage/constraints/root_route.rb