class Mintaka::PageFinder

A command for finding pages by id. This encapsulates the concepts of mapping page names to file names.

Constants

VALID_CHARACTERS

Attributes

page_id[R]

The raw page id passed in by the user

Public Class Methods

new(page_id) click to toggle source
# File lib/mintaka/page_finder.rb, line 7
def initialize(page_id)
  @page_id = page_id
end

Public Instance Methods

content_path() click to toggle source
# File lib/mintaka/page_finder.rb, line 17
def content_path
  Mintaka.content_path
end
find() click to toggle source

Produce a template path to the page, in a format understood by `render :template => find`

# File lib/mintaka/page_finder.rb, line 13
def find
  "#{content_path}#{clean_path}"
end

Private Instance Methods

clean_id() click to toggle source
# File lib/mintaka/page_finder.rb, line 37
def clean_id
  @page_id.tr("^#{VALID_CHARACTERS}", "").tap do |id|
    if invalid_page_id?(id)
      raise InvalidPageIdError.new "Invalid page id: #{@page_id}"
    end
  end
end
clean_path() click to toggle source
# File lib/mintaka/page_finder.rb, line 28
def clean_path
  path = Pathname.new("/#{clean_id}")
  path.cleanpath.to_s[1..-1].tap do |p|
    if p.blank?
      raise InvalidPageIdError.new "Invalid page id: #{@page_id}"
    end
  end
end
invalid_page_id?(id) click to toggle source
# File lib/mintaka/page_finder.rb, line 45
def invalid_page_id?(id)
  id.blank? || (id.first == ".")
end