-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd_git_pages.R
More file actions
117 lines (88 loc) · 3.58 KB
/
cmd_git_pages.R
File metadata and controls
117 lines (88 loc) · 3.58 KB
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
setwd("/home/chernan/Workspace/DataAnalysis/RNotes4Bioinformatics")
projectWd <- getwd()
## Checkout branch where doc is stored
dir.create('./dist_doc')
setwd(paste0(getwd(), '/dist_doc'))
# system('git clone https://github.com/chernan/RNotes4Bioinformatics.git')
setwd(paste0(getwd(), '/RNotes4Bioinformatics'))
# system('git fetch origin')
# system('git checkout gh-pages')
alldocWd <- getwd()
## List files to be transformed
filesRmd <- data.frame(
directory=rep(c("General", "Graphics"),
times=c(8,4)
),
fileName=c("dataManipulationAggregation",
"dataStructures",
"inputOutput",
"stringManipulation",
#"efficientProgramming",
"expressionEvaluation",
"objectOrientedProgramming",
"workspaceManagement",
"packageConstruction",
"base",
"lattice",
"ggplot2",
"ggplot2_howtos"
))
## For each listed file
## create folder if doesn't exist
## Knit HTML
library("knitr")
library("markdown")
oldBasedir <- opts_knit$get("base.dir")
## Temp files for knitr will be stored there
temp_knitr <- paste0(projectWd, '/dist_doc/temp/')
dir.create(temp_knitr)
opts_knit$set(base.dir = temp_knitr)
## Style (in <head>)
styleConnection <- file(paste0(projectWd, '/help_css/style.txt'))
styleHTMLText <- readLines(styleConnection, n=-1)
styleHTMLText <- paste(styleHTMLText, collapse="\n")
close(styleConnection)
## Header
headerConnection <- file(paste0(projectWd, '/help_css/header.txt'))
headerHTMLText <- readLines(headerConnection, n=-1)
headerHTMLText <- paste(headerHTMLText, collapse="\n")
close(headerConnection)
## Footer
footerConnection <- file(paste0(projectWd, '/help_css/footer.txt'))
footerHTMLText <- readLines(footerConnection, n=-1)
footerHTMLText <- paste(footerHTMLText, collapse="\n")
close(footerConnection)
# fileRmd <- c(directory="General", fileName="dataManipulationAggregation")
apply(filesRmd, 1, FUN=function(fileRmd) {
current_RmdWd <- paste0(projectWd, '/', fileRmd["directory"])
current_docWd <- paste0(alldocWd, '/', fileRmd["directory"])
## HTML output will be created there
dir.create(current_docWd)
filePathRmd <- paste0(current_RmdWd, '/', fileRmd["fileName"], '.Rmd')
filePathMd <- paste0(temp_knitr, '/', fileRmd["fileName"], '.md')
filePathHtml <- paste0(current_docWd, '/', fileRmd["fileName"], '.html')
knit(filePathRmd, output = filePathMd)
markdownToHTML(file = filePathMd, output = filePathHtml)
## Open HTML file to add style, header, footer
htmlConnection <- file(filePathHtml)
allHTMLText <- readLines(htmlConnection)
allHTMLText <- paste(allHTMLText, collapse="&&&")
close(htmlConnection)
## Add style
newText <- sub(pattern='.*<title>', replacement=styleHTMLText, x=allHTMLText, perl=TRUE)
newText <- sub(pattern='</title>.*</head>', replacement='</title>&&&</head>', x=newText, perl=TRUE)
## Add header
newText <- sub(pattern='<body>', replacement=headerHTMLText, x=newText, fixed=TRUE)
## Add footer
newText <- sub(pattern='</body>', replacement=footerHTMLText, x=newText, fixed=TRUE)
newText <- gsub(pattern='&&&',replacement="\n", x=newText)
write(newText, file=filePathHtml)
})
opts_knit$set(base.dir = oldBasedir)
setwd(projectWd)
## Manual step (to be sure...)
## Open project in dist_doc
## Add newly created files
## Commit changes
## Go to : http://chernan.github.io/RNotes4Bioinformatics
## When everything is fine, folder dist_doc can be deleted