From 5af85e203b5f98bd0755fac49e55162bedec2308 Mon Sep 17 00:00:00 2001 From: Jan Schulz-Hofen Date: Wed, 17 Feb 2016 15:07:04 +0700 Subject: [PATCH 1/4] Reduce view code duplication by using a nested layout for file rendering --- app/views/attachments/diff.html.erb | 16 ++-------------- app/views/attachments/file.html.erb | 17 ++--------------- app/views/layouts/_file.html.erb | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 29 deletions(-) create mode 100644 app/views/layouts/_file.html.erb diff --git a/app/views/attachments/diff.html.erb b/app/views/attachments/diff.html.erb index d125f82..5f5f4d7 100644 --- a/app/views/attachments/diff.html.erb +++ b/app/views/attachments/diff.html.erb @@ -1,11 +1,4 @@ -

<%=h @attachment.filename %>

- -
-

<%= "#{@attachment.description} - " unless @attachment.description.blank? %> - <%= link_to_user(@attachment.author) %>, <%= format_time(@attachment.created_on) %>

-

<%= link_to_attachment @attachment, :text => l(:button_download), :download => true -%> - (<%= number_to_human_size @attachment.filesize %>)

-
+<%= render :layout => 'layouts/file' do %> <%= form_tag({}, :method => 'get') do %>

<%= l(:label_view_diff) %>: @@ -14,9 +7,4 @@

<% end %> <%= render :partial => 'common/diff', :locals => {:diff => @diff, :diff_type => @diff_type, :diff_style => nil} %> - -<% html_title @attachment.filename %> - -<% content_for :header_tags do -%> - <%= stylesheet_link_tag "scm" -%> -<% end -%> +<% end %> diff --git a/app/views/attachments/file.html.erb b/app/views/attachments/file.html.erb index e507ab6..e691249 100644 --- a/app/views/attachments/file.html.erb +++ b/app/views/attachments/file.html.erb @@ -1,17 +1,4 @@ -

<%=h @attachment.filename %>

- -
-

<%= "#{@attachment.description} - " unless @attachment.description.blank? %> - <%= link_to_user(@attachment.author) %>, <%= format_time(@attachment.created_on) %>

-

<%= link_to_attachment @attachment, :text => l(:button_download), :download => true -%> - (<%= number_to_human_size @attachment.filesize %>)

- -
+<%= render :layout => 'layouts/file' do %>   <%= render :partial => 'common/file', :locals => {:content => @content, :filename => @attachment.filename} %> - -<% html_title @attachment.filename %> - -<% content_for :header_tags do -%> - <%= stylesheet_link_tag "scm" -%> -<% end -%> +<% end %> diff --git a/app/views/layouts/_file.html.erb b/app/views/layouts/_file.html.erb new file mode 100644 index 0000000..7bb939a --- /dev/null +++ b/app/views/layouts/_file.html.erb @@ -0,0 +1,15 @@ +

<%=h @attachment.filename %>

+ +
+

<%= "#{@attachment.description} - " unless @attachment.description.blank? %> + <%= link_to_user(@attachment.author) %>, <%= format_time(@attachment.created_on) %>

+

<%= link_to_attachment @attachment, :text => l(:button_download), :download => true -%> + (<%= number_to_human_size @attachment.filesize %>)

+
+<%= yield %> + +<% html_title @attachment.filename %> + +<% content_for :header_tags do -%> + <%= stylesheet_link_tag "scm" -%> +<% end -%> -- 2.4.0