Sha256: f6b3920291e84ce291d5e30d1f00c5a515f848c7169520e3e10a9401307e97ef

Contents?: true

Size: 787 Bytes

Versions: 8

Compression:

Stored size: 787 Bytes

Contents

module HighVoltage
  # A command for finding pages by id. This encapsulates the concepts of
  # mapping page names to file names.
  class PageFinder
    VALID_CHARACTERS = "a-zA-Z0-9~!@$%^&*()#`_+-=<>\"{}|[];',?".freeze

    def initialize(page_id)
      @page_id = page_id
    end

    # Produce a template path to the page, in a format understood by
    # `render :template => find`
    def find
      "#{content_path}#{clean_path}"
    end

    def content_path
      HighVoltage.content_path
    end

    protected

    # The raw page id passed in by the user
    attr_reader :page_id

    private

    def clean_path
      path = Pathname.new("/#{clean_id}")
      path.cleanpath.to_s[1..-1]
    end

    def clean_id
      @page_id.tr("^#{VALID_CHARACTERS}", '')
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
high_voltage-2.2.1 lib/high_voltage/page_finder.rb
high_voltage-2.2.0 lib/high_voltage/page_finder.rb
high_voltage-2.1.0 lib/high_voltage/page_finder.rb
high_voltage-2.0.0 lib/high_voltage/page_finder.rb
high_voltage-1.2.4 lib/high_voltage/page_finder.rb
high_voltage-1.2.3 lib/high_voltage/page_finder.rb
high_voltage-1.2.2 lib/high_voltage/page_finder.rb
high_voltage-1.2.1 lib/high_voltage/page_finder.rb