Class: Pageflow::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/pageflow/configuration.rb,
lib/pageflow/configuration/defaults.rb,
lib/pageflow/configuration/permissions.rb

Overview

Options to be defined in the pageflow initializer of the main app.

Defined Under Namespace

Modules: Defaults Classes: FeatureLevelConfiguration, Permissions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
# File 'lib/pageflow/configuration.rb', line 312

def initialize
  @paperclip_attachments_version = 'v1'
  @paperclip_filesystem_root = Rails.public_path.join('system/uploads')
  @paperclip_s3_root = 'main'

  @paperclip_filesystem_default_options = Defaults::PAPERCLIP_FILESYSTEM_DEFAULT_OPTIONS.dup
  @paperclip_s3_default_options = Defaults::PAPERCLIP_S3_DEFAULT_OPTIONS.dup

  @zencoder_options = {}

  @mailer_sender = '[email protected]'

  @features = Features.new
  @hooks = Hooks.new
  @quotas = Quotas.new
  @themes = Themes.new
  @page_types = PageTypes.new
  @file_types = FileTypes.new(page_types)
  @widget_types = WidgetTypes.new
  @help_entries = HelpEntries.new

  @thumbnail_styles = Defaults::THUMBNAIL_STYLES.dup
  @css_rendered_thumbnail_styles = Defaults::CSS_RENDERED_THUMBNAIL_STYLES.dup

  @theming_request_scope = CnameThemingRequestScope.new
  @public_entry_request_scope = lambda { |entries, request| entries }
  @public_entry_redirect = ->(_entry, _request) { nil }
  @public_entry_url_options = Pageflow::ThemingsHelper::DEFAULT_PUBLIC_ENTRY_OPTIONS
  @entry_embed_url_options = {protocol: 'https'}

  @confirm_encoding_jobs = false

  @admin_resource_tabs = Pageflow::Admin::Tabs.new
  @admin_form_inputs = Pageflow::Admin::FormInputs.new
  @admin_attributes_table_rows = Pageflow::Admin::AttributesTableRows.new

  @available_locales = [:en, :de]
  @available_public_locales = PublicI18n.available_locales

  @public_https_mode = :prevent

  @default_keywords_meta_tag = 'pageflow, multimedia, reportage'
  @default_author_meta_tag = 'Pageflow'
  @default_publisher_meta_tag = 'Pageflow'

  @authorize_user_deletion = lambda { |_user| true }

  @available_text_track_kinds = [:captions, :subtitles, :descriptions]

  @allow_multiaccount_users = true

  @account_admin_menu_options = {}

  @permissions = Permissions.new

  @edit_lock_polling_interval = 15.seconds
end

Instance Attribute Details

#account_admin_menu_optionsObject

Options hash for account admin menu. Options from config precede defaults.

Since:

  • 12.1



295
296
297
# File 'lib/pageflow/configuration.rb', line 295

def 
  @account_admin_menu_options
end

#admin_attributes_table_rowsAdmin::AttributesTableRows (readonly)

Insert additional rows into admin attributes tables.

Examples:


config.admin_attributes_table_rows.register(:entry, :custom)
config.admin_attributes_table_rows.register(:entry, :my_attribute, after: :title)
config.admin_attributes_table_rows.register(:entry, :some_attribute, before: :updated_at)

Custom content


config.admin_attributes_table_rows.register(:entry, :custom) do |entry|
  span(entry.custom_attribute)
end

Returns:

Since:

  • 12.2



233
234
235
# File 'lib/pageflow/configuration.rb', line 233

def admin_attributes_table_rows
  @admin_attributes_table_rows
end

#admin_form_inputsAdmin::FormInputs (readonly)

Add custom form fields to admin forms.

Examples:


config.admin_form_inputs.register(:entry, :custom_field) do

Returns:

Since:

  • 0.9



215
216
217
# File 'lib/pageflow/configuration.rb', line 215

def admin_form_inputs
  @admin_form_inputs
end

#admin_resource_tabsAdmin::Tabs (readonly)

Used by Pageflow extensions to provide new tabs to be displayed in the admin.

Examples:


config.admin_resource_tabs.register(:entry, Admin::CustomTab)

Returns:



205
206
207
# File 'lib/pageflow/configuration.rb', line 205

def admin_resource_tabs
  @admin_resource_tabs
end

#allow_multiaccount_usersObject

