From 6186117886b0b4a43437cc196756b9f99c4b9a1e Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 4 Mar 2007 21:34:42 +0000 Subject: [PATCH] added wiki functionalities: * simple page export to plain text * full wiki export to a single html file with index git-svn-id: http://redmine.rubyforge.org/svn/branches/work@299 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- wiki/app/controllers/wiki_controller.rb | 12 ++++++++- wiki/app/helpers/application_helper.rb | 12 ++++++--- wiki/app/views/projects/_form.rhtml | 3 +++ wiki/app/views/wiki/export.rhtml | 6 ++++- wiki/app/views/wiki/export_multiple.rhtml | 27 +++++++++++++++++++ wiki/app/views/wiki/show.rhtml | 3 ++- wiki/app/views/wiki/special_page_index.rhtml | 6 +++++ wiki/lang/fr.yml | 2 +- wiki/public/images/txt.png | Bin 0 -> 633 bytes wiki/public/stylesheets/application.css | 1 + 10 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 wiki/app/views/wiki/export_multiple.rhtml create mode 100644 wiki/public/images/txt.png diff --git a/wiki/app/controllers/wiki_controller.rb b/wiki/app/controllers/wiki_controller.rb index 2dbc3724b..251ef8ca0 100644 --- a/wiki/app/controllers/wiki_controller.rb +++ b/wiki/app/controllers/wiki_controller.rb @@ -32,6 +32,9 @@ class WikiController < ApplicationController export = render_to_string :action => 'export', :layout => false send_data(export, :type => 'text/html', :filename => "#{@page.title}.html") return + elsif params[:export] == 'txt' + send_data(@page.content.text, :type => 'text/plain', :filename => "#{@page.title}.txt") + return end render :action => 'show' end @@ -66,11 +69,18 @@ class WikiController < ApplicationController def special page_title = params[:page].downcase case page_title + # show pages index, sorted by title when 'page_index' - # eagger load information about last updates, without loading text + # eager load information about last updates, without loading text @pages = @wiki.pages.find :all, :select => "wiki_pages.*, wiki_contents.updated_on", :joins => "LEFT JOIN wiki_contents ON wiki_contents.page_id = wiki_pages.id", :order => 'title' + # export wiki to a single html file + when 'export' + @pages = @wiki.pages.find :all, :order => 'title' + export = render_to_string :action => 'export_multiple', :layout => false + send_data(export, :type => 'text/html', :filename => "wiki.html") + return else # requested special page doesn't exist, redirect to default page redirect_to :action => 'index', :id => @project, :page => nil and return diff --git a/wiki/app/helpers/application_helper.rb b/wiki/app/helpers/application_helper.rb index 779c54cbe..16ade7b9d 100644 --- a/wiki/app/helpers/application_helper.rb +++ b/wiki/app/helpers/application_helper.rb @@ -93,11 +93,17 @@ module ApplicationHelper end # textilize text according to system settings and RedCloth availability - # options: - # - basename: if set to true, generates local wiki links (used for html exports) def textilizable(text, options = {}) + case options[:wiki_links] + when :local + wiki_link_format = 'Wiki.titleize($1) + ".html"' + when :anchor + wiki_link_format = '"#" + Wiki.titleize($1)' + else + wiki_link_format = '"/wiki/#{@project.id}/#{Wiki.titleize($1)}"' + end # turn wiki links in textile links: "text":url - text = text.gsub(/\[\[([^\]\|]+)(\|([^\]\|]+))?\]\]/) {|m| "\"#{$3 || $1}\":" + (options[:wiki_basename] ? Wiki.titleize($1) : "/wiki/#{@project.id}/#{Wiki.titleize($1)}") } if @project + text = text.gsub(/\[\[([^\]\|]+)(\|([^\]\|]+))?\]\]/) {|m| "\"#{$3 || $1}\":" + (eval wiki_link_format) } if @project text = (Setting.text_formatting == 'textile') && (ActionView::Helpers::TextHelper.method_defined? "textilize") ? auto_link(RedCloth.new(text, [:filter_html]).to_html) : simple_format(auto_link(h(text))) # turn "#id" patterns into links to issues text = text.gsub(/#(\d+)([^;\d])/, "#\\1\\2") diff --git a/wiki/app/views/projects/_form.rhtml b/wiki/app/views/projects/_form.rhtml index 159c06047..b10379cf0 100644 --- a/wiki/app/views/projects/_form.rhtml +++ b/wiki/app/views/projects/_form.rhtml @@ -42,6 +42,9 @@
<% fields_for :wiki, @project.wiki, { :builder => TabularFormBuilder, :lang => current_language} do |wiki| %>

<%= wiki.text_field :start_page, :size => 60, :required => true %>

+<% # content_tag("div", "", :id => "wiki_start_page_auto_complete", :class => "auto_complete") + + # auto_complete_field("wiki_start_page", { :url => { :controller => 'wiki', :action => 'auto_complete_for_wiki_page', :id => @project } }) +%> <% end %>
<%= javascript_tag "Element.hide('wiki');" if @project.wiki.nil? %> diff --git a/wiki/app/views/wiki/export.rhtml b/wiki/app/views/wiki/export.rhtml index fbaf71b42..10a311923 100644 --- a/wiki/app/views/wiki/export.rhtml +++ b/wiki/app/views/wiki/export.rhtml @@ -3,10 +3,14 @@ <%=h @page.pretty_title %> +

<%=h @page.pretty_title %>


-<%= textilizable @content.text, :wiki_basename => true %> +<%= textilizable @content.text, :wiki_links => :local %> diff --git a/wiki/app/views/wiki/export_multiple.rhtml b/wiki/app/views/wiki/export_multiple.rhtml new file mode 100644 index 000000000..bcbf448d1 --- /dev/null +++ b/wiki/app/views/wiki/export_multiple.rhtml @@ -0,0 +1,27 @@ + + + +<%=h @wiki.project.name %> + + + + + +<%= l(:label_page_index) %> + + +<% @pages.each do |page| %> +
+

<%=h page.pretty_title %>

+<%= textilizable page.content.text, :wiki_links => :anchor %> +<% end %> + + + diff --git a/wiki/app/views/wiki/show.rhtml b/wiki/app/views/wiki/show.rhtml index a0d0035c3..901216bf3 100644 --- a/wiki/app/views/wiki/show.rhtml +++ b/wiki/app/views/wiki/show.rhtml @@ -27,5 +27,6 @@
<%= l(:label_export_to) %> -<%= link_to 'HTML', {:export => 'html'}, :class => 'icon icon-html' %> +<%= link_to 'HTML', {:export => 'html'}, :class => 'icon icon-html' %>, +<%= link_to 'TXT', {:export => 'txt'}, :class => 'icon icon-txt' %>
\ No newline at end of file diff --git a/wiki/app/views/wiki/special_page_index.rhtml b/wiki/app/views/wiki/special_page_index.rhtml index 35bdb5a38..e6e3e7020 100644 --- a/wiki/app/views/wiki/special_page_index.rhtml +++ b/wiki/app/views/wiki/special_page_index.rhtml @@ -1,3 +1,9 @@ +
+<% unless @pages.empty? %> +<%= l(:label_export_to) %> <%= link_to 'HTML', {:action => 'special', :page => 'export'}, :class => 'icon icon-html' %> +<% end %> +
+

<%= l(:label_page_index) %>

<% if @pages.empty? %>

<%= l(:label_no_data) %>

<% end %> diff --git a/wiki/lang/fr.yml b/wiki/lang/fr.yml index 79ed13cfa..399bd4756 100644 --- a/wiki/lang/fr.yml +++ b/wiki/lang/fr.yml @@ -321,7 +321,7 @@ label_search: Recherche label_result: %d résultat label_result_plural: %d résultats label_wiki: Wiki -label_page_index: Index des pages +label_page_index: Index label_current_version: Version actuelle button_login: Connexion diff --git a/wiki/public/images/txt.png b/wiki/public/images/txt.png new file mode 100644 index 0000000000000000000000000000000000000000..6915d2df49adce24c4473e45a8d9c2a80c1cd3ce GIT binary patch literal 633 zcmV-<0*3vGP)$c5J{>?NE|xrZ+i_yE30Qlx#go7ejYt{wvT3N8#uj$lP1MR6vD zwd)rkQ*Zzd@y+~x9HXi{JUrC*_xHb9Yptppfd9$LB}yrJcX#*4%gamg0Da%LBJ%s; za6m*55dap81y@&B7-KNTV6DX%gNSf_ef=l!322(ej>WpJ+3)wLD!bi|?RJZE4r2`G z^O<27sH%$F+glGL4^Y>&jWM#_ZfTl^QVJ<0s;Zi%an9kr=k4u{<#Nd|3?AU~@ZQa4 zGZu>lA~H>qbH+JG2!T=xUDpvpU^bi4b=?;rgkamYrK&30wnbH^&cLL9lnF4O&#RvS z4&Zz~PY_wv=C0;;d5rCXC)>@o%lu~G#hPtj%HJFPTBfyT`_xnA@7;?_kb&ZISQeqf}&tI^P zQogp;UzWs&5J)KzLO@k9#-OS==SV3bA{>vAe-4rUrsH%v8321R(dC>`RZ>dioJlE7 zKXP+(L)Y~zmjlbb!+Xc`^Yb3Ss47oSPrs~Is~;jV=@yaEZM?6@`3xvc6L@`n{cE*a z{kmSSqX#%1kAJ_vzkgFz0Yp{B7$d4Gsz?zn=krOL5Kg<@?(OmM@%wtcjsX7xoFhDv TnQ;VS00000NkvXXu0mjfKglMR literal 0 HcmV?d00001 diff --git a/wiki/public/stylesheets/application.css b/wiki/public/stylesheets/application.css index f0bae4d8a..2abcb61ea 100644 --- a/wiki/public/stylesheets/application.css +++ b/wiki/public/stylesheets/application.css @@ -140,6 +140,7 @@ vertical-align: middle; .icon-pdf { background-image: url(../images/pdf.png); } .icon-csv { background-image: url(../images/csv.png); } .icon-html { background-image: url(../images/html.png); } +.icon-txt { background-image: url(../images/txt.png); } .icon-file { background-image: url(../images/file.png); } .icon-folder { background-image: url(../images/folder.png); } .icon-package { background-image: url(../images/package.png); }