-
Notifications
You must be signed in to change notification settings - Fork 4
/
tutorial11.R
111 lines (103 loc) · 2.65 KB
/
tutorial11.R
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
library(htmltools)
library(pipeR)
tagList(
tags$div(
id = "content"
)
,tags$script(type = "text/babel"
,'
// tutorial9.js
var CommentBox = React.createClass({
render: function() {
return (
<div className="commentBox">
<h1>Comments</h1>
<CommentList data={this.props.data} />
<CommentForm />
</div>
);
}
});
// tutorial10.js
var CommentList = React.createClass({
render: function() {
var commentNodes = this.props.data.map(function(comment){
return (
<Comment author={comment.author} key={comment.id}>
{comment.text}
</Comment>
)
});
return (
<div className="commentList">
{commentNodes}
</div>
);
}
});
var CommentForm = React.createClass({
render: function() {
return (
<div className="commentForm">
Hello, world! I am a CommentForm.
</div>
);
}
});
// tutorial7.js
var Comment = React.createClass({
rawMarkup: function() {
var rawMarkup = marked(this.props.children.toString(), {sanitize: true});
return { __html: rawMarkup };
},
render: function() {
return (
<div className="comment">
<h2 className="commentAuthor">
{this.props.author}
</h2>
<span dangerouslySetInnerHTML={this.rawMarkup()} />
</div>
);
}
});
// tutorial8.js
var data = [
{author: "Pete Hunt", text: "This is one comment"},
{author: "Jordan Walke", text: "This is *another* comment"}
];
// tutorial11.js
ReactDOM.render(
<CommentBox url="comments.json" />,
document.getElementById("content")
);
' %>>% HTML
)
) %>>%
attachDependencies(list(
htmlDependency(
name = "react"
,version = "0.14.8"
,src = c(paste0(getwd(),"/build"))
,script = c("react.min.js","react-dom.min.js")
)
,htmlDependency(
name = "babel-browser"
,version = "5.8.23"
,src = c(href="http://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23")
,script = c("browser.min.js")
)
,htmlDependency(
name = "jquery"
,version = "2.2.0"
,src = c(href = "http://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/")
,script = c("jquery.min.js")
)
,htmlDependency(
name = "marked"
,version = "0.3.5"
,src = c(href = "http://cdnjs.cloudflare.com/ajax/libs/marked/0.3.5/")
,script = c("marked.min.js")
)
)) %>>%
html_print