Class: Alchemy::Admin::PublishPageButton
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Alchemy::Admin::PublishPageButton
- Defined in:
- app/components/alchemy/admin/publish_page_button.rb
Overview
The button publishes the page and indicates unpublished changes if any.
Example
<%= render Alchemy::Admin::PublishPageButton.new(page: @page) %>
Instance Attribute Summary collapse
-
#page ⇒ Object
readonly
Returns the value of attribute page.
Instance Method Summary collapse
- #button_label ⇒ Object
- #disabled? ⇒ Boolean
- #has_unpublished_changes? ⇒ Boolean
-
#initialize(page:, published: false) ⇒ PublishPageButton
constructor
A new instance of PublishPageButton.
- #publish_path ⇒ Object
- #tooltip_content ⇒ Object
Constructor Details
#initialize(page:, published: false) ⇒ PublishPageButton
16 17 18 19 |
# File 'app/components/alchemy/admin/publish_page_button.rb', line 16 def initialize(page:, published: false) @page = page @published = published end |
Instance Attribute Details
#page ⇒ Object (readonly)
Returns the value of attribute page.
14 15 16 |
# File 'app/components/alchemy/admin/publish_page_button.rb', line 14 def page @page end |
Instance Method Details
#button_label ⇒ Object
41 42 43 44 45 46 47 |
# File 'app/components/alchemy/admin/publish_page_button.rb', line 41 def if page.public_version.nil? t(".publish_page") else t(".publish_changes") end end |
#disabled? ⇒ Boolean
21 22 23 |
# File 'app/components/alchemy/admin/publish_page_button.rb', line 21 def disabled? @published || cannot?(:publish, page) || !has_unpublished_changes? end |
#has_unpublished_changes? ⇒ Boolean
25 26 27 |
# File 'app/components/alchemy/admin/publish_page_button.rb', line 25 def has_unpublished_changes? !@published && page.has_unpublished_changes? end |
#publish_path ⇒ Object
49 50 51 |
# File 'app/components/alchemy/admin/publish_page_button.rb', line 49 def publish_path Alchemy::Engine.routes.url_helpers.publish_admin_page_path(page) end |
#tooltip_content ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/components/alchemy/admin/publish_page_button.rb', line 29 def tooltip_content if !page.language.public? Alchemy.t(:publish_page_language_not_public) elsif cannot?(:publish, page) Alchemy.t(:publish_page_not_allowed) elsif @published || !has_unpublished_changes? Alchemy.t(:no_unpublished_changes) else Alchemy.t(:explain_publishing) end end |