Class: Pageflow::PageType
- Inherits:
-
Object
- Object
- Pageflow::PageType
- Defined in:
- lib/pageflow/page_type.rb
Overview
Base class for defining page types.
Direct Known Subclasses
Defined Under Namespace
Modules: Engine
Class Method Summary collapse
-
.name(name = nil) ⇒ Object
Helper method to define the name of a subclassed page type.
Instance Method Summary collapse
-
#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.
-
#translation_key ⇒ Object
Name to display in editor.
-
#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.
102 103 104 105 106 107 |
# File 'lib/pageflow/page_type.rb', line 102 def self.name(name = nil) return super() unless name define_method :name do name end end |
Instance Method Details
#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.json.jbuilder'
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;
// ...
}
});
98 99 |
# File 'lib/pageflow/page_type.rb', line 98 def json_seed_template end |
#name ⇒ Object
Override to return a string in snake_case.
15 16 17 |
# File 'lib/pageflow/page_type.rb', line 15 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
65 66 67 |
# File 'lib/pageflow/page_type.rb', line 65 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 |
#translation_key ⇒ Object
Name to display in editor.
10 11 12 |
# File 'lib/pageflow/page_type.rb', line 10 def translation_key "pageflow.#{name}.page_type_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 %>
40 41 42 |
# File 'lib/pageflow/page_type.rb', line 40 def view_helpers [] end |