r723 - in trunk: doxia-module-jrst/src/main/java/org/nuiton/jrst doxia-module-jrst/src/main/resources/META-INF/maven jrst-doc/src/site/rst/user
Author: jpages Date: 2012-06-19 16:33:14 +0200 (Tue, 19 Jun 2012) New Revision: 723 Url: http://nuiton.org/repositories/revision/jrst/723 Log: Suite de la g?\195?\169n?\195?\169ration dans doxia-module-jrst de la doc en pdf (pas termin?\195?\169 encore) Attention : dans certains projets, les ressources ne sont pas r?\195?\169cup?\195?\169r?\195?\169es o?\195?\185 il faut, ce qui cause des erreurs. Modified: trunk/doxia-module-jrst/src/main/java/org/nuiton/jrst/JrstSiteRenderer.java trunk/doxia-module-jrst/src/main/resources/META-INF/maven/RstAggregation.vm trunk/jrst-doc/src/site/rst/user/presentationRST.rst Modified: trunk/doxia-module-jrst/src/main/java/org/nuiton/jrst/JrstSiteRenderer.java =================================================================== --- trunk/doxia-module-jrst/src/main/java/org/nuiton/jrst/JrstSiteRenderer.java 2012-06-18 16:34:48 UTC (rev 722) +++ trunk/doxia-module-jrst/src/main/java/org/nuiton/jrst/JrstSiteRenderer.java 2012-06-19 14:33:14 UTC (rev 723) @@ -5,7 +5,7 @@ import java.io.UnsupportedEncodingException; import java.lang.reflect.Field; import java.util.Collections; -import java.util.Iterator; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; import org.apache.commons.lang3.StringUtils; @@ -56,12 +56,14 @@ * * @component */ - private Locale locale; + public Locale locale; - private MavenProject mavenProject; + public MavenProject mavenProject; - private boolean pdfGenerationEnabled; + public boolean pdfGenerationEnabled; + public HashMap<String, String> map; + public void render(Collection<DocumentRenderer> documents, SiteRenderingContext siteRenderingContext, File outputDirectory) @@ -77,10 +79,11 @@ mavenProject = (MavenProject) templateProperties.get("project"); - pdfGenerationEnabled = true; - /* getBooleanProperty( - (String) mavenProject.getProperties().get("pdfGenerationEnabled")); */ + map = new HashMap<String, String>(); + pdfGenerationEnabled = getBooleanProperty( + (String) mavenProject.getProperties().get("pdfGenerationEnabled")); + if (pdfGenerationEnabled) { String absolutePath = outputDirectory.getAbsolutePath(); try { @@ -113,16 +116,20 @@ String docName = DOC_NAME_EN; String filename = FILE_NAME_EN; if (locale.equals(Locale.FRENCH)) { + tableOfContent = CONTENT_FR; docName = DOC_NAME_FR; - tableOfContent = CONTENT_FR; filename = FILE_NAME_FR; } - String titleDecoration = StringUtils.rightPad("", docName.length(), '='); vc.put("titleDecoration", titleDecoration); vc.put( "docName", docName); vc.put( "tableContentName", tableOfContent); + // Build the map of html documents from .rst or .rst.vm files + File basedir = buildDocMap(documents); + vc.put("basedir", basedir.getAbsolutePath()); + vc.put("separator", File.separatorChar); + // Build the list of item's href DecorationModel decoration = siteRenderingContext.getDecoration(); List<Menu> menus = decoration.getMenus(); @@ -134,31 +141,8 @@ } } - // Build the map of html documents from .rst or .rst.vm files - //HashMap<String, String> map = new HashMap<String, String>(); - LinkedList<String> htmlFiles = new LinkedList<String>(); - Iterator<DocumentRenderer> iterator = documents.iterator(); - while (iterator.hasNext()) { - DocumentRenderer doc = iterator.next(); - RenderingContext renderingContext = doc.getRenderingContext(); - String inputName = renderingContext.getInputName(); - if (inputName.endsWith("rst") || inputName.endsWith("rst.vm")) { - String[] splitName = inputName.split("\\."); - String htmlName = splitName[0] + "." + "html"; - htmlFiles.add(htmlName); - } - } - // Merge of the map of html file and the list of paths - List<String> documentRefs = new LinkedList<String>(); - for (String path: paths) { - for (String file : htmlFiles) { - if (file.equals(path)) { - documentRefs.add(file); - - } - } - } + List<String> documentRefs = mergeListAndMap(paths); if (documentRefs.size() > 0) { vc.put("documentRefs", documentRefs); @@ -169,6 +153,7 @@ File pdfDoc = new File(tempFilePath); FileUtils.writeStringToFile(pdfDoc, fileContent, "UTF-8"); String outputFilePath = outputDirectory + File.separatorChar + filename; + log.info(outputFilePath); // Define the output file File fileOut = new File(outputFilePath); @@ -183,6 +168,42 @@ } } + public File buildDocMap(Collection<DocumentRenderer> documents) { + File basedir = new File("."); + for (DocumentRenderer doc : documents) { + RenderingContext renderingContext = doc.getRenderingContext(); + String inputName = renderingContext.getInputName(); + String relativeDir = renderingContext.getRelativePath(); + if (inputName.endsWith("rst") || inputName.endsWith("rst.vm")) { + // Change the extension to html + String[] splitName = inputName.split("\\."); + String htmlName = splitName[0] + "." + "html"; + String relativePath = "." + File.separator + htmlName; + log.info("relativePath: " + relativePath); + // Add in a hashmap + map.put(relativePath, inputName); + + if (relativeDir.equals(".") && inputName.startsWith("index")) { + basedir = renderingContext.getBasedir(); + } + } + } + return basedir; + } + + public List<String> mergeListAndMap(Collection<String> paths) { + // Merge the map and the list to obtain a list of rst files we can add in the pdf + List<String> documentRefs = new LinkedList<String>(); + for (String path: paths) { + // Seek in the hashmap if the rst file exists to add it in the doc list + String rstFilename = map.get(path); + if ( rstFilename != null) { + documentRefs.add(rstFilename); + } + } + return documentRefs; + } + public Collection<String> buildListPaths(MenuItem item, Collection<String> paths, SiteRenderingContext siteRenderingContext) { // add hrefs to paths if they don't start with "http" or ".." @@ -195,6 +216,10 @@ } } if (addHref) { + if(!href.startsWith("./")) { + href = "./" + href; + } + log.info("xml: " + href); paths.add(href); } } Modified: trunk/doxia-module-jrst/src/main/resources/META-INF/maven/RstAggregation.vm =================================================================== --- trunk/doxia-module-jrst/src/main/resources/META-INF/maven/RstAggregation.vm 2012-06-18 16:34:48 UTC (rev 722) +++ trunk/doxia-module-jrst/src/main/resources/META-INF/maven/RstAggregation.vm 2012-06-19 14:33:14 UTC (rev 723) @@ -30,6 +30,6 @@ .. contents:: $tableContentName -#foreach($document in $documents) -.. include:: $documentRefs +#foreach($ref in $documentRefs) +.. include:: $basedir$separator$ref #end \ No newline at end of file Modified: trunk/jrst-doc/src/site/rst/user/presentationRST.rst =================================================================== --- trunk/jrst-doc/src/site/rst/user/presentationRST.rst 2012-06-18 16:34:48 UTC (rev 722) +++ trunk/jrst-doc/src/site/rst/user/presentationRST.rst 2012-06-19 14:33:14 UTC (rev 723) @@ -43,7 +43,7 @@ Structure ---------- +========= Pour commencer, il me semble que "Structured Text" n'est pas tout à fait la bonne appellation. Nous devrions plutôt le nommer "Relaxed Text" qui contient @@ -77,7 +77,7 @@ __ http://docutils.sourceforge.net/docs/rst/quickref.html#paragraphs Styles de texte ---------------- +=============== (quickref__) @@ -106,7 +106,7 @@ __ http://docutils.sourceforge.net/docs/rst/quickref.html#escaping Listes ------- +====== Il y a trois types de listes: **numérotées**, **avec puces** et de **définitions**. Dans chaque cas, nous pouvons avoir autant @@ -220,7 +220,7 @@ Les lignes vides ne sont pas autorisées entre le terme et la définition. Préformatage ------------- +============ (quickref__) __ http://docutils.sourceforge.net/docs/rst/quickref.html#literal-blocks @@ -253,7 +253,7 @@ le paragraphe "::" est ignoré. Sections --------- +======== (quickref__) __ http://docutils.sourceforge.net/docs/rst/quickref.html#section-structure @@ -331,7 +331,7 @@ Images ------- +====== (quickref__) __ http://docutils.sourceforge.net/docs/rst/quickref.html#directives @@ -364,7 +364,7 @@ Et ensuite ? ------------- +============ Cette introduction montre les possibilités les plus courantes de reStructuredText, mais il y en a bien d'autres à explorer. Le manuel de référence utilisateur
participants (1)
-
jpages@users.nuiton.org