Class: Pageflow::PageType
- Inherits:
-
Object
- Object
- Pageflow::PageType
- Defined in:
- lib/pageflow/page_type.rb
Overview
Base class for defining page types.
Class Method Summary collapse
-
.name(name = nil) ⇒ Object
Helper method to define the name of a subclassed page type.
Instance Method Summary collapse
-
#category_translation_key ⇒ Object
Translation key for the category the page type shall be displayed in inside the page type select menu.
-
#description_translation_key ⇒ Object
Translation key for a one line description of the page type.
-
#export_version ⇒ Object
Current plugin version.
-
#file_types ⇒ Object
File types to enable when this page type is registered..
-
#help_entry_translation_key ⇒ Object
Translation key for a markdown text fragment describing the page type.
-
#import_version_requirement ⇒ Object
Gets included in JSON file during export of an entry.
-
#json_seed_template ⇒ Object
View path of a template containing additional json to pass to the editor.
-
#name ⇒ Object
Override to return a string in snake_case.
-
#revision_components ⇒ Object
ActiveRecord models to be copied together with a revision.
-
#template_path ⇒ Object
View path to the html template.
-
#thumbnail_candidates ⇒ Object
A list of hashes used to determine a thumbnail for a page.
-
#translation_key ⇒ Object
Name to display in editor.
-
#translation_key_prefix ⇒ Object
Common prefix of all page type translation keys.
-
#view_helpers ⇒ Object
Rails helper modules to make available in the html template.
Class Method Details
.name(name = nil) ⇒ Object
Helper method to define the name of a subclassed page type.
222 223 224 225 226 227 228 |
# File 'lib/pageflow/page_type.rb', line 222 def self.name(name = nil) return super() unless name define_method :name do name end end |
Instance Method Details
#category_translation_key ⇒ Object
Translation key for the category the page type shall be displayed in inside the page type select menu.
21 22 23 |
# File 'lib/pageflow/page_type.rb', line 21 def category_translation_key "#{translation_key_prefix}.page_type_category_name" end |
#description_translation_key ⇒ Object
Translation key for a one line description of the page type.
15 16 17 |
# File 'lib/pageflow/page_type.rb', line 15 def description_translation_key "#{translation_key_prefix}.page_type_description" end |
#export_version ⇒ Object
Current plugin version
97 98 99 100 101 102 103 104 105 |
# File 'lib/pageflow/page_type.rb', line 97 def export_version "Pageflow::#{name.camelize}::VERSION".constantize rescue NameError begin "#{name.camelize}::VERSION".constantize rescue NameError raise "PageType #{name} needs to define export_version." end end |
#file_types ⇒ Object
File types to enable when this page type is registered..
92 93 94 |
# File 'lib/pageflow/page_type.rb', line 92 def file_types [] end |
#help_entry_translation_key ⇒ Object
Translation key for a markdown text fragment describing the page type.
27 28 29 |
# File 'lib/pageflow/page_type.rb', line 27 def help_entry_translation_key "#{translation_key_prefix}.help_entries.page_type" end |
#import_version_requirement ⇒ Object
Gets included in JSON file during export of an entry. The host application needs to compare this version with the version (above) for each page type before importing. Defaults to the plugins version but can be overwritten during registry of the page type, using the same notation as version requirements in the Gemfile.
112 113 114 |
# File 'lib/pageflow/page_type.rb', line 112 def import_version_requirement export_version end |
#json_seed_template ⇒ Object
View path of a template containing additional json to pass to the editor. The data is available in the javascript definition of the page type’s configuration editor. By default nothing is added.
In particular this can be used to make configuration options of page type engines available to the editor.
Example:
class RainbowPageType < Pageflow::PageType
name 'rainbow'
def json_seed_template
'pageflow/rainbow/page_type'
end
end
# page_types/pageflow/rainbow/page_type.json.jbuilder
json.colors ['red', 'blue', 'yellow']
# page_types/pageflow/rainbow/editor.js
pageflow.ConfigurationEditorView.register('rainbow', {
configure: function() {
var colors = this..pageType.colors;
// ...
}
});
219 |
# File 'lib/pageflow/page_type.rb', line 219 def json_seed_template; end |
#name ⇒ Object
Override to return a string in snake_case.
37 38 39 |
# File 'lib/pageflow/page_type.rb', line 37 def name raise(NotImplementedError, 'PageType subclass needs to define a name.') end |
#revision_components ⇒ Object
ActiveRecord models to be copied together with a revision.
This allows authors of PageTypes to attach models to the Pageflow revision mechanism.
Example:
class Rainbow < ActiveRecord::Base
include Pageflow::RevisionComponent
[...]
end
class RainbowPageType < Pageflow::PageType
name 'rainbow'
def revision_components
[Rainbow]
end
end
86 87 88 |
# File 'lib/pageflow/page_type.rb', line 86 def revision_components [] end |
#template_path ⇒ Object
View path to the html template.
5 6 7 |
# File 'lib/pageflow/page_type.rb', line 5 def template_path File.join('pageflow', name, 'page') end |
#thumbnail_candidates ⇒ Object
A list of hashes used to determine a thumbnail for a page. Each hash in the list must contain two keys: ‘attribute` and `file_collection`.
For each item, the given attribute is fetched from the page configuration and used to find a file from the given collection. ‘file_collection` must equal the collection_name of a registered FileType. The first file found is used as thumbnail.
[
{attribute: 'thumbnail_image_id', file_collection: 'image_files'},
{attribute: 'background_image_id', file_collection: 'image_files'}
]
It is possible to specify further conditions under which the candidate may be used via ‘if` or `unless` keys:
[
{
attribute: 'video_id',
file_collection: 'video_files',
if: {
attribute: 'background_type',
value: 'video',
}
},
{
attribute: 'image_id',
file_collection: 'image_files',
unless: {
attribute: 'background_type',
value: 'video',
}
}
]
The candidate will only be used if the given attribute has the given value.
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/pageflow/page_type.rb', line 157 def thumbnail_candidates [ { file_collection: 'image_files', attribute: 'thumbnail_image_id' }, { file_collection: 'image_files', attribute: 'background_image_id', unless: { attribute: 'background_type', value: 'video' } }, { file_collection: 'image_files', attribute: 'poster_image_id', if: { attribute: 'background_type', value: 'video' } }, { file_collection: 'video_files', attribute: 'video_file_id', if: { attribute: 'background_type', value: 'video' } } ] end |
#translation_key ⇒ Object
Name to display in editor.
10 11 12 |
# File 'lib/pageflow/page_type.rb', line 10 def translation_key "#{translation_key_prefix}.page_type_name" end |
#translation_key_prefix ⇒ Object
Common prefix of all page type translation keys.
32 33 34 |
# File 'lib/pageflow/page_type.rb', line 32 def translation_key_prefix "pageflow.#{name}" end |
#view_helpers ⇒ Object
Rails helper modules to make available in the html template.
Example:
module RainbowsHelper
def rainbow
tag(:rainbow)
end
end
class RainbowPageType < Pageflow::PageType
name 'rainbow'
def view_helpers
[RainbowsHelper]
end
end
# page_types/pageflow/rainbow/page.html.erb
<%= rainbow %>
62 63 64 |
# File 'lib/pageflow/page_type.rb', line 62 def view_helpers [] end |