Permalink
Browse files

Moved code from InstanceMethod to helper which really makes more sense.

  • Loading branch information...
1 parent 8f98837 commit 685832b4b1b974e6149cbe21b30a08d1ec4969ba Francesc Esplugas committed Feb 13, 2010
Showing with 32 additions and 22 deletions.
  1. +19 −1 app/helpers/admin/table_helper.rb
  2. +13 −0 app/views/admin/helpers/_preview_on_table.html.erb
  3. +0 −21 lib/typus/preview.rb
@@ -172,8 +172,26 @@ def typus_table_selector(attribute, item)
end
def typus_table_file_field(attribute, item, link_options = {})
- content = item.typus_preview_on_table(attribute)
+
+ attachment = attribute.split("_file_name").first
+ file_preview = Typus::Configuration.options[:file_preview]
+ file_thumbnail = Typus::Configuration.options[:file_thumbnail]
+
+ has_file_preview = item.send(attachment).styles.member?(file_preview)
+ file_preview_is_image = item.send("#{attachment}_content_type") =~ /^image\/.+/
+
+ content = if has_file_preview && file_preview_is_image
+ render "admin/helpers/preview_on_table",
+ :attribute => attribute,
+ :attachment => attachment,
+ :file_preview => file_preview,
+ :item => item
+ else
+ link_to item.send(attribute), item.send(attachment).url
+ end
+
return content_tag(:td, content)
+
end
# OPTIMIZE: Move html code to partial.
@@ -0,0 +1,13 @@
+<%
+ dom = item.to_dom(:suffix => "#{attribute}_preview" )
+%>
+
+<script type="text/javascript" charset="utf-8">
+ $(document).ready(function() {
+ $("#<%= dom %>").fancybox();
+ });
+</script>
+
+<a id="<%= dom %>"
+ href="<%= item.send(attachment).url(file_preview) %>"
+ title="<%= item.to_label %>"><%= item.send(attribute) %></a>
View
@@ -5,27 +5,6 @@ module InstanceMethods
include ActionView::Helpers::UrlHelper
# OPTIMIZE: Move html code to helper.
- def typus_preview_on_table(attribute)
-
- attachment = attribute.split('_file_name').first
- file_preview = Typus::Configuration.options[:file_preview]
- file_thumbnail = Typus::Configuration.options[:file_thumbnail]
-
- if send(attachment).styles.member?(file_preview) && send("#{attachment}_content_type") =~ /^image\/.+/
- <<-HTML
-<script type="text/javascript" charset="utf-8">
- $(document).ready(function() { $("##{to_dom}_#{attribute}_preview").fancybox(); });
-</script>
-<a id="#{to_dom}_#{attribute}_preview" href="#{send(attachment).url(file_preview)}" title="#{to_label}">#{send(attribute)}</a>
- HTML
- else
- <<-HTML
-<a href="#{send(attachment).url}">#{send(attribute)}</a>
- HTML
- end
- end
-
- # OPTIMIZE: Move html code to helper.
def typus_preview(attribute)
attachment = attribute.split('_file_name').first

0 comments on commit 685832b

Please sign in to comment.