Allow one user to be member of multiple accounts. Defaults to true.

Since:

  • 12.1



290
291
292
# File 'lib/pageflow/configuration.rb', line 290

def allow_multiaccount_users
  @allow_multiaccount_users
end

#authorize_user_deletionObject

Whether a user can be deleted.

Examples:


config.authorize_user_deletion =
  lambda do |user_to_delete|
    if user_to_delete.accounts.all? { || .users.size > 1 }
      true
    else
      'Last user on account. Permission denied'
    end
  end

Since:

  • 0.11



281
282
283
# File 'lib/pageflow/configuration.rb', line 281

def authorize_user_deletion
  @authorize_user_deletion
end

#available_localesObject

Array of locales which can be chosen as interface language by a user. Defaults to ‘[:en, :de]`.

Since:

  • 0.7



238
239
240
# File 'lib/pageflow/configuration.rb', line 238

def available_locales
  @available_locales
end

#available_public_localesObject

Array of locales which can be chosen as interface language for an entry. Defaults to the locales supported by the ‘pageflow-public-i18n` gem.

Since:

  • 0.10



244
245
246
# File 'lib/pageflow/configuration.rb', line 244

def available_public_locales
  @available_public_locales
end

#available_text_track_kindsObject (readonly)

Array of values that the ‘kind` attribute on text tracks can take. Defaults to `[:captions, :subtitles, :descriptions]`.



285
286
287
# File 'lib/pageflow/configuration.rb', line 285

def available_text_track_kinds
  @available_text_track_kinds
end

#confirm_encoding_jobsObject

Submit video/audio encoding jobs only after the user has explicitly confirmed in the editor. Defaults to false.



195
196
197
# File 'lib/pageflow/configuration.rb', line 195

def confirm_encoding_jobs
  @confirm_encoding_jobs
end

#css_rendered_thumbnail_stylesObject

Names of Paperclip styles that shall be rendered into entry specific stylesheets.



119
120
121
# File 'lib/pageflow/configuration.rb', line 119

def css_rendered_thumbnail_styles
  @css_rendered_thumbnail_styles
end

#default_author_meta_tagObject

Returns the value of attribute default_author_meta_tag.



265
266
267
# File 'lib/pageflow/configuration.rb', line 265

def default_author_meta_tag
  @default_author_meta_tag
end

#default_keywords_meta_tagObject

Meta tag defaults.

These defaults will be included in the page <head> unless overriden by the Entry. If you set these to nil or "" the meta tag won’t be included.

Since:

  • 0.10



264
265
266
# File 'lib/pageflow/configuration.rb', line 264

def default_keywords_meta_tag
  @default_keywords_meta_tag
end

#default_publisher_meta_tagObject

Returns the value of attribute default_publisher_meta_tag.



266
267
268
# File 'lib/pageflow/configuration.rb', line 266

def default_publisher_meta_tag
  @default_publisher_meta_tag
end

#edit_lock_polling_intervalnumber

Defines the editor lock polling interval.

Returns:

  • (number)

Since:

  • 12.1



304
305
306
# File 'lib/pageflow/configuration.rb', line 304

def edit_lock_polling_interval
  @edit_lock_polling_interval
end

#editor_route_constraintObject

A constraint used by the pageflow engine to restrict access to the editor related HTTP end points. This can be used to ensure the editor is only accessable via a certain host when different CNAMES are used to access the public end points of pageflow.



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

def editor_route_constraint
  @editor_route_constraint
end

#editor_routing_constraintObject

Either a lambda or an object with a ‘match?` method, to restrict access to the editor routes defined by Pageflow.

This can be used if published entries shall be available under different CNAMES but the admin and the editor shall only be accessible via one official url.



127
128
129
# File 'lib/pageflow/configuration.rb', line 127

def editor_routing_constraint
  @editor_routing_constraint
end

#entry_embed_url_optionsObject

