Class: Locomotive::Wagon::PageDecorator

Inherits:
Steam::Decorators::TemplateDecorator
  • Object
show all
Includes:
PersistAssetsConcern, ToHashConcern
Defined in:
lib/locomotive/wagon/decorators/page_decorator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PersistAssetsConcern

#asset_io, #replace_with_content_assets!, #replace_with_content_assets_in_hash!

Methods included from ToHashConcern

#prepare_value_for_hash, #to_hash

Constructor Details

#initialize(object, locale, content_assets_pusher, persist_content) ⇒ PageDecorator

Returns a new instance of PageDecorator.



11
12
13
14
15
# File 'lib/locomotive/wagon/decorators/page_decorator.rb', line 11

def initialize(object, locale, content_assets_pusher, persist_content)
  self.__content_assets_pusher__ = content_assets_pusher
  self.__persist_content__ = persist_content
  super(object, locale, nil) # we don't need a fallback to the default locale
end

Instance Attribute Details

#__content_assets_pusher__Object

Returns the value of attribute content_assets_pusher.



9
10
11
# File 'lib/locomotive/wagon/decorators/page_decorator.rb', line 9

def __content_assets_pusher__
  @__content_assets_pusher__
end

#__persist_content__Object

Returns the value of attribute persist_content.



9
10
11
# File 'lib/locomotive/wagon/decorators/page_decorator.rb', line 9

def __persist_content__
  @__persist_content__
end

Instance Method Details

#__attributes__Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/locomotive/wagon/decorators/page_decorator.rb', line 17

def __attributes__
  _attributes = %i(title slug parent
    handle response_type published
    position listed
    is_layout allow_layout
    redirect_url redirect_type
    seo_title meta_keywords meta_description
    editable_elements
    sections_dropzone_content
    sections_content
    content_type
    template
    display_settings)

  # remove the attributes that end-users might have modified in the back-office
  if persisted? && !__persist_content__
    _attributes -= %i(title published listed position seo_title meta_keywords meta_description editable_elements sections_dropzone_content sections_content)
  end

  # no need to update the slug if this is for an update
  # in case of a localized site, if this is a new page, the _id will remain empty
  # for the other locales.
  _attributes -= %i(slug) if persisted?

  _attributes
end

#_idObject



48
49
50
# File 'lib/locomotive/wagon/decorators/page_decorator.rb', line 48

def _id
  __getobj__[:remote_id]
end

#_id=(id) ⇒ Object



44
45
46
# File 'lib/locomotive/wagon/decorators/page_decorator.rb', line 44

def _id=(id)
  __getobj__[:remote_id] = id
end

#allow_layoutObject



60
61
62
# File 'lib/locomotive/wagon/decorators/page_decorator.rb', line 60

def allow_layout
  self[:allow_layout]
end

#content_typeObject



76
77
78
# File 'lib/locomotive/wagon/decorators/page_decorator.rb', line 76

def content_type
  templatized? ? content_type_id : nil
end

#display_settingsObject



72
73
74
# File 'lib/locomotive/wagon/decorators/page_decorator.rb', line 72

def display_settings
  self[:display_settings]
end

#editable_elementsObject



80
81
82
83
84
85
86
# File 'lib/locomotive/wagon/decorators/page_decorator.rb', line 80

def editable_elements
  return nil if __getobj__.editable_elements.all.count == 0

  __getobj__.editable_elements.all.map do |element|
    EditableElementDecorator.new(element, __locale__, __content_assets_pusher__)
  end
end

#folder_pathObject



100
101
102
103
# File 'lib/locomotive/wagon/decorators/page_decorator.rb', line 100

def folder_path
  *segments, slug = fullpath.split('/')
  segments.join('/')
end

#is_layoutObject



52
53
54
55
56
57
58
# File 'lib/locomotive/wagon/decorators/page_decorator.rb', line 52

def is_layout
  if self[:is_layout].nil?
    !(__getobj__._fullpath =~ %r(^layouts/)).nil?
  else
    self[:is_layout]
  end
end

#parentObject



68
69
70
# File 'lib/locomotive/wagon/decorators/page_decorator.rb', line 68

def parent
  self[:parent]
end

#response_typeObject



64
65
66
# File 'lib/locomotive/wagon/decorators/page_decorator.rb', line 64

def response_type
  self[:response_type]
end

#sections_contentObject



92
93
94
# File 'lib/locomotive/wagon/decorators/page_decorator.rb', line 92

def sections_content
  replace_with_content_assets!(super&.to_json)
end

#sections_dropzone_contentObject



88
89
90
# File 'lib/locomotive/wagon/decorators/page_decorator.rb', line 88

def sections_dropzone_content
  replace_with_content_assets!(super&.to_json)
end

#templateObject



96
97
98
# File 'lib/locomotive/wagon/decorators/page_decorator.rb', line 96

def template
  replace_with_content_assets!(self.liquid_source)
end