Class: Tramway::Landing::BlockDecorator

Inherits:
Core::ApplicationDecorator
  • Object
show all
Defined in:
app/decorators/tramway/landing/block_decorator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.collectionsObject



5
6
7
# File 'app/decorators/tramway/landing/block_decorator.rb', line 5

def collections
  [:all]
end

.list_attributesObject



9
10
11
# File 'app/decorators/tramway/landing/block_decorator.rb', line 9

def list_attributes
  %i[page_title position view_state block_type]
end

.show_associationsObject



13
14
15
# File 'app/decorators/tramway/landing/block_decorator.rb', line 13

def show_associations
  [:forms]
end

Instance Method Details

#block_typeObject



35
36
37
# File 'app/decorators/tramway/landing/block_decorator.rb', line 35

def block_type
  object.block_type_text
end

#buttonObject



56
57
58
59
60
61
62
# File 'app/decorators/tramway/landing/block_decorator.rb', line 56

def button
  if object.button.present? && object.button['button_title'].present? && object.button['button_link'].present?
     :a, href: object.button['button_link'], target: '_blank', class: 'btn btn-primary' do
      object.button['button_title']
    end
  end
end


43
44
45
# File 'app/decorators/tramway/landing/block_decorator.rb', line 43

def link
  "##{object.anchor}"
end

#page_titleObject



31
32
33
# File 'app/decorators/tramway/landing/block_decorator.rb', line 31

def page_title
  object.page&.title
end

#public_pathObject



23
24
25
26
27
28
29
# File 'app/decorators/tramway/landing/block_decorator.rb', line 23

def public_path
  if object.published?
    Tramway::Page::Engine.routes.url_helpers.page_path slug: object.page.slug if object.page.slug.present?
  else
    Tramway::Page::Engine.routes.url_helpers.preview_path id: object.page.id
  end
end

#view_stateObject



39
40
41
# File 'app/decorators/tramway/landing/block_decorator.rb', line 39

def view_state
  object.view_state
end

#view_state_button_color(event) ⇒ Object



47
48
49
50
51
52
53
54
# File 'app/decorators/tramway/landing/block_decorator.rb', line 47

def view_state_button_color(event)
  case event
  when :publish
    :primary
  when :hide
    :secondary
  end
end