Sha256: cdadff153d130b3c9977eeca4c379c4680d6e6b96556240868856777967c9d5e

Contents?: true

Size: 667 Bytes

Versions: 1

Compression:

Stored size: 667 Bytes

Contents

module HighVoltage
  module Constraints
    # Routing constraint to validate request.path has a corresponding view
    class RootRoute
      class << self
        def matches?(request)
          page_id = clean_page_path(request.path)
          pattern = file_pattern(page_id)

          Dir.glob(pattern).any?
        end

        private

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

        def file_pattern(page_id)
          "#{content_path}#{page_id}.html*"
        end

        def content_path
          Rails.root.join("app", "views", HighVoltage.content_path).to_s
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
high_voltage-3.0.0 lib/high_voltage/constraints/root_route.rb