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: ConfigView, FeatureLevelConfiguration, Permissions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_type_name = nil) ⇒ Configuration

Returns a new instance of Configuration.



384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
# File 'lib/pageflow/configuration.rb', line 384

def initialize(target_type_name = nil)
  @target_type_name = target_type_name

  @paperclip_attachments_version = 'v1'
  @paperclip_s3_root = 'main'

  @paperclip_s3_default_options = Defaults::PAPERCLIP_S3_DEFAULT_OPTIONS.dup

  @paperclip_direct_upload_options = lambda { |attachment|
    max_upload_size = 4_294_967_296 # max file size in bytes
    presigned_post_config = attachment.s3_bucket
                                      .presigned_post(key: attachment.path,
                                                      success_action_status: '201',
                                                      acl: 'public-read',
                                                      content_length_range: 0..max_upload_size)
    {
      url: presigned_post_config.url,
      fields: presigned_post_config.fields
    }
  }

  @zencoder_options = {}

  @encryption_options = {}

  @mailer_sender = '[email protected]'

  @features = Features.new
  @hooks = Hooks.new
  @quotas = Quotas.new
  @themes = Themes.new
  @entry_types = EntryTypes.new
  @entry_type_configs = {}
  @entry_type_configure_blocks = Hash.new { |h, k| h[k] = [] }
  @file_types = FileTypes.new
  @widget_types = WidgetTypes.new
  @file_importers = FileImporters.new
  @help_entries = HelpEntries.new
  @revision_components = RevisionComponents.new

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

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

  @transform_theme_customization_overrides = ->(overrides, _entry) { overrides }
  @transform_theme_customization_files = ->(files, _entry) { files }

  @confirm_encoding_jobs = false
  @default_published_until_duration_in_months = 12

  @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
  @available_share_providers = [:email, :facebook, :linked_in, :twitter, :telegram, :whats_app]

  @public_https_mode = :prevent

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

  @default_share_providers = @available_share_providers

  @authorize_user_deletion = lambda { |_user| true }

  @available_file_licenses = [
    :cc_by_4, :cc_by_sa_4, :cc_by_nc_4, :cc_by_nc_sa_4, :cc_by_nd_4, :cc_by_nc_nd_4
  ]

  @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



367
368
369
# File 'lib/pageflow/configuration.rb', line 367

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



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

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



272
273
274
# File 'lib/pageflow/configuration.rb', line 272

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:



262
263
264
# File 'lib/pageflow/configuration.rb', line 262

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



362
363
364
# File 'lib/pageflow/configuration.rb', line 362

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



350
351
352
# File 'lib/pageflow/configuration.rb', line 350

def authorize_user_deletion
  @authorize_user_deletion
end

#available_file_licensesObject

Array of values that the ‘license` attribute on files can take.



353
354
355
# File 'lib/pageflow/configuration.rb', line 353

def available_file_licenses
  @available_file_licenses
end

#available_localesObject

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

Since:

  • 0.7



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

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



301
302
303
# File 'lib/pageflow/configuration.rb', line 301

def available_public_locales
  @available_public_locales
end

#available_share_providersObject

Array of sharing providers which can be configured on site level. Defaults to ‘[:facebook, :twitter, :linked_in, :whats_app, :telegram, :email]`.

Since:

  • 14.1



306
307
308
# File 'lib/pageflow/configuration.rb', line 306

def available_share_providers
  @available_share_providers
end

#available_text_track_kindsObject

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



357
358
359
# File 'lib/pageflow/configuration.rb', line 357

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. Can either be set to a boolean or a lambda that is passed the file and returns a boolean. Defaults to false.



246
247
248
# File 'lib/pageflow/configuration.rb', line 246

def confirm_encoding_jobs
  @confirm_encoding_jobs
end

#css_rendered_thumbnail_stylesObject

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



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

def css_rendered_thumbnail_styles
  @css_rendered_thumbnail_styles
end

#default_author_meta_tagObject

Returns the value of attribute default_author_meta_tag.



327
328
329
# File 'lib/pageflow/configuration.rb', line 327

def default_author_meta_tag
  @default_author_meta_tag
end

#default_entry_type#call

Either a lambda or an object with a ‘call` method taking an Account as paramater and returing the entry type that shall be selected by default when creating a new entry.

Returns:

  • (#call)

Since:

  • 15.7



103
104
105
# File 'lib/pageflow/configuration.rb', line 103

def default_entry_type
  @default_entry_type
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



326
327
328
# File 'lib/pageflow/configuration.rb', line 326

def default_keywords_meta_tag
  @default_keywords_meta_tag
end

#default_published_until_duration_in_monthsObject

Controls default value of “published until” date field in editor publish entry view.

Since:

  • 16.1



252
253
254
# File 'lib/pageflow/configuration.rb', line 252

def default_published_until_duration_in_months
  @default_published_until_duration_in_months
end

#default_publisher_meta_tagObject

Returns the value of attribute default_publisher_meta_tag.



328
329
330
# File 'lib/pageflow/configuration.rb', line 328

def default_publisher_meta_tag
  @default_publisher_meta_tag
end

#default_share_providersObject

Share provider defaults.

Default share providers for new sites. Must be a subset or equal to ‘available_share_providers`

