Class: Alchemy::Admin::PageNode
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Alchemy::Admin::PageNode
- Defined in:
- app/components/alchemy/admin/page_node.rb
Constant Summary collapse
- PAGE_ID =
"__ID__"
Instance Attribute Summary collapse
-
#page ⇒ Object
readonly
Returns the value of attribute page.
Class Method Summary collapse
-
.routes ⇒ Object
URL templates - computed once, reused for all pages.
-
.translations ⇒ Object
Translations - computed once, reused for all pages.
Instance Method Summary collapse
- #can?(action) ⇒ Boolean
-
#initialize(page:) ⇒ PageNode
constructor
A new instance of PageNode.
-
#t(key) ⇒ Object
Memoized translation lookup.
-
#url(key) ⇒ Object
Memoized URL path.
Constructor Details
#initialize(page:) ⇒ PageNode
Returns a new instance of PageNode.
15 16 17 |
# File 'app/components/alchemy/admin/page_node.rb', line 15 def initialize(page:) @page = page end |
Instance Attribute Details
#page ⇒ Object (readonly)
Returns the value of attribute page.
6 7 8 |
# File 'app/components/alchemy/admin/page_node.rb', line 6 def page @page end |
Class Method Details
.routes ⇒ Object
URL templates - computed once, reused for all pages
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/components/alchemy/admin/page_node.rb', line 37 def routes @_routes ||= begin router = Alchemy::Engine.routes.url_helpers { edit_page: router.edit_admin_page_path(PAGE_ID), info_page: router.info_admin_page_path(PAGE_ID), configure_page: router.configure_admin_page_path(PAGE_ID), page: router.admin_page_path(PAGE_ID), new_child_page: router.new_admin_page_path(parent_id: PAGE_ID), clipboard_insert: router.insert_admin_clipboard_path( remarkable_type: :pages, remarkable_id: PAGE_ID ) }.freeze end end |
.translations ⇒ Object
Translations - computed once, reused for all pages
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/components/alchemy/admin/page_node.rb', line 55 def translations @_translations ||= { cannot_edit_page: Alchemy.t("Your user role does not allow you to edit this page"), edit_page: Alchemy.t(:edit_page), page_infos: Alchemy.t(:page_infos), edit_page_properties: Alchemy.t(:edit_page_properties), copy_page: Alchemy.t(:copy_page), delete_page: Alchemy.t(:delete_page), confirm_to_delete_page: Alchemy.t(:confirm_to_delete_page), create_page: Alchemy.t(:create_page) }.freeze end |
Instance Method Details
#can?(action) ⇒ Boolean
19 20 21 |
# File 'app/components/alchemy/admin/page_node.rb', line 19 def can?(action) helpers.can?(action, page.__getobj__) end |
#t(key) ⇒ Object
Memoized translation lookup
29 30 31 |
# File 'app/components/alchemy/admin/page_node.rb', line 29 def t(key) self.class.translations[key] end |
#url(key) ⇒ Object
Memoized URL path
24 25 26 |
# File 'app/components/alchemy/admin/page_node.rb', line 24 def url(key) self.class.routes[key].sub(PAGE_ID, page.id.to_s) end |