Module: Pageflow::EntriesControllerEnvHelper
- Defined in:
- lib/pageflow/entries_controller_env_helper.rb
Overview
A helper module that can be included in an entry type's frontend app to access the PublishedEntry.
Class Method Summary collapse
- .add_entry_info_to_env(env, entry:, mode: nil, embed: false, ui_locale: nil) ⇒ Object private
-
.get_embed_from_env(env = request.env) ⇒ Object
Returns
trueif the entry is being rendered as an embed. -
.get_entry_mode_from_env(env = request.env) ⇒ Object
Returns
:previewif a signed in user is currently viewing the entry via the preview feature. - .get_pageflow_hash(env) ⇒ Object private
-
.get_published_entry_from_env(env = request.env) ⇒ Object
Read the PublishedEntry from the request env.
-
.get_ui_locale_from_env(env = request.env) ⇒ Object
Returns the locale of the signed in user, i.e.
Class Method Details
.add_entry_info_to_env(env, entry:, mode: nil, embed: false, ui_locale: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
57 58 59 60 61 62 63 64 |
# File 'lib/pageflow/entries_controller_env_helper.rb', line 57 def self.add_entry_info_to_env(env, entry:, mode: nil, embed: false, ui_locale: nil) env['pageflow'] = { 'published_entry' => entry, 'entry_mode' => mode, 'embed' => , 'ui_locale' => ui_locale } end |
.get_embed_from_env(env = request.env) ⇒ Object
Returns true if the entry is being rendered as an embed. The
information will be placed in the request env by the Pageflow
engine before delegating to the entry type's frontend app.
Use EntriesControllerTestHelper to set up the request environment in controller tests.
37 38 39 |
# File 'lib/pageflow/entries_controller_env_helper.rb', line 37 def (env = request.env) EntriesControllerEnvHelper.get_pageflow_hash(env)['embed'] end |
.get_entry_mode_from_env(env = request.env) ⇒ Object
Returns :preview if a signed in user is currently viewing the
entry via the preview feature. Returns :published if the entry
is rendered on a publicly available site. The information will
be placed in the request env by the Pageflow engine before
delegating to the entry type's frontend app.
Use EntriesControllerTestHelper to set up the request environment in controller tests.
27 28 29 |
# File 'lib/pageflow/entries_controller_env_helper.rb', line 27 def get_entry_mode_from_env(env = request.env) EntriesControllerEnvHelper.get_pageflow_hash(env)['entry_mode'] end |
.get_pageflow_hash(env) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
67 68 69 70 71 72 |
# File 'lib/pageflow/entries_controller_env_helper.rb', line 67 def self.get_pageflow_hash(env) env.fetch('pageflow') do throw('Missing pageflow key in request env. Use Pageflow::EntriesControllerTestHelper ' \ 'to set it in controller tests.') end end |
.get_published_entry_from_env(env = request.env) ⇒ Object
Read the PublishedEntry from the request env. It will be placed there by the Pageflow engine before delegating to the entry type's frontend app.
Use EntriesControllerTestHelper to set up the request environment in controller tests.
15 16 17 |
# File 'lib/pageflow/entries_controller_env_helper.rb', line 15 def get_published_entry_from_env(env = request.env) EntriesControllerEnvHelper.get_pageflow_hash(env)['published_entry'] end |
.get_ui_locale_from_env(env = request.env) ⇒ Object
Returns the locale of the signed in user, i.e. the locale any
user interface displayed on top of the entry shall use. Returns
nil for published entries since those are not rendered for a
specific user. Entry types are expected to render the entry
itself in the locale of the entry, no matter which locale is
returned here.
Use EntriesControllerTestHelper to set up the request environment in controller tests.
52 53 54 |
# File 'lib/pageflow/entries_controller_env_helper.rb', line 52 def get_ui_locale_from_env(env = request.env) EntriesControllerEnvHelper.get_pageflow_hash(env)['ui_locale'] end |