Since:

  • 14.1



335
336
337
# File 'lib/pageflow/configuration.rb', line 335

def default_share_providers
  @default_share_providers
end

#edit_lock_polling_intervalnumber

Defines the editor lock polling interval.

Returns:

  • (number)

Since:

  • 12.1



376
377
378
# File 'lib/pageflow/configuration.rb', line 376

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.



44
45
46
# File 'lib/pageflow/configuration.rb', line 44

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.



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

def editor_routing_constraint
  @editor_routing_constraint
end

#encryption_optionsObject

Contains key and iv used to encrypt string used by SymmetricEncryption



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

def encryption_options
  @encryption_options
end

#entry_embed_url_optionsObject

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



228
229
230
# File 'lib/pageflow/configuration.rb', line 228

def entry_embed_url_options
  @entry_embed_url_options
end

#entry_typesEntryTypes (readonly)

Register new types of entries.

Returns:

Since:

  • 15.1



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

def entry_types
  @entry_types
end

#featuresObject (readonly)

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

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

config.features.register('some_special_widget_type' do |config
  config.widget_types.register(Pageflow::SomeSpecial.widget_type)
end

Since:

  • 0.9



64
65
66
# File 'lib/pageflow/configuration.rb', line 64

def features
  @features
end

#file_importersfileImporters (readonly)

Used to register new file importers, to be used for importing files

Returns:

  • (fileImporters)


121
122
123
# File 'lib/pageflow/configuration.rb', line 121

def file_importers
  @file_importers
end

#file_typesFileTypes (readonly)

List of FileType instances. Can be registered globally or provided by page types.

Returns:



108
109
110
# File 'lib/pageflow/configuration.rb', line 108

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



134
135
136
# File 'lib/pageflow/configuration.rb', line 134

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 })


73
74
75
# File 'lib/pageflow/configuration.rb', line 73

def hooks
  @hooks
end

#mailer_senderObject

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



48
49
50
# File 'lib/pageflow/configuration.rb', line 48

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



382
383
384
# File 'lib/pageflow/configuration.rb', line 382

def news
  @news
end

#paperclip_attachments_versionObject

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



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

def paperclip_attachments_version
  @paperclip_attachments_version
end

#paperclip_direct_upload_optionsObject

Upload options provided to direct upload form. Defaults to S3 storage options. returns a hash with keys:

  • url: The URL to use as the action of the form

  • fields: A hash of fields that will be included in the direct upload form.

    This hash should include the signed POST policy, the access key ID and
    security token (if present), etc.
    These fields will be included as input elements of type 'hidden' on the form
    

# @since 14.0



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

def paperclip_direct_upload_options
  @paperclip_direct_upload_options
end

#paperclip_s3_default_optionsObject

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



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

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



18
19
20
# File 'lib/pageflow/configuration.rb', line 18

def paperclip_s3_root
  @paperclip_s3_root
end

#permissionsObject (readonly)

Sublayer for permissions related config.

Since:

  • 12.1



371
372
373
# File 'lib/pageflow/configuration.rb', line 371

def permissions
  @permissions
end

#public_entry_cache_control_headerString

Cache-Control header to set for published entries that have been published without a password. For password protected entries, cache control is always set to private to prevent caching authenticated responses in public caches like CDNs and serving them to unauthenticated users.

Can be wrapped in a ‘features.register` block to use different caching strategies for different entries or accounts.

Returns:

  • (String)

Since:

  • 16.1



209
210
211
# File 'lib/pageflow/configuration.rb', line 209

def public_entry_cache_control_header
  @public_entry_cache_control_header
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



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

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


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

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 Site 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 |site|
  {host: "#{site..name}.example.com"}
end


223
224
225
# File 'lib/pageflow/configuration.rb', line 223

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



319
320
321
# File 'lib/pageflow/configuration.rb', line 319

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)


82
83
84
# File 'lib/pageflow/configuration.rb', line 82

def quotas
  @quotas
end

#revision_componentsRevisionComponents (readonly)

Used to register components whose current state must be persisted as part of a revision.

Returns:



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

def revision_components
  @revision_components
end

#site_request_scopeObject

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

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

Example:

config.site_request_scope = lambda do |sites, request|
  sites.where(id: Pageflow::Account.find_by_name!(request.subdomain).default_site_id)
end


168
169
170
# File 'lib/pageflow/configuration.rb', line 168

def site_request_scope
  @site_request_scope
end

#themesThemes (readonly)

Additional themes can be registered to use custom css.

Example:

config.themes.register(:custom)

Returns:



91
92
93
# File 'lib/pageflow/configuration.rb', line 91

def themes
  @themes
end

#thumbnail_stylesObject

Paperclip style definitions of thumbnails used by Pageflow.

Returns:

  • Hash



138
139
140
# File 'lib/pageflow/configuration.rb', line 138

def thumbnail_styles
  @thumbnail_styles
end

#transform_theme_customization_filesObject

Either a lambda or an object with a ‘call` method taking a hash of theme customization files and an EntryAtRevision and returning a transformed hash of files. Can be used to filter files based on feature flags and other entry or account traits.