Either a lambda or an object with a ‘call` method taking a Theming as paramater and returing a hash of options used to construct the embed url of a published entry.



191
192
193
# File 'lib/pageflow/configuration.rb', line 191

def entry_embed_url_options
  @entry_embed_url_options
end

#featuresObject (readonly)

Extend the configuration based on feature flags set for accounts or entries.

Make a page type only available if a feature flag is set on the entry or its account

config.features.register('some_special_page_type' do |config
  config.page_types.register(Pageflow::SomeSpecial.page_type)
end

Since:

  • 0.9



57
58
59
# File 'lib/pageflow/configuration.rb', line 57

def features
  @features
end

#file_typesFileTypes (readonly)

List of FileType instances provided by page types.

Returns:



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

def file_types
  @file_types
end

#help_entriesHelpEntries (readonly)

Used to add new sections to the help dialog displayed in the editor.

Returns:

Since:

  • 0.7



110
111
112
# File 'lib/pageflow/configuration.rb', line 110

def help_entries
  @help_entries
end

#hooksObject (readonly)

Subscribe to hooks in order to be notified of events. Any object with a call method can be a subscriber

Example:

config.hooks.subscribe(:submit_file, -> { do_something })


66
67
68
# File 'lib/pageflow/configuration.rb', line 66

def hooks
  @hooks
end

#mailer_senderObject

The email address to use as from header in invitation mails to new users



41
42
43
# File 'lib/pageflow/configuration.rb', line 41

def mailer_sender
  @mailer_sender
end

#news#item

News collection to add items to. Can be used to integrate Pageflow with Krant (see github.com/codevise/krant).

Returns:

  • (#item)

Since:

  • 12.2



310
311
312
# File 'lib/pageflow/configuration.rb', line 310

def news
  @news
end

#page_typesPageTypes (readonly)

Register new types of pages.

Returns:

Since:

  • 0.9



89
90
91
# File 'lib/pageflow/configuration.rb', line 89

def page_types
  @page_types
end

#paperclip_attachments_versionObject

String to interpolate into paths of files generated by paperclip preprocessors. This allows to refresh cdn caches after reprocessing attachments.



15
16
17
# File 'lib/pageflow/configuration.rb', line 15

def paperclip_attachments_version
  @paperclip_attachments_version
end

#paperclip_filesystem_default_optionsObject

Default options for paperclip attachments which are supposed to use filesystem storage.



6
7
8
# File 'lib/pageflow/configuration.rb', line 6

def paperclip_filesystem_default_options
  @paperclip_filesystem_default_options
end

#paperclip_filesystem_rootObject

Path to the location in the filesystem where attachments shall be stored. The value of this option is available via the pageflow_filesystem_root paperclip interpolation.



20
21
22
# File 'lib/pageflow/configuration.rb', line 20

def paperclip_filesystem_root
  @paperclip_filesystem_root
end

#paperclip_s3_default_optionsObject

Default options for paperclip attachments which are supposed to use s3 storage.



10
11
12
# File 'lib/pageflow/configuration.rb', line 10

def paperclip_s3_default_options
  @paperclip_s3_default_options
end

#paperclip_s3_rootObject

Root folder in S3 bucket to store files in. Can be used to separate files of multiple development instances in a shared development S3 bucket.

Since:

  • 13.0



27
28
29
# File 'lib/pageflow/configuration.rb', line 27

def paperclip_s3_root
  @paperclip_s3_root
end

#permissionsObject (readonly)

Sublayer for permissions related config.

Since:

  • 12.1



299
300
301
# File 'lib/pageflow/configuration.rb', line 299

def permissions
  @permissions
end

#public_entry_redirectObject

Either a lambda or an object with a ‘call` method taking an Entry record and an ActionDispatch::Request object and returning `nil` or a path to redirect to. Can be used in conjuction with PrimaryDomainEntryRedirect to make sure entries are accessed via their account’s configured cname.

Since:

  • 12.4



172
173
174
# File 'lib/pageflow/configuration.rb', line 172

def public_entry_redirect
  @public_entry_redirect
end

#public_entry_request_scopeObject

Either a lambda or an object with a ‘call` method taking two parameters: An `ActiveRecord` scope of `Pageflow::Entry` records and an `ActionDispatch::Request` object. Has to return the scope in which to find entries.

Used by all public actions that display entries to restrict the available entries by hostname or other request attributes.

Use #public_entry_url_options to make sure urls of published entries conform twith the restrictions.

Example:

# Only make entries of one account available under <account.name>.example.com
config.public_entry_request_scope = lambda do |entries, request|
  entries.includes(:account).where(pageflow_accounts: {name: request.subdomain})
end


163
164
165
# File 'lib/pageflow/configuration.rb', line 163

def public_entry_request_scope
  @public_entry_request_scope
end

#public_entry_url_optionsObject

Either a lambda or an object with a ‘call` method taking a Theming as paramater and returing a hash of options used to construct the url of a published entry.

