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



37
38
39
# File 'app/decorators/tramway/landing/block_decorator.rb', line 37

def block_type
  object.block_type_text
end

#buttonObject



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

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


45
46
47
# File 'app/decorators/tramway/landing/block_decorator.rb', line 45

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

#page_titleObject



33
34
35
# File 'app/decorators/tramway/landing/block_decorator.rb', line 33

def page_title
  object.page&.title
end

#public_pathObject



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

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



41
42
43
# File 'app/decorators/tramway/landing/block_decorator.rb', line 41

def view_state
  object.human_view_state_name
end

#view_state_button_color(event) ⇒ Object



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

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