From 824780cc0795fe6e0da66a3978580f806331f3eb Mon Sep 17 00:00:00 2001 From: Alex Legler Date: Thu, 18 Aug 2011 14:31:13 +0200 Subject: Fix glsa/diff action --- app/controllers/application_controller.rb | 1 + app/controllers/glsa_controller.rb | 16 ++++++++-------- app/helpers/application_helper.rb | 10 ++++++++++ app/views/glsa/diff.html.erb | 6 +++--- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3b8b8ab..98f7de2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -20,6 +20,7 @@ class ApplicationController < ActionController::Base # filter_parameter_logging :password include Authentication + include ApplicationHelper protected def deny_access(msg) diff --git a/app/controllers/glsa_controller.rb b/app/controllers/glsa_controller.rb index f0f2f50..22d03db 100644 --- a/app/controllers/glsa_controller.rb +++ b/app/controllers/glsa_controller.rb @@ -1,5 +1,5 @@ # ===GLSAMaker v2 -# Copyright (C) 2010 Alex Legler +# Copyright (C) 2010-11 Alex Legler # Copyright (C) 2009 Pierre-Yves Rofes # # This program is free software: you can redistribute it and/or modify @@ -17,19 +17,19 @@ class GlsaController < ApplicationController def requests @pageID = "requests" @pageTitle = "Pooled GLSA requests" - @glsas = Glsa.find(:all, :conditions => "status = 'request'", :order => "updated_at DESC") + @glsas = Glsa.where(:status => 'request').order('updated_at DESC') end def drafts @pageID = "drafts" - @pageTitle = "Pooled GLSA drafts" - @glsas = Glsa.find(:all, :conditions => "status = 'draft'", :order => "updated_at DESC") + @pageTitle = "Pooled GLSA drafts" + @glsas = Glsa.where(:status => 'draft').order('updated_at DESC') end def archive @pageID = "archive" @pageTitle = "GLSA archive" - @glsas = Glsa.find(:all, :conditions => "status = 'release'", :order => "updated_at DESC") + @glsas = Glsa.where(:status => 'release').order('updated_at DESC') end def new @@ -307,7 +307,7 @@ class GlsaController < ApplicationController rev_old = @glsa.revisions.find_by_revid(params[:old]) rev_new = @glsa.revisions.find_by_revid(params[:new]) - @diff = rev_diff(@glsa, rev_old, rev_new) + @diff = with_format(:xml) { rev_diff(@glsa, rev_old, rev_new) } end def addbug @@ -461,7 +461,7 @@ class GlsaController < ApplicationController end end - return true + true end def rev_diff(glsa, rev_old, rev_new, format = :unified, context_lines = 3) @@ -485,7 +485,7 @@ class GlsaController < ApplicationController ), {:indent => 2, :maxcols => 80} ) - + Glsamaker::Diff.diff(old_text, new_text, format, context_lines) end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index dafeb14..778d8f6 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -135,4 +135,14 @@ module ApplicationHelper content_tag("h2", content, :class => "boxtitle") end + + def with_format(format, &block) + old_formats = formats + begin + self.formats = [format] + return block.call + ensure + self.formats = old_formats + end + end end diff --git a/app/views/glsa/diff.html.erb b/app/views/glsa/diff.html.erb index 05a7cf9..4a54bd0 100644 --- a/app/views/glsa/diff.html.erb +++ b/app/views/glsa/diff.html.erb @@ -2,9 +2,9 @@
- <%= link_to "#{image_tag 'icons/draft.png'} Back", {:controller => 'glsa', :action => 'show', :id => @glsa}, {:class => 'button'} %> + <%= link_to "#{image_tag 'icons/draft.png'} Back".html_safe, {:controller => 'glsa', :action => 'show', :id => @glsa}, {:class => 'button'} %> - <% form_tag(:action => :diff, :id => @glsa.id) do %> + <%= form_tag(:action => :diff, :id => @glsa.id) do %> <%= submit_tag 'Compare' %> revisions <%= select_tag :old, options_from_collection_for_select(@glsa.revisions, :revid, :revid) %> (old) @@ -15,5 +15,5 @@
-<%= h @diff %>
+<%= @diff %>
 
\ No newline at end of file -- cgit v1.2.3-65-gdbad