Patch #29649 » 0003-Add-a-rake-task-to-dump-whole-wikis.patch
| lib/tasks/wikydump.rake (working copy) | ||
|---|---|---|
|
namespace :redmine do
|
||
|
namespace :wikidump do
|
||
|
def export_wiki(project, template, path)
|
||
|
pages = project.wiki.pages.
|
||
|
order('title').
|
||
|
includes([:content, { attachments: :author }]).
|
||
|
to_a
|
||
|
assigns = {
|
||
|
wiki: project.wiki,
|
||
|
project: project,
|
||
|
pages: pages,
|
||
|
action_name: 'export_multiple'
|
||
|
}
|
||
|
lookup_context = ActionView::LookupContext.new(ActionController::Base.view_paths)
|
||
|
view = ActionView::Base.with_empty_template_cache.new(lookup_context, assigns, ActionController::Base.new)
|
||
|
view.class_eval do
|
||
|
include Rails.application.routes.url_helpers
|
||
|
include ApplicationHelper
|
||
|
include WikiHelper
|
||
|
include Redmine::I18n
|
||
|
def url_options
|
||
|
{ host: Setting.host_name.split('/')[0] }
|
||
|
end
|
||
|
end
|
||
|
File.open(path, 'w') do |f|
|
||
|
f.write view.render(template: template)
|
||
|
end
|
||
|
end
|
||
|
desc <<-END_DESC
|
||
|
Dump the wiki of a project to a PDF file.
|
||
|
Available options:
|
||
|
* project => id or identifier of project (defaults to first projects)
|
||
|
* directory => output directory (defaults to rails temporary directory)
|
||
|
Example:
|
||
|
rake redmine:wikidump:pdf project=my-project-identifier directory=/tmp RAILS_ENV="production"
|
||
|
END_DESC
|
||
|
task pdf: :environment do
|
||
|
project = ENV['project'] ? Project.find(ENV['project']) : Project.first
|
||
|
directory = ENV['directory'] || File.join(Rails.root, 'tmp')
|
||
|
path = File.join(directory, "#{project.identifier}.pdf")
|
||
|
export_wiki(project, 'wiki/export.pdf', path)
|
||
|
end
|
||
|
desc <<-END_DESC
|
||
|
Dump the wiki of a project to a HTML file.
|
||
|
Available options:
|
||
|
* project => id or identifier of project (defaults to first projects)
|
||
|
* directory => output directory (defaults to rails temporary directory)
|
||
|
Example:
|
||
|
rake redmine:wikidump:html project=my-project-identifier directory=/tmp RAILS_ENV="production"
|
||
|
END_DESC
|
||
|
task html: :environment do
|
||
|
project = ENV['project'] ? Project.find(ENV['project']) : Project.first
|
||
|
directory = ENV['directory'] || File.join(Rails.root, 'tmp')
|
||
|
path = File.join(directory, "#{project.identifier}.html")
|
||
|
export_wiki project, 'wiki/export_multiple.html', path
|
||
|
end
|
||
|
end
|
||
|
end
|
||
- « Previous
- 1
- 2
- 3
- Next »