diff --git a/R/class.R b/R/class.R index 2c4094c67399aba9784e87c7681a23b1aca3719b..4761add57c81f8cfacfe964d17c71510623a225a 100644 --- a/R/class.R +++ b/R/class.R @@ -18,15 +18,30 @@ library(R6) #'@field content the future content of \code{page_name}, which will be incrementally constructed using object methods #'@examples #' mwHandler <- Mediawikir$new("http://my.wiki.org", "reg_user", "mypassword", "wikiPage") +#' mwHandler$addContent("This is an introduction to Mediawikir") +#' mwHandler$addContent("First step","h2") +#' mwHandler$addContent("First step of the first step","h3") #'@section Methods: #'\describe{ -#' \item{\code{initialize(instance_url, user, page, pass)}}{Creates a new Mediawikir object out of:\describe{ +#' \item{\code{initialize(instance_url, user, page, pass)}}{Creates a new Mediawikir object out of: +#' \describe{ #' \item{\code{instance_url}}{The base url to the mediawiki instance} #' \item{\code{user}}{The screen name of the user who will be credited for the changes in the wiki} #' \item{\code{page}}{The wiki page which contains the changes} #' \item{\code{pass}}{The user's password} #' }} #' \item{\code{connect(pass)}}{Should not be called directly (see initialize for detail)} +#' \item{\code{addContent(theContent, type="p")}}{To add content that will later on be posted to mediawiki. This is where structuring elements are provided +#' \describe{ +#' \item{\code{theContent}}{Either text (using mediawiki syntax) or path to a file} +#' \item{\code{type}}{\describe{ +#' \item{\code{p} → A plain paragraph.}{} +#' \item{\code{h2} → Level 2 title}{} +#' \item{\code{h3} → Level 3 title}{} +#' \item{\code{h4} → Level 4 title}{} +#' \item{\code{h5} → Level 5 title}{} +#' }} +#' }} #'} Mediawikir <- R6Class("Mediawikir", public = list( @@ -90,6 +105,20 @@ Mediawikir <- R6Class("Mediawikir", print(e$message) self <- FALSE }) + }, + + ###### + # addContent + ###### + addContent = function(theContent, type="p"){ + switch(type, + h2 = theContent <- paste("==", theContent, "=="), + h3 = theContent <- paste("===", theContent, "==="), + h4 = theContent <- paste("====", theContent, "===="), + h5 = theContent <- paste("=====", theContent, "====="), + p = theContent <- paste(theContent, "\n", sep=""), + ) + self$content <- paste(self$content, theContent, sep="\n") } ) ) diff --git a/man/Mediawikir.Rd b/man/Mediawikir.Rd index d2c6c3a4761f27d8efe8dbc8f31b262ddb3812ff..64d20d1a9bc0e99699c198631edd28140cfbd949 100644 --- a/man/Mediawikir.Rd +++ b/man/Mediawikir.Rd @@ -29,17 +29,32 @@ A Mediawikir controller serves to connect to a mediawiki API as a registered use \section{Methods}{ \describe{ - \item{\code{initialize(instance_url, user, page, pass)}}{Creates a new Mediawikir object out of:\describe{ + \item{\code{initialize(instance_url, user, page, pass)}}{Creates a new Mediawikir object out of: + \describe{ \item{\code{instance_url}}{The base url to the mediawiki instance} \item{\code{user}}{The screen name of the user who will be credited for the changes in the wiki} \item{\code{page}}{The wiki page which contains the changes} \item{\code{pass}}{The user's password} }} \item{\code{connect(pass)}}{Should not be called directly (see initialize for detail)} + \item{\code{addContent(theContent, type="p")}}{To add content that will later on be posted to mediawiki. This is where structuring elements are provided + \describe{ + \item{\code{theContent}}{Either text (using mediawiki syntax) or path to a file} + \item{\code{type}}{\describe{ + \item{\code{p} → A plain paragraph.}{} + \item{\code{h2} → Level 2 title}{} + \item{\code{h3} → Level 3 title}{} + \item{\code{h4} → Level 4 title}{} + \item{\code{h5} → Level 5 title}{} + }} + }} } } \examples{ mwHandler <- Mediawikir$new("http://my.wiki.org", "reg_user", "mypassword", "wikiPage") + mwHandler$addContent("This is an introduction to Mediawikir") + mwHandler$addContent("First step","h2") + mwHandler$addContent("First step of the first step","h3") } \keyword{mediawiki}