Skip to content

Commit

Permalink
Add or tweak documentation for the controllers
Browse files Browse the repository at this point in the history
Small improvements and additions to the documentation of the Scrapbook
controllers.
  • Loading branch information
bfad committed Jun 21, 2023
1 parent 45c1ca8 commit dd0ccfb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 0 additions & 1 deletion app/controllers/scrapbook/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module Scrapbook
# @private
#
# Base controller for collecting shared functionality for the Scaapbook App.
# placeholder
class ApplicationController < ActionController::Base
end
end
8 changes: 8 additions & 0 deletions app/controllers/scrapbook/empty_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

module Scrapbook
# This controller is used to specify view paths to check if a template exists.
#
# Scapbook views (Rails templates) exist outside the normal Rails views hierarchy. This is
# fine, we can prepend the view path for Scrapbook pages to our controller when we need to
# render Scrapbook pages. However, part of the process for to determine if we need to
# render a Scrapbook page is determining if the template exists. We want to know if the
# template exists before we prepend the path to the controller and render it. This empty
# controller allows us to call `EmptyController#template_exists?` to do just that after we
# prepend the view path to it.
class EmptyController < ApplicationController
self.view_paths = []
end
Expand Down
9 changes: 9 additions & 0 deletions app/controllers/scrapbook/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

module Scrapbook
# @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.
class PagesController < ApplicationController
self.view_paths = Engine.config.paths['app/views'].to_a

layout -> { false if request.headers.include?('Turbo-Frame') }

# Displays the requested page for both full page loads, or Turbo Drive requests from
# page navigation.
def show
return head(:not_found) if (scrapbook = find_scrapbook).nil?

Expand All @@ -20,6 +26,9 @@ def show
end
end

# 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).
def raw
return head(:not_found) if (scrapbook = find_scrapbook).nil?

Expand Down

0 comments on commit dd0ccfb

Please sign in to comment.