-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_post_data.rb
51 lines (40 loc) · 1020 Bytes
/
generate_post_data.rb
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
require 'json'
require 'cgi'
# Output fulldoc.txt and fragments.json for use with curl scripts
c1 = <<EOF
```{r first_r_chunk}
vec <- c(1, 2, 3)
print(vec)
```
EOF
c2 = <<EOF
```{r second_r_chunk, echo = TRUE}
vec2 <- c(10, 20, 30)
vec3 <- vec * vec2
print(vec3)
```
EOF
c3 = <<EOF
```{r echo = FALSE}
data(mpg, package="ggplot2")
mpg_select <- mpg[mpg$manufacturer %in% c("audi", "ford", "honda", "hyundai"), ]
# Scatterplot
theme_set(theme_bw()) # pre-set the bw theme.
g <- ggplot(mpg_select, aes(displ, cty)) +
labs(subtitle="mpg: Displacement vs City Mileage",
title="Bubble chart")
g + geom_jitter(aes(col=manufacturer, size=hwy)) +
geom_smooth(aes(col=manufacturer), method="lm", se=F)
```
EOF
fulldoc = <<EOF
#{c1}
<p>Some separating text</p>
#{c2}
<p>More separating</p>
#{c3}
EOF
fulldoc_data = "doc=#{CGI.escape(fulldoc)}"
fragments_json = ({:fragments => [c1, c2, c3]}).to_json
File.open('fulldoc.txt','w').puts(fulldoc_data)
File.open('fragments.json','w').puts(fragments_json)