From 0a02fbf10ea8c412a9331dec0c5d9bebeabbc3a2 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Wed, 17 Sep 2014 15:04:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=B5=84=E6=BA=90=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=EF=BC=8C=E8=B5=84=E6=BA=90=E5=88=97=E8=A1=A8=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E9=94=99=E8=AF=AF=20#1262=20=E9=93=BE=E6=8E=A5?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E6=96=B9=E6=B3=95=E4=B8=8D=E5=AF=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/application_helper.rb | 14 ++- app/views/attachments/_app_link.html.erb | 6 +- app/views/attachments/_links.html.erb | 2 +- app/views/homework_attach/_app_link.html.erb | 6 +- app/views/stores/index.html.erb | 113 ++++++++++--------- 5 files changed, 80 insertions(+), 61 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b63f1071b..f976918d8 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -126,7 +126,7 @@ module ApplicationHelper # Options: # * :text - Link text (default to attachment filename) # * :download - Force download (default: false) - def link_to_attachment(attachment, options={}) + def link_to_short_attachment(attachment, options={}) text = h(truncate(options.delete(:text) || attachment.filename, length: 25, omission: '...')) route_method = options.delete(:download) ? :download_named_attachment_path : :named_attachment_path html_options = options.slice!(:only_path) @@ -134,6 +134,18 @@ module ApplicationHelper link_to text, url, html_options end + # Generates a link to an attachment. + # Options: + # * :text - Link text (default to attachment filename) + # * :download - Force download (default: false) + def link_to_attachment(attachment, options={}) + text = options.delete(:text) || attachment.filename + route_method = options.delete(:download) ? :download_named_attachment_path : :named_attachment_path + html_options = options.slice!(:only_path) + url = send(route_method, attachment, attachment.filename, options) + link_to text, url, html_options + end + def link_to_attachment_img(attachment, options={}) text = options.delete(:text) || attachment.filename route_method = options.delete(:download) ? :download_named_attachment_path : :named_attachment_path diff --git a/app/views/attachments/_app_link.html.erb b/app/views/attachments/_app_link.html.erb index 6934b76e1..263f51dc8 100644 --- a/app/views/attachments/_app_link.html.erb +++ b/app/views/attachments/_app_link.html.erb @@ -3,13 +3,15 @@ <% if attachments.count > 1 && attachment != attachments.first%>
                 <% end %> - <%= link_to_attachment attachment, :class => 'icon icon-attachment', :download => true -%> + <%= link_to_short_attachment attachment, :class => 'icon icon-attachment', :download => true -%> <% if attachment.is_text? %> <%= link_to image_tag('magnifier.png'), :controller => 'attachments', :action => 'show', :id => attachment, :filename => attachment.filename %> <% end %> - <%= h(" - #{attachment.description}") unless attachment.description.blank? %> + + <%= h(truncate(" - #{attachment.description}", length: 20, omission: '...')) unless attachment.description.blank? %> + (<%= number_to_human_size attachment.filesize %>) <% end -%> diff --git a/app/views/attachments/_links.html.erb b/app/views/attachments/_links.html.erb index 2b12b21d1..de43dce4c 100644 --- a/app/views/attachments/_links.html.erb +++ b/app/views/attachments/_links.html.erb @@ -2,7 +2,7 @@ <% for attachment in attachments %>

- <%= link_to_attachment attachment, :class => 'icon icon-attachment', :download => true -%> + <%= link_to_short_attachment attachment, :class => 'icon icon-attachment', :download => true -%> <% if attachment.is_text? %> <%= link_to image_tag('magnifier.png'), diff --git a/app/views/homework_attach/_app_link.html.erb b/app/views/homework_attach/_app_link.html.erb index 48f116ce6..3aba96d27 100644 --- a/app/views/homework_attach/_app_link.html.erb +++ b/app/views/homework_attach/_app_link.html.erb @@ -2,12 +2,14 @@ <% if attachments.count > 1 && attachment != attachments.first%>
                 <% end %> - <%= link_to_attachment attachment, :class => 'icon icon-attachment', :download => true -%> + <%= link_to_short_attachment attachment, :class => 'icon icon-attachment', :download => true -%> <% if attachment.is_text? %> <%= link_to image_tag('magnifier.png'), :controller => 'attachments', :action => 'show', :id => attachment, :filename => attachment.filename %> <% end %> - <%= h(" - #{attachment.description}") unless attachment.description.blank? %> + + <%= h(truncate(" - #{attachment.description}", length: 20, omission: '...')) unless attachment.description.blank? %> + (<%= number_to_human_size attachment.filesize %>) <% end -%> diff --git a/app/views/stores/index.html.erb b/app/views/stores/index.html.erb index 47ea32b91..5df6ecca8 100644 --- a/app/views/stores/index.html.erb +++ b/app/views/stores/index.html.erb @@ -1,68 +1,71 @@ <% content_for :top_field do%> - <%= render 'search_bar' %> + <%= render 'search_bar' %> <% end %> -

- <% @attach_array.each do |k|%> -
-

- <%= @str_arr.shift %> -

+
+<% @attach_array.each do |k|%> +
+

+ <%= @str_arr.shift %> +

-
-
-
<%=l(:label_attachment)%>
-
<%=l(:field_downloads)%>
-
<%=l(:button_download)%>
-
-
+
+
+
<%=l(:label_attachment)%>
+
<%=l(:field_downloads)%>
+
<%=l(:button_download)%>
+
+
-
- <% k.each do |c1|%> -
-
- <%= link_to c1.filename, (attachFromUrl c1), {:title => c1.filename, :target => "_blank"} %> -
-
- <%= c1.downloads %> -
-
- <%= link_to_attachment c1, {:download => true, :text => image_tag("/images/button/download.png", width: "22px", alt: l(:button_download)) }%> -
-
- <% end -%> -
+
+ <% k.each do |c1|%> +
+
+ <%= link_to c1.filename, (attachFromUrl c1), {:title => c1.filename, :target => "_blank"} %> +
+
+ <%= c1.downloads %> +
+
+ <%= link_to_attachment c1, {:download => true, :text => image_tag("/images/button/download.png", width: "22px", alt: l(:button_download)) }%> +
+
+ <% end -%> +
-
- <% end; reset_cycle %> +
+<% end; reset_cycle %>
\ No newline at end of file