Sha256: a58d81ea2876e396bea2ff6f78c2796bb98b3fa934b6e61bcafa3372672cce29

Contents?: true

Size: 1.7 KB

Versions: 3

Compression:

Stored size: 1.7 KB

Contents

# frozen_string_literal: true

module Katalyst
  module Content
    module Editor
      class StatusBar < Base
        ACTIONS = <<~ACTIONS.gsub(/\s+/, " ").freeze
          content:change@document->#{STATUS_BAR_CONTROLLER}#change
        ACTIONS

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

        def status(state, **options)
          tag.span(t("views.katalyst.content.editor.#{state}_html", **options),
                   class: "status-text",
                   data:  { state => "" })
        end

        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

        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

        private

        def default_options(**options)
          add_option(options, :data, :controller, STATUS_BAR_CONTROLLER)
          add_option(options, :data, :action, ACTIONS)
          add_option(options, :data, :state, container.state)

          options
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
katalyst-content-0.1.2 app/helpers/katalyst/content/editor/status_bar.rb
katalyst-content-0.1.1 app/helpers/katalyst/content/editor/status_bar.rb
katalyst-content-0.1.0 app/helpers/katalyst/content/editor/status_bar.rb