Can be used to change the host of the url under which entries are available.

Example:

config.public_entry_url_options = lambda do |theming|
  {host: "#{theming..name}.example.com"}
end


186
187
188
# File 'lib/pageflow/configuration.rb', line 186

def public_entry_url_options
  @public_entry_url_options
end

#public_https_modeObject

How to handle https requests for URLs which will have assets in the page. If you wish to serve all assets over http and prevent mixed-content warnings, you can force a redirect to http. The inverse is also true: you can force a redirect to https for all http requests.

Examples:


config.public_https_mode = :prevent (default) # => redirects https to http
config.public_https_mode = :enforce # => redirects http to https
config.public_https_mode = :ignore # => does nothing

Since:

  • 0.9



257
258
259
# File 'lib/pageflow/configuration.rb', line 257

def public_https_mode
  @public_https_mode
end

#quotasObject

Limit the use of certain resources. Any object implementing the interface of Pageflow::Quota can be registered.

Example:

config.quotas.register(:users, UserQuota)


75
76
77
# File 'lib/pageflow/configuration.rb', line 75

def quotas
  @quotas
end

#themesThemes (readonly)

Additional themes can be registered to use custom css.

Example:

config.themes.register(:custom)

Returns:



84
85
86
# File 'lib/pageflow/configuration.rb', line 84

def themes
  @themes
end

#theming_request_scopeObject

Either a lambda or an object with a ‘call` method taking two parameters: An `ActiveRecord` scope of Theming records and an ActionDispatch::Request object. Has to return the scope in which to find themings.

Defaults to Pageflow::CnameThemingRequestScope which finds themings based on the request subdomain. Can be used to alter the logic of finding a theming whose home_url to redirect to when visiting the public root path.

Example:

config.theming_request_scope = lambda do |themings, request|
  themings.where(id: Pageflow::Account.find_by_name!(request.subdomain).default_theming_id)
end


144
145
146
# File 'lib/pageflow/configuration.rb', line 144

def theming_request_scope
  @theming_request_scope
end

#thumbnail_stylesObject

Paperclip style definitions of thumbnails used by Pageflow.

Returns:

  • Hash



114
115
116
# File 'lib/pageflow/configuration.rb', line 114

def thumbnail_styles
  @thumbnail_styles
end

#widget_typesWidgetTypes (readonly)

Used to register new types of widgets to be displayed in entries.

Returns:



97
98
99
# File 'lib/pageflow/configuration.rb', line 97

def widget_types
  @widget_types
end

#zencoder_optionsObject

Refer to the pageflow initializer template for a list of supported options.



31
32
33
# File 'lib/pageflow/configuration.rb', line 31

def zencoder_options
  @zencoder_options
end

Instance Method Details

#enable_all_featuresObject

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.



405
406
407
# File 'lib/pageflow/configuration.rb', line 405

def enable_all_features
  features.enable_all(FeatureLevelConfiguration.new(self))
end

#enable_features(names) ⇒ 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.



400
401
402
# File 'lib/pageflow/configuration.rb', line 400

def enable_features(names)
  features.enable(names, FeatureLevelConfiguration.new(self))
end

#lint!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.



389
390
391
# File 'lib/pageflow/configuration.rb', line 389

def lint!
  @features.lint!
end

#plugin(plugin) ⇒ Object

Activate a plugin.

Parameters:

Since:

  • 0.7



374
375
376
# File 'lib/pageflow/configuration.rb', line 374

def plugin(plugin)
  plugin.configure(self)
end

#register_page_type(page_type) ⇒ Object

Deprecated.

Use ‘config.page_types.register` instead.



379
380
381
382
# File 'lib/pageflow/configuration.rb', line 379

def register_page_type(page_type)
  ActiveSupport::Deprecation.warn('Pageflow::Configuration#register_page_type is deprecated. Use config.page_types.register instead.', caller)
  page_types.register(page_type)
end

#revision_componentsObject



384
385
386
# File 'lib/pageflow/configuration.rb', line 384

def revision_components
  page_types.map(&:revision_components).flatten.uniq
end

#theming_url_options(theming) ⇒ 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.



394
395
396
397
# File 'lib/pageflow/configuration.rb', line 394

def theming_url_options(theming)
  options = public_entry_url_options
  options.respond_to?(:call) ? options.call(theming) : options
end