aboutsummaryrefslogtreecommitdiff
path: root/src/templates
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2007-11-03 22:14:03 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2007-11-03 22:14:03 +0000
commit4a841bfc5464907adea4cdd655485565565b40ae (patch)
tree36c0a21e3639614c8d25b5fb1909c32d0ab11dcd /src/templates
parent3116d30133196e1bb258f7e74e03d4a85f3b21ae (diff)
downloadpandoc-4a841bfc5464907adea4cdd655485565565b40ae.tar.gz
Use template haskell to avoid the need for templates:
+ Added library Text.Pandoc.Include, with a template haskell function $(includeStrFrom fname) to include a file as a string constant at compile time. + This removes the need for the 'templates' directory or Makefile target. These have been removed. + The base source directory has been changed from src to . + A new 'data' directory has been added, containing the ASCIIMathML.js script, writer headers, and S5 files. + The src/wrappers directory has been moved to 'wrappers'. + The Text.Pandoc.ASCIIMathML library is no longer needed, since Text.Pandoc.Writers.HTML can use includeStrFrom to include the ASCIIMathML.js code directly. It has been removed. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1063 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src/templates')
-rw-r--r--src/templates/ASCIIMathML.hs7
-rw-r--r--src/templates/DefaultHeaders.hs52
-rw-r--r--src/templates/Makefile20
-rw-r--r--src/templates/S5.hs133
-rwxr-xr-xsrc/templates/fillTemplates.pl131
5 files changed, 0 insertions, 343 deletions
diff --git a/src/templates/ASCIIMathML.hs b/src/templates/ASCIIMathML.hs
deleted file mode 100644
index 1d04c6ff7..000000000
--- a/src/templates/ASCIIMathML.hs
+++ /dev/null
@@ -1,7 +0,0 @@
--- | Definitions for use of ASCIIMathML in HTML.
--- (See <http://www1.chapman.edu/~jipsen/mathml/asciimath.html>.)
-module Text.Pandoc.ASCIIMathML ( asciiMathMLScript ) where
-
--- | String containing ASCIIMathML javascript.
-asciiMathMLScript :: String
-asciiMathMLScript = "<script type=\"text/javascript\">\n@ASCIIMathML.js@</script>\n"
diff --git a/src/templates/DefaultHeaders.hs b/src/templates/DefaultHeaders.hs
deleted file mode 100644
index 1bd9fe1d2..000000000
--- a/src/templates/DefaultHeaders.hs
+++ /dev/null
@@ -1,52 +0,0 @@
-{-
-Copyright (C) 2006-7 John MacFarlane <jgm@berkeley.edu>
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
--}
-
-{- |
- Module : Text.Pandoc.Writers.DefaultHeaders
- Copyright : Copyright (C) 2006-7 John MacFarlane
- License : GNU GPL, version 2 or above
-
- Maintainer : John MacFarlane <jgm@berkeley.edu>
- Stability : alpha
- Portability : portable
-
-Default headers for Pandoc writers.
--}
-module Text.Pandoc.Writers.DefaultHeaders (
- defaultLaTeXHeader,
- defaultConTeXtHeader,
- defaultDocbookHeader,
- defaultS5Header,
- defaultRTFHeader
- ) where
-import Text.Pandoc.Writers.S5
-
-defaultLaTeXHeader :: String
-defaultLaTeXHeader = "@LaTeXHeader@"
-
-defaultConTeXtHeader :: String
-defaultConTeXtHeader = "@ConTeXtHeader@"
-
-defaultDocbookHeader :: String
-defaultDocbookHeader = "@DocbookHeader@"
-
-defaultS5Header :: String
-defaultS5Header = s5Meta ++ s5CSS ++ s5Javascript
-
-defaultRTFHeader :: String
-defaultRTFHeader = "@RTFHeader@"
diff --git a/src/templates/Makefile b/src/templates/Makefile
deleted file mode 100644
index 9522666c5..000000000
--- a/src/templates/Makefile
+++ /dev/null
@@ -1,20 +0,0 @@
-VPATH := ..
-PROCESSOR := ./fillTemplates.pl
-TARGETS := Text/Pandoc/ASCIIMathML.hs \
- Text/Pandoc/Writers/S5.hs \
- Text/Pandoc/Writers/DefaultHeaders.hs
-
-all: $(TARGETS)
-
-Text/Pandoc/ASCIIMathML.hs: ASCIIMathML.hs $(PROCESSOR) $(VPATH)/ASCIIMathML.js
- perl $(PROCESSOR) $@ $(VPATH)
-
-Text/Pandoc/Writers/S5.hs: S5.hs $(PROCESSOR) $(VPATH)/ui/default/*
- perl $(PROCESSOR) $@ $(VPATH)
-
-Text/Pandoc/Writers/DefaultHeaders.hs: DefaultHeaders.hs $(PROCESSOR) $(VPATH)/headers/*
- perl $(PROCESSOR) $@ $(VPATH)
-
-.PHONY: clean
-clean:
- cd $(VPATH); rm -f $(TARGETS)
diff --git a/src/templates/S5.hs b/src/templates/S5.hs
deleted file mode 100644
index a0b69b132..000000000
--- a/src/templates/S5.hs
+++ /dev/null
@@ -1,133 +0,0 @@
-{-
-Copyright (C) 2006-7 John MacFarlane <jgm@berkeley.edu>
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
--}
-
-{- |
- Module : Text.Pandoc.Writers.S5
- Copyright : Copyright (C) 2006-7 John MacFarlane
- License : GNU GPL, version 2 or above
-
- Maintainer : John MacFarlane <jgm@berkeley.edu>
- Stability : alpha
- Portability : portable
-
-Definitions for creation of S5 powerpoint-like HTML.
-(See <http://meyerweb.com/eric/tools/s5/>.)
--}
-module Text.Pandoc.Writers.S5 (
- -- * Strings
- s5Meta,
- s5Javascript,
- s5CSS,
- s5Links,
- -- * Functions
- writeS5,
- writeS5String,
- insertS5Structure
- ) where
-import Text.Pandoc.Shared ( joinWithSep, WriterOptions )
-import Text.Pandoc.Writers.HTML ( writeHtml, writeHtmlString )
-import Text.Pandoc.Definition
-import Text.XHtml.Strict
-
-s5Meta :: String
-s5Meta = "<!-- configuration parameters -->\n<meta name=\"defaultView\" content=\"slideshow\" />\n<meta name=\"controlVis\" content=\"hidden\" />\n"
-
-s5Javascript :: String
-s5Javascript = "<script type=\"text/javascript\">\n@slides.js@</script>\n"
-
-s5CoreCSS :: String
-s5CoreCSS = "@s5-core.css@"
-
-s5FramingCSS :: String
-s5FramingCSS = "@framing.css@"
-
-s5PrettyCSS :: String
-s5PrettyCSS = "@pretty.css@"
-
-s5OperaCSS :: String
-s5OperaCSS = "@opera.css@"
-
-s5OutlineCSS :: String
-s5OutlineCSS = "@outline.css@"
-
-s5PrintCSS :: String
-s5PrintCSS = "@print.css@"
-
-s5CSS :: String
-s5CSS = "<style type=\"text/css\" media=\"projection\" id=\"slideProj\">\n" ++ s5CoreCSS ++ "\n" ++ s5FramingCSS ++ "\n" ++ s5PrettyCSS ++ "\n</style>\n<style type=\"text/css\" media=\"projection\" id=\"operaFix\">\n" ++ s5OperaCSS ++ "\n</style>\n<style type=\"text/css\" media=\"screen\" id=\"outlineStyle\">\n" ++ s5OutlineCSS ++ "\n</style>\n<style type=\"text/css\" media=\"print\" id=\"slidePrint\">\n" ++ s5PrintCSS ++ "\n</style>\n"
-
-s5Links :: String
-s5Links = "<!-- style sheet links -->\n<link rel=\"stylesheet\" href=\"ui/default/slides.css\" type=\"text/css\" media=\"projection\" id=\"slideProj\" />\n<link rel=\"stylesheet\" href=\"ui/default/outline.css\" type=\"text/css\" media=\"screen\" id=\"outlineStyle\" />\n<link rel=\"stylesheet\" href=\"ui/default/print.css\" type=\"text/css\" media=\"print\" id=\"slidePrint\" />\n<link rel=\"stylesheet\" href=\"ui/default/opera.css\" type=\"text/css\" media=\"projection\" id=\"operaFix\" />\n<!-- S5 JS -->\n<script src=\"ui/default/slides.js\" type=\"text/javascript\"></script>\n"
-
--- | Converts Pandoc document to an S5 HTML presentation (Html structure).
-writeS5 :: WriterOptions -> Pandoc -> Html
-writeS5 options = (writeHtml options) . insertS5Structure
-
--- | Converts Pandoc document to an S5 HTML presentation (string).
-writeS5String :: WriterOptions -> Pandoc -> String
-writeS5String options = (writeHtmlString options) . insertS5Structure
-
--- | Inserts HTML needed for an S5 presentation (e.g. around slides).
-layoutDiv :: [Inline] -- ^ Title of document (for header or footer)
- -> String -- ^ Date of document (for header or footer)
- -> [Block] -- ^ List of block elements returned
-layoutDiv title date = [(RawHtml "<div class=\"layout\">\n<div id=\"controls\"></div>\n<div id=\"currentSlide\"></div>\n<div id=\"header\"></div>\n<div id=\"footer\">\n"), (Header 1 [Str date]), (Header 2 title), (RawHtml "</div>\n</div>\n")]
-
-presentationStart = RawHtml "<div class=\"presentation\">\n\n"
-
-presentationEnd = RawHtml "</div>\n"
-
-slideStart = RawHtml "<div class=\"slide\">\n"
-
-slideEnd = RawHtml "</div>\n"
-
--- | Returns 'True' if block is a Header 1.
-isH1 :: Block -> Bool
-isH1 (Header 1 _) = True
-isH1 _ = False
-
--- | Insert HTML around sections to make individual slides.
-insertSlides :: Bool -> [Block] -> [Block]
-insertSlides beginning blocks =
- let (beforeHead, rest) = break isH1 blocks in
- if (null rest) then
- if beginning then
- beforeHead
- else
- beforeHead ++ [slideEnd]
- else
- if beginning then
- beforeHead ++
- slideStart:(head rest):(insertSlides False (tail rest))
- else
- beforeHead ++
- slideEnd:slideStart:(head rest):(insertSlides False (tail rest))
-
--- | Insert blocks into 'Pandoc' for slide structure.
-insertS5Structure :: Pandoc -> Pandoc
-insertS5Structure (Pandoc meta []) = Pandoc meta []
-insertS5Structure (Pandoc (Meta title authors date) blocks) =
- let slides = insertSlides True blocks
- firstSlide = if not (null title)
- then [slideStart, (Header 1 title),
- (Header 3 [Str (joinWithSep ", " authors)]),
- (Header 4 [Str date]), slideEnd]
- else []
- newBlocks = (layoutDiv title date) ++ presentationStart:firstSlide ++
- slides ++ [presentationEnd]
- in Pandoc (Meta title authors date) newBlocks
diff --git a/src/templates/fillTemplates.pl b/src/templates/fillTemplates.pl
deleted file mode 100755
index 85e6eaa18..000000000
--- a/src/templates/fillTemplates.pl
+++ /dev/null
@@ -1,131 +0,0 @@
-#!/usr/bin/env perl
-# Fills templates with haskell-escaped strings slurped from input files.
-# Takes two arguments, the first specifying the pathname of the target
-# relative to the root directory, the second specifying the root directory
-# (defaulting to ..). The template is assumed to have the same base name
-# as the target and to reside in the templates subdirectory of the root
-# directory.
-
-use strict;
-use warnings;
-
-# Utility routines:
-
-sub slurp {
- open FILE, $_[0] or die "couldn't open file '$_[0]': $!";
- my $contents = do { local $/; <FILE>;};
- close FILE;
- return $contents;
-}
-
-sub escape_for_haskell {
- my ($contents) = @_;
-
- $contents =~ s/\\/\\\\/g;
- $contents =~ s/\t/\\t/g;
- $contents =~ s/"/\\"/g;
- $contents =~ s/\n/\\n/g;
- return $contents;
-}
-
-# Template processors.
-
-my %processor = (
- # --------------------------------------------------------------------------
- 'Text/Pandoc/Writers/S5.hs' => {
- # --------------------------------------------------------------------------
- proc => sub {
- my ($template) = @_;
-
- my (@files) = qw(slides.js s5-core.css framing.css pretty.css
- opera.css outline.css print.css);
-
- foreach my $file (@files) {
- my $replacement = escape_for_haskell(slurp "ui/default/$file");
- my $escapedfile = $file;
- $escapedfile =~ s/\./\\./g;
- $template =~ s/\@$escapedfile\@/$replacement/;
- }
- return $template;
- },
- },
- # --------------------------------------------------------------------------
- 'Text/Pandoc/ASCIIMathML.hs' => {
- # --------------------------------------------------------------------------
- proc => sub {
- my ($template) = @_;
-
- my $script = escape_for_haskell(slurp "ASCIIMathML.js");
- my $acknowledgements =
- " ASCIIMathML.js - copyright Peter Jipsen,".
- " released under the GPL\\nSee ".
- "http://www1.chapman.edu/~jipsen/mathml/asciimath.html/ ";
- $script =~ s/\/\*.*?\*\//\/\*$acknowledgements\*\//g; # strip comments
- $template =~ s/\@ASCIIMathML\.js@/$script/;
-
- return $template;
- },
- },
- # --------------------------------------------------------------------------
- 'Text/Pandoc/Writers/DefaultHeaders.hs' => {
- # --------------------------------------------------------------------------
- proc => sub {
- my ($template) = @_;
-
- my (@headers) = split(/\s/,`ls headers`);
- foreach my $header (@headers) {
- my ($replacement) = escape_for_haskell(slurp "headers/$header");
- $template =~ s/\@$header\@/$replacement/;
- }
-
- return $template;
- },
- },
- # --------------------------------------------------------------------------
- # 'foo/bar/baz' => {
- # --------------------------------------------------------------------------
- # template => 'optional-template-filename-defaults-to-baz'
- # proc => sub {
- # my ($template) = @_;
- # # Process.
- # return $template;
- # },
- #},
-);
-
-# Main.
-
-my $target = shift @ARGV;
-if (!defined $target || !length $target) {
- print STDERR "Available targets:\n\n" . join "\n", keys %processor;
- die "\n\nYou must supply a target!\n";
-}
-
-die "No processor exists for '$target'!\n" if ! exists $processor{$target};
-
-my $rootdir = shift @ARGV || '..';
-chdir $rootdir or die "Couldn't chdir to '$rootdir': $!";
-
-my $template;
-if (exists $processor{$target}->{template}) {
- $template = $processor{$target}->{template};
-}
-else {
- ($template = $target) =~ s!.*/+!!;
-}
-$template = "templates/$template";
-die "No template exists for '$target'!\n" if ! -f "$template";
-
-open OUTFILE, ">$target" or die "couldn't open file '$target': $!";
-print OUTFILE <<END;
-----------------------------------------------------
--- Do not edit this file by hand. Edit
--- '$template'
--- and run $0 $target
-----------------------------------------------------
-
-END
-
-print OUTFILE $processor{$target}->{proc}->(slurp($template));
-print OUTFILE "\n";
-close OUTFILE;