Class: Pageflow::BuiltInPageType

Inherits:
PageType
  • Object
show all
Defined in:
lib/pageflow/built_in_page_type.rb

Overview

Definition of page type located inside the Pageflow gem.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PageType

#category_translation_key, #description_translation_key, #json_seed_template, name, #revision_components, #view_helpers

Constructor Details

#initialize(name, options = {}) ⇒ BuiltInPageType

Returns a new instance of BuiltInPageType.



6
7
8
9
10
# File 'lib/pageflow/built_in_page_type.rb', line 6

def initialize(name, options = {})
  @name = name.to_s
  @file_type_models = options.fetch(:file_type_models, [])
  @thumbnail_candidates = options.fetch(:thumbnail_candidates, nil)
end

Instance Attribute Details

#file_type_modelsObject (readonly)

Returns the value of attribute file_type_models.



4
5
6
# File 'lib/pageflow/built_in_page_type.rb', line 4

def file_type_models
  @file_type_models
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/pageflow/built_in_page_type.rb', line 4

def name
  @name
end

Class Method Details

.audioObject

Factory methods to decouple Pageflow initializers from concrete page type classes, so we might decide later to create a VideoPageType subclass etc.



47
48
49
# File 'lib/pageflow/built_in_page_type.rb', line 47

def self.audio
  new('audio', file_type_models: ['Pageflow::ImageFile', 'Pageflow::AudioFile'])
end

.audio_loopObject



51
52
53
# File 'lib/pageflow/built_in_page_type.rb', line 51

def self.audio_loop
  new('audio_loop', file_type_models: ['Pageflow::ImageFile', 'Pageflow::AudioFile'])
end

.background_imageObject



55
56
57
# File 'lib/pageflow/built_in_page_type.rb', line 55

def self.background_image
  new('background_image', file_type_models: ['Pageflow::ImageFile'])
end

.background_videoObject



59
60
61
62
63
# File 'lib/pageflow/built_in_page_type.rb', line 59

def self.background_video
  new('background_video',
      file_type_models: ['Pageflow::ImageFile', 'Pageflow::VideoFile'],
      thumbnail_candidates: video_thumbnail_candidates)
end

.videoObject



65
66
67
68
69
# File 'lib/pageflow/built_in_page_type.rb', line 65

def self.video
  new('video',
      file_type_models: ['Pageflow::ImageFile', 'Pageflow::VideoFile'],
      thumbnail_candidates: video_thumbnail_candidates)
end

.video_thumbnail_candidatesObject



71
72
73
74
75
76
77
# File 'lib/pageflow/built_in_page_type.rb', line 71

def self.video_thumbnail_candidates
  [
    {file_collection: 'image_files', attribute: 'thumbnail_image_id'},
    {file_collection: 'image_files', attribute: 'poster_image_id'},
    {file_collection: 'video_files', attribute: 'video_file_id'}
  ]
end

Instance Method Details

#file_typesObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/pageflow/built_in_page_type.rb', line 12

def file_types
  @file_types ||= file_type_models.map do |model_name|
    model = model_name.constantize
    base_name = model_name.underscore.split('/').last

    FileType.new(model: model,
                 editor_partial: "pageflow/editor/#{base_name.pluralize}/#{base_name}",
                 collection_name: base_name.pluralize)
  end
end

#help_entry_translation_keyObject



31
32
33
# File 'lib/pageflow/built_in_page_type.rb', line 31

def help_entry_translation_key
  "pageflow.help_entries.built_in_page_type.#{name}"
end

#template_pathObject



23
24
25
# File 'lib/pageflow/built_in_page_type.rb', line 23

def template_path
  File.join('pageflow', 'pages', 'templates', "_#{name}.html.erb")
end

#thumbnail_candidatesObject



39
40
41
# File 'lib/pageflow/built_in_page_type.rb', line 39

def thumbnail_candidates
  @thumbnail_candidates.presence || super
end

#translation_keyObject



27
28
29
# File 'lib/pageflow/built_in_page_type.rb', line 27

def translation_key
  "activerecord.values.pageflow/page.template.#{name}"
end

#translation_key_prefixObject



35
36
37
# File 'lib/pageflow/built_in_page_type.rb', line 35

def translation_key_prefix
  "pageflow.built_in_page_type.#{name}"
end