Class: Refinery::Admin::ImagePresenter
- Inherits:
-
BasePresenter
- Object
- BasePresenter
- Refinery::Admin::ImagePresenter
- Includes:
- ActionView::Context, ActionView::Helpers::TagHelper, ActionView::Helpers::UrlHelper, ActionView::RecordIdentifier, Refinery::ActionHelper, ImagesHelper, TranslationHelper
- Defined in:
- app/presenters/refinery/admin/image_presenter.rb
Overview
Refinery::Admin::ImagePresenter
This class represents a presenter for managing and displaying image data in the Refinery admin interface. It provides methods to format image-related data for display and to generate necessary HTML components for interacting with images in the admin UI.
Includes
-
ActionView::RecordIdentifier: Provides methods for DOM ID generation for records.
-
ActionView::Helpers::UrlHelper: Allows generation of URLs and links.
-
ActionView::Helpers::TagHelper: Provides methods for generating HTML tags.
-
ActionView::Context: Allows rendering within the correct context.
-
Refinery::TranslationHelper: Adds support for translation-related helper methods.
-
Refinery::Admin::ImagesHelper: Includes specific helper methods for working with images.
-
Refinery::ActionHelper: Provides additional action-based helper methods.
Attributes
-
‘image` [Reader]: The image object being presented.
-
‘context` [Reader]: Context of the current view, often required for generating paths and URLs.
-
‘index_keys` [Reader]: Used to specify the attributes displayed in the index table for images.
-
‘i18n_scope` [Reader]: Specifies the internationalization scope for localization of text.
-
‘title` [Writer]: Sets the title for the image.
-
‘alt` [Writer]: Sets the alt text for the image.
-
‘filename` [Writer]: Sets the filename for the image.
-
‘translations` [Writer]: Stores translations for the image fields.
-
‘edit_attributes` [Writer]: Stores attributes to be used for editing the image.
-
‘delete_attributes` [Writer]: Stores attributes to be used for deleting the image.
-
‘preview_attributes` [Writer]: Stores attributes for image preview options.
Constants
-
‘IndexEntry`: Defines a structure to hold index entry data, including the image ID, edit link, text elements, locales, and actionable items.
Instance Methods
-
‘initialize(image, context, scope = nil)`: Constructor that initializes the ImagePresenter with the given image object, view context, and optional internationalization scope.
-
‘index_entry(index_keys)`: Generates an index entry for the image, including its ID, edit link, text elements, and actions. Accepts an array of keys for specifying index fields. These keys differ between the grid_view and list_view, and other views could be added
-
‘link_to_edit(edit_key)`: Creates a link to edit the image, using the given key for determining the “text” of the link.
-
‘text_elements(keys)`: Generates text elements for display based on the provided keys, wrapping them in HTML spans.
-
‘thumbnail`: Returns the thumbnail for the image, including specific attributes such as its URL, description (alt) and title
Defined Under Namespace
Classes: IndexEntry
Instance Attribute Summary collapse
- #alt ⇒ Object
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#delete_attributes ⇒ Object
writeonly
Sets the attribute delete_attributes.
-
#edit_attributes ⇒ Object
writeonly
Sets the attribute edit_attributes.
- #filename ⇒ Object
-
#i18n_scope ⇒ Object
readonly
Returns the value of attribute i18n_scope.
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#index_keys ⇒ Object
readonly
Returns the value of attribute index_keys.
-
#preview_attributes ⇒ Object
writeonly
Sets the attribute preview_attributes.
- #title ⇒ Object
-
#translations ⇒ Object
writeonly
Sets the attribute translations.
Instance Method Summary collapse
- #delete_action(options = {}) ⇒ Object
- #edit_actions ⇒ Object
- #image_actions ⇒ Object
- #index_entry(index_keys) ⇒ Object
-
#initialize(image, context, scope = nil) ⇒ ImagePresenter
constructor
A new instance of ImagePresenter.
- #link_to_edit(edit_key) ⇒ Object
- #preview_action(options = {}) ⇒ Object
- #text_elements(keys) ⇒ Object
- #thumbnail ⇒ Object
Methods included from ImagesHelper
#locale_text_icon, #other_image_views, #thumbnail_urls
Constructor Details
#initialize(image, context, scope = nil) ⇒ ImagePresenter
Returns a new instance of ImagePresenter.
74 75 76 77 78 79 |
# File 'app/presenters/refinery/admin/image_presenter.rb', line 74 def initialize(image, context, scope = nil) super(image) @image = image @context = context @i18n_scope = scope || 'refinery.admin.images' end |
Instance Attribute Details
#alt ⇒ Object
112 113 114 115 |
# File 'app/presenters/refinery/admin/image_presenter.rb', line 112 def alt alt_text = translated_field(@image, :alt) alt_text unless alt_text === translated_field(image, :title) end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
67 68 69 |
# File 'app/presenters/refinery/admin/image_presenter.rb', line 67 def context @context end |
#delete_attributes=(value) ⇒ Object (writeonly)
Sets the attribute delete_attributes
68 69 70 |
# File 'app/presenters/refinery/admin/image_presenter.rb', line 68 def delete_attributes=(value) @delete_attributes = value end |
#edit_attributes=(value) ⇒ Object (writeonly)
Sets the attribute edit_attributes
68 69 70 |
# File 'app/presenters/refinery/admin/image_presenter.rb', line 68 def edit_attributes=(value) @edit_attributes = value end |
#filename ⇒ Object
117 118 119 |
# File 'app/presenters/refinery/admin/image_presenter.rb', line 117 def filename image.image_name end |
#i18n_scope ⇒ Object (readonly)
Returns the value of attribute i18n_scope.
67 68 69 |
# File 'app/presenters/refinery/admin/image_presenter.rb', line 67 def i18n_scope @i18n_scope end |
#image ⇒ Object (readonly)
Returns the value of attribute image.
67 68 69 |
# File 'app/presenters/refinery/admin/image_presenter.rb', line 67 def image @image end |
#index_keys ⇒ Object (readonly)
Returns the value of attribute index_keys.
67 68 69 |
# File 'app/presenters/refinery/admin/image_presenter.rb', line 67 def index_keys @index_keys end |
#preview_attributes=(value) ⇒ Object (writeonly)
Sets the attribute preview_attributes
68 69 70 |
# File 'app/presenters/refinery/admin/image_presenter.rb', line 68 def preview_attributes=(value) @preview_attributes = value end |
#title ⇒ Object
108 109 110 |
# File 'app/presenters/refinery/admin/image_presenter.rb', line 108 def title translated_field(image, :title) end |
#translations=(value) ⇒ Object (writeonly)
Sets the attribute translations
68 69 70 |
# File 'app/presenters/refinery/admin/image_presenter.rb', line 68 def translations=(value) @translations = value end |
Instance Method Details
#delete_action(options = {}) ⇒ Object
137 138 139 140 141 142 |
# File 'app/presenters/refinery/admin/image_presenter.rb', line 137 def delete_action( = {}) action_icon(:delete, context.admin_image_path(image), ::I18n.t('.delete', scope: i18n_scope), data: { confirm: ::I18n.t('message', scope: 'refinery.admin.delete', title: image.title) }, ** ) end |
#edit_actions ⇒ Object
127 128 129 130 |
# File 'app/presenters/refinery/admin/image_presenter.rb', line 127 def edit_actions translated_locales = locales_with_translated_field(image, :image_title) edit_in_locales(context.edit_admin_image_path(image), translated_locales) end |
#image_actions ⇒ Object
121 122 123 124 125 |
# File 'app/presenters/refinery/admin/image_presenter.rb', line 121 def image_actions [*edit_actions, delete_action, preview_action].reduce(ActiveSupport::SafeBuffer.new) do |buffer, action| buffer << action end end |
#index_entry(index_keys) ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'app/presenters/refinery/admin/image_presenter.rb', line 81 def index_entry(index_keys) edit_key, *text_keys = index_keys IndexEntry.new( id: image.id, edit_link: link_to_edit(index_keys[0]), text_elements: text_elements(index_keys[1..]), actions: tag.span( image_actions, class: :actions) ) end |
#link_to_edit(edit_key) ⇒ Object
91 92 93 94 95 |
# File 'app/presenters/refinery/admin/image_presenter.rb', line 91 def link_to_edit(edit_key) link_to(self.send(edit_key), context.edit_admin_image_path(image), { title: ::I18n.t('.edit', title: image.title, scope: i18n_scope), class: :edit_link}) end |
#preview_action(options = {}) ⇒ Object
132 133 134 135 |
# File 'app/presenters/refinery/admin/image_presenter.rb', line 132 def preview_action( = {}) action_icon(:preview, image.url, ::I18n.t('.view_live_html', scope: i18n_scope), options: ) end |
#text_elements(keys) ⇒ Object
97 98 99 100 101 |
# File 'app/presenters/refinery/admin/image_presenter.rb', line 97 def text_elements(keys) keys.reduce(ActiveSupport::SafeBuffer.new) do |buffer, key| buffer << tag.span(self.send(key), title: ::I18n.t(key, scope: i18n_scope), class: key) end end |