@@ -73,7 +73,7 class WikiController < ApplicationController | |||||
73 | @content = @page.content_for_version(params[:version]) |
|
73 | @content = @page.content_for_version(params[:version]) | |
74 | if User.current.allowed_to?(:export_wiki_pages, @project) |
|
74 | if User.current.allowed_to?(:export_wiki_pages, @project) | |
75 | if params[:format] == 'pdf' |
|
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 | return |
|
77 | return | |
78 | elsif params[:format] == 'html' |
|
78 | elsif params[:format] == 'html' | |
79 | export = render_to_string :action => 'export', :layout => false |
|
79 | export = render_to_string :action => 'export', :layout => false | |
@@ -239,14 +239,22 class WikiController < ApplicationController | |||||
239 | redirect_to :action => 'index', :project_id => @project |
|
239 | redirect_to :action => 'index', :project_id => @project | |
240 | end |
|
240 | end | |
241 |
|
241 | |||
242 | # Export wiki to a single html file |
|
242 | # Export wiki to a single pdf or html file | |
243 | def export |
|
243 | def export | |
244 |
|
|
244 | unless User.current.allowed_to?(:export_wiki_pages, @project) | |
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 |
|
|||
249 | redirect_to :action => 'show', :project_id => @project, :id => nil |
|
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 | end |
|
258 | end | |
251 | end |
|
259 | end | |
252 |
|
260 |
@@ -24,7 +24,10 | |||||
24 | <% unless @pages.empty? %> |
|
24 | <% unless @pages.empty? %> | |
25 | <% other_formats_links do |f| %> |
|
25 | <% other_formats_links do |f| %> | |
26 | <%= f.link_to 'Atom', :url => {:controller => 'activities', :action => 'index', :id => @project, :show_wiki_edits => 1, :key => User.current.rss_key} %> |
|
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 | <% end %> |
|
31 | <% end %> | |
29 | <% end %> |
|
32 | <% end %> | |
30 |
|
33 |
@@ -20,9 +20,10 | |||||
20 | :url => {:controller => 'activities', :action => 'index', |
|
20 | :url => {:controller => 'activities', :action => 'index', | |
21 | :id => @project, :show_wiki_edits => 1, |
|
21 | :id => @project, :show_wiki_edits => 1, | |
22 | :key => User.current.rss_key} %> |
|
22 | :key => User.current.rss_key} %> | |
23 | <%= f.link_to('HTML', |
|
23 | <% if User.current.allowed_to?(:export_wiki_pages, @project) %> | |
24 | :url => {:action => 'export'} |
|
24 | <%= f.link_to('PDF', :url => {:action => 'export', :format => 'pdf'}) %> | |
25 | ) if User.current.allowed_to?(:export_wiki_pages, @project) %> |
|
25 | <%= f.link_to('HTML', :url => {:action => 'export'}) %> | |
|
26 | <% end %> | |||
26 | <% end %> |
|
27 | <% end %> | |
27 | <% end %> |
|
28 | <% end %> | |
28 |
|
29 |
@@ -573,8 +573,25 module Redmine | |||||
573 | pdf.Output |
|
573 | pdf.Output | |
574 | end |
|
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 | # Returns a PDF string of a single wiki page |
|
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 | pdf = ITCPDF.new(current_language) |
|
595 | pdf = ITCPDF.new(current_language) | |
579 | pdf.SetTitle("#{project} - #{page.title}") |
|
596 | pdf.SetTitle("#{project} - #{page.title}") | |
580 | pdf.alias_nb_pages |
|
597 | pdf.alias_nb_pages | |
@@ -587,6 +604,26 module Redmine | |||||
587 | # Set resize image scale |
|
604 | # Set resize image scale | |
588 | pdf.SetImageScale(1.6) |
|
605 | pdf.SetImageScale(1.6) | |
589 | pdf.SetFontStyle('',9) |
|
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 | pdf.RDMwriteHTMLCell(190,5,0,0, |
|
627 | pdf.RDMwriteHTMLCell(190,5,0,0, | |
591 | page.content.text.to_s, page.attachments, "TLRB") |
|
628 | page.content.text.to_s, page.attachments, "TLRB") | |
592 | if page.attachments.any? |
|
629 | if page.attachments.any? | |
@@ -603,7 +640,6 module Redmine | |||||
603 | pdf.Ln |
|
640 | pdf.Ln | |
604 | end |
|
641 | end | |
605 | end |
|
642 | end | |
606 | pdf.Output |
|
|||
607 | end |
|
643 | end | |
608 |
|
644 | |||
609 | class RDMPdfEncoding |
|
645 | class RDMPdfEncoding |
@@ -618,12 +618,13 class WikiControllerTest < ActionController::TestCase | |||||
618 | assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'} |
|
618 | assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'} | |
619 | end |
|
619 | end | |
620 |
|
620 | |||
621 | def test_export |
|
621 | def test_export_to_html | |
622 | @request.session[:user_id] = 2 |
|
622 | @request.session[:user_id] = 2 | |
623 | get :export, :project_id => 'ecookbook' |
|
623 | get :export, :project_id => 'ecookbook' | |
624 |
|
624 | |||
625 | assert_response :success |
|
625 | assert_response :success | |
626 | assert_not_nil assigns(:pages) |
|
626 | assert_not_nil assigns(:pages) | |
|
627 | assert assigns(:pages).any? | |||
627 | assert_equal "text/html", @response.content_type |
|
628 | assert_equal "text/html", @response.content_type | |
628 |
|
629 | |||
629 | assert_select "a[name=?]", "CookBook_documentation" |
|
630 | assert_select "a[name=?]", "CookBook_documentation" | |
@@ -631,7 +632,19 class WikiControllerTest < ActionController::TestCase | |||||
631 | assert_select "a[name=?]", "Page_with_an_inline_image" |
|
632 | assert_select "a[name=?]", "Page_with_an_inline_image" | |
632 | end |
|
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 | get :export, :project_id => 'ecookbook' |
|
648 | get :export, :project_id => 'ecookbook' | |
636 |
|
649 | |||
637 | assert_response 302 |
|
650 | assert_response 302 |
@@ -29,6 +29,11 class RoutingWikiTest < ActionController::IntegrationTest | |||||
29 | :id => 'lalala' } |
|
29 | :id => 'lalala' } | |
30 | ) |
|
30 | ) | |
31 | assert_routing( |
|
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 | { :method => 'get', :path => "/projects/1/wiki/CookBook_documentation/diff" }, |
|
37 | { :method => 'get', :path => "/projects/1/wiki/CookBook_documentation/diff" }, | |
33 | { :controller => 'wiki', :action => 'diff', :project_id => '1', |
|
38 | { :controller => 'wiki', :action => 'diff', :project_id => '1', | |
34 | :id => 'CookBook_documentation' } |
|
39 | :id => 'CookBook_documentation' } | |
@@ -60,6 +65,10 class RoutingWikiTest < ActionController::IntegrationTest | |||||
60 | { :controller => 'wiki', :action => 'export', :project_id => '567' } |
|
65 | { :controller => 'wiki', :action => 'export', :project_id => '567' } | |
61 | ) |
|
66 | ) | |
62 | assert_routing( |
|
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 | { :method => 'get', :path => "/projects/567/wiki/index" }, |
|
72 | { :method => 'get', :path => "/projects/567/wiki/index" }, | |
64 | { :controller => 'wiki', :action => 'index', :project_id => '567' } |
|
73 | { :controller => 'wiki', :action => 'index', :project_id => '567' } | |
65 | ) |
|
74 | ) |
General Comments 0
You need to be logged in to leave comments.
Login now