Class: Stationary::ApplicationController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/stationary/application_controller.rb

Instance Method Summary collapse

Instance Method Details

#showObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/stationary/application_controller.rb', line 16

def show
  # make sure filenames are any combination of letters, separated by zero or more hypens
  unless (segments = url_path.grep(/\A[a-z](?:-?[a-z]+)*\z/)) == url_path
    raise InvalidPath, "Path contains invalid characters #{url_path}"
  end

  path = Pathname.new(Stationary.configuration.root)
  segments.each { |s| path += s }

  if template = template_path(path)
    render :file => template.to_s
  else
    raise UnknownTemplate, "No template for #{path}"
  end
end