Skip to content

Commit

Permalink
Add options: tex.template.add, html.css.add, epub.css.add
Browse files Browse the repository at this point in the history
These three options allow to specify inline code that will be added to
the templates.

Fixes #18
  • Loading branch information
crowdagger committed Dec 15, 2016
1 parent 97c3769 commit de68445
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/lib/bookoptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import_config:path # {import_config}
html.header:str # {html_header}
html.footer:str # {html_footer}
html.css:tpl # {html_css}
html.css.add:str # {html_css_add}
html.css.colours:tpl # {css_colours}
html.js:tpl # {html_js}
html.css.print:tpl # {css_print}
Expand All @@ -68,12 +69,14 @@ html_dir.chapter.html:tpl # {chapter_html}
# {epub_opt}
epub.version:int:2 # {epub_ver}
epub.css:tpl # {epub_css}
epub.css.add:str # {epub_css_add}
epub.chapter.xhtml:tpl # {chapter_xhtml}
# {tex_opt}
tex.links_as_footnotes:bool:true # {tex_links}
tex.command:str:xelatex # {tex_command}
tex.template:tpl # {tex_tmpl}
tex.template.add:str # {tex_tmpl_add}
tex.class:str:book # {tex_class}
tex.paper_size:str:a5paper # {tex_paper_size}
tex.title:bool:true # {tex_title}
Expand Down Expand Up @@ -196,6 +199,7 @@ html.crowbook_link:alias # {removed}
html_header = lformat!("Custom header to display at the beginning of html file(s)"),
html_footer = lformat!("Custom footer to display at the end of HTML file(s)"),
html_css = lformat!("Path of a stylesheet for HTML rendering"),
html_css_add = lformat!("Some inline CSS added to the stylesheet template"),
css_colours = lformat!("Path of a stylesheet for the colours for HTML"),
html_js = lformat!("Path of a javascript file"),
css_print = lformat!("Path of a media print stylesheet for HTML rendering"),
Expand All @@ -214,11 +218,13 @@ html.crowbook_link:alias # {removed}

epub_ver = lformat!("EPUB version to generate (2 or 3)"),
epub_css = lformat!("Path of a stylesheet for EPUB"),
epub_css_add = lformat!("Inline CSS added to the EPUB stylesheet template"),
chapter_xhtml = lformat!("Path of an xhtml template for each chapter"),

tex_links = lformat!("Add foontotes to URL of links so they are readable when printed"),
tex_command = lformat!("LaTeX command to use for generating PDF"),
tex_tmpl = lformat!("Path of a LaTeX template file"),
tex_tmpl_add = lformat!("Inline code added in the LaTeX template"),
tex_class = lformat!("LaTeX class to use"),
tex_title = lformat!("If true, generate a title with maketitle"),
tex_paper_size = lformat!("Specifies the size of the page."),
Expand Down
9 changes: 6 additions & 3 deletions src/lib/epub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,14 @@ impl<'a> EpubRenderer<'a> {
compile_str(self.html.book.get_template("epub.css").unwrap().as_ref(),
&self.html.book.source,
lformat!("could not compile template 'epub.css'"))?;
let data = self.html
let mut data = self.html
.book
.get_metadata(|s| self.render_vec(&Parser::new().parse_inline(s)?))?
.insert_bool(self.html.book.options.get_str("lang").unwrap(), true)
.build();
.insert_bool(self.html.book.options.get_str("lang").unwrap(), true);
if let Ok(epub_css_add) = self.html.book.options.get_str("epub.css.add") {
data = data.insert_str("additional_code", epub_css_add);
}
let data = data.build();
let mut res: Vec<u8> = vec![];
template_css.render_data(&mut res, &data)?;
let css = String::from_utf8_lossy(&res);
Expand Down
3 changes: 3 additions & 0 deletions src/lib/html_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@ impl<'a> HtmlDirRenderer<'a> {
let mut data = self.html.book.get_metadata(|s| Ok(s.to_owned()))?;
data = data.insert_str("colours",
self.html.book.get_template("html.css.colours")?);
if let Ok(html_css_add) = self.html.book.options.get_str("html.css.add") {
data = data.insert_str("additional_code", html_css_add);
}
if self.html.proofread && self.html.book.options.get_bool("proofread.nb_spaces").unwrap() {
data = data.insert_bool("display_spaces", true);
}
Expand Down
3 changes: 3 additions & 0 deletions src/lib/html_single.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ impl<'a> HtmlSingleRenderer<'a> {
.get_metadata(|s| self.render_vec(&Parser::new().parse_inline(s)?))?
.insert_str("colours",
self.html.book.get_template("html.css.colours")?);
if let Ok(html_css_add) = self.html.book.options.get_str("html.css.add") {
data = data.insert_str("additional_code", html_css_add);
}
if self.html.proofread && self.html.book.options.get_bool("proofread.nb_spaces").unwrap() {
data = data.insert_bool("display_spaces", true);
}
Expand Down
3 changes: 3 additions & 0 deletions src/lib/latex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ impl<'a> LatexRenderer<'a> {
.insert_bool("tex_title", self.book.options.get_bool("tex.title").unwrap())
.insert_str("papersize", self.book.options.get_str("tex.paper_size").unwrap())
.insert_str("tex_lang", tex_lang);
if let Ok(tex_tmpl_add) = self.book.options.get_str("tex.template.add") {
data = data.insert_str("additional_code", tex_tmpl_add);
}
if let Ok(tex_font_size) = self.book.options.get_i32("tex.font_size") {
data = data
.insert_bool("has_tex_size", true)
Expand Down
4 changes: 3 additions & 1 deletion templates/epub/stylesheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,6 @@ p.first-para {
.nbsp {
background-color: #ffff66;
}
{{/display_spaces}}
{{/display_spaces}}

{{{additional_code}}}
1 change: 1 addition & 0 deletions templates/html/template.css
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,4 @@ footer p {
width: 70%;
}

{{{additional_code}}}
3 changes: 3 additions & 0 deletions templates/latex/template.tex
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@
\chead[\fancyplain{}{\rm\thepage}]{\fancyplain{}{\rm\thepage}}
% Footer
\cfoot{\fancyplain{}{}}

<<&additional_code>>

\makeatother

\title{<<&title>>}
Expand Down

0 comments on commit de68445

Please sign in to comment.