Class: Pageflow::PageType

Inherits:
Object
  • Object
show all
Defined in:
lib/pageflow/page_type.rb

Overview

Base class for defining page types.

Direct Known Subclasses

BuiltInPageType

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.name(name = nil) ⇒ Object

Helper method to define the name of a subclassed page type.



155
156
157
158
159
160
# File 'lib/pageflow/page_type.rb', line 155

def self.name(name = nil)
  return super() unless name
  define_method :name do
    name
  end
end

Instance Method Details

#category_translation_keyObject

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_keyObject

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

#file_typesObject

File types to enable when this page type is registered..



93
94
95
# File 'lib/pageflow/page_type.rb', line 93

def file_types
  []
end

#help_entry_translation_keyObject

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

#json_seed_templateObject

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.options.pageType.colors;
    // ...
  }
});


151
152
# File 'lib/pageflow/page_type.rb', line 151

def json_seed_template
end

#nameObject

Override to return a string in snake_case.

Raises:

  • (NotImplementedError)


37
38
39
# File 'lib/pageflow/page_type.rb', line 37

def name
  raise(NotImplementedError, 'PageType subclass needs to define a name.')
end

#revision_componentsObject

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


87
88
89
# File 'lib/pageflow/page_type.rb', line 87

def revision_components
  []
end

#template_pathObject

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_candidatesObject

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.

Examples:

Default return value


[
  {attribute: 'thumbnail_image_id', file_collection: 'image_files'},
  {attribute: 'background_image_id', file_collection: 'image_files'}
]


115
116
117
118
119
120
# File 'lib/pageflow/page_type.rb', line 115

def thumbnail_candidates
  [
    {attribute: 'thumbnail_image_id', file_collection: 'image_files'},
    {attribute: 'background_image_id', file_collection: 'image_files'}
  ]
end

#translation_keyObject

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_prefixObject

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_helpersObject

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