Move documents partials to components
This way it'll be easier to change them. Note that there were two `.document-link` elements which aren't part of a `.documents` element. We're renaming the HTML class of the link in investments because it didn't contain links to download documents and are slightly duplicating the CSS in the poll answer documents in order to keep the `word-wrap` property.
This commit is contained in:
23
app/components/documents/document_component.html.erb
Normal file
23
app/components/documents/document_component.html.erb
Normal file
@@ -0,0 +1,23 @@
|
||||
<li id="<%= dom_id(document) %>">
|
||||
<%= link_to t("documents.buttons.download_document"),
|
||||
document.attachment,
|
||||
target: "_blank",
|
||||
rel: "nofollow",
|
||||
class: "button hollow medium float-right" %>
|
||||
|
||||
<strong><%= document.title %></strong>
|
||||
<br>
|
||||
<small>
|
||||
<%= document.humanized_content_type %> |
|
||||
<%= number_to_human_size(document.attachment_file_size, precision: 2) %>
|
||||
</small>
|
||||
|
||||
<% if can?(:destroy, document) %>
|
||||
<br>
|
||||
<%= link_to t("documents.buttons.destroy_document"),
|
||||
document,
|
||||
method: :delete,
|
||||
data: { confirm: t("documents.actions.destroy.confirm") },
|
||||
class: "delete" %>
|
||||
<% end %>
|
||||
</li>
|
||||
8
app/components/documents/document_component.rb
Normal file
8
app/components/documents/document_component.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
class Documents::DocumentComponent < ApplicationComponent
|
||||
attr_reader :document
|
||||
delegate :can?, to: :helpers
|
||||
|
||||
def initialize(document)
|
||||
@document = document
|
||||
end
|
||||
end
|
||||
9
app/components/documents/documents_component.html.erb
Normal file
9
app/components/documents/documents_component.html.erb
Normal file
@@ -0,0 +1,9 @@
|
||||
<div id="documents" class="documents">
|
||||
<h2><%= t("documents.title") %> <span>(<%= documents.count %>)</span></h2>
|
||||
|
||||
<ul class="no-bullet document-link">
|
||||
<% documents.each do |document| %>
|
||||
<%= render Documents::DocumentComponent.new(document) %>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
11
app/components/documents/documents_component.rb
Normal file
11
app/components/documents/documents_component.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
class Documents::DocumentsComponent < ApplicationComponent
|
||||
attr_reader :documents
|
||||
|
||||
def initialize(documents)
|
||||
@documents = documents
|
||||
end
|
||||
|
||||
def render?
|
||||
documents.any?
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user