Skip to content

Commit

Permalink
Use Alchemy::Current.preview_page? in views
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdeyen committed Jan 24, 2024
1 parent bc4f79e commit f7cc9a6
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/controllers/alchemy/admin/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def tree
# Used by page preview iframe in Page#edit view.
#
def show
Current.preview_page = @page
# Setting the locale to pages language, so the page content has it's correct translations.
::I18n.locale = @page.language.locale
render(layout: Alchemy::Config.get(:admin_page_preview_layout) || "application")
Expand Down Expand Up @@ -407,6 +406,7 @@ def load_languages_and_layouts
end

def set_preview_mode
Current.preview_page = @page
@preview_mode = true
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/alchemy/_menubar.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% if !@preview_mode && @page && can?(:edit_content, @page) %>
<% if !Alchemy::Current.preview_page? && @page && can?(:edit_content, @page) %>
<alchemy-menubar>
<template>
<%= stylesheet_link_tag("alchemy/menubar") %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/alchemy/_preview_mode_code.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% if @preview_mode %>
<% if Alchemy::Current.preview_page? %>
<script type="text/javascript">
Alchemy = { locale: "<%= session[:alchemy_locale] %>" };
</script>
Expand Down
4 changes: 2 additions & 2 deletions lib/generators/alchemy/menus/templates/node.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<%% cache [node, @page, @preview_mode] do %>
<%% cache [node, @page, Alchemy::Current.preview_page?] do %>
<%%= content_tag :li, class: ['nav-item', node.children.any? ? 'dropdown' : nil].compact do %>
<%%= link_to_if node.url,
node.name,
@preview_mode ? 'javascript: void(0)' : node.url,
Alchemy::Current.preview_page? ? 'javascript: void(0)' : node.url,
class: ['nav-link', current_page?(node.url) ? 'active' : nil].compact,
title: node.title,
target: node.external? ? '_blank' : nil,
Expand Down
4 changes: 2 additions & 2 deletions lib/generators/alchemy/menus/templates/node.html.haml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
- cache [node, @page, @preview_mode] do
- cache [node, @page, Alchemy::Current.preview_page?] do
= content_tag :li,
class: ['nav-item', node.children.any? ? 'dropdown' : nil].compact do
= link_to_if node.url,
node.name,
@preview_mode ? 'javascript: void(0)' : node.url,
Alchemy::Current.preview_page? ? 'javascript: void(0)' : node.url,
class: ['nav-link', current_page?(node.url) ? 'active' : nil].compact,
title: node.title,
target: node.external? ? '_blank' : nil,
Expand Down
4 changes: 2 additions & 2 deletions lib/generators/alchemy/menus/templates/node.html.slim
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
- cache [node, @page, @preview_mode] do
- cache [node, @page, Alchemy::Current.preview_page?] do
= content_tag :li,
class: ['nav-item', node.children.any? ? 'dropdown' : nil].compact do
= link_to_if node.url,
node.name,
@preview_mode ? 'javascript: void(0)' : node.url,
Alchemy::Current.preview_page? ? 'javascript: void(0)' : node.url,
class: ['nav-link', current_page?(node.url) ? 'active' : nil].compact,
title: node.title,
target: node.external? ? '_blank' : nil,
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/alchemy/menus/templates/wrapper.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%% cache [menu, @page, @preview_mode] do %>
<%% cache [menu, @page, Alchemy::Current.preview_page?] do %>
<ul class="nav">
<%%= render partial: menu.to_partial_path,
collection: menu.children.includes(:page, :children),
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/alchemy/menus/templates/wrapper.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- cache [menu, @page, @preview_mode] do
- cache [menu, @page, Alchemy::Current.preview_page?] do
%ul.nav
= render partial: menu.to_partial_path,
collection: menu.children.includes(:page, :children),
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/alchemy/menus/templates/wrapper.html.slim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- cache [menu, @page, @preview_mode] do
- cache [menu, @page, Alchemy::Current.preview_page?] do
ul.nav
= render partial: menu.to_partial_path,
collection: menu.children.includes(:page, :children),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<%= content_tag :li, class: ['nav-item', node.children.any? ? 'dropdown' : nil].compact do %>
<%= link_to_if node.url,
node.name,
@preview_mode ? 'javascript: void(0)' : node.url,
Alchemy::Current.preview_page? ? 'javascript: void(0)' : node.url,
class: ['nav-link', current_page?(node.url) ? 'active' : nil].compact,
title: node.title,
target: node.external? ? '_blank' : nil,
Expand Down
4 changes: 2 additions & 2 deletions spec/dummy/app/views/alchemy/menus/main_menu/_node.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<% cache [node, @page, @preview_mode] do %>
<% cache [node, @page, Alchemy::Current.preview_page?] do %>
<%= content_tag :li, class: ['nav-item', node.children.any? ? 'dropdown' : nil].compact do %>
<%= link_to_if node.url,
node.name,
@preview_mode ? 'javascript: void(0)' : node.url,
Alchemy::Current.preview_page? ? 'javascript: void(0)' : node.url,
class: ['nav-link', current_page?(node.url) ? 'active' : nil].compact,
title: node.title,
target: node.external? ? '_blank' : nil,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% cache [menu, @page, @preview_mode] do %>
<% cache [menu, @page, Alchemy::Current.preview_page?] do %>
<ul class="nav">
<%= render partial: menu.to_partial_path,
collection: menu.children.includes(:page, :children),
Expand Down
1 change: 1 addition & 0 deletions spec/requests/alchemy/admin/pages_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ module Alchemy
it "should store page as current preview" do
expect(Current).to receive(:preview_page=).with(page)
get admin_page_path(page)
expect(Alchemy::Current.preview_page?).to be_truthy
end

it "should set the I18n locale to the pages language code" do
Expand Down

0 comments on commit f7cc9a6

Please sign in to comment.