aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJavan Makhmali <javan@javan.us>2018-10-03 14:41:47 -0400
committerJavan Makhmali <javan@javan.us>2018-10-03 14:41:47 -0400
commit30443121286c3bb970d4d24bf7f24472498e9633 (patch)
tree6799fe7cc8aaabd6bfa35c8dfc75a11eb7f4e332 /app
parent7a993324342d5542dcb40902eed097f7eaac3f1b (diff)
downloadrails-30443121286c3bb970d4d24bf7f24472498e9633.tar.gz
rails-30443121286c3bb970d4d24bf7f24472498e9633.tar.bz2
rails-30443121286c3bb970d4d24bf7f24472498e9633.zip
Move attachment rendering to a helper
Fixes #5
Diffstat (limited to 'app')
-rw-r--r--app/helpers/action_text/content_helper.rb24
-rw-r--r--app/views/action_text/content/_layout.html.erb2
-rw-r--r--app/views/active_storage/blobs/_blob.html.erb5
3 files changed, 28 insertions, 3 deletions
diff --git a/app/helpers/action_text/content_helper.rb b/app/helpers/action_text/content_helper.rb
new file mode 100644
index 0000000000..6d00eee648
--- /dev/null
+++ b/app/helpers/action_text/content_helper.rb
@@ -0,0 +1,24 @@
+module ActionText
+ module ContentHelper
+ def render_action_text_content(content)
+ content = content.render_attachments do |attachment|
+ unless attachment.in?(content.gallery_attachments)
+ attachment.node.tap do |node|
+ node.inner_html = render(attachment, in_gallery: false).chomp
+ end
+ end
+ end
+
+ content = content.render_attachment_galleries do |attachment_gallery|
+ render(layout: attachment_gallery, object: attachment_gallery) do
+ attachment_gallery.attachments.map do |attachment|
+ attachment.node.inner_html = render(attachment, in_gallery: true).chomp
+ attachment.to_html
+ end.join("").html_safe
+ end.chomp
+ end
+
+ content.to_html
+ end
+ end
+end
diff --git a/app/views/action_text/content/_layout.html.erb b/app/views/action_text/content/_layout.html.erb
index b8c8ab6fc6..60d65cd0d5 100644
--- a/app/views/action_text/content/_layout.html.erb
+++ b/app/views/action_text/content/_layout.html.erb
@@ -1,3 +1,3 @@
<div class="trix-content">
- <%= sanitize document %>
+ <%= sanitize render_action_text_content(content) %>
</div>
diff --git a/app/views/active_storage/blobs/_blob.html.erb b/app/views/active_storage/blobs/_blob.html.erb
index c7c70c110e..6e4105d5cf 100644
--- a/app/views/active_storage/blobs/_blob.html.erb
+++ b/app/views/active_storage/blobs/_blob.html.erb
@@ -1,8 +1,9 @@
+<% transformations = { resize: local_assigns[:in_gallery] ? "800x600>" : "1024x768>" } %>
<figure class="attachment attachment--<%= blob.representable? ? "preview" : "file" %> attachment--<%= blob.filename.extension %>">
<% if blob.variable? %>
- <%= image_tag blob.variant(resize: "1024x768>") %>
+ <%= image_tag blob.variant(transformations) %>
<% elsif blob.previewable? %>
- <%= image_tag blob.preview(resize: "1024x768>") %>
+ <%= image_tag blob.preview(transformations) %>
<% end %>
<figcaption class="attachment__caption">