Class: HighVoltage::PageFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/high_voltage/page_finder.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(page_id) ⇒ PageFinder

Returns a new instance of PageFinder.



5
6
7
# File 'lib/high_voltage/page_finder.rb', line 5

def initialize(page_id)
  @page_id = page_id
end

Instance Method Details

#content_pathObject



21
22
23
# File 'lib/high_voltage/page_finder.rb', line 21

def content_path
  HighVoltage.content_path
end

#findObject

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



11
12
13
14
15
16
17
18
19
# File 'lib/high_voltage/page_finder.rb', line 11

def find
  path = clean_content_pathname.join(page_id.tr("\\", "/")).cleanpath.to_s
  if !path.start_with?("#{clean_content_pathname}/")
    raise InvalidPageIdError.new "Invalid page id: #{page_id}"
  end
  path
rescue ArgumentError
  raise InvalidPageIdError.new "Invalid page id: #{page_id}"
end