papyrus 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING +340 -0
- data/README.rdoc +132 -0
- data/VERSION.txt +1 -0
- data/data/main.tex.erb +186 -0
- data/data/module.tex.erb +110 -0
- data/data/rdoc_file.tex.erb +26 -0
- data/lib/rdoc/discover.rb +22 -0
- data/lib/rdoc/generator/latex_markup.rb +174 -0
- data/lib/rdoc/generator/papyrus.rb +382 -0
- data/lib/rdoc/generator/papyrus/options.rb +87 -0
- data/lib/rdoc/markup/to_latex.rb +399 -0
- data/lib/rdoc/markup/to_latex_crossref.rb +182 -0
- metadata +91 -0
data/VERSION.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/data/main.tex.erb
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
\documentclass[a4paper,11pt]{article}
|
2
|
+
|
3
|
+
% This file is part of RDoc PDF LaTeX.
|
4
|
+
%
|
5
|
+
% RDoc PDF LaTeX is a RDoc plugin for generating PDF files.
|
6
|
+
% Copyright © 2011 Pegasus Alpha
|
7
|
+
%
|
8
|
+
% RDoc PDF LaTeX is free software; you can redistribute it and/or modify
|
9
|
+
% it under the terms of the GNU General Public License as published by
|
10
|
+
% the Free Software Foundation; either version 2 of the License, or
|
11
|
+
% (at your option) any later version.
|
12
|
+
%
|
13
|
+
% RDoc PDF LaTeX is distributed in the hope that it will be useful,
|
14
|
+
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
% GNU General Public License for more details.
|
17
|
+
%
|
18
|
+
% You should have received a copy of the GNU General Public License
|
19
|
+
% along with RDoc PDF LaTeX; if not, write to the Free Software
|
20
|
+
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
21
|
+
|
22
|
+
% Variables used for the ERB template:
|
23
|
+
%
|
24
|
+
% babel_lang: Something like "ngerman", determines the babel language
|
25
|
+
% to load.
|
26
|
+
% doc_title: Title of the documentation.
|
27
|
+
% @rdoc_files: List of RDoc::TopLevel objects for all found files
|
28
|
+
% (first one will become the title file).
|
29
|
+
% @classes_and_modules: List of RDoc::ClassModule objects for all found classes
|
30
|
+
% and modules.
|
31
|
+
|
32
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
33
|
+
% Packages
|
34
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
35
|
+
|
36
|
+
\usepackage[<%= babel_lang %>]{babel} %Hyphenation, etc.
|
37
|
+
\usepackage[utf8]{inputenc} %Input encoding: UTF-8
|
38
|
+
\usepackage[T1]{fontenc} %Output encoding: T1
|
39
|
+
\usepackage{lmodern} %Pretty fonts for T1
|
40
|
+
\usepackage{textcomp} %Useful things like \textdegree
|
41
|
+
\usepackage[official]{eurosym} %Official \euro symbol
|
42
|
+
\usepackage{lastpage} %Get a reference on the last page
|
43
|
+
\usepackage[lmargin=3cm,rmargin=3cm,bmargin=2cm]{geometry}
|
44
|
+
\usepackage{fancyhdr} %Headers and footers
|
45
|
+
\usepackage{fancyvrb} %Better verbatim text
|
46
|
+
\usepackage{longtable}
|
47
|
+
%\usepackage{amsmath} %For math
|
48
|
+
%\usepackage{amsfonts} %Math fonts
|
49
|
+
%\usepackage[retainorgcmds]{IEEEtrantools} %For equations
|
50
|
+
%\usepackage{listings} %Syntax hightlighting
|
51
|
+
\usepackage{xcolor} %Colored text
|
52
|
+
%\usepackage{graphicx} %Graphics
|
53
|
+
\usepackage{titlesec} %Easily define new heading styles
|
54
|
+
\usepackage{titletoc} %For telling LaTeX where to put the new headings in the TOC
|
55
|
+
\usepackage[unicode=true,pdftex]{hyperref} %For hyperlinks
|
56
|
+
|
57
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
58
|
+
% General information
|
59
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
60
|
+
|
61
|
+
\author{\LaTeX PDF generator for RDoc}
|
62
|
+
\title{<%= doc_title %>}
|
63
|
+
\date{\today}
|
64
|
+
|
65
|
+
%Generate TOC only till level 2
|
66
|
+
\setcounter{tocdepth}{2}
|
67
|
+
%Disable section numbering
|
68
|
+
\setcounter{secnumdepth}{-2}
|
69
|
+
|
70
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
71
|
+
% New commands and environments
|
72
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
73
|
+
% TODO: Make this a LaTeX package?
|
74
|
+
|
75
|
+
\titleclass{\subsubsubsection}{straight}[\subsubsection]
|
76
|
+
\titleformat{\subsubsubsection}[hang]{\raggedleft\sffamily\bfseries}{%
|
77
|
+
\thesubsubsubsection}{1em}{}[\vspace{-3mm}\rule{\textwidth}{1pt}]
|
78
|
+
\titlespacing{\subsubsubsection}{0pt}{*1}{\baselineskip}
|
79
|
+
\newcounter{subsubsubsection}
|
80
|
+
\renewcommand{\thesubsubsubsection}{\thesubsubsection.\arabic{subsubsubsection}}
|
81
|
+
\titlecontents{subsubsubsection}[0pt]{}{\thecontentslabel}{}{\titlerule*[8pt]{.}\contentspage}
|
82
|
+
|
83
|
+
\titleclass{\microsection}{straight}[\subsubsubsection]
|
84
|
+
\titleformat{\microsection}[hang]{\vspace{\baselineskip}\sffamily\small\bfseries\slshape}{%
|
85
|
+
\themicrosection}{1em}{}
|
86
|
+
\titlespacing{\microsection}{0pt}{*1}{\baselineskip}
|
87
|
+
\newcounter{microsection}
|
88
|
+
\renewcommand{\themicrosection}{\thesubsubsubsection.\arabic{microsection}}
|
89
|
+
\titlecontents{microsection}[0pt]{}{\thecontentslabel}{}{\titlerule*[8pt]{.}\contentspage}
|
90
|
+
|
91
|
+
\titleformat{\part}[hang]{\normalfont\LARGE\scshape\color{blue}}{\thepart}{1em}{}[\vspace{-3mm}\rule{0.6\textwidth}{1mm}]
|
92
|
+
\titlespacing{\part}{-1cm}{0pt}{\baselineskip}
|
93
|
+
|
94
|
+
\newcommand{\class}[2]{\subsection[#1]{{\normalfont\textsc{Class}} {#1}}\vspace{-3mm}{\footnotesize Parent: \texttt{#2}\par\vspace{\baselineskip}}}
|
95
|
+
\newcommand{\module}[1]{\subsection[#1]{{\normalfont\textsc{Module}} {#1}}}
|
96
|
+
\newcommand{\method}[1]{\subsubsubsection*{#1}}
|
97
|
+
|
98
|
+
|
99
|
+
%Code without specification
|
100
|
+
\newcommand{\code}[1]{\texttt{#1}}
|
101
|
+
|
102
|
+
%Environments for RDoc’s lists
|
103
|
+
%1. Completely lower-alpha list
|
104
|
+
\newenvironment{lalphaenum}{
|
105
|
+
\renewcommand{\theenumi}{\alph{enumi}}
|
106
|
+
\renewcommand{\theenumii}{\alph{enumii}}
|
107
|
+
\renewcommand{\theenumiii}{\alph{enumiii}}
|
108
|
+
\renewcommand{\theenumiv}{\alph{enumiv}}
|
109
|
+
\begin{enumerate}}{
|
110
|
+
\end{enumerate}
|
111
|
+
}
|
112
|
+
|
113
|
+
%2. Completely upper-alpha list
|
114
|
+
\newenvironment{ualphaenum}{
|
115
|
+
\renewcommand{\theenumi}{\Alph{enumi}}
|
116
|
+
\renewcommand{\theenumii}{\Alph{enumii}}
|
117
|
+
\renewcommand{\theenumiii}{\Alph{enumiii}}
|
118
|
+
\renewcommand{\theenumiv}{\Alph{enumiv}}
|
119
|
+
\begin{enumerate}}{
|
120
|
+
\end{enumerate}
|
121
|
+
}
|
122
|
+
|
123
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
124
|
+
% Package-specific settings
|
125
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
126
|
+
|
127
|
+
% fancyvrb
|
128
|
+
\fvset{fontsize=\scriptsize}
|
129
|
+
|
130
|
+
% hyperref
|
131
|
+
\hypersetup{colorlinks=true,urlcolor=blue}
|
132
|
+
\hypersetup{pdfauthor={Papyrus generator for RDoc},pdftitle={<%= doc_title %>}}
|
133
|
+
|
134
|
+
% fancyhdr
|
135
|
+
\pagestyle{fancy}
|
136
|
+
\fancyhf{} %Delete everything
|
137
|
+
\fancyhead[L]{\rightmark}
|
138
|
+
\fancyhead[R]{\thepage{} / \pageref*{LastPage}}
|
139
|
+
\setlength{\headheight}{14.5pt} %Otherwise LaTeX complains
|
140
|
+
\renewcommand{\headrulewidth}{0.4pt}
|
141
|
+
|
142
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
143
|
+
% Document start
|
144
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
145
|
+
|
146
|
+
\begin{document}
|
147
|
+
|
148
|
+
\begin{titlepage}
|
149
|
+
\begin{center}
|
150
|
+
\Huge <%= doc_title %>
|
151
|
+
\end{center}
|
152
|
+
\begin{flushright}
|
153
|
+
\rule{4.5cm}{0.1cm}\\
|
154
|
+
\normalsize Generated \today\\
|
155
|
+
\tiny by the Papyrus generator for RDoc
|
156
|
+
\end{flushright}
|
157
|
+
\end{titlepage}
|
158
|
+
|
159
|
+
% Typeset the title page (if any) before the TOC
|
160
|
+
%<% if (title_file = @rdoc_files.shift) %>
|
161
|
+
\input{<%= render_rdoc_file(title_file) %>}
|
162
|
+
%<% end %>
|
163
|
+
|
164
|
+
\hypersetup{linkcolor=black} %Red TOC looks absolutely awful
|
165
|
+
\tableofcontents
|
166
|
+
\hypersetup{linkcolor=red} %Restore original link color
|
167
|
+
\clearpage
|
168
|
+
%
|
169
|
+
%Typeset the other RDOc files after the TOC
|
170
|
+
%<% @rdoc_files.each do |file| %>
|
171
|
+
\input{<%= render_rdoc_file(file) %>}
|
172
|
+
%<% end %>
|
173
|
+
|
174
|
+
\part{Generated Documentation}
|
175
|
+
|
176
|
+
\section{Methods overview}
|
177
|
+
<%= generate_method_toc_table %>
|
178
|
+
|
179
|
+
\clearpage
|
180
|
+
|
181
|
+
\section{Class and module reference}
|
182
|
+
<% @classes_and_modules.each do |mod| %>
|
183
|
+
\input{<%= render_module(mod) %>}\clearpage %Always start a new page for a new class/module
|
184
|
+
<% end %>
|
185
|
+
|
186
|
+
\end{document}
|
data/data/module.tex.erb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
% This file is part of RDoc PDF LaTeX.
|
2
|
+
%
|
3
|
+
% RDoc PDF LaTeX is a RDoc plugin for generating PDF files.
|
4
|
+
% Copyright © 2011 Pegasus Alpha
|
5
|
+
%
|
6
|
+
% RDoc PDF LaTeX is free software; you can redistribute it and/or modify
|
7
|
+
% it under the terms of the GNU General Public License as published by
|
8
|
+
% the Free Software Foundation; either version 2 of the License, or
|
9
|
+
% (at your option) any later version.
|
10
|
+
%
|
11
|
+
% RDoc PDF LaTeX is distributed in the hope that it will be useful,
|
12
|
+
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
% GNU General Public License for more details.
|
15
|
+
%
|
16
|
+
% You should have received a copy of the GNU General Public License
|
17
|
+
% along with RDoc PDF LaTeX; if not, write to the Free Software
|
18
|
+
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
|
20
|
+
% This ERB template takes the following variables:
|
21
|
+
% mod: The module or class (RDoc::ClassModule) to document
|
22
|
+
%
|
23
|
+
%<% if mod.module? %>
|
24
|
+
\module{<%= mod.latexized :full_name %>}\label{<%= mod.latex_label %>}
|
25
|
+
% <% else %>
|
26
|
+
\class{<%= mod.latexized :full_name %>}{<%= superclass_string(mod.superclass) %>}\label{<%= mod.latex_label %>}
|
27
|
+
%<% end %>
|
28
|
+
|
29
|
+
<%= mod.description %>
|
30
|
+
|
31
|
+
%<% unless mod.method_list.empty? %>
|
32
|
+
\subsubsection*{Method list}
|
33
|
+
<%= generate_method_table(mod.method_list) %>
|
34
|
+
%<% end %>
|
35
|
+
|
36
|
+
%<% unless mod.includes.empty? %>
|
37
|
+
\subsubsection*{Included Modules}
|
38
|
+
\begin{itemize}
|
39
|
+
% <% mod.includes.sort_by{|i| i.name}.each do |inc| %>
|
40
|
+
\item \texttt{<%= inc.latexized :full_name %>}
|
41
|
+
% <% end %>
|
42
|
+
\end{itemize}
|
43
|
+
%<% end %>
|
44
|
+
|
45
|
+
%<% consts = mod.constants.sort_by{|c| c.name} %>
|
46
|
+
%<% unless consts.empty? %>
|
47
|
+
\subsubsection*{Constants}
|
48
|
+
|
49
|
+
\begin{longtable}{p{0.3\textwidth}|p{0.2\textwidth}|p{0.4\textwidth}}
|
50
|
+
\bfseries Name & \bfseries Value & \bfseries Description \\
|
51
|
+
\hline
|
52
|
+
\endhead
|
53
|
+
% <% consts.each do |const| %>
|
54
|
+
\label{<%= const.latex_label %>}%
|
55
|
+
\small{\code{<%= const.latexized :name %>}} & %
|
56
|
+
\small{\code{<%= const.latexized_value %>}} & %
|
57
|
+
<%= const.description %> \\
|
58
|
+
& & \\ %Empty row for readability
|
59
|
+
% <% end %>
|
60
|
+
\end{longtable}
|
61
|
+
%<% end %>
|
62
|
+
|
63
|
+
%<% unless mod.attributes.empty? %>
|
64
|
+
\subsubsection*{Attributes}
|
65
|
+
\begin{description}
|
66
|
+
% <% mod.attributes.sort_by{|a| a.name}.each do |att| %>
|
67
|
+
\item[\texttt{<%= att.latexized :name %>}]
|
68
|
+
\textsf{[<%= att.rw %>]} \label{<%= att.latex_label %>}<%= att.description %>
|
69
|
+
% <% end %>
|
70
|
+
\end{description}
|
71
|
+
%<% end %>
|
72
|
+
|
73
|
+
%<% unless mod.aliases.empty? %>
|
74
|
+
\subsubsection*{Aliases}
|
75
|
+
\begin{itemize}
|
76
|
+
% <% mod.aliases.sort_by{|a| a.name}.each do |al| %>
|
77
|
+
\item \texttt{<%= al.latexized :old_name %>} $\to$ \texttt{<%= al.latexized :new_name %>}
|
78
|
+
% <% end %>
|
79
|
+
\end{itemize}
|
80
|
+
%<% end %>
|
81
|
+
|
82
|
+
%<% [["Public class methods", true, :public],
|
83
|
+
["Protected class methods", true, :protected],
|
84
|
+
["Private class methods", true, :private],
|
85
|
+
["Public instance methods", false, :public],
|
86
|
+
["Protected instance methods", false, :protected],
|
87
|
+
["Private instance methods", false, :private]].each do |caption, is_singleton, visibility| %>
|
88
|
+
% <% meths = mod.method_list.select{|m|m.singleton == is_singleton && m.visibility == visibility}.sort_by{|m| m.name}%>
|
89
|
+
%
|
90
|
+
% <% unless meths.empty? %>
|
91
|
+
\subsubsection*{<%= caption %>}
|
92
|
+
% <% meths.each do |meth| %>
|
93
|
+
\method{<%= meth.latexized :pretty_name %>}
|
94
|
+
\label{<%= meth.latex_label %>}
|
95
|
+
|
96
|
+
\begin{Verbatim}
|
97
|
+
<%= meth.arglists %>
|
98
|
+
\end{Verbatim}
|
99
|
+
|
100
|
+
% <% unless meth.aliases.empty? %>
|
101
|
+
\marginpar{\footnotesize\emph{Aliases: <%= meth.aliases.map{|m| hyperref_method(m, false)}.join(", ") %>}}
|
102
|
+
% <% end %>
|
103
|
+
% <% if meth.is_alias_for %>
|
104
|
+
\noindent \emph{Alias for <%= hyperref(meth.latex_label, meth.is_alias_for.latexized(:pretty_name)) %>}
|
105
|
+
% <% else %>
|
106
|
+
\noindent <%= meth.description %>
|
107
|
+
% <% end %>
|
108
|
+
% <% end %>
|
109
|
+
% <% end %>
|
110
|
+
%<% end %>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
% This file is part of RDoc PDF LaTeX.
|
2
|
+
%
|
3
|
+
% RDoc PDF LaTeX is a RDoc plugin for generating PDF files.
|
4
|
+
% Copyright © 2011 Pegasus Alpha
|
5
|
+
%
|
6
|
+
% RDoc PDF LaTeX is free software; you can redistribute it and/or modify
|
7
|
+
% it under the terms of the GNU General Public License as published by
|
8
|
+
% the Free Software Foundation; either version 2 of the License, or
|
9
|
+
% (at your option) any later version.
|
10
|
+
%
|
11
|
+
% RDoc PDF LaTeX is distributed in the hope that it will be useful,
|
12
|
+
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
% GNU General Public License for more details.
|
15
|
+
%
|
16
|
+
% You should have received a copy of the GNU General Public License
|
17
|
+
% along with RDoc PDF LaTeX; if not, write to the Free Software
|
18
|
+
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
|
20
|
+
% This ERB template takes the following variables:
|
21
|
+
% rdoc_file: The RDoc::TopLevel do document
|
22
|
+
%
|
23
|
+
\part{<%= rdoc_file.latexized :name %>}
|
24
|
+
|
25
|
+
<%= rdoc_file.description %>
|
26
|
+
\clearpage
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# This file is part of Papyrus.
|
4
|
+
#
|
5
|
+
# Papyrus is a RDoc plugin for generating PDF files.
|
6
|
+
# Copyright © 2011 Pegasus Alpha
|
7
|
+
#
|
8
|
+
# Papyrus is free software; you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation; either version 2 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# Papyrus is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with Papyrus; if not, write to the Free Software
|
20
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
21
|
+
|
22
|
+
require_relative "generator/papyrus"
|
@@ -0,0 +1,174 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# This file is part of Papyrus.
|
4
|
+
#
|
5
|
+
# Papyrus is a RDoc plugin for generating PDF files.
|
6
|
+
# Copyright © 2011 Pegasus Alpha
|
7
|
+
#
|
8
|
+
# Papyrus is free software; you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation; either version 2 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# Papyrus is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with Papyrus; if not, write to the Free Software
|
20
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
21
|
+
|
22
|
+
#Mixin module mixed into RDoc::CodeObject subclasses in order
|
23
|
+
#to overwrite RDoc’s standard RDoc::Generator::Markup mixin module that
|
24
|
+
#forces RDoc to HTML output. This module forces RDoc to LaTeX output ;-).
|
25
|
+
#
|
26
|
+
#Note that just mixing this into RDoc::CodeObject isn’t enough as the
|
27
|
+
#RDoc::Generator::Markup module is mixed into the subclasses and
|
28
|
+
#would therefore take precedence during method lookup.
|
29
|
+
module RDoc::Generator::LaTeX_Markup
|
30
|
+
|
31
|
+
#Create an unique label for this CodeObject.
|
32
|
+
#==Return value
|
33
|
+
#A string (hopefully) uniquely identifying this CodeObject. Intended for
|
34
|
+
#use as the reference in a <tt>\href</tt> command.
|
35
|
+
#==Raises
|
36
|
+
#[PapyrusError] +self+ isn’t a CodeObject (→ Context::Section).
|
37
|
+
def latex_label
|
38
|
+
case self
|
39
|
+
when RDoc::Context then "class-module-#{full_name}"
|
40
|
+
when RDoc::MethodAttr then "method-attr-#{full_name.gsub('#', '+')}" # '#' doesn’t work in references
|
41
|
+
when RDoc::Constant then "const-#{parent.full_name}::#{name}"
|
42
|
+
else
|
43
|
+
raise(RDoc::Generator::Papyrus::PapyrusError, "Unrecognized token: #{self.inspect}!")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
#Calls a method of this CodeObject and passes the return value
|
48
|
+
#to RDoc::Markup::ToLaTeX#escape.
|
49
|
+
#==Parameter
|
50
|
+
#[symbol] The symbol of the method (or attribute getter, same in Ruby) to call.
|
51
|
+
#[*args] Any arguments to pass to the method.
|
52
|
+
#[&block] A block to pass to the method.
|
53
|
+
#==Return value
|
54
|
+
#A string from which everything LaTeXnically dangerous has been escaped.
|
55
|
+
#==Raises
|
56
|
+
#[NoMethodError] You passed a +symbol+ of an undefined method.
|
57
|
+
def latexized(symbol, *args, &block)
|
58
|
+
if respond_to?(symbol)
|
59
|
+
formatter.escape(send(symbol, *args, &block).to_s) #formatter method defined below
|
60
|
+
else
|
61
|
+
raise(NoMethodError, "Requested call to unknown method #{self.class}##{symbol} to be latexized!")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
#Instanciates the LaTeX formatter if it is necessary and stores it
|
66
|
+
#in an instance variable @formatter. This method is automatically
|
67
|
+
#called by RDoc to obtain the formatter this generator wants
|
68
|
+
#to use.
|
69
|
+
#==Return value
|
70
|
+
#Returns the newly instanciated or already stored LaTeX formatter.
|
71
|
+
def formatter
|
72
|
+
return @formatter if defined?(@formatter)
|
73
|
+
|
74
|
+
@formatter = RDoc::Markup::ToLaTeX_Crossref.new(self.kind_of?(RDoc::Context) ? self : @parent, #Thanks to RDoc for this
|
75
|
+
current_heading_level,
|
76
|
+
RDoc::RDoc.current.options.show_hash,
|
77
|
+
RDoc::RDoc.current.options.show_pages,
|
78
|
+
RDoc::RDoc.current.options.hyperlink_all)
|
79
|
+
end
|
80
|
+
|
81
|
+
#Heading depth the formatter is currently in. This is added to
|
82
|
+
#any heading request the processed markup mades in order to ensure
|
83
|
+
#that the correct LaTeX heading order is always preserved. For example,
|
84
|
+
#if the user orders a level 2 heading in a file (the README for instance),
|
85
|
+
#he gets a larger heading as if he had ordered a level 2 heading inside a
|
86
|
+
#method description.
|
87
|
+
def current_heading_level
|
88
|
+
case self
|
89
|
+
when RDoc::TopLevel then 0
|
90
|
+
when RDoc::ClassModule then 1 #Never-ever use level 1 headings apart from TopLevels...
|
91
|
+
when RDoc::MethodAttr, RDoc::Alias, RDoc::Constant, RDoc::Include then 3
|
92
|
+
else
|
93
|
+
0
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
#FIXME:
|
99
|
+
#This *doesn't* overwrite the inclusion in the subclasses that
|
100
|
+
#RDoc::Generator::Markup does!! Therefore I need to monkeypatch
|
101
|
+
#the subclasses affected by the monkeypatch in markup.rb (RDoc::
|
102
|
+
#Generator::Markup) as well! YEAH, workarounds for the workarounds!
|
103
|
+
|
104
|
+
#class RDoc::CodeObject
|
105
|
+
# include RDoc::Generator::LaTeX_Markup
|
106
|
+
#end
|
107
|
+
|
108
|
+
#Note that RDoc::Context::Section is special, as it doesn't inherit
|
109
|
+
#from RDoc::CodeObject. For the rest, refer to the comment above.
|
110
|
+
[RDoc::Context::Section, RDoc::AnyMethod, RDoc::Attr, RDoc::Include, RDoc::Alias, RDoc::Constant, RDoc::Context].each do |klass|
|
111
|
+
klass.send(:include, RDoc::Generator::LaTeX_Markup) #private method
|
112
|
+
end
|
113
|
+
|
114
|
+
class RDoc::Constant
|
115
|
+
|
116
|
+
#No more characters than specified here will be shown
|
117
|
+
#as a constant’s value. If the content is longer, an
|
118
|
+
#ellipsis will be put at the end of the value.
|
119
|
+
LATEX_VALUE_LENGTH = 10
|
120
|
+
|
121
|
+
#Shortens the value to LATEX_VALUE_LENGTH characters (plus ellipsis ...)
|
122
|
+
#and escapes all LaTeX control characters.
|
123
|
+
def latexized_value
|
124
|
+
if value.chars.count > LATEX_VALUE_LENGTH
|
125
|
+
str = formatter.escape(value.chars.first(LATEX_VALUE_LENGTH).join) + "\\ldots"
|
126
|
+
else
|
127
|
+
str = formatter.escape(value)
|
128
|
+
end
|
129
|
+
str
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
class RDoc::AnyMethod
|
134
|
+
include Comparable
|
135
|
+
|
136
|
+
#Compares two methods with each other. A method is considered smaller
|
137
|
+
#than another if it is a class method. If +self+ and +other+ are both
|
138
|
+
#of the same type (either "class" or "instance"), they’re compared
|
139
|
+
#alphabetically.
|
140
|
+
#==Parameter
|
141
|
+
#[other] The other method to compare with.
|
142
|
+
#==Return value
|
143
|
+
#-1 if +self+ is smaller than +other+, 0 if they’re equal and
|
144
|
+
#+1 if +self+ is bigger than +other+. +nil+ if +other+ isn’t
|
145
|
+
#a RDoc::AnyMethod.
|
146
|
+
#==Example
|
147
|
+
# m1.name #=> foo
|
148
|
+
# m1.type #=> instance
|
149
|
+
# m2.name #=> bar
|
150
|
+
# m2.type #=> instance
|
151
|
+
# m3.name #=> foo
|
152
|
+
# m3.type #=> class
|
153
|
+
#
|
154
|
+
# m1 <=> m2 #=> 1
|
155
|
+
# m2 <=> m1 #=> -1
|
156
|
+
# m1 <=> m3 #=> 1
|
157
|
+
# m3 <=> m1 #=> -1
|
158
|
+
# m2 <=> m2 #=> 0
|
159
|
+
def <=>(other)
|
160
|
+
return nil unless other.kind_of?(RDoc::AnyMethod)
|
161
|
+
|
162
|
+
if type == "class" and other.type == "class" #RDoc uses strings, not symbols?
|
163
|
+
name <=> other.name
|
164
|
+
elsif type == "class" and other.type == "instance"
|
165
|
+
-1
|
166
|
+
elsif type == "instance" and other.type == "class"
|
167
|
+
1
|
168
|
+
elsif type == "instance" and other.type == "instance"
|
169
|
+
name <=> other.name
|
170
|
+
else #Shouldn’t be
|
171
|
+
nil
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|