Class: Katalyst::Content::Editor::StatusBar

Inherits:
Base
  • Object
show all
Defined in:
app/helpers/katalyst/content/editor/status_bar.rb

Constant Summary collapse

ACTIONS =
<<~ACTIONS.gsub(/\s+/, " ").freeze
  content:change@document->#{STATUS_BAR_CONTROLLER}#change
ACTIONS

Constants inherited from Base

Base::CONTAINER_CONTROLLER, Base::ITEM_CONTROLLER, Base::LIST_CONTROLLER, Base::NEW_ITEM_CONTROLLER, Base::STATUS_BAR_CONTROLLER, Base::TURBO_FRAME

Instance Attribute Summary

Attributes inherited from Base

#container, #template

Instance Method Summary collapse

Methods inherited from Base

#attributes_scope, #container_form_id, #initialize

Constructor Details

This class inherits a constructor from Katalyst::Content::Editor::Base

Instance Method Details

#action(action, **options) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'app/helpers/katalyst/content/editor/status_bar.rb', line 44

def action(action, **options)
  tag.li do
    button_tag(t("views.katalyst.content.editor.#{action}"),
               name:  "commit",
               value: action,
               form:  container_form_id,
               **options)
  end
end

#actionsObject



35
36
37
38
39
40
41
42
# File 'app/helpers/katalyst/content/editor/status_bar.rb', line 35

def actions
  tag.menu do
    concat action(:discard, class: "button button--text")
    concat action(:revert, class: "button button--text") if container.state == :draft
    concat action(:save, class: "button button--secondary")
    concat action(:publish, class: "button button--primary")
  end
end

#build(**options) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'app/helpers/katalyst/content/editor/status_bar.rb', line 11

def build(**options)
  tag.div **default_options(**options) do
    concat status(:published, last_update: l(container.updated_at, format: :short))
    concat status(:unpublished)
    concat status(:draft)
    concat status(:dirty)
    concat actions
  end
end

#status(state, **options) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/helpers/katalyst/content/editor/status_bar.rb', line 21

def status(state, **options)
  status_text  = t("views.katalyst.content.editor.#{state}_html", **options)
  html_options = { class: "status-text", data: { state => "", turbo: false } }

  case state
  when :published
    link_to status_text, url_for(container), **html_options
  when :unpublished, :draft
    link_to status_text, "#{url_for(container)}/preview", **html_options
  else
    tag.span status_text, **html_options
  end
end