File: promptXML.Sxml

package info (click to toggle)
r-cran-xml 3.99-0.19-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,688 kB
  • sloc: ansic: 6,659; xml: 2,890; asm: 486; sh: 12; makefile: 2
file content (217 lines) | stat: -rw-r--r-- 4,936 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?xml version="1.0"?>
<!DOCTYPE SSource SYSTEM "/home/duncan/Projects/org/omegahat/XML/RS/examples/SSource.dtd"
  [
     <!-- Temporarily use _ rather thant <- as it screws things up. -->
    <!ENTITY sgets "_" >
    <!ENTITY Latex "LaTex" >
  ]>

<SSource>
<overview>
Here we define some 
</overview>



<function>
<sname>prompt.xml</sname>
<selfDoc>
<description>
</description>
<args>
<arg name="file">
this is the name of the file into which the documentation
is placed. In the future, this will be a connection object.
</arg>
<arg name="header">
 this is text that is to be placed immediately
after the <![CDATA[<?xml version="1.0"?>]]>
string emitted as the first part of the text.
In the future, we will want to append/insert
content into existing documents and so we  will have to recognize
not to add this PI again, etc.
</arg>
</args>
</selfDoc>
<def>
<![CDATA[
function(object, file = NULL, ..., header='<!DOCTYPE Rhelp system "Rhelp.dtd"&gt;\n\n&lt;Rhelp&gt;',footer="&lt;/Rhelp&gt;")
{
  local <- list(...)

  name <- substitute(object)
    
    # Taken from prompt.default
  is.missing.arg <- function(arg) typeof(arg) == "symbol" && 
        deparse(arg) == ""

  if (is.language(name) && !is.name(name)) 
        name <- eval(name)
  name <- as.character(name)
  fn <- get(name)

  xml <- xmlWriteBuffer()
  if(!is.null(header))
     xml$add(header)

  xml$addTag("sname",name)   
  xml$addTag("alias",name)   
  xml$addTag("title"," ~~function to do ... ~~ ")   

  xml$addTag("description","~~ A concise (1-5 lines) description of what the function does. ~~")   

  xml$addTag("usage", close=F)     


    # Now handle arguments  and generate the call.
   s <- seq(length = n <- length(argls <- formals(fn)))   
        if (n > 0) {
            arg.names <- names(argls)
        }
        xml$addTag("sname", name,sep="")
      
        for (i in s) {
            xml$addTag("arg", xml$tagString("argName", arg.names[i]), close=F)
           
            if(!is.missing.arg(argls[[i]]))  {
               xml$addTag("defaultValue", deparse(argls[[i]]),sep="")
            }
            xml$closeTag("arg")
            if(i < n)
              xml$addTag("next")
        }
  xml$add("</usage>")     

  xml$addTag("arguments", close=F)
    for(i in arg.names) {
      xml$addTag("argument", xml$tagString("argDescriptionName", i), "\n<argDescription>", 
                    "~~Describe ",i," here~~", "</argDescription>")
    }
  xml$add("</arguments>")


  xml$addTag("details","  ~~ If necessary, more details than the __description__  above ~~")
  xml$addTag("value", "~Describe the value returned",
               "  If it is a LIST, use", "  \\item{comp1 }{Description of `comp1'}", 
               "  \\item{comp2 }{Description of `comp2'}", "  ...")


  xml$addTag("references", ifelse(!is.null(local$references), local$references, ""))

  xml$addTag("author", ifelse(!is.null(local$author), local$author, ""))
  xml$addTag("note")

  xml$addTag("seeAlso", xml$tagString("a", attrs=list("href"="\"\"")))
  
  xml$addTag("examples", xml$tagString("example"))

  xml$addTag("keywords", xml$tagString("keyword"))

  if(!is.null(footer))
     xml$add(footer)

  val <- xml$value()

  if(!missing(file))
     cat(val, file=file)

  val
}
]]>
</def>
<examples>
<example>
<description>
</description>
<code>
   # Always start with the perverse one!
 xmlPrompt(xmlPrompt)
</code>
</example>
</examples>
</function>



<function>
<sname>xmlWriteBuffer</sname>
<selfDoc>
<description>
 Want to check with the DTD whether a tag is legitimate
  attributes are valid, etc.

 Add an indentation level.

  Need to escape characters via entities:
<![CDATA[
      <-   => %sgets;
      <    => %lt;
      >    => %gt;
]]>
   etc.
</description>
</selfDoc>
<def>
<![CDATA[
function(dtd = NULL)
{
  paste0 <- function(...) paste(..., sep = "")
  buf <- "<?xml version=\"1.0\"?>"

  add <- function(..., sep="\n") {
    buf <<- paste(buf, paste0(...), sep=sep) 
  }

  tagString <- function(tag, ..., attrs, close=F) {
   tmp <- ""
    if(!missing(attrs)) {
     tmp <- paste(" ", paste(names(attrs), attrs,sep="=", collapse=" "),sep="")
    }
   return(paste0("<", tag,tmp, ">",...,"</",tag,">"))
  }

  addTag <- function(tag, ..., attrs=NULL, sep="\n", close=T) {
    tmp <- ""
    if(!missing(attrs)) {
      tmp <- paste(" ", paste(names(attrs), attrs,sep="=", collapse=" "),sep="")
    }

    add(paste("<",tag, tmp, ">", sep=""))

    if(length(list(...)) > 0) {
      add(..., sep=sep)
    }
    if(close) {
      add(paste("</",tag, ">", sep=""), sep="")
    } 

    NULL
  }

   closeTag <- function(name) {
     add("\n", "</",name,">", sep="")
   }


  list( value=function() {buf},
        add = add,
        addTag = addTag,
        closeTag = closeTag,
        tagString = tagString
      )

}
]]>
</def>
<examples>
<example>
<description>
</description>
<code>
</code>
</example>
</examples>
</function>
</SSource>