Class: Pageflow::Page

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/pageflow/page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#is_firstObject

Returns the value of attribute is_first.



5
6
7
# File 'app/models/pageflow/page.rb', line 5

def is_first
  @is_first
end

Instance Method Details

#configurationObject



48
49
50
# File 'app/models/pageflow/page.rb', line 48

def configuration
  super || {}
end

#configuration=(value) ⇒ Object



52
53
54
55
# File 'app/models/pageflow/page.rb', line 52

def configuration=(value)
  self.display_in_navigation = value['display_in_navigation']
  super
end

#copy_to(chapter) ⇒ Object



57
58
59
# File 'app/models/pageflow/page.rb', line 57

def copy_to(chapter)
  chapter.pages << dup
end

#ensure_perma_idObject



61
62
63
# File 'app/models/pageflow/page.rb', line 61

def ensure_perma_id
  self.perma_id ||= (Page.maximum(:perma_id) || 0) + 1
end

#thumbnailObject



19
20
21
22
23
24
25
26
27
# File 'app/models/pageflow/page.rb', line 19

def thumbnail
  model_name, attachment, property, model_class = thumbnail_definition

  begin
    model_name.to_s.camelcase.constantize.find(configuration[property]).send(attachment)
  rescue ActiveRecord::RecordNotFound
    ImageFile.new.processed_attachment
  end
end

#thumbnail_definitionObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/models/pageflow/page.rb', line 29

def thumbnail_definition
  # TODO: this has to be refactored to be page type agnostic
  if template == 'video' || template == 'background_video'
    if configuration['poster_image_id'].present?
      ['pageflow/image_file', :processed_attachment, 'poster_image_id', 'image_file']
    else
      ['pageflow/video_file', :poster, 'video_file_id', 'video_file']
    end
  else
    if configuration['thumbnail_image_id'].present?
      ['pageflow/image_file', :processed_attachment, 'thumbnail_image_id', 'image_file']
    elsif configuration['after_image_id'].present?
      ['pageflow/image_file', :processed_attachment, 'after_image_id','image_file']
    else
      ['pageflow/image_file', :processed_attachment, 'background_image_id', 'image_file']
    end
  end
end

#titleObject



15
16
17
# File 'app/models/pageflow/page.rb', line 15

def title
  configuration['title'].presence || configuration['additional_title']
end