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

#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.


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

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

.audio_loopObject


43
44
45
# File 'lib/pageflow/built_in_page_type.rb', line 43

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

.background_imageObject


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

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

.background_videoObject


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

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

57
58
59
# File 'lib/pageflow/built_in_page_type.rb', line 57

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

.videoObject


61
62
63
64
65
# File 'lib/pageflow/built_in_page_type.rb', line 61

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

.video_thumbnail_candidatesObject


67
68
69
70
71
72
73
# File 'lib/pageflow/built_in_page_type.rb', line 67

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

#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


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

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