@@ -73,7 +73,7 class WikiController < ApplicationController | |||
|
73 | 73 | @content = @page.content_for_version(params[:version]) |
|
74 | 74 | if User.current.allowed_to?(:export_wiki_pages, @project) |
|
75 | 75 | if params[:format] == 'pdf' |
|
76 | send_data(wiki_to_pdf(@page, @project), :type => 'application/pdf', :filename => "#{@page.title}.pdf") | |
|
76 | send_data(wiki_page_to_pdf(@page, @project), :type => 'application/pdf', :filename => "#{@page.title}.pdf") | |
|
77 | 77 | return |
|
78 | 78 | elsif params[:format] == 'html' |
|
79 | 79 | export = render_to_string :action => 'export', :layout => false |
@@ -239,14 +239,22 class WikiController < ApplicationController | |||
|
239 | 239 | redirect_to :action => 'index', :project_id => @project |
|
240 | 240 | end |
|
241 | 241 | |
|
242 | # Export wiki to a single html file | |
|
242 | # Export wiki to a single pdf or html file | |
|
243 | 243 | def export |
|
244 |
|
|
|
245 | @pages = @wiki.pages.find :all, :order => 'title' | |
|
246 | export = render_to_string :action => 'export_multiple', :layout => false | |
|
247 | send_data(export, :type => 'text/html', :filename => "wiki.html") | |
|
248 | else | |
|
244 | unless User.current.allowed_to?(:export_wiki_pages, @project) | |
|
249 | 245 | redirect_to :action => 'show', :project_id => @project, :id => nil |
|
246 | return | |
|
247 | end | |
|
248 | ||
|
249 | @pages = @wiki.pages.all(:order => 'title', :include => [:content, :attachments], :limit => 75) | |
|
250 | respond_to do |format| | |
|
251 | format.html { | |
|
252 | export = render_to_string :action => 'export_multiple', :layout => false | |
|
253 | send_data(export, :type => 'text/html', :filename => "wiki.html") | |
|
254 | } | |
|
255 | format.pdf { | |
|
256 | send_data(wiki_pages_to_pdf(@pages, @project), :type => 'application/pdf', :filename => "#{@project.identifier}.pdf") | |
|
257 | } | |
|
250 | 258 | end |
|
251 | 259 | end |
|
252 | 260 |
@@ -24,7 +24,10 | |||
|
24 | 24 | <% unless @pages.empty? %> |
|
25 | 25 | <% other_formats_links do |f| %> |
|
26 | 26 | <%= f.link_to 'Atom', :url => {:controller => 'activities', :action => 'index', :id => @project, :show_wiki_edits => 1, :key => User.current.rss_key} %> |
|
27 |
<% |
|
|
27 | <% if User.current.allowed_to?(:export_wiki_pages, @project) %> | |
|
28 | <%= f.link_to('PDF', :url => {:action => 'export', :format => 'pdf'}) %> | |
|
29 | <%= f.link_to('HTML', :url => {:action => 'export'}) %> | |
|
30 | <% end %> | |
|
28 | 31 | <% end %> |
|
29 | 32 | <% end %> |
|
30 | 33 |
@@ -20,9 +20,10 | |||
|
20 | 20 | :url => {:controller => 'activities', :action => 'index', |
|
21 | 21 | :id => @project, :show_wiki_edits => 1, |
|
22 | 22 | :key => User.current.rss_key} %> |
|
23 | <%= f.link_to('HTML', | |
|
24 | :url => {:action => 'export'} | |
|
25 | ) if User.current.allowed_to?(:export_wiki_pages, @project) %> | |
|
23 | <% if User.current.allowed_to?(:export_wiki_pages, @project) %> | |
|
24 | <%= f.link_to('PDF', :url => {:action => 'export', :format => 'pdf'}) %> | |
|
25 | <%= f.link_to('HTML', :url => {:action => 'export'}) %> | |
|
26 | <% end %> | |
|
26 | 27 | <% end %> |
|
27 | 28 | <% end %> |
|
28 | 29 |
@@ -573,8 +573,25 module Redmine | |||
|
573 | 573 | pdf.Output |
|
574 | 574 | end |
|
575 | 575 | |
|
576 | # Returns a PDF string of a set of wiki pages | |
|
577 | def wiki_pages_to_pdf(pages, project) | |
|
578 | pdf = ITCPDF.new(current_language) | |
|
579 | pdf.SetTitle(project.name) | |
|
580 | pdf.alias_nb_pages | |
|
581 | pdf.footer_date = format_date(Date.today) | |
|
582 | pdf.AddPage | |
|
583 | pdf.SetFontStyle('B',11) | |
|
584 | pdf.RDMMultiCell(190,5, project.name) | |
|
585 | pdf.Ln | |
|
586 | # Set resize image scale | |
|
587 | pdf.SetImageScale(1.6) | |
|
588 | pdf.SetFontStyle('',9) | |
|
589 | write_page_hierarchy(pdf, pages.group_by(&:parent_id)) | |
|
590 | pdf.Output | |
|
591 | end | |
|
592 | ||
|
576 | 593 | # Returns a PDF string of a single wiki page |
|
577 | def wiki_to_pdf(page, project) | |
|
594 | def wiki_page_to_pdf(page, project) | |
|
578 | 595 | pdf = ITCPDF.new(current_language) |
|
579 | 596 | pdf.SetTitle("#{project} - #{page.title}") |
|
580 | 597 | pdf.alias_nb_pages |
@@ -587,6 +604,26 module Redmine | |||
|
587 | 604 | # Set resize image scale |
|
588 | 605 | pdf.SetImageScale(1.6) |
|
589 | 606 | pdf.SetFontStyle('',9) |
|
607 | write_wiki_page(pdf, page) | |
|
608 | pdf.Output | |
|
609 | end | |
|
610 | ||
|
611 | def write_page_hierarchy(pdf, pages, node=nil, level=0) | |
|
612 | if pages[node] | |
|
613 | pages[node].each do |page| | |
|
614 | if @new_page | |
|
615 | pdf.AddPage | |
|
616 | else | |
|
617 | @new_page = true | |
|
618 | end | |
|
619 | pdf.Bookmark page.title, level | |
|
620 | write_wiki_page(pdf, page) | |
|
621 | write_page_hierarchy(pdf, pages, page.id, level + 1) if pages[page.id] | |
|
622 | end | |
|
623 | end | |
|
624 | end | |
|
625 | ||
|
626 | def write_wiki_page(pdf, page) | |
|
590 | 627 | pdf.RDMwriteHTMLCell(190,5,0,0, |
|
591 | 628 | page.content.text.to_s, page.attachments, "TLRB") |
|
592 | 629 | if page.attachments.any? |
@@ -603,7 +640,6 module Redmine | |||
|
603 | 640 | pdf.Ln |
|
604 | 641 | end |
|
605 | 642 | end |
|
606 | pdf.Output | |
|
607 | 643 | end |
|
608 | 644 | |
|
609 | 645 | class RDMPdfEncoding |
@@ -618,12 +618,13 class WikiControllerTest < ActionController::TestCase | |||
|
618 | 618 | assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'} |
|
619 | 619 | end |
|
620 | 620 | |
|
621 | def test_export | |
|
621 | def test_export_to_html | |
|
622 | 622 | @request.session[:user_id] = 2 |
|
623 | 623 | get :export, :project_id => 'ecookbook' |
|
624 | 624 | |
|
625 | 625 | assert_response :success |
|
626 | 626 | assert_not_nil assigns(:pages) |
|
627 | assert assigns(:pages).any? | |
|
627 | 628 | assert_equal "text/html", @response.content_type |
|
628 | 629 | |
|
629 | 630 | assert_select "a[name=?]", "CookBook_documentation" |
@@ -631,7 +632,19 class WikiControllerTest < ActionController::TestCase | |||
|
631 | 632 | assert_select "a[name=?]", "Page_with_an_inline_image" |
|
632 | 633 | end |
|
633 | 634 | |
|
634 |
def test_export_ |
|
|
635 | def test_export_to_pdf | |
|
636 | @request.session[:user_id] = 2 | |
|
637 | get :export, :project_id => 'ecookbook', :format => 'pdf' | |
|
638 | ||
|
639 | assert_response :success | |
|
640 | assert_not_nil assigns(:pages) | |
|
641 | assert assigns(:pages).any? | |
|
642 | assert_equal 'application/pdf', @response.content_type | |
|
643 | assert_equal 'attachment; filename="ecookbook.pdf"', @response.headers['Content-Disposition'] | |
|
644 | assert @response.body.starts_with?('%PDF') | |
|
645 | end | |
|
646 | ||
|
647 | def test_export_without_permission_should_redirect | |
|
635 | 648 | get :export, :project_id => 'ecookbook' |
|
636 | 649 | |
|
637 | 650 | assert_response 302 |
@@ -29,6 +29,11 class RoutingWikiTest < ActionController::IntegrationTest | |||
|
29 | 29 | :id => 'lalala' } |
|
30 | 30 | ) |
|
31 | 31 | assert_routing( |
|
32 | { :method => 'get', :path => "/projects/567/wiki/lalala.pdf" }, | |
|
33 | { :controller => 'wiki', :action => 'show', :project_id => '567', | |
|
34 | :id => 'lalala', :format => 'pdf' } | |
|
35 | ) | |
|
36 | assert_routing( | |
|
32 | 37 | { :method => 'get', :path => "/projects/1/wiki/CookBook_documentation/diff" }, |
|
33 | 38 | { :controller => 'wiki', :action => 'diff', :project_id => '1', |
|
34 | 39 | :id => 'CookBook_documentation' } |
@@ -60,6 +65,10 class RoutingWikiTest < ActionController::IntegrationTest | |||
|
60 | 65 | { :controller => 'wiki', :action => 'export', :project_id => '567' } |
|
61 | 66 | ) |
|
62 | 67 | assert_routing( |
|
68 | { :method => 'get', :path => "/projects/567/wiki/export.pdf" }, | |
|
69 | { :controller => 'wiki', :action => 'export', :project_id => '567', :format => 'pdf' } | |
|
70 | ) | |
|
71 | assert_routing( | |
|
63 | 72 | { :method => 'get', :path => "/projects/567/wiki/index" }, |
|
64 | 73 | { :controller => 'wiki', :action => 'index', :project_id => '567' } |
|
65 | 74 | ) |
General Comments 0
You need to be logged in to leave comments.
Login now