Class: Pageflow::FileType
- Inherits:
-
Object
- Object
- Pageflow::FileType
- Defined in:
- lib/pageflow/file_type.rb
Overview
Describes a type of file that can be managed in the editor and used in revisions.
Defined Under Namespace
Classes: NotFoundError
Instance Attribute Summary collapse
-
#css_background_image_urls ⇒ #call
readonly
Callable that receives a file record and returns a hash of one of the following forms:.
- #custom_attributes ⇒ Object readonly private
-
#editor_partial ⇒ String
readonly
Path of a partial rendered in the json representation of the file inside the editor.
-
#nested_file_types ⇒ Array<FileType>
readonly
File types that are allowed to be nested inside the file.
-
#partial ⇒ String
readonly
Path of a partial rendered in the json representation of the file in both the editor and published entries.
-
#top_level_type ⇒ Boolean
readonly
Is this file type used in situations where it is not nested into another file type?.
-
#url_templates ⇒ #call
readonly
Callable that returns a hash of url template strings indexed by their names.
Instance Method Summary collapse
-
#collection_name ⇒ String
Underscored plural name for usage in routes.
- #css_background_image_class_prefix ⇒ Object private
- #css_background_image_urls_for(file, **options) ⇒ Object
- #i18n_key ⇒ Object private
-
#initialize(options) ⇒ FileType
constructor
Create file type to be returned in PageType#file_types.
-
#model ⇒ ActiveRecord::Model
ActiveRecord model that represents the files of this type.
- #param_key ⇒ Object (also: #short_name) private
- #type_name ⇒ Object private
Constructor Details
#initialize(options) ⇒ FileType
Create file type to be returned in PageType#file_types.
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/pageflow/file_type.rb', line 87 def initialize() @model_string_or_reference = .fetch(:model) @partial = [:partial] @editor_partial = [:editor_partial] @collection_name_or_blank = [:collection_name] @nested_file_types = .fetch(:nested_file_types, []) @top_level_type = .fetch(:top_level_type, false) @css_background_image_urls = [:css_background_image_urls] @css_background_image_class_prefix = [:css_background_image_class_prefix] @url_templates = .fetch(:url_templates, -> { {} }) @custom_attributes = convert_custom_attributes_option([:custom_attributes]) end |
Instance Attribute Details
#css_background_image_urls ⇒ #call (readonly)
Callable that receives a file record and returns a hash of one of the following forms:
{
poster: "url/of/image"
}
where ‘poster` is an arbitrary css class infix. Use `default` to skip the infix in the generated css class name. Or
{
poster: {
desktop: "desktop/url/of/image",
mobile: "mobile/url/of/image"
}
}
to provide different urls for the two media breakpoints.
47 48 49 |
# File 'lib/pageflow/file_type.rb', line 47 def css_background_image_urls @css_background_image_urls end |
#custom_attributes ⇒ Object (readonly)
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.
55 56 57 |
# File 'lib/pageflow/file_type.rb', line 55 def custom_attributes @custom_attributes end |
#editor_partial ⇒ String (readonly)
Path of a partial rendered in the json representation of the file inside the editor.
16 17 18 |
# File 'lib/pageflow/file_type.rb', line 16 def editor_partial @editor_partial end |
#nested_file_types ⇒ Array<FileType> (readonly)
File types that are allowed to be nested inside the file
20 21 22 |
# File 'lib/pageflow/file_type.rb', line 20 def nested_file_types @nested_file_types end |
#partial ⇒ String (readonly)
Path of a partial rendered in the json representation of the file in both the editor and published entries
11 12 13 |
# File 'lib/pageflow/file_type.rb', line 11 def partial @partial end |
#top_level_type ⇒ Boolean (readonly)
Is this file type used in situations where it is not nested into another file type?
25 26 27 |
# File 'lib/pageflow/file_type.rb', line 25 def top_level_type @top_level_type end |
#url_templates ⇒ #call (readonly)
Callable that returns a hash of url template strings indexed by their names.
52 53 54 |
# File 'lib/pageflow/file_type.rb', line 52 def url_templates @url_templates end |
Instance Method Details
#collection_name ⇒ String
Underscored plural name for usage in routes.
113 114 115 116 117 118 119 |
# File 'lib/pageflow/file_type.rb', line 113 def collection_name if @collection_name_or_blank.blank? model.model_name.plural else @collection_name_or_blank end end |
#css_background_image_class_prefix ⇒ 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.
122 123 124 |
# File 'lib/pageflow/file_type.rb', line 122 def css_background_image_class_prefix @css_background_image_class_prefix || model.model_name.singular end |
#css_background_image_urls_for(file, **options) ⇒ Object
126 127 128 129 130 131 132 |
# File 'lib/pageflow/file_type.rb', line 126 def css_background_image_urls_for(file, **) if call_arity(css_background_image_urls) == 1 css_background_image_urls.call(file) else css_background_image_urls.call(file, **) end end |
#i18n_key ⇒ 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.
148 149 150 |
# File 'lib/pageflow/file_type.rb', line 148 def i18n_key model.model_name.i18n_key end |
#model ⇒ ActiveRecord::Model
ActiveRecord model that represents the files of this type.
102 103 104 105 106 107 108 109 |
# File 'lib/pageflow/file_type.rb', line 102 def model @model ||= if @model_string_or_reference.is_a?(String) @model_string_or_reference.constantize else @model_string_or_reference end end |
#param_key ⇒ Object Also known as: short_name
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.
135 136 137 |
# File 'lib/pageflow/file_type.rb', line 135 def param_key model.model_name.param_key.to_sym end |
#type_name ⇒ 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.
143 144 145 |
# File 'lib/pageflow/file_type.rb', line 143 def type_name model.name end |