[Sciviews-commits] r510 - in pkg: . svDoc svDoc/R svDoc/inst svDoc/inst/asciidoc svDoc/inst/asciidoc/filters svDoc/inst/asciidoc/filters/code svDoc/inst/asciidoc/filters/graphviz svDoc/inst/asciidoc/filters/latex svDoc/inst/asciidoc/filters/music svDoc/inst/asciidoc/filters/source svDoc/inst/asciidoc/javascripts svDoc/inst/asciidoc/stylesheets svDoc/inst/asciidoc/themes svDoc/inst/asciidoc/themes/compact svDoc/inst/asciidoc/themes/flask svDoc/inst/asciidoc/themes/sciviews svDoc/inst/asciidoc/themes/slidy2black svDoc/inst/asciidoc/themes/slidy2blue svDoc/inst/asciidoc/themes/slidy2green svDoc/inst/asciidoc/themes/slidy2none svDoc/inst/asciidoc/themes/slidy2yellow svDoc/inst/asciidoc/themes/volnitsky svDoc/inst/examples svDoc/inst/www svDoc/inst/www/jquery svDoc/man svSweave svSweave/R svSweave/inst svSweave/man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jan 11 16:28:59 CET 2013


Author: phgrosjean
Date: 2013-01-11 16:28:59 +0100 (Fri, 11 Jan 2013)
New Revision: 510

Added:
   pkg/svDoc/
   pkg/svDoc/DESCRIPTION
   pkg/svDoc/LICENSE
   pkg/svDoc/NAMESPACE
   pkg/svDoc/NEWS
   pkg/svDoc/R/
   pkg/svDoc/R/asciidoc.R
   pkg/svDoc/R/header.R
   pkg/svDoc/R/svDoc-internal.R
   pkg/svDoc/TODO
   pkg/svDoc/inst/
   pkg/svDoc/inst/asciidoc/
   pkg/svDoc/inst/asciidoc/BUGS.txt
   pkg/svDoc/inst/asciidoc/CHANGELOG.txt
   pkg/svDoc/inst/asciidoc/COPYING
   pkg/svDoc/inst/asciidoc/COPYRIGHT
   pkg/svDoc/inst/asciidoc/README.txt
   pkg/svDoc/inst/asciidoc/asciidoc.conf
   pkg/svDoc/inst/asciidoc/asciidoc.py
   pkg/svDoc/inst/asciidoc/filters/
   pkg/svDoc/inst/asciidoc/filters/code/
   pkg/svDoc/inst/asciidoc/filters/code/code-filter-readme.txt
   pkg/svDoc/inst/asciidoc/filters/code/code-filter-test.txt
   pkg/svDoc/inst/asciidoc/filters/code/code-filter.conf
   pkg/svDoc/inst/asciidoc/filters/code/code-filter.py
   pkg/svDoc/inst/asciidoc/filters/graphviz/
   pkg/svDoc/inst/asciidoc/filters/graphviz/asciidoc-graphviz-sample.txt
   pkg/svDoc/inst/asciidoc/filters/graphviz/graphviz-filter.conf
   pkg/svDoc/inst/asciidoc/filters/graphviz/graphviz2png.py
   pkg/svDoc/inst/asciidoc/filters/latex/
   pkg/svDoc/inst/asciidoc/filters/latex/latex-filter.conf
   pkg/svDoc/inst/asciidoc/filters/latex/latex2png.py
   pkg/svDoc/inst/asciidoc/filters/music/
   pkg/svDoc/inst/asciidoc/filters/music/music-filter-test.txt
   pkg/svDoc/inst/asciidoc/filters/music/music-filter.conf
   pkg/svDoc/inst/asciidoc/filters/music/music2png.py
   pkg/svDoc/inst/asciidoc/filters/source/
   pkg/svDoc/inst/asciidoc/filters/source/source-highlight-filter-test.txt
   pkg/svDoc/inst/asciidoc/filters/source/source-highlight-filter.conf
   pkg/svDoc/inst/asciidoc/help.conf
   pkg/svDoc/inst/asciidoc/html4.conf
   pkg/svDoc/inst/asciidoc/html5.conf
   pkg/svDoc/inst/asciidoc/javascripts/
   pkg/svDoc/inst/asciidoc/javascripts/ASCIIMathML.js
   pkg/svDoc/inst/asciidoc/javascripts/LaTeXMathML.js
   pkg/svDoc/inst/asciidoc/javascripts/asciidoc.js
   pkg/svDoc/inst/asciidoc/javascripts/slidy.js
   pkg/svDoc/inst/asciidoc/javascripts/slidy2.js
   pkg/svDoc/inst/asciidoc/javascripts/toc.js
   pkg/svDoc/inst/asciidoc/lang-de.conf
   pkg/svDoc/inst/asciidoc/lang-el.conf
   pkg/svDoc/inst/asciidoc/lang-en.conf
   pkg/svDoc/inst/asciidoc/lang-es.conf
   pkg/svDoc/inst/asciidoc/lang-fr.conf
   pkg/svDoc/inst/asciidoc/lang-hu.conf
   pkg/svDoc/inst/asciidoc/lang-it.conf
   pkg/svDoc/inst/asciidoc/lang-nl.conf
   pkg/svDoc/inst/asciidoc/lang-pt-BR.conf
   pkg/svDoc/inst/asciidoc/lang-ru.conf
   pkg/svDoc/inst/asciidoc/lang-uk.conf
   pkg/svDoc/inst/asciidoc/latex.conf
   pkg/svDoc/inst/asciidoc/slidy.conf
   pkg/svDoc/inst/asciidoc/slidy2.conf
   pkg/svDoc/inst/asciidoc/stylesheets/
   pkg/svDoc/inst/asciidoc/stylesheets/asciidoc.css
   pkg/svDoc/inst/asciidoc/stylesheets/pygments.css
   pkg/svDoc/inst/asciidoc/stylesheets/slidy.css
   pkg/svDoc/inst/asciidoc/stylesheets/slidy2.css
   pkg/svDoc/inst/asciidoc/stylesheets/toc2.css
   pkg/svDoc/inst/asciidoc/stylesheets/xhtml11-quirks.css
   pkg/svDoc/inst/asciidoc/text.conf
   pkg/svDoc/inst/asciidoc/themes/
   pkg/svDoc/inst/asciidoc/themes/compact/
   pkg/svDoc/inst/asciidoc/themes/compact/compact.css
   pkg/svDoc/inst/asciidoc/themes/flask/
   pkg/svDoc/inst/asciidoc/themes/flask/flask.css
   pkg/svDoc/inst/asciidoc/themes/sciviews/
   pkg/svDoc/inst/asciidoc/themes/sciviews/sciviews.css
   pkg/svDoc/inst/asciidoc/themes/slidy2black/
   pkg/svDoc/inst/asciidoc/themes/slidy2black/slidy2black.css
   pkg/svDoc/inst/asciidoc/themes/slidy2blue/
   pkg/svDoc/inst/asciidoc/themes/slidy2blue/slidy2blue.css
   pkg/svDoc/inst/asciidoc/themes/slidy2green/
   pkg/svDoc/inst/asciidoc/themes/slidy2green/slidy2green.css
   pkg/svDoc/inst/asciidoc/themes/slidy2none/
   pkg/svDoc/inst/asciidoc/themes/slidy2none/slidy2none.css
   pkg/svDoc/inst/asciidoc/themes/slidy2yellow/
   pkg/svDoc/inst/asciidoc/themes/slidy2yellow/slidy2yellow.css
   pkg/svDoc/inst/asciidoc/themes/volnitsky/
   pkg/svDoc/inst/asciidoc/themes/volnitsky/volnitsky.css
   pkg/svDoc/inst/asciidoc/wordpress.conf
   pkg/svDoc/inst/asciidoc/xhtml11-quirks.conf
   pkg/svDoc/inst/asciidoc/xhtml11.conf
   pkg/svDoc/inst/examples/
   pkg/svDoc/inst/examples/Dynamic01.R
   pkg/svDoc/inst/examples/Dynamic02.R
   pkg/svDoc/inst/examples/Dynamic03.R
   pkg/svDoc/inst/examples/Dynamic04.R
   pkg/svDoc/inst/examples/Dynamic05.R
   pkg/svDoc/inst/examples/Dynamic06.R
   pkg/svDoc/inst/examples/Dynamic07.R
   pkg/svDoc/inst/examples/Dynamic08.R
   pkg/svDoc/inst/examples/Dynamic09.R
   pkg/svDoc/inst/examples/Dynamic10.R
   pkg/svDoc/inst/www/
   pkg/svDoc/inst/www/jquery/
   pkg/svDoc/inst/www/jquery/README
   pkg/svDoc/inst/www/jquery/jquery.easytabs.min.css
   pkg/svDoc/inst/www/jquery/jquery.easytabs.min.js
   pkg/svDoc/inst/www/jquery/jquery.hashchange.min.js
   pkg/svDoc/inst/www/jquery/jquery.slider.min.css
   pkg/svDoc/inst/www/jquery/jquery.slider.min.js
   pkg/svDoc/man/
   pkg/svDoc/man/asciidoc.Rd
   pkg/svDoc/man/header.Rd
   pkg/svDoc/man/svDoc-package.Rd
Removed:
   pkg/svSweave/LICENSE
   pkg/svSweave/R/asciidoc.R
   pkg/svSweave/R/header.R
   pkg/svSweave/R/svSweave-internal.R
   pkg/svSweave/inst/LICENSE
   pkg/svSweave/man/asciidoc.Rd
   pkg/svSweave/man/header.Rd
Modified:
   pkg/svSweave/DESCRIPTION
   pkg/svSweave/NAMESPACE
   pkg/svSweave/NEWS
   pkg/svSweave/R/tangleLyxRnw.R
   pkg/svSweave/R/weaveLyxRnw.R
   pkg/svSweave/TODO
   pkg/svSweave/man/svSweave-package.Rd
Log:
Asciidoc and SciViews doc functions moved from svSweave to svDoc R package

Added: pkg/svDoc/DESCRIPTION
===================================================================
--- pkg/svDoc/DESCRIPTION	                        (rev 0)
+++ pkg/svDoc/DESCRIPTION	2013-01-11 15:28:59 UTC (rev 510)
@@ -0,0 +1,16 @@
+Package: svDoc
+Type: Package
+Version: 0.9-7
+Date: 2013-01-11
+Title: SciViews GUI API - svDoc functions
+Authors at R: c(person("Philippe", "Grosjean", role = c("aut", "cre"),
+  email = "phgrosjean at sciviews.org"))
+Author: Philippe Grosjean
+Maintainer: Philippe Grosjean <phgrosjean at sciviews.org>
+Depends: R (>= 2.6.0), svMisc, ascii
+Imports: utils
+SystemRequirements: Python (>= 2.4) to run Asciidoc (http://www.python.org/)
+Description: Supporting functions for the GUI API (SciViews documents management)
+License: file LICENSE
+URL: http://www.sciviews.org/SciViews-R
+BugReports: https://r-forge.r-project.org/tracker/?group_id=194

Added: pkg/svDoc/LICENSE
===================================================================
--- pkg/svDoc/LICENSE	                        (rev 0)
+++ pkg/svDoc/LICENSE	2013-01-11 15:28:59 UTC (rev 510)
@@ -0,0 +1,66 @@
+The svDoc package is licensed underg GPL-2 license.
+However, it includes other open source software components with the following
+licenses:
+
+- jQuery
+- jslider
+- easytabs
+
+
+jQuery License
+----------------------------------------------------------------------   
+
+Copyright (c) 2012 jQuery Foundation and other contributors, 
+http://jquery.com/
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+
+jslider License
+----------------------------------------------------------------------   
+
+The MIT License (MIT)
+Copyright (c) 2012 Egor Khmelev
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
+
+easytabs License
+----------------------------------------------------------------------
+
+By Steve Schwartz](https://github.com/JangoSteve - http://www.alfajango.com)
+Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
+and GPL (http://www.gnu.org/licenses/gpl.html) licenses.

Added: pkg/svDoc/NAMESPACE
===================================================================
--- pkg/svDoc/NAMESPACE	                        (rev 0)
+++ pkg/svDoc/NAMESPACE	2013-01-11 15:28:59 UTC (rev 510)
@@ -0,0 +1,8 @@
+import(utils, ascii)
+importFrom(svMisc, existsTemp)
+
+export(header,
+       render...,
+       svDocToRnw,
+       svDocConvert,
+       svDocThemes)

Added: pkg/svDoc/NEWS
===================================================================
--- pkg/svDoc/NEWS	                        (rev 0)
+++ pkg/svDoc/NEWS	2013-01-11 15:28:59 UTC (rev 510)
@@ -0,0 +1,7 @@
+= svDoc News
+
+== Changes in svDoc 0.9-7
+
+This is the first version of this package, collecting functions that manage
+SciViews documents and Asciidoc features here, from svSweave 0.9-6, initially.
+Name of many function are adapted to the new context.

Added: pkg/svDoc/R/asciidoc.R
===================================================================
--- pkg/svDoc/R/asciidoc.R	                        (rev 0)
+++ pkg/svDoc/R/asciidoc.R	2013-01-11 15:28:59 UTC (rev 510)
@@ -0,0 +1,311 @@
+## Routines to manage and convert SciViews svDoc to asciidoc-sweave
+## Copyright (c) 2012, Ph. Grosjean (phgrosjean at sciviews.org)
+## Note: !!"doc block" is managed by the SciViews version of `!`,
+## otherwise it produces an error... So, you have to place require(SciViews)
+## in the initialisation block (second line) of the SciViews Rdoc!
+
+svDocToRnw <- function (svDocFile, RnwFile, encoding)
+{
+	## Converts a SciViews doc into an sweave document (.Rnw)
+	
+	## If svDocFile is missing, try to get it from option or the command line
+	if (missing(svDocFile)) svDocFile <- .svDocFile()
+	svDocFile <- normalizePath(svDocFile)
+	
+	## Get RnwFile
+	if (missing(RnwFile)) RnwFile <- getOption("Rnw.file",
+		.fileExt(svDocFile, "Rnw"))
+	## Make sure it is not an old file at the end of the process that remains
+	unlink(RnwFile)
+
+	## Get encoding
+	if (missing(encoding)) encoding <- getOption("svDoc.encoding", "UTF-8")
+		
+	## Read svDocFile content
+	Rscript <- readLines(svDocFile, encoding = encoding)
+	l <- length(Rscript)
+	
+	## Detect doc chunks (start with !!", and end with !<<...>>=")
+	start <- grepl('^!!"[ \t]*$', Rscript)
+	end <- grepl('^<<.*>>="[ \t]*$', Rscript)
+	## Must have at least one doc chunk and same number of starts and ends
+	nstart <- sum(start)
+	nend <- sum(end)
+	if (nstart < 1)
+		stop("Incorrect SciViews doc (it must contain at least one doc chunk)")
+	if (sum(end) != nstart)
+		stop("Incorrect SciViews doc (", nstart, " doc chunk starts but ",
+			nend, " ends)")
+	## Lines containing starts and ends
+	lstart <- (1:l)[start]
+	lend <- (1:l)[end]
+	## All starts must occur, of course before ends
+	cstart <- cumsum(start)
+	cend <- cumsum(end)
+	if (any(cend > cstart))
+		stop("Incorrect SciViews doc",
+			 " (inversion of start and end in one or more text chunks)")
+	
+	## Check that the SciViews doc file starts with #!
+	if (!grepl("^#!", Rscript[1]))
+		stop("Incorrect SciViews doc (it must start with #!)")
+	## Change this line into an init code chunk
+	Rscript[1] <- "<<header, echo=FALSE, results=ascii, strip.white=false>>="
+	
+	## Text chunks are lines where cstart > cend
+	inDoc <- cstart > cend
+	
+	## Convert \" into " inside doc blocks
+	Rscript[inDoc] <- gsub('\\\\"', '"', Rscript[inDoc])
+	
+	## Convert \\ into \ inside doc blocks
+	Rscript[inDoc] <- gsub("\\\\\\\\", "\\\\", Rscript[inDoc])
+	
+	## Convert comments blocks using four or more #### by ////
+	Rscript[inDoc] <- gsub("^####+$", "////", Rscript[inDoc])
+	
+	## Convert line comments using ## by __
+	Rscript[inDoc] <- gsub("^##", "__", Rscript[inDoc])
+	
+	## Replace all doc chunk starters (!") by @
+	Rscript[start] <- "@"
+	
+	## Replace all doc chunk ends (<<.*>>=") by the same without trailing "
+	Rscript[end] <- sub('^(.*>>=)"[ \t]*$', "\\1", Rscript[end])
+	
+	## Polish the end of the document...
+	lastDoc <- lend[length(lend)]
+	## If there is no R code after last doc chunk...
+	if (l == lastDoc || all(grepl("^[ \t]*$", Rscript[lastDoc:l]))) {
+		## Nothing after last doc => eliminate last <<.*>>=
+		Rscript[lastDoc] <- ""
+	} else {
+		## Some R code after last doc chunk... we have to add '@' at the end
+		## of the .Rnw file to finish the last code chunk
+		Rscript <- c(Rscript, "@")
+	}
+	
+	## Write result to the RnwFile
+	## TODO: check encoding of .Rnw file on all platforms
+#	utf8conv <- function(x) gsub("<U\\+([0-9A-F]{4})>","\\\\u\\1", x)
+#	Rscript <- utf8conv(Rscript)
+	writeLines(Rscript, RnwFile, useBytes = TRUE)
+#	writeLines(enc2utf8(Rscript), RnwFile, useBytes = TRUE)
+
+	## ... and that's done!
+	return(invisible(Rscript))
+}
+
+## TODO: use figs.dir!!!
+svDocConvert <- function (svDocFile, theme, format, show.it, figs.dir,
+keep.RnwFile, keep.TxtFile, encoding, asciidoc)
+{
+	## If svDocFile is missing, try to get it from option or the command line
+	if (missing(svDocFile)) svDocFile <- .svDocFile()
+	svDocFile <- normalizePath(svDocFile)
+	
+	## RnwFile is either same place, same name as svDocFile, or option Rnw.file
+	RnwFile <- getOption("Rnw.file", .fileExt(svDocFile, "Rnw"))
+
+	## TODO: use .adoc instead as extention!!!
+	## TxtFile is from option, or from SciViews session directory structure
+	## or at the same location as the svDocFile
+	TxtFile <- getOption("Txt.file", .fileExt(svDocFile, "txt"))
+	ReportDir <- .svSessionDirs(svDocFile)$reportdir
+	if (length(ReportDir)) {
+		TxtFile <- file.path(ReportDir, basename(TxtFile))
+	} else TxtFile <- TxtFile
+	## Make sure this is not an old file
+	unlink(TxtFile)
+	
+	## If figs.dir is defined (default to 'figures'), make sure it exists
+	if (missing(figs.dir)) figs.dir <- getOption("svDoc.figs.dir", "figures")
+	if (length(figs.dir)) {
+		figs.dir <- file.path(dirname(TxtFile), figs.dir)
+		if (!file.exists(figs.dir)) {
+			dir.create(figs.dir, showWarnings = FALSE, recursive = TRUE)
+		} else figs.dir <- NULL # Avoid eliminating a dir that already exists!
+	}
+	
+	## If format is missing, try getting it from options(), or assume "html"
+	if (missing(format)) format <- getOption("svDoc.format", "html")
+	## The resulting file extension depends on the format used
+	## Note that EndFile is always at same location as TxtFile
+	EndExt <- switch(format,
+		html = "html",
+		html11 = "html",
+		html5 = "html",
+		html4 = "html",
+		slidy = "html",
+		slidy2 = "html",
+		wordpress = "html",
+		docbook = "xml",
+		docbook45 = "xml",
+		latex = "tex",
+		stop("Unknown format,",
+			" use html/html4/html5/slidy/slidy2/wordpress/docbook/latex")
+		)
+	EndFile <- .fileExt(TxtFile, EndExt)
+		
+	## If theme is missing, try getting it from options()
+	if (missing(theme)) theme <- getOption("svDoc.theme", "sciviews")
+	## If there is an initialization file for this theme, run it now
+	## TODO...
+		
+	## Do we show the resulting Html file in the current browser at the end?
+	## By default YES, unless in non-interactive mode
+	if (missing(show.it)) show.it <- getOption("svDoc.show.it", interactive())
+	
+	## Do we keep intermediary .Rnw and .txt files? Default to FALSE
+	if (missing(keep.RnwFile))
+		keep.RnwFile <- getOption("svDoc.keep.RnwFile", FALSE)
+	if (missing(keep.TxtFile))
+		keep.TxtFile <- getOption("svDoc.keep.TxtFile", FALSE)
+	
+	## Get encoding... should be UTF-8 for usual SciViews doc
+	## and make sure to configure the system as UTF-8 (except on Windows)
+	if (missing(encoding)) encoding <- getOption("svDoc.encoding", "UTF-8")
+	if (toupper(encoding) == "UTF-8") {
+		if (.Platform$OS.type != "windows") {
+			## Make sure current locale is UTF-8
+			## It is not, for instance, if started from terminal in Mac OS X!
+			## Also force 'en_US' for homogeneity of R behaviour across systems
+			Sys.setlocale(, "en_US.UTF-8")
+			on.exit(Sys.setlocale(, "")) # Reset default locale for the system
+		}
+	}
+	
+	## Get asciidoc Python script
+	if (missing(asciidoc)) asciidoc <- getOption("asciidoc",
+		system.file("asciidoc", "asciidoc.py", package = "svDoc",
+		mustWork = TRUE))
+	
+	## We need also Python >= version 2.4
+	python <- getOption("python", NULL)
+	## Search (again)...
+	if (is.null(python)) {
+		python <- .python()
+		options(python = python)
+	}
+	## Nothing to do... no Python found!
+	if (is.null(python)) stop("Python >= 2.4 is required for asciidoc")
+	
+	## Convert from Rscript to .Rnw file
+	cat("Creating R noweb file ", basename(RnwFile), "\n", sep = "")
+	svDocToRnw(svDocFile = svDocFile, RnwFile = RnwFile, encoding = encoding)
+	if (!file.exists(RnwFile))
+		stop("Problems while creating the R noweb file(", RnwFile, ")")
+	
+	## Copy it to where the Txt file must be created...
+	if (dirname(TxtFile) != dirname(RnwFile)) {
+		RnwFile2 <- file.path(dirname(TxtFile), basename(RnwFile))
+		file.copy(RnwFile, RnwFile2, overwrite = TRUE)
+		if (!file.exists(RnwFile2))
+			stop("Problems while copying the R noweb file(", RnwFile, " to ",
+				dirname(TxtFile), ")")
+		unlink(RnwFile)
+	} else RnwFile2 <- RnwFile
+	
+	## Sweave that document to .txt file
+	## Note that the ascii package must be loaded first!
+	require(ascii, quietly = TRUE, warn.conflicts = FALSE)
+	odir <- setwd(dirname(RnwFile2)) # Work now relative to destination file
+	## Also display warnings immediately
+	owarn <- options(warn = 1)
+	
+	## Make sure intermediary filles will be deleted on exit
+	on.exit({
+		setwd(odir)
+		## Possibly delete intermediary files
+		if (!isTRUE(keep.RnwFile)) unlink(RnwFile2)
+		if (!isTRUE(keep.TxtFile)) unlink(TxtFile)
+		## If figs.dir is empty, delete it
+		if (length(figs.dir) && !length(dir(figs.dir, include.dirs = TRUE)))
+			unlink(figs.dir, recursive = TRUE)
+		## Restore warn option
+		options(owarn)
+	}, add = TRUE)
+	
+	## Sweave this document... (creating the TxtFile)
+	## Note: we change some default options here!
+	Asciidoc(RnwFile2, encoding = encoding, prefix.string = "figures/fig",
+		width = 7.2, height = 7.2, png = TRUE, jpeg = FALSE, format = "png")
+	
+	if (!file.exists(TxtFile))
+		stop("Problems while creating the Asciidoc file (", TxtFile, ")")
+	
+	## Do we use a particular theme with Asciidoc
+	if (theme == "classic") {
+		opts <- paste('" -b ', format, ' -a asciimath -a caption "', sep = "")
+	} else {
+		opts <- paste('" -b ', format, ' -a asciimath -a caption --theme=',
+			theme, '@ "', sep = "")
+	}
+
+	## Use AsciiDoc to convert the .txt file into an .html file
+	cat("Running asciidoc to create ", basename(EndFile), "\n", sep = "")
+	system(paste('"', python, '" "', asciidoc, opts, TxtFile, '"', sep = ""))
+		
+	## If there is a finalize code for this theme, run it now
+	## TODO...
+
+	## Check that the final file exists!
+	if (!file.exists(EndFile))
+		stop("Asciidoc was unable to format your document")
+	
+	## Do we view the resulting .html file?
+	if (isTRUE(show.it) && EndExt == "html") {
+		cat("Opening the formatted document", basename(EndFile),
+			"in the Web browser\n")
+		browseURL(normalizePath(EndFile))
+	} else cat("Formatted document available at ", EndFile, "\n", sep = "")
+	invisible(EndFile)
+}
+
+svDocThemes <- function ()
+{
+	themesDir <- file.path(dirname(system.file("asciidoc", "asciidoc.py",
+		package = "svDoc")), "themes")
+	c("classic", dir(themesDir, include.dirs = TRUE))
+}
+
+render... <- function (svDocFile, encoding)
+{
+	## A function to run an a SciViews doc file, and that looks at the #!
+	## line to determine what function to run for compiling the final document
+
+	## If svDocFile is missing, try to get it from option or the command line
+	if (missing(svDocFile)) svDocFile <- .svDocFile()
+	
+	## Check svDocFile
+	if (missing(svDocFile) || !length(svDocFile)) stop("No file provided")
+	if (!file.exists(svDocFile)) stop("svDocFile not found (", svDocFile, ")")
+	svocFile <- normalizePath(svDocFile)
+	
+	## Get encoding
+	if (missing(encoding)) encoding <- getOption("svDoc.encoding", "UTF-8")	
+	
+	## Check that it is a R script file (first line starting with #!)
+	Rscript <- readLines(svDocFile, n = 1L, encoding = encoding)
+	if (!grepl("^#!", Rscript))
+		stop("Incorrect SciViews doc file (it must start with #!)")
+
+	## Decrypt first line to know what function to run to make this file
+	cmd <- sub("^#!.+ -e[ \t]*(.+)$", "\\1", Rscript)
+	if (cmd == Rscript) stop("Malformed #! line in '", svDocFile, "'")
+	
+	## Eliminate possible quotes around the command and trailing spaces
+	cmd <- sub("[ \t]+$", "", cmd)
+	cmdNoQuotes <- sub("^'(.+)'$", "\\1", cmd) # Single quotes
+	if (cmdNoQuotes == cmd)
+		cmdNoQuotes <- sub('^"(.+)"$', "\\1", cmd) # Double quotes
+	
+	## Pass the file name to the build procedure
+	ofile <- options(svDoc.file = svDocFile)$svDoc.file
+	oencoding <- options(svDoc.encoding = encoding)$svDoc.encoding
+	on.exit(options(svDoc.file = ofile, encoding = oencoding))
+	
+	## Run that command
+	cmd <- try(parse(text = cmdNoQuotes))
+	if (!inherits(cmd, "try-error")) eval(cmd, envir = parent.frame())
+}

Added: pkg/svDoc/R/header.R
===================================================================
--- pkg/svDoc/R/header.R	                        (rev 0)
+++ pkg/svDoc/R/header.R	2013-01-11 15:28:59 UTC (rev 510)
@@ -0,0 +1,111 @@
+## Create an Asciidoc header according to these items
+
+header <- function (title, author = NULL, email = NULL, revnumber = NULL,
+revdate = NULL, revremark = NULL, copyright = "cc-by", encoding = "UTF-8",
+lang = "en", pagetitle = NULL, description = "SciViews document", keywords = NULL,
+theme = "sciviews", max.width = 640, width = NULL,
+toc = c("top", "side", "manual", "none"), toc.title = NULL, toclevels = 2,
+numbered = TRUE, data.uri = TRUE, frame = "topbot", grid = "rows",
+align = "center", halign = "center", pygments = FALSE, slidefontsizeadjust = 0,
+SweaveInit = { options(width = 80); options(SweaveHooks = list(fig = function()
+par(col.lab = "#434366", col.main = "#434366"))) }
+)
+{
+	## Format Asciidoc attributes
+	asciiAttr <- function (header = NULL, name, value) {
+		if (!length(value)) return(header)
+		paste0(header, ":", name, ": ", paste(value, collapse = ","), "\n")
+	}
+	
+	## Create the Asciidoc header
+	header <- character(0)
+	
+	## Title must be a single string and start with '= '
+	if (length(title)) header <- paste0(as.character(title)[1], "\n")
+	if (substring("= ", 1, 2) != "= ") header <- paste("=", header)
+	
+	## Idem for author, but allow several names
+	if (length(author)) {
+		author <- paste(author, collapse = ", ")
+	
+		## Check also email
+		if (length(email)) {
+			email <- as.character(email)[1]
+			if (!grepl("^.+ at .+$", email))
+				stop("You must provide a correct email address for your svDoc")
+			header <- paste0(header, author, " <", email, ">\n")
+		} else {
+			header <- paste0(header, author, "\n")	
+		}
+	}
+	
+	## Compute revision field: [revnumber], [revdate]:\n[revremark]
+	## TODO: check all this in function of all possible missing items
+	if (length(revnumber) || length(revdate) || length(revremark)) {
+		if (length(revnumber))
+			revfield <- paste0("v", revnumber, ", ") else revfield <- ""
+		if (!length(revdate)) revdate <- format(Sys.Date(), format = "%B %Y")
+		revfield <- paste0(revfield, revdate)
+		if (length(revremark))
+			revfield <- paste0(revfield, ":\n", paste(revremark, collapse = "\n"))
+		header <- paste0(header, revfield, "\n")
+	}
+	
+	## Rework copyright
+	if (length(copyright)) {
+		if (!grepl("^[^,]+,[^,]+,[ \t]*[0-9]{4}$", copyright)) {
+			if (length(revdate)) {
+				year <- substring(revdate, nchar(revdate) - 3)
+			} else year <- format(Sys.Date(), format = "%Y")
+			if (!length(author)) {
+				copyright <- paste0(copyright, ", ", year)	
+			} else {
+				copyright <- paste0(copyright, ", ", author, ", ", year)
+			}
+		}
+		header <- asciiAttr(header, "copyright", copyright)
+	}
+	
+	## Add more attributes
+	header <- asciiAttr(header, "encoding", encoding)
+	header <- asciiAttr(header, "lang", lang)
+	header <- asciiAttr(header, "title", pagetitle)
+	header <- asciiAttr(header, "description", description)
+	header <- asciiAttr(header, "keywords", keywords)
+	header <- asciiAttr(header, "theme", theme)
+	header <- asciiAttr(header, "max-width", max.width)
+	header <- asciiAttr(header, "width", width)
+	
+	## How to format the toc?
+	toc <- switch(as.character(toc)[1],
+		top = ":toc:\n",
+		side = ":toc2:\n",
+		manual = ":toc:\n:toc-placement: manual\n",
+		none = ":toc!:\n",
+		stop("'toc' must be 'top', 'side', 'manual' or ''none'"))
+	header <- paste0(header, toc)
+	header <- asciiAttr(header, "toc-title", toc.title)
+	header <- asciiAttr(header, "toclevels", toclevels)
+	if (isTRUE(numbered)) header <- paste0(header, ":numbered:\n")
+	if (isTRUE(data.uri)) header <- paste0(header, ":data-uri:\n")
+	header <- asciiAttr(header, "frame", frame)
+	header <- asciiAttr(header, "grid", grid)
+	header <- asciiAttr(header, "align", align)
+	header <- asciiAttr(header, "halign", halign)
+	if (isTRUE(pygments)) header <- paste0(header, ":pygments:\n")
+	header <- asciiAttr(header, "slidefontsizeadjust", slidefontsizeadjust)
+	## Are we currently building a dynamic document?
+	if (svMisc::existsTemp(".build__dynamic__svDoc__"))
+		header <- paste0(header, ":dynamic:\n")
+	header <- paste0(header, "\n") # End of header section
+	
+	## Run SweaveInit now
+	SweaveInit
+	## More initialization (make sure svDoc and SciViews are attached)
+	req <- base::require
+	req("svSweave", quietly = TRUE, warn.conflicts = FALSE)
+	
+	## Print the header and return it invisibly
+	cat(header)
+	invisible(header)
+}

Added: pkg/svDoc/R/svDoc-internal.R
===================================================================
--- pkg/svDoc/R/svDoc-internal.R	                        (rev 0)
+++ pkg/svDoc/R/svDoc-internal.R	2013-01-11 15:28:59 UTC (rev 510)
@@ -0,0 +1,122 @@
+.onLoad <- function (lib, pkg)
+{
+	## Look for a suitable python executable
+	py <- .python()
+	if (!is.null(py)) options(python = py)
+}
+
+.packageName <- "svDoc"
+
+.fileExt <- function (file, extension)
+{
+	## Change the extension of a file
+	file <- sub("\\.[^\\.]*$", "", file)
+	paste(file, extension, sep = ".")
+}
+
+.svDocFile <- function ()
+{
+	## Try to get svDocFile from option or the command line
+	## Note: the file from the command line is for #! scripts!
+	svDocFile <- getOption("svDoc.file", NULL)
+	if (is.null(svDocFile)) svDocFile <- commandArgs(TRUE)[1] # If #! script
+	if (!length(svDocFile) || !file.exists(svDocFile))
+		stop("svDocFile not found (", svDocFile, ")")
+	return(normalizePath(svDocFile, winslash = "/"))
+	
+}
+
+.svSessionDirs <- function (file, ensure.exist = TRUE)
+{
+	## Get the structure of the current session, giving a file or dir
+	## in the base directory or a child directory of a SciViews session
+	if (!file.exists(file))
+		stop("File not found (", file, ")")
+	if (file.info(file)$isdir) {
+		dir <- file
+	} else {
+		dir <- dirname(file)
+		if (dir == ".") dir <- getwd()
+	}
+	
+	## Look if these is a .svData file there or in the parent dir
+	if (file.exists(svDataFile <- file.path(dir, ".svData"))) {
+		baseDir <- normalizePath(dir, winslash = "/") 
+	} else if (file.exists(svDataFile <- file.path(dirname(dir), ".svData"))) {
+		baseDir <- normalizePath(dirname(dir), winslash = "/")
+	} else { # Apparently not a SciViews session
+		return(list(basedir = character(0), datadir = character(0),
+			scriptdir = character(0), reportdir = character(0)))
+	}
+	
+	## Read the .svData file and get datadir, scriptdir and reportdir
+	svData <- strsplit(suppressWarnings(
+		readLines(svDataFile)), "=", fixed = TRUE)
+	items <- sapply(svData, function (x) sub("^ *", "", sub(" *$", "", x[1])))
+	values <- lapply(svData, function (x) sub("^ *", "", sub(" *$", "",
+		paste(x[-1], collapse = "="))))
+	names(values) <- items
+	
+	## Rework svData to have a list of base, data, script & report absolute dirs
+	svNames <- c("basedir", "datadir", "scriptdir", "reportdir")
+	svDirs <- values[svNames]
+	names(svDirs) <- svNames
+	
+	## Combine these to get absolute paths
+	svDirs <- lapply(svDirs, function (x) if (!length(x)) baseDir else
+		file.path(baseDir, x))
+	
+	## Make sure these paths exist
+	if (isTRUE(ensure.exist))
+		lapply(svDirs, dir.create, showWarnings = FALSE, recursive = TRUE)
+
+	## Returns this list of paths
+	return(svDirs)
+}
+
+.python <- function (min.version = 2.4)
+{
+	## Try getting a valid python executable, with version at least min.version
+	.pyCheck <- function (py, min.version = min.version) {
+		if (Sys.which(paste('"', py, '"', sep = "")) == "")
+			return(FALSE) # Not found
+		## Check version...
+		## The following is obvious, but does not work in Rterm.exe (stdout is
+		## *not* redirected to stdin there!)
+		#pyVersion <- sub("^Python ", "",
+		#	system(paste('"', py, '" --version 2>&1', sep = ""), intern = TRUE))
+		pyVersion <- sub("^([^ ]+).*$", "\\1", system(paste('"', py,
+			'" -c "import sys; print sys.version"', sep = ""),
+			intern = TRUE)[1])
+		res <- try(suppressWarnings(compareVersion(pyVersion, "2.4") > 0),
+			silent = TRUE)
+		## If there is an error, by-pass version checking and just look if
+		## the file is there (sometimes it fails on Windows)
+		if (inherits(res, "try-error")) res <- file.exists(py)
+		return(as.logical(res)[1])
+	}
+	
+	## Try easiest first!
+	py <- Sys.getenv("python")
+	if (py == "") py <- "python"
+	if (.pyCheck(py)) return(py)
+	
+	## If Komodo Edit/IDE is installed, it comes with a suitable Python version
+	ko <- Sys.which("komodo")
+	if (ko == "") return(NULL)
+
+	## This is a symlink on Linux & Mac OS X => get original executable
+	ko2 <- Sys.readlink(ko)	
+	if (ko2 != "") koDir <- dirname(ko2) else koDir <- dirname(ko)
+	
+	## Python executable can be located at different places, relative to komodo
+	py <- file.path(koDir, "mozpython") # On Mac OS X
+	if (!file.exists(py)) # On Windows
+		py <- file.path(dirname(koDir), "python", "python.exe")
+	if (!file.exists(py)) # On Linux
+		py <- file.path(dirname(koDir), "lib", "python", "bin", "python")
+	if (!file.exists(py)) return(NULL)
+
+	## Recheck now...
+	if (.pyCheck(py)) return(py) else return(NULL)
+}

Added: pkg/svDoc/TODO
===================================================================
--- pkg/svDoc/TODO	                        (rev 0)
+++ pkg/svDoc/TODO	2013-01-11 15:28:59 UTC (rev 510)
@@ -0,0 +1,62 @@
+= svDoc - To do list
+
+* Package svShiny code here + runExample()/runGist()
+
+* Use more sensible values for toc: if missing and no author/revfield => no toc.
+
+* A better management of theme: define one form html and one for slidy/slidy2.
+
+* With the shiny jslider, I would like to be able to move left cursor and keep
+  interval between left and right cursor constant... or, better, be able to drag
+  the interval between the two cursors.
+  
+* Make a better default_shiny.R page that lists all existing pages on the server
+
+* Rename xxx_shiny.R as xxx.svDoc, simply?!
+
+* Make interface for writing SciViews documents in Komodo/SciViews-K.
+
+* ascii() => view() + aware if ascii or latex and results=ascii/tex accordingly
+
+* Clean up the latex export filter and make a LyX export filter
+
+* Also allow to convert from LyX/LaTeX to Asciidoc
+
+* Enable timer events on the page server and daemonize it on Windows
+  (using Tcl loop)?
+  
+* A better logic for startPageServer() call, e.g., if the server does not run
+  and a page is created
+ 
+* Rename pageXXX() functions into docXXX() functions. 
+  
+* In non interactive mode, detect when the last client exit and quit then
+  also automatically, unles differently specified
+  
+* Allow for several author names
+
+* Numbered items for figures, tables, equations and listings using Asciidoc
+  replacement macros
+  
+* Save/reload pages installed on a server with R code
+
+* Eliminate footer for slidy2 (interferes with dynamic documents)
+
+* Allow to specify two themes: one for html, one for slidy/slidy2
+
+* A better uiSideBySide() system
+
+* Something similar to runExample() & runGist() in shiny
+
+* Move the definition of `!` here from SciViews? Or put in svMisc?
+
+* In shiny, when ui.R or server.R is updated, the app is also updated. Do the
+  same here?
+  
+* Add an option(dynamic.trace = TRUE) to trace calls to dynamicXXX() functions.
+
+* In presentation or screencast mode: have a series of premared snippets to help
+  construct the SciViews Rdoc in live.
+
+* To use Ubuntu and Ubuntu mono on a HTML page, add at the beginning og head section:
+  <link href='http://fonts.googleapis.com/css?family=Ubuntu:400,400italic,700,700italic|Ubuntu+Mono:400,400italic,700,700italic&subset=latin,greek,latin-ext' rel='stylesheet' type='text/css'>
\ No newline at end of file

Added: pkg/svDoc/inst/asciidoc/BUGS.txt
===================================================================
--- pkg/svDoc/inst/asciidoc/BUGS.txt	                        (rev 0)
+++ pkg/svDoc/inst/asciidoc/BUGS.txt	2013-01-11 15:28:59 UTC (rev 510)
@@ -0,0 +1,20 @@
+Bugs and Known Problems
+=======================
+
+AsciiDoc
+--------
+- A benign warning 'with will become a reserved keyword
+  in Python 2.6' sometimes occurs when using Python 2.5 -- it's
+  harmless and will disappear with Python 3.
+- Reported line numbers in diagnostic messages are sometimes wrong.
+- Attribute references in macro attribute lists can't be unescaped
+  (with the exception of attribute list entry `{0}`).
+- Section numbering is incorrect when outputting HTML from a
+  multi-part book type document. This is not a biggy since multi-part
+  books are generally processed to DocBook.
+- A row of apostrophes in an inline context throws AsciiDoc into an
+  endless loop. The problem seems to be in the input file 'Reader'.
+
+dblatex
+-------
+See `./dblatex/dblatex-readme.txt`.

Added: pkg/svDoc/inst/asciidoc/CHANGELOG.txt
===================================================================
--- pkg/svDoc/inst/asciidoc/CHANGELOG.txt	                        (rev 0)
+++ pkg/svDoc/inst/asciidoc/CHANGELOG.txt	2013-01-11 15:28:59 UTC (rev 510)
@@ -0,0 +1,3128 @@
+AsciiDoc ChangeLog
+==================
+
+:website: http://www.methods.co.nz/asciidoc/
+
+
+Version 8.6.8 (2012-07-17)
+--------------------------
+.Release highlights
+Added full complement of styles to 'Open Blocks' and 'Normal
+Paragraphs' -- those with a minimalist bent could construct virtually
+any document using just Title, Normal Paragraph and Open Block
+syntaxes.
+
+.Other additions and changes
+- Increased default maximum include depth from 5 to 10.
+- Emit warning if maximum include depth is exceeded.
+- Suppress repeated console messages.
+- Music filter: removed '--beams=None' option from abc2ly invocation
+  because it is broken on LilyPond 2.14 (Ubuntu 12.04).
+- Replaced obsolete '<tt>' tag with '<code>' in HTML backends.
+- Allow configuration attribute entries to create a new section
+  (previously you could only modify existing sections).  See:
+  https://groups.google.com/group/asciidoc/browse_thread/thread/7be28e9714f249c7[discussion
+  list].
+- Documented `{wj}` (word-joiner) attribute and updated FAQ.  See:
+  https://groups.google.com/group/asciidoc/browse_thread/thread/961a957ab5872ebf[discussion
+  list].
+- FAQ: Added 'How can I place a footnote immediately following quoted
+  text?' See
+  https://groups.google.com/group/asciidoc/browse_thread/thread/961a957ab5872ebf[discussion
+  list].
+- Added Greek language configuration file. Contributed by Michael
+  Dourmousoglou.  See
+  https://groups.google.com/group/asciidoc/browse_thread/thread/9e79d8494ef8d870[discussion
+  list].
+- FAQ: Added 'Using roles to select fonts for PDF'. Submitted by Lex
+  Trotman and based on solution by Antonio Borneo. See:
+  https://groups.google.com/group/asciidoc/browse_frm/thread/64b071bb21de9cf0[discussion
+  list].
+- Apply same monospaced font size to all monospaced text.
+- Changed '0' number padding to spaces in numbered GNU
+  source-highlight outputs.
+- Allow 'highlight' source highlighter to use 'python' for Python
+  `{language}` name.  r1142: Update the AsciiDoc 'source' filter to
+  allow the use of the 'highlight' source code highlighter.  See
+  https://groups.google.com/group/asciidoc/browse_frm/thread/e045c9986c71d72a[discussion
+  list].
++
+NOTE: The 'pygments' attribute has been deprecated in favor of the new
+'source-highlighter' attribute.
+
+- Vim syntax highlighter: Don't confuse trailing open block delimiter
+  with section underline.
+- Added 'skip' option to paragraphs (c.f. Delimited Block 'skip'
+  option).
+
+.Bug fixes
+- *FIXED*: latex, music and graphviz filters: When the filter output
+  image is data-uri encoded write it to the indir (instead of the
+  outdir) so that encoder can find it. See
+  https://groups.google.com/group/asciidoc/browse_thread/thread/f5174f450a61f14b[discussion
+  list].
+- *FIXED*: Escape the ']' character inside inline macros.  See
+  https://groups.google.com/group/asciidoc/browse_thread/thread/db3b734a6931cb74[discussion
+  list].
+- *FIXED*: source highlighter filter: Pass 'role' attribute to HTML
+  backends.
+- *FIXED*: source highlight filter: docbook backend: 'role' attribute
+  was not passed to listings without a title. Patch submitted by Lex
+  Trotman. See
+  https://groups.google.com/group/asciidoc/browse_thread/thread/13c9ee97930342b3[discussion
+  list].
+- *FIXED*: music2png.py: 'FOPException: Raster ByteInterleavedRaster'
+  error (FOP 1.0, ImageMagick 6.6.9-7).
+
+
+
+Version 8.6.7 (2012-03-17)
+--------------------------
+.Release highlights
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/sciviews -r 510


More information about the Sciviews-commits mailing list