Class: Scrapbook::PagesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/scrapbook/pages_controller.rb

Overview

TODO:

Document this controller

Handles requests for specific pages — either a full page load, or Turbo Drive request for navigation. Handles requests to display a specifc page — both for the Scrapbook application itself and the content within the user’s Scrapbook.

Instance Method Summary collapse

Instance Method Details

#rawObject

Handles translating the path to look up and generate the content from the Scrapbook. The content could be a template page, a template for a directory, the default content for directories without associated content pages, or just a raw file (like an image).



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/scrapbook/pages_controller.rb', line 32

def raw
  return head(:not_found) if (scrapbook = find_scrapbook).nil?

  pathname = calculate_pathname(scrapbook, params[:id])
  template = calculate_template

  if scrapbook_template_exists?(scrapbook, template)
    prepend_view_path(scrapbook.root)
    render template: template,
      locals: {scrapbook: scrapbook, pathname: pathname},
      layout: 'layouts/scrapbook/host_application'
  elsif pathname.directory?
    render '/pages',
      locals: {scrapbook: scrapbook, pathname: pathname},
      layout: 'layouts/scrapbook/host_application'
  elsif pathname.exist?
    render file: pathname
  else
    head :not_found
  end
end

#showObject

Displays the requested page for both full page loads, or Turbo Drive requests from page navigation.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/scrapbook/pages_controller.rb', line 16

def show
  return head(:not_found) if (scrapbook = find_scrapbook).nil?

  pathname = calculate_pathname(scrapbook, params[:id])

  if request.headers['Turbo-Frame']&.start_with?('path_')
    render partial: 'layouts/scrapbook/folder_listing',
      locals: {scrapbook: scrapbook, pathname: pathname}
  else
    render locals: {scrapbook: scrapbook, pathname: pathname}, formats: [:html]
  end
end