240
241
242
# File 'lib/pageflow/configuration.rb', line 240

def transform_theme_customization_files
  @transform_theme_customization_files
end

#transform_theme_customization_overridesObject

Either a lambda or an object with a ‘call` method taking a hash of theme option overrides and an EntryAtRevision and returning a transformed hash of overrides. Can be used to filter overrides based on feature flags and other entry or account traits.



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

def transform_theme_customization_overrides
  @transform_theme_customization_overrides
end

#widget_typesWidgetTypes (readonly)

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

Returns:



117
118
119
# File 'lib/pageflow/configuration.rb', line 117

def widget_types
  @widget_types
end

#zencoder_optionsObject

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



34
35
36
# File 'lib/pageflow/configuration.rb', line 34

def zencoder_options
  @zencoder_options
end

Instance Method Details

#confirm_encoding_jobs?(file) ⇒ Boolean

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.

Returns:

  • (Boolean)


536
537
538
539
540
541
542
# File 'lib/pageflow/configuration.rb', line 536

def confirm_encoding_jobs?(file)
  if confirm_encoding_jobs.respond_to?(:call)
    confirm_encoding_jobs.call(file)
  else
    confirm_encoding_jobs
  end
end

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



556
557
558
# File 'lib/pageflow/configuration.rb', line 556

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.



551
552
553
# File 'lib/pageflow/configuration.rb', line 551

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

#for_entry_type(type) {|entry_type_config| ... } ⇒ Object

Scope configuration to entries of a certain entry type or access entry type specific configuration. When building a configuration object for an entry, the passed block is only evaluated when types match. When building ‘Pageflow.config`, all `for_entry_type` blocks are evaluated.

Parameters:

Yield Parameters:

  • entry_type_config (EntryTypeConfiguration)

    - Instance of configuration class passed as ‘configuration` option during registration of entry type.

Since:

  • 15.1



519
520
521
522
523
# File 'lib/pageflow/configuration.rb', line 519

def for_entry_type(type)
  return if @target_type_name && @target_type_name != type.name

  yield get_entry_type_config(type)
end

#get_entry_type_config(type) ⇒ 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.



526
527
528
# File 'lib/pageflow/configuration.rb', line 526

def get_entry_type_config(type)
  @entry_type_configs[type.name] ||= type.configuration.new(self, type)
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.



531
532
533
# File 'lib/pageflow/configuration.rb', line 531

def lint!
  @features.lint!
end

#page_typesPageTypes

Provide backwards compatibility as long as paged entry type has not been extracted completely. Prefer accessing entry type specific config via #for_entry_type for new code.

Returns:

Since:

  • 0.7



486
487
488
# File 'lib/pageflow/configuration.rb', line 486

def page_types
  get_entry_type_config(PageflowPaged.entry_type).page_types
end

#paperclip_filesystem_rootObject

Deprecated.

Pageflow now supports direct uploads to S3 via signed post requests.

Please change your forms accordingly.



498
499
500
# File 'lib/pageflow/configuration.rb', line 498

def paperclip_filesystem_root
  ActiveSupport::Deprecation.warn('Pageflow::Configuration#paperclip_filesystem_root is deprecated.', caller)
end

#paperclip_filesystem_root=(_val) ⇒ Object



502
503
504
# File 'lib/pageflow/configuration.rb', line 502

def paperclip_filesystem_root=(_val)
  ActiveSupport::Deprecation.warn('Pageflow::Configuration#paperclip_filesystem_root is deprecated.', caller)
end

#plugin(plugin) ⇒ Object

Activate a plugin.

Parameters:

Since:

  • 0.7



476
477
478
# File 'lib/pageflow/configuration.rb', line 476

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

#register_page_type(page_type) ⇒ Object

Deprecated.

Use ‘config.page_types.register` instead.



491
492
493
494
# File 'lib/pageflow/configuration.rb', line 491

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

#site_url_options(site) ⇒ 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.



545
546
547
548
# File 'lib/pageflow/configuration.rb', line 545

def site_url_options(site)
  options = public_entry_url_options
  options.respond_to?(:call) ? options.call(site) : options
end