Class: Pressroom::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/pressroom/configuration.rb

Overview

Host-application settings. Every value has a safe default; the one deliberate exception is authenticate_with, which defaults to nil so that an unconfigured admin refuses access instead of granting it.

Constant Summary collapse

DEFAULT_SANITIZER_TAGS =
%w[b strong i em u s mark code br a].freeze
DEFAULT_SANITIZER_ATTRIBUTES =
%w[href target rel class].freeze
DEFAULT_TRANSLITERATOR =

Drops unknown characters instead of replacing them with "?", so that a fully non-Latin title yields an empty string the slug generator can detect and fall back from. See Pressroom::Transliteration for why this does not simply call I18n.transliterate.

lambda do |string, locale|
  Pressroom::Transliteration.call(string, locale)
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/pressroom/configuration.rb', line 27

def initialize
  @parent_controller       = "ApplicationController"
  @authenticate_with       = nil
  @author_class            = nil
  @author_name_method      = :name
  @comments                = false
  @transliteration_locale  = nil
  @transliterator          = DEFAULT_TRANSLITERATOR
  @sanitizer_tags          = DEFAULT_SANITIZER_TAGS.dup
  @sanitizer_attributes    = DEFAULT_SANITIZER_ATTRIBUTES.dup
  @unknown_block_strategy  = nil
  @admin_per_page          = 25
  @image_content_types     = %w[image/png image/jpeg image/gif image/webp]
  @max_image_bytes         = 5 * 1024 * 1024
end

Instance Attribute Details

#admin_per_pageObject

Returns the value of attribute admin_per_page.



19
20
21
# File 'lib/pressroom/configuration.rb', line 19

def admin_per_page
  @admin_per_page
end

#authenticate_with(&block) ⇒ Object

Reader and block-form writer in one, so both spellings work:

config.authenticate_with { redirect_to main_app.root_path unless ... }
config.authenticate_with = ->(*) { ... }


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

def authenticate_with(&block)
  @authenticate_with = block if block
  @authenticate_with
end

#author_classObject

Returns the value of attribute author_class.



19
20
21
# File 'lib/pressroom/configuration.rb', line 19

def author_class
  @author_class
end

#author_name_methodObject

Returns the value of attribute author_name_method.



19
20
21
# File 'lib/pressroom/configuration.rb', line 19

def author_name_method
  @author_name_method
end

#commentsObject

Returns the value of attribute comments.



19
20
21
# File 'lib/pressroom/configuration.rb', line 19

def comments
  @comments
end

#image_content_typesObject

Returns the value of attribute image_content_types.



19
20
21
# File 'lib/pressroom/configuration.rb', line 19

def image_content_types
  @image_content_types
end

#max_image_bytesObject

Returns the value of attribute max_image_bytes.



19
20
21
# File 'lib/pressroom/configuration.rb', line 19

def max_image_bytes
  @max_image_bytes
end

#parent_controllerObject

Returns the value of attribute parent_controller.



19
20
21
# File 'lib/pressroom/configuration.rb', line 19

def parent_controller
  @parent_controller
end

#sanitizer_attributesObject

Returns the value of attribute sanitizer_attributes.



19
20
21
# File 'lib/pressroom/configuration.rb', line 19

def sanitizer_attributes
  @sanitizer_attributes
end

#sanitizer_tagsObject

Returns the value of attribute sanitizer_tags.



19
20
21
# File 'lib/pressroom/configuration.rb', line 19

def sanitizer_tags
  @sanitizer_tags
end

#transliteration_localeObject

Returns the value of attribute transliteration_locale.



19
20
21
# File 'lib/pressroom/configuration.rb', line 19

def transliteration_locale
  @transliteration_locale
end

#transliteratorObject

Returns the value of attribute transliterator.



19
20
21
# File 'lib/pressroom/configuration.rb', line 19

def transliterator
  @transliterator
end

#unknown_block_strategyObject

Returns the value of attribute unknown_block_strategy.



19
20
21
# File 'lib/pressroom/configuration.rb', line 19

def unknown_block_strategy
  @unknown_block_strategy
end

Instance Method Details

#author_class_objectObject



60
61
62
# File 'lib/pressroom/configuration.rb', line 60

def author_class_object
  author_class&.constantize
end

#resolved_unknown_block_strategyObject

Explicit configuration wins; otherwise fail loudly where a developer will see it and degrade quietly where users would.



54
55
56
57
58
# File 'lib/pressroom/configuration.rb', line 54

def resolved_unknown_block_strategy
  return unknown_block_strategy if unknown_block_strategy

  defined?(Rails) && Rails.env.local? ? :raise : :skip
end