Class: DmCms::PagesController

Inherits:
ApplicationController show all
Includes:
ApplicationHelper, DmCore::LiquidHelper, DmCore::UrlHelper
Defined in:
app/controllers/dm_cms/pages_controller.rb

Instance Method Summary collapse

Instance Method Details

#coming_soonObject

Basically empty, as well as the view. But gets rendered by dm_core when the site is disabled




59
60
# File 'app/controllers/dm_cms/pages_controller.rb', line 59

def coming_soon
end

#indexObject




9
10
11
# File 'app/controllers/dm_cms/pages_controller.rb', line 9

def index
  redirect_to "/#{DmCore::Language.locale}/index"
end

#showObject




14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/dm_cms/pages_controller.rb', line 14

def show
  render(file: 'public/404.html', status: :not_found, layout: false) && return if invalid_slug?

  #--- make sure we have a valid locale for this site set
  DmCore::Language.locale = .verify_locale(params[:locale])
  
  #--- find the requested page, and if not found try to find the 'missing' page
  @current_page = CmsPage.friendly.find_by_slug(params[:slug])
  if @current_page.nil? || !can?(:read, @current_page)
    @current_page = CmsPage.friendly.find_by_slug('missing')
    render(file: 'public/404.html', status: :not_found, layout: false) && return if @current_page.nil? || !@current_page.is_published?
  end

  if @current_page. && !signed_in?
    redirect_to(main_app.new_user_session_url, alert: 'You must be signed into your account before you can access this page') and return
  end

  case @current_page.pagetype
  when 'content'
    status = (@current_page.slug == 'missing' ? 404 : 200)
    content_for :page_title, @current_page.title
    set_meta description: @current_page.summary, "og:description" => sanitize_text(markdown(@current_page.summary, safe: false))
    set_meta "og:image" => site_asset_media_url(@current_page.featured_image) if @current_page.featured_image.present?
    #--- if body=true, then use a minimal template to render, suitable for a minimal iFrame
    if params['body'] == 'true'
      render action: :show, layout: "cms_templates/minimal_page", status: status
    else
      render action: :show, layout: "cms_templates/#{@current_page.page_template}", status: status, formats: [:html]
    end
  when 'pagelink'
    redirect_to showpage_url(slug: @current_page.link)
  when 'controller/action'
    redirect_to "/#{DmCore::Language.locale}/#{@current_page.link}"
  when 'link'
    redirect_to @current_page.link
  when 'link-new-window'
    redirect_to @current_page.link
  when 'divider'
    render text: 'Not a real page'
  end
end