Class: Pressroom::Configuration
- Inherits:
-
Object
- Object
- Pressroom::Configuration
- 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
-
#admin_per_page ⇒ Object
Returns the value of attribute admin_per_page.
-
#authenticate_with(&block) ⇒ Object
Reader and block-form writer in one, so both spellings work:.
-
#author_class ⇒ Object
Returns the value of attribute author_class.
-
#author_name_method ⇒ Object
Returns the value of attribute author_name_method.
-
#comments ⇒ Object
Returns the value of attribute comments.
-
#image_content_types ⇒ Object
Returns the value of attribute image_content_types.
-
#max_image_bytes ⇒ Object
Returns the value of attribute max_image_bytes.
-
#parent_controller ⇒ Object
Returns the value of attribute parent_controller.
-
#sanitizer_attributes ⇒ Object
Returns the value of attribute sanitizer_attributes.
-
#sanitizer_tags ⇒ Object
Returns the value of attribute sanitizer_tags.
-
#transliteration_locale ⇒ Object
Returns the value of attribute transliteration_locale.
-
#transliterator ⇒ Object
Returns the value of attribute transliterator.
-
#unknown_block_strategy ⇒ Object
Returns the value of attribute unknown_block_strategy.
Instance Method Summary collapse
- #author_class_object ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#resolved_unknown_block_strategy ⇒ Object
Explicit configuration wins; otherwise fail loudly where a developer will see it and degrade quietly where users would.
Constructor Details
#initialize ⇒ Configuration
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_page ⇒ Object
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_class ⇒ Object
Returns the value of attribute author_class.
19 20 21 |
# File 'lib/pressroom/configuration.rb', line 19 def @author_class end |
#author_name_method ⇒ Object
Returns the value of attribute author_name_method.
19 20 21 |
# File 'lib/pressroom/configuration.rb', line 19 def @author_name_method end |
#comments ⇒ Object
Returns the value of attribute comments.
19 20 21 |
# File 'lib/pressroom/configuration.rb', line 19 def comments @comments end |
#image_content_types ⇒ Object
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_bytes ⇒ Object
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_controller ⇒ Object
Returns the value of attribute parent_controller.
19 20 21 |
# File 'lib/pressroom/configuration.rb', line 19 def parent_controller @parent_controller end |
#sanitizer_attributes ⇒ Object
Returns the value of attribute sanitizer_attributes.
19 20 21 |
# File 'lib/pressroom/configuration.rb', line 19 def sanitizer_attributes @sanitizer_attributes end |
#sanitizer_tags ⇒ Object
Returns the value of attribute sanitizer_tags.
19 20 21 |
# File 'lib/pressroom/configuration.rb', line 19 def @sanitizer_tags end |
#transliteration_locale ⇒ Object
Returns the value of attribute transliteration_locale.
19 20 21 |
# File 'lib/pressroom/configuration.rb', line 19 def transliteration_locale @transliteration_locale end |
#transliterator ⇒ Object
Returns the value of attribute transliterator.
19 20 21 |
# File 'lib/pressroom/configuration.rb', line 19 def transliterator @transliterator end |
#unknown_block_strategy ⇒ Object
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_object ⇒ Object
60 61 62 |
# File 'lib/pressroom/configuration.rb', line 60 def &.constantize end |
#resolved_unknown_block_strategy ⇒ Object
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 |