Class: Decidim::PageFinder

Inherits:
HighVoltage::PageFinder
  • Object
show all
Defined in:
lib/decidim/page_finder.rb

Overview

A custom implementation for HighVoltage so we can correctly find which page to render. We need this because we allow rendering pages with content from the database (with Decidim::Page) but also fallback to a template if it exists.

Constant Summary collapse

DECIDIM_PAGE_TEMPLATE =
"decidim_page"

Instance Method Summary collapse

Constructor Details

#initialize(page_id, organization) ⇒ PageFinder

Initializes the finder.

page_id - A String with the id or slug of the page to render. organization - A Decidim::Organization to look for pages in.



14
15
16
17
# File 'lib/decidim/page_finder.rb', line 14

def initialize(page_id, organization)
  @page_id = page_id
  @organization = organization
end

Instance Method Details

#pageObject

Finds a Decidim::Page by slug.

Returns a Decidim::Page or nil.



22
23
24
# File 'lib/decidim/page_finder.rb', line 22

def page
  @page ||= organization.static_pages.where(slug: page_id).first
end