HenrikBengtsson / R.rsp
1
###########################################################################/**
2
# @RdocDefault compileAsciiDocNoweb
3
#
4
# @title "Compiles an AsciiDoc noweb file"
5
#
6
# \description{
7
#  @get "title".
8
#
9
#  \emph{NOTE: This function requires the \bold{ascii} package, which was
10
#  "removed" (archived) from CRAN on 2019-01-26.}
11
# }
12
#
13
# @synopsis
14
#
15
# \arguments{
16
#   \item{filename, path}{The filename and (optional) path of the
17
#      document to be compiled.}
18
#   \item{...}{Additional arguments passed to \code{Asciidoc()} of the
19
#      \bold{ascii} package.}
20
#   \item{outPath}{The output and working directory.}
21
#   \item{verbose}{See @see "R.utils::Verbose".}
22
# }
23
#
24
# \value{
25
#   Returns the pathname of the generated document.
26
# }
27
#
28
# @author
29
#
30
# @keyword file
31
# @keyword IO
32
# @keyword internal
33
#*/###########################################################################
34
setMethodS3("compileAsciiDocNoweb", "default", function(filename, path=NULL, ..., outPath=".", postprocess=TRUE, verbose=FALSE) {
35 1
  use("ascii", quietly=TRUE)
36
  # To please R CMD check
37 0
  Asciidoc <- NULL; rm(list="Asciidoc")
38

39
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
40
  # Validate arguments
41
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
42
  # Arguments 'filename' & 'path':
43 0
  pathname <- if (is.null(path)) filename else file.path(path, filename)
44 0
  if (!isUrl(pathname)) {
45 0
    pathname <- Arguments$getReadablePathname(pathname)
46
  }
47

48
  # Arguments 'outPath':
49 0
  outPath <- Arguments$getWritablePath(outPath)
50 0
  if (is.null(outPath)) outPath <- "."
51

52
  # Argument 'verbose':
53 0
  verbose <- Arguments$getVerbose(verbose)
54 0
  if (verbose) {
55 0
    pushState(verbose)
56 0
    on.exit(popState(verbose))
57
  }
58

59

60 0
  verbose && enter(verbose, "Compiling AsciiDoc noweb document")
61
  # Download URL?
62 0
  if (isUrl(pathname)) {
63 0
    verbose && enter(verbose, "Downloading URL")
64 0
    url <- pathname
65 0
    verbose && cat(verbose, "URL: ", url)
66 0
    pathname <- downloadFile(url, verbose=less(verbose,50))
67 0
    verbose && cat(verbose, "Local file: ", pathname)
68 0
    verbose && exit(verbose)
69
  }
70

71 0
  pathname <- getAbsolutePath(pathname)
72 0
  verbose && cat(verbose, "Pathname (absolute): ", pathname)
73 0
  verbose && printf(verbose, "Input file size: %g bytes\n", file.info(pathname)$size)
74 0
  verbose && cat(verbose, "Output and working directory: ", outPath)
75

76 0
  opwd <- "."
77 0
  on.exit(setwd(opwd), add=TRUE)
78 0
  if (!is.null(outPath)) {
79 0
    opwd <- setwd(outPath)
80
  }
81

82 0
  pathname2 <- Asciidoc(pathname)
83 0
  pathname2 <- getAbsolutePath(pathname2)
84 0
  setwd(opwd); opwd <- "."
85

86 0
  res <- RspFileProduct(pathname2, type="application/x-asciidoc")
87 0
  verbose && print(verbose, res)
88

89
  # Postprocess?
90 0
  if (postprocess) {
91 0
    res <- process(res, outPath=outPath, recursive=TRUE, verbose=verbose)
92
  }
93

94 0
  verbose && exit(verbose)
95

96 0
  res
97
}) # compileAsciiDocNoweb()

Read our documentation on viewing source code .

Loading