Commit bf80644ccec9f4c62e0b96c7b0442be57925b3d6
Committed by
Daniela Feitosa
1 parent
4ab1ad9c
Exists in
master
and in
29 other branches
Add new template to display versioned article
Also included revision number on cache key Signed-off-by: Daniela Feitosa (ActionItem2822)
Showing
4 changed files
with
46 additions
and
5 deletions
Show diff stats
app/controllers/public/content_viewer_controller.rb
... | ... | @@ -23,10 +23,6 @@ class ContentViewerController < ApplicationController |
23 | 23 | redirect_to profile.url.merge(:page => page_from_old_path.explode_path) |
24 | 24 | return |
25 | 25 | end |
26 | - else | |
27 | - if version | |
28 | - @page = @page.versions.find_by_version version | |
29 | - end | |
30 | 26 | end |
31 | 27 | end |
32 | 28 | |
... | ... | @@ -48,6 +44,12 @@ class ContentViewerController < ApplicationController |
48 | 44 | return |
49 | 45 | end |
50 | 46 | |
47 | + if version | |
48 | + @versioned_article = @page.versions.find_by_version(version) | |
49 | + render :template => 'content_viewer/versioned_article.rhtml' | |
50 | + return | |
51 | + end | |
52 | + | |
51 | 53 | if request.xhr? && params[:toolbar] |
52 | 54 | render :partial => 'article_toolbar' |
53 | 55 | return | ... | ... |
app/models/article.rb
... | ... | @@ -631,7 +631,9 @@ class Article < ActiveRecord::Base |
631 | 631 | (allow_post_content?(the_profile) ? "-owner" : '') + |
632 | 632 | (params[:npage] ? "-npage-#{params[:npage]}" : '') + |
633 | 633 | (params[:year] ? "-year-#{params[:year]}" : '') + |
634 | - (params[:month] ? "-month-#{params[:month]}" : '') | |
634 | + (params[:month] ? "-month-#{params[:month]}" : '') + | |
635 | + (params[:rev] ? "-rev-#{params[:rev]}" : '') | |
636 | + | |
635 | 637 | end |
636 | 638 | |
637 | 639 | def first_paragraph | ... | ... |
... | ... | @@ -0,0 +1,32 @@ |
1 | +<div id="article" class="<%= @page.css_class_name %>"> | |
2 | + | |
3 | +<div id="article-toolbar"><%= _("This is the revision %s of this content") % @versioned_article.version %></div> | |
4 | + | |
5 | +<% if @page.display_hits? || @page.license.present? %> | |
6 | + <div id='article-sub-header'> | |
7 | + <% if @versioned_article.license.present? %> | |
8 | + <div id="article-license"> | |
9 | + <%= _('Licensed under %s') % (@versioned_article.license.url.present? ? link_to(@versioned_article.license.name, @versioned_article.license.url, :target => '_blank') : @versioned_article.license.name) %> | |
10 | + </div> | |
11 | + <% end %> | |
12 | + </div> | |
13 | +<% end %> | |
14 | + | |
15 | +<% cache(@page.cache_key(params, user, language)) do %> | |
16 | + <div class="<%="article-body article-body-" + @page.css_class_name %>"> | |
17 | + <% options = @page.image? ? {:gallery_view => true} : {} %> | |
18 | + <%= article_to_html(@page, options) %> | |
19 | + <br style="clear:both" /> | |
20 | + </div> <!-- end class="article-body" --> | |
21 | +<% end %> | |
22 | + | |
23 | + | |
24 | +<div id="article-versions"> | |
25 | + <%= #TODO Review this %> | |
26 | + <%= @page.versions.map {|v| link_to("r#{v.version}", @page.url.merge(:rev => v.version))} %> | |
27 | +</div> | |
28 | + | |
29 | +<%= display_source_info(@versioned_article) %> | |
30 | + | |
31 | +</div><!-- end id="article" --> | |
32 | +<%= add_zoom_to_article_images %> | ... | ... |
test/unit/article_test.rb
... | ... | @@ -740,6 +740,11 @@ class ArticleTest < ActiveSupport::TestCase |
740 | 740 | assert_match(/-year-2009-month-04/, a.cache_key(:year => '2009', :month => '04')) |
741 | 741 | end |
742 | 742 | |
743 | + should 'use revision number to compose cache key' do | |
744 | + a = fast_create(Article, :name => 'Versioned article', :profile_id => profile.id) | |
745 | + assert_match(/-rev-2/,a.cache_key(:rev => 2)) | |
746 | + end | |
747 | + | |
743 | 748 | should 'not be highlighted by default' do |
744 | 749 | a = Article.new |
745 | 750 | assert !a.highlighted | ... | ... |