Skip to content

Commit

Permalink
Merge pull request #1 from vvmruder/redmine_3.2.0
Browse files Browse the repository at this point in the history
Redmine 3.2.0
  • Loading branch information
KalleBlomquist committed Jan 22, 2016
2 parents 00e5c40 + e8d371c commit 7399bd2
Show file tree
Hide file tree
Showing 14 changed files with 155 additions and 64 deletions.
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ DocPu, Document publishing plugin
This plugin enables PDF export and generation for Redmine wiki pages using the LaTeX typesetting system. But it is even more than an simple PDF exporter since it uses the LaTeX text and figure layout engine.

Originally this redmine plugin was created by Christian Raschko (sponsored by [ATV-Elektronik](http://atv-elektronik.co.at/)). It was intended to be used for 1.1.x verisions of redmine and below.
Since this plugin creates eye catching documents and of cause can be extended a little more I decided to adopt the code and make it valid for use in __redmine 2.6.x__ versions.
Since this plugin creates eye catching documents and of cause can be extended a little more I decided to adopt the code and make it valid for use in __redmine 3.2.x__ versions.

Mainly all features as described below should work. You may find formatting in Redmine's wiki-syntax which isn't covered yet. If so-feel free to contact me.

Expand All @@ -28,14 +28,19 @@ Features
Dependencies
============

DocPu uses and extends the [RedCloth4](http://redcloth.org/) LaTeX export module, which is a converter for the Textile markup language. The system which hosts redmine should also have an working installation of LaTeX. Since the code highlighting is done by pygments, this python package should be installed too. This version of the plugin is made to work with __redmine 2.6.x__. This indicate a dependency to [rails 3.2](http://guides.rubyonrails.org/v3.2.21/3_2_release_notes.html) as you can see [here](http://www.redmine.org/projects/redmine/wiki/RedmineInstall#Ruby-interpreter). For older redmines you can refer to this [version](http://www.redmine.org/plugins/redmine_doc_pu) of the plugin.
DocPu uses and extends the [RedCloth4](http://redcloth.org/) LaTeX export module, which is a converter for the Textile markup language. The system which hosts redmine should also have an working installation of LaTeX. Since the code highlighting is done by pygments, this python package should be installed too. This version of the plugin is made to work with __redmine 3.2.x__. This indicate a dependency to [rails 4.2.5](http://guides.rubyonrails.org/4_2_release_notes.html) as you can see [here](http://www.redmine.org/projects/redmine/wiki/RedmineInstall#Ruby-interpreter). For older redmines you can refer to this [version](http://www.redmine.org/plugins/redmine_doc_pu) of the plugin.

List of Dependencies in a quick view:
* redmine 3.2.0 (tested with ruby 2.0, rails 4.2.5, RedCloth 4.2.9)
* Tex (tested with pdfTeX 3.14159265-2.6-1.40.15 (TeX Live 2014))
* Packeges which are important due to creation process of the PDF inside the plugin (newfloat, minted, caption, ulem, graphicx, float, multirow, makeidx, hyperref, tabularx, footnote, scrhack)

Installing RedCloth4
--------------------

Currently Redmine uses RedCloth3, so you have to additionally install RedCloth4.
The simplest solution is by typing gem install RedCloth, but this only works if you have a compiler set-up, since some parts are written in C code.
For windows users a pre compiled gem package can be downloaded from the repository. Download it first and install it via eg. gem install RedCloth-4.2.2-x86-mswin32-60.gem
For windows users a pre compiled gem package can be downloaded from the repository.

LaTeX
-----
Expand All @@ -47,6 +52,7 @@ On Windows machines you can download and install the [MikTex](http://miktex.org/

DocPu Requires the following LaTeX packages, be sure you have them installed as well:

* newfloat
* tabularx
* listings
* ulem
Expand All @@ -57,6 +63,8 @@ DocPu Requires the following LaTeX packages, be sure you have them installed as
* hyperref
* minted
* caption
* footnote
* scrhack

### Testing LaTeX

Expand Down Expand Up @@ -154,6 +162,8 @@ The image position can be fixed or floated. Fixed images occur at the text posit

Normally you have the standard LaTeX [image types](https://en.wikibooks.org/wiki/LaTeX/Importing_Graphics#Supported_image_formats) available for use.

Note that all images are scaled to fit in the text width space with keeping the spect ratio if they are to large for the page.

## Tables

DocPu supports the Redmine/Textile table syntax with table span and heading.
Expand All @@ -162,3 +172,11 @@ DocPu supports the Redmine/Textile table syntax with table span and heading.
# Template handling

The templates in the plugins template directory are simply LeTeX-Templates. Please refer to [this](https://en.wikibooks.org/wiki/LaTeX) guide to learn more about LaTeX and how to use it.

It is really important, that you have a look at the templates which are included in this plugin. There you can have a look how a template must be written to match the criteria set by this plugin. We designed around this pattern several special looking templates, which are working well. You should be able to do so as well. But keep in mind to NOT DELETE/EDIT ANY CONTENT/PACKAGES which is given in this templates. You can copy one of them (keeping all stuff which is in it) and use the copy to add your own styling. Again: If you delete/edit any thing of the given parameters it will probably not work. But you have enough options to build a nice looking template on top of the existing pattern.

# Known Problems

* Footnotes in tables are placed directly under the table and not to the end of the page (this is due to LaTeX-dependet problems => you may google for it).
* Sometimes the index will not be created well (it helps to build the document 2-3 times again => the number of warnings should decrease)
* to get rid of the warnings and sometimes the errors it can be helpful to rebuild the document 2-3 times before having a look on the templates (also use the clean function in the build view to delete all generated files if you are facing any problems)
11 changes: 6 additions & 5 deletions app/controllers/doc_pu_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@ class DocPuController < ApplicationController

# Show all documents
def index
@documents = DocPuDocument.find_all_by_project_id(@project)
@documents = DocPuDocument.where(project_id: @project)
end


# Create new document
def new

@templates_list = DocPuTemplates.new(Rails.root.join(Setting.plugin_redmine_doc_pu['template_dir'])).list
@doc = DocPuDocument.new
@doc.project = @project
@doc.user = User.current
if request.post?
# Save object
@doc.attributes = checkbox_to_boolean(params[:doc])
@doc.attributes = checkbox_to_boolean(params.require(:doc).permit!)
if @doc.save
flash[:notice] = t(:flash_document_saved)
redirect_to :action => :edit, :project_id => @project, :id => @doc
Expand All @@ -34,10 +35,10 @@ def new

# Edit document
def edit
@doc = DocPuDocument.find(params[:id])
if request.put?
@doc = DocPuDocument.find(params[:id])
if request.patch?
# Update document
@doc.attributes = checkbox_to_boolean(params[:doc])
@doc.attributes = checkbox_to_boolean(params.require(:doc).permit!)
flash[:notice] = t(:flash_document_updated) if @doc.save
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/doc_pu_wiki_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def new
if request.post?
# Save object
reorder_pages(@doc_pu.doc_pu_wiki_pages.all)
@doc_pu_wiki = @doc_pu.doc_pu_wiki_pages.create(checkbox_to_boolean params[:doc_pu_wiki])
@doc_pu_wiki = @doc_pu.doc_pu_wiki_pages.create(checkbox_to_boolean params.require(:doc_pu_wiki).permit!)
@doc_pu_wiki.wiki_page_order = get_new_page_order()
@doc_pu_wiki.wiki_page_version = 0
if @doc_pu_wiki.save
Expand All @@ -34,7 +34,7 @@ def edit
@doc_pu_wiki = DocPuWikiPage.find(params[:id])
if request.put?
# Update object
@doc_pu_wiki.attributes = checkbox_to_boolean(params[:doc_pu_wiki])
@doc_pu_wiki.attributes = checkbox_to_boolean(params.require(:doc_pu_wiki).permit!)
if @doc_pu_wiki.save
flash[:notice] = t(:flash_page_updated)
redirect_to :controller => :doc_pu, :action => :edit, :project_id => @project, :id => @doc_pu
Expand Down
2 changes: 1 addition & 1 deletion app/models/doc_pu_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class DocPuDocument < ActiveRecord::Base

belongs_to :user
belongs_to :project
has_many :doc_pu_wiki_pages, :dependent => :destroy, :order => 'wiki_page_order'
has_many :doc_pu_wiki_pages, :dependent => :destroy

validates_presence_of :name, :template, :user_id, :project_id
validates_uniqueness_of :name
Expand Down
7 changes: 7 additions & 0 deletions app/views/doc_pu/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
<p><%= f.check_box :latex_table_border %> <%= acronym_info_tag t(:info_latex_table_border) %></p>
<p><%= f.check_box :latex_image_ref %> <%= acronym_info_tag t(:info_latex_image_ref) %></p>
</td>
<td class="doc_pu_edit_table_column">
<p><%= f.check_box :latex_table_of_contents %> <%= acronym_info_tag t(:info_latex_table_of_contents) %></p>
<p><%= f.check_box :latex_list_of_figures %> <%= acronym_info_tag t(:info_latex_list_of_figures) %></p>
<p><%= f.check_box :latex_list_of_tables %> <%= acronym_info_tag t(:info_latex_list_of_tables) %></p>
<p><%= f.check_box :latex_list_of_listings %> <%= acronym_info_tag t(:info_latex_list_of_listings) %></p>
<p><%= f.check_box :latex_generate_index %> <%= acronym_info_tag t(:info_latex_generate_index) %></p>
</td>
</tr>
</table>
<div align=left><%= submit_tag l(:button_save) %></div>
Expand Down
10 changes: 10 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ de:
field_latex_index_importance: "Wichtige Wörter indizieren"
field_latex_table_border: "Rahmen für Tabellen"
field_latex_image_ref: "Bilder refernzieren"
field_latex_list_of_listings: "Codeverzeichnis"
field_latex_table_of_contents: "Inhaltsverzeichnis"
field_latex_list_of_figures: "Abbildungsverzeichnis"
field_latex_list_of_tables: "Tabellenverzeichnis"
field_latex_generate_index: "Index"
field_wiki_page: "Wiki Seite"
field_chapter_name: "Kapitel Name"
field_use_doc_flags: "Dokument Flags verwenden"
Expand Down Expand Up @@ -74,6 +79,11 @@ de:
info_latex_index_importance: ""
info_latex_table_border: "Stellt Tabellenlinien dar."
info_latex_image_ref: "Erzeuge Bildverzeichnis"
info_latex_list_of_listings: "Erzeugt ein Verzeichnis aller Code-Beispiele. Dieses wird am Anfang des Dokumentes eingefügt."
info_latex_list_of_figures: "Erzeugt eine Verzeichnis aller Abbildungen. Dieses wird am Anfang des Dokumentes eingefügt."
info_latex_list_of_tables: "Erzeugt eine Verzeichnis aller Tabellen. Dieses wird am Anfang des Dokumentes eingefügt."
info_latex_table_of_contents: "Erzeugt ein Inhaltsverzeichnis für das gesamte Dokument. Dieses wird am Anfang des Dokumentes eingefügt."
info_latex_generate_index: "Erzeugt einen Index von hervorgehobenen Wörtern (dies sind alle Wörter die mit \\*WORT\\* fett gedruckt werden). Es wird am Ende des Dokumentes eingefügt."
button_test: "Test"
field_latex_bin: "LaTeX Binärdatei (pdflatex)"
field_makindex_bin: "makeindex Binärdatei"
Expand Down
4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
match 'doc_pu', :controller => 'doc_pu', :action => 'index', :via => :get
match 'doc_pu/new', :controller => 'doc_pu', :action => 'new', :via => [:get, :post]
match 'doc_pu/edit', :controller => 'doc_pu', :action => 'edit', :via => [:get, :post, :put]
match 'doc_pu/edit', :controller => 'doc_pu', :action => 'edit', :via => [:get, :post, :patch]
match 'doc_pu/open', :controller => 'doc_pu', :action => 'open', :via => [:get, :post]
match 'doc_pu/build', :controller => 'doc_pu', :action => 'build', :via => [:get, :post]
match 'doc_pu/build_remote', :controller => 'doc_pu', :action => 'build_remote', :via => [:get, :post]
Expand All @@ -12,7 +12,7 @@

match 'doc_pu_wiki', :controller => 'doc_pu_wiki', :action => 'index', :via => [:get]
match 'doc_pu_wiki/new', :controller => 'doc_pu_wiki', :action => 'new', :via => [:get, :post]
match 'doc_pu_wiki/edit', :controller => 'doc_pu_wiki', :action => 'edit', :via => [:get, :post, :put]
match 'doc_pu_wiki/edit', :controller => 'doc_pu_wiki', :action => 'edit', :via => [:get, :post, :patch]
match 'doc_pu_wiki/delete', :controller => 'doc_pu_wiki', :action => 'delete', :via => [:get, :post]
match 'doc_pu_wiki/edit_order', :controller => 'doc_pu_wiki', :action => 'edit_order', :via => [:get, :post]

Expand Down
4 changes: 2 additions & 2 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
name 'Redmine DocPu plugin'
author 'Christian Raschko'
description 'A wiki export and document publishing tool, sponsored by: ATV-Elektronik and modified for further use by: GIS-Fachstelle BL'
version '0.0.4'
version '2.0.0'
url 'https://github.com/vvmruder/redmine_doc_pu'

# Settings
Expand All @@ -22,7 +22,7 @@
:partial => 'settings/doc_pu_settings'

# Redmine version
requires_redmine :version_or_higher => '2.6.0'
requires_redmine :version_or_higher => '3.2.0'

# Create project module
project_module :doc_pu do
Expand Down
43 changes: 43 additions & 0 deletions lib/latex_doc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,49 @@ def to_latex
self.wiki_pages.each do |page|
doc_txt += page.to_latex
end
intro_content = false
pre_text = ""

if self.latex_table_of_contents
# Add table of contents to the begin of the document
with_table_of_content = "\\tableofcontents\n\n"
pre_text << with_table_of_content
intro_content = true
end

if self.latex_list_of_figures
# Add list of figures to the begin of the document
with_list_of_figures = "\\listoffigures\n\n"
pre_text << with_list_of_figures
intro_content = true
end

if self.latex_list_of_tables
# Add list of tables to the begin of the document
with_list_of_tables = "\\listoftables\n\n"
pre_text << with_list_of_tables
intro_content = true
end

if self.latex_list_of_listings
# Add list of code listings to the begin of the document
with_list_of_listings = "\\listoflistings\n\n"
pre_text << with_list_of_listings
intro_content = true
end

if intro_content
with_roman_numbers = "\n\n\\pagenumbering{roman}\n\n\\setcounter{page}{1}\n\n"
pre_text = with_roman_numbers << pre_text
pre_text << "\n\n\\cleardoublepage\\pagenumbering{arabic}\n\n\\setcounter{page}{1}\n\n"
doc_txt = pre_text << doc_txt
end

if self.latex_generate_index
# Add list of code listings to the begin of the document
with_index = "\n\n\\printindex"
doc_txt << with_index
end
doc_txt
end

Expand Down
7 changes: 6 additions & 1 deletion lib/latex_flags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ module ModuleLatexFlags
:latex_index_emphasis => true,
:latex_index_importance => true,
:latex_table_border => true,
:latex_image_ref => false
:latex_image_ref => false,
:latex_list_of_listings => false,
:latex_list_of_figures => false,
:latex_list_of_tables => false,
:latex_table_of_contents => false,
:latex_generate_index => false
}


Expand Down
9 changes: 4 additions & 5 deletions lib/latex_wiki_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ def to_latex()
page_txt.gsub!(fn, dsk_fn)
end

# Check wiki referenzes for redirects
# Check wiki references for redirects
page_txt.gsub!(/(\s|^)\[\[(.*?)(\|(.*?)|)\]\]/i) do |_|
ref = $2
label = $4
ref = Wiki.titleize(ref)
redir = WikiRedirect.all(:conditions => ['title = ?', ref])[0]
redir = WikiRedirect.where(title: ref)
ref = redir.redirects_to unless redir.nil?
" [[#{ref}|#{label}]]"
end
Expand All @@ -46,12 +46,11 @@ def to_latex()
rules.push(:latex_index_emphasis) if self.latex_index_emphasis
rules.push(:latex_index_importance) if self.latex_index_importance
rules.push(:latex_remove_macro) if self.latex_remove_macro

# Convert page to latex
r = TextileDocLatex.new(page_txt)
r.draw_table_border_latex = self.latex_table_border
page_txt = r.to_latex(*rules)

if self.latex_add_chapter
# Add chapter tag
page_txt = "\n\\chapter{#{self.chapter_name}} \\label{page:#{self.wiki_page.title}}\n" + page_txt
Expand All @@ -60,7 +59,7 @@ def to_latex()
page_txt.sub!(/\\section\{(.+)\}/i) do |_|
"\\section{#{$1}}\\label{page:#{self.wiki_page.title.gsub(' ', '_')}}"
end
end
end

page_txt
end
Expand Down
22 changes: 13 additions & 9 deletions lib/textile_doc_latex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

module RedCloth::Formatters::LATEX_EX
include RedCloth::Formatters::LATEX

def td(opts)
if opts[:text]
if opts[:text].include? "\n"
Expand Down Expand Up @@ -30,10 +29,12 @@ def td(opts)
end

def table_close(opts)
output = "\\begin{table}[H]\n"
output = "\\begin{savenotes}\n"
output << "\\begin{table}[H]\n"
output << " \\centering\n"
cols = 'X' * @table[0].size if not draw_table_border_latex
cols = '|' + 'X|' * @table[0].size if draw_table_border_latex
output << "\\begin{minipage}{\\linewidth}\n"
output << " \\begin{tabularx}{\\textwidth}{#{cols}}\n"
output << " \\hline \n" if draw_table_border_latex
@table.each do |row|
Expand All @@ -42,7 +43,9 @@ def table_close(opts)
end
output << " \\end{tabularx}\n"
output << " \\caption{}\n"
output << " \\end{minipage}\n"
output << "\\end{table}\n"
output << "\\end{savenotes}\n"
output
end

Expand All @@ -55,7 +58,7 @@ def image(opts)
# Build latex code
[ "\\begin{figure}[#{(opts[:align].nil? ? 'H' : 'htb')}]",
" \\centering",
" \\includegraphics[#{styling}]{#{opts[:src]}}",
" \\lwincludegraphics[#{styling}]{#{opts[:src]}}",
(" \\caption{#{escape opts[:title]}}" if opts[:title]),
(" \\label{#{opts[:alt]}}" if opts[:alt]),
"\\end{figure}",
Expand All @@ -75,9 +78,10 @@ def latex_code(text)
code = $2
lang = "{#{$1}}"
end
minted_settings = %W(mathescape linenos numbersep=5pt frame=lines framesep=2mm tabsize=4 fontsize=\\footnotesize)
minted_settings = %W(mathescape linenos numbersep=5pt frame=lines framesep=2mm tabsize=4 fontsize=\\footnotesize breaklines)
.join(",")
latex_code_text = "<notextile>\\begin{listing}[H]\n\\begin{minted}[#{minted_settings}]#{lang}#{code}\n\\end{minted}\n\\caption{}\n\\end{listing}</notextile>\n"
puts minted_settings
latex_code_text = "<notextile>\\begin{code}\\begin{minted}[#{minted_settings}]#{lang}#{code}\n\\end{minted}\n\\caption{}\n\\end{code}\n</notextile>\n"
latex_code_text
end
end
Expand Down Expand Up @@ -126,11 +130,11 @@ def latex_index_importance(text)
end
end

def latex_remove_macro(text)
text.gsub!(/(\s|^)\{\{(.*?)\}\}/i) do |_|
def latex_remove_macro(text)
text.gsub!(/(\s|^)\{\{(.*?)\}\}/i) do |_|
''
end
end
end
end
end

# Include rules
Expand Down
Loading

0 comments on commit 7399bd2

Please sign in to comment.