Method: Pageflow::FileType#initialize

Defined in:
lib/pageflow/file_type.rb

#initialize(options) ⇒ FileType

Create file type to be returned in PageType#file_types.

Examples:


Pageflow::FileType.new(model: 'Pageflow::Rainbow::File',
                       editor_partial: 'pageflow/rainbow/editor/files/file')

Parameters:

  • options (Hash)

Options Hash (options):

  • :model (ActiveRecord::Base, String)

    Required. Name of model representing the file. Model reference still works, but is deprecated

  • :partial (String)

    Optional. Path of a partial to include in json representations of the file both inside the editor and published entries.

  • :editor_partial (String)

    Optional. Path of a partial to include in json representations of the file inside the editor.

  • :collection_name (String)

    Optional. String to be used in routes. Defaults to ‘“pageflow_rainbow_file”` for model `Pageflow::Rainbow::File`.

  • :nested_file_types (Array<FileType>)

    Optional. Array of FileTypes allowed for nested files. Defaults to [].

  • :css_background_image_urls (#call)
  • :url_templates (#call)

    Optional. Callable returning a hash of url template strings indexed by their names.

  • :custom_attributes (Array<Symbol>)

    Optional. Array of strings containing attribute names that are custom to this file type



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/pageflow/file_type.rb', line 87

def initialize(options)
  @model_string_or_reference = options.fetch(:model)
  @partial = options[:partial]
  @editor_partial = options[:editor_partial]
  @collection_name_or_blank = options[:collection_name]
  @nested_file_types = options.fetch(:nested_file_types, [])
  @top_level_type = options.fetch(:top_level_type, false)
  @css_background_image_urls = options[:css_background_image_urls]
  @css_background_image_class_prefix = options[:css_background_image_class_prefix]
  @url_templates = options.fetch(:url_templates, -> { {} })
  @custom_attributes = convert_custom_attributes_option(options[:custom_attributes])
end