-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContributingHelper.html
340 lines (290 loc) · 11.2 KB
/
ContributingHelper.html
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"
integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<link rel="stylesheet" href="helpers.css">
<title>Contributing Helper</title>
<script src="https://unpkg.com/react@latest/dist/react.js"></script>
<script src="https://unpkg.com/react-dom@latest/dist/react-dom.js"></script>
<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous"></script>
<script src="lib/marked.js"></script>
<script>
// Uses:
// https://facebook.github.io/react/downloads/single-file-example.html
// https://getbootstrap.com/
// https://github.com/chjj/marked
var baseDoc = [];
baseDoc.push({
level: 1,
input: "line",
text: "System Name",
comment: "This is the name of your system"
});
baseDoc.push({
level: 0,
input: "line",
text: "Repository URL",
style: "url",
comment: "The main idea for the contributing file is to concisely describe to a contributor the commitments the team makes to anyone providing code to the system - host or guest."
});
baseDoc.push({
level: 2,
text: "We're glad you are here"
});
baseDoc.push({
level: 0,
text: "This document outlines the house rules that our team uses when making code contributions. If you want to start contributing to our project, please read through this document first.",
comment: "Having the team welcome contributors tells both the team and the contributors that contributing is not just possible but is an expected part of how a system grows and develops.\
\
People are more likely to both read the rules and follow them if the team opens with a friendly greeting. When people feel like they are welcomed they will think beyond just their immediate conncerns and will be more likely to be aware of larger issues."
});
// class FFInput extends React.Component {
// constructor(props) {
// // console.log('Created FFInput component');
// super(props);
// }
//
// render() {
// //console.log('FFInput-render called');
// const value = this.props.value;
//
// return React.createElement("textarea", {
// onChange: this.props.onChange,
// value: value
// });
//
// }
//
// }
class EditorStrip extends React.Component {
constructor(props) {
super(props);
}
render() {
// console.log("ES-render: [%s] %o", typeof(this.props.onChange), this.props.onChange);
const text = this.props.docText;
//const style = this.props.editStyle;
//const level = this.props.textLevel;
const comment = this.props.comment;
const id = this.props.id;
return React.createElement(
"div",
{className: "row"},
React.createElement(
"textarea",
{
id: id,
name: id + "-inputText",
onChange: this.props.onChange,
className: "col-sm-5",
defaultValue: text
}
),
React.createElement(
"div",
{
className: "col-sm-6 well col-sm-offset-1"
},
comment
)
);
}
}
class InteractiveEditor extends React.Component {
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);
//this.handleEdit = this.handleEdit.bind(this);
// TODO: Load all properties into initial state
// TODO: update change handler to dereference another level
// TODO: update markdown converter to use level property
// TODO: Add URL type
this.state = {};
// console.log(marked('# Marked in browser\n\nRendered by **marked**.'));
}
componentWillMount() {
var docNodes = {};
var docText = '';
var nodeCount = 0;
var i;
for (i = 0; i < baseDoc.length; i = i + 1) {
docNodes[i] = baseDoc[i];
nodeCount = nodeCount + 1;
// docText = docText + docNodes[i].text + "\n\n";
}
docText = this.convertNodesToMarkdown(docNodes, nodeCount);
this.state = {
docNodes: docNodes,
docNodeCount: nodeCount,
docText: docText
};
}
handleChange(e) {
// console.log('Main handleChange called');
const target = e.target;
const name = target.name;
const value = target.value;
const key = target.key;
const id = target.id;
// console.log("target name: %s, key: %s, id: %s, value: %s, target: %s", name, key, id, value, target);
// console.log("State: %o", this.state);
var docNodes = this.state.docNodes;
docNodes[id].text = value;
var docText = this.convertNodesToMarkdown(docNodes, this.state.docNodeCount);
this.setState({
docNodes: docNodes,
docText: docText
});
}
convertNodeToMarkdown(docNode) {
const header = '#####';
var prefix = '';
var text = docNode.text;
if (docNode.level) {
prefix = header.slice(0, docNode.level) + ' ';
}
if (docNode.style && docNode.style === 'url') {
text = '[' + text + '](' + text + ')';
}
return prefix + text + "\n\n";
}
convertNodesToMarkdown(docNodes, nodeCount) {
var i;
var tempText = '';
for (i = 0; i < nodeCount; i = i + 1) {
tempText = tempText + this.convertNodeToMarkdown(docNodes[i]);
}
return tempText;
}
// convertTextToMarkdown(docNodes) {
// var i;
// var
// for (i=0; i < this.state.docNodeCount; i = i + 1) {
//
// }
//
// return Object.values(textHash).join("\n");
// }
convertToHTML(markdownText) {
// console.log("convertToHTML hash: %o", markdownText);
return {__html: marked(markdownText)};
}
convertToMarkdown(markdownText) {
return {__html: "<pre>" + markdownText + "</pre>"}
}
render() {
var segments = [];
var i;
// console.log('Checking baseDoc array: %d', baseDoc.length)
for (i = 0; i < this.state.docNodeCount; i = i + 1) {
// console.log("Section %d level %d", i, baseDoc[i].level);
segments.push(React.createElement(
EditorStrip,
{
key: i,
id: i,
onChange: this.handleChange,
docText: this.state.docNodes[i].text,
comment: this.state.docNodes[i].comment
}
));
}
return React.createElement(
"div",
{className: "InteractiveEditorClass"},
segments,
React.createElement("div",
{className: "page-header"},
// React.createElement("h1", null, "Output"),
React.createElement("div",
{className: "row"},
React.createElement("div",
{className: "col-sm-6"},
React.createElement("div",
{className: "panel panel-info"},
React.createElement("div",
{className: "panel-heading"},
React.createElement("h4",
{
className: "panel-title"
},
"Preview"
)
),
React.createElement("div",
{
className: "panel-body",
dangerouslySetInnerHTML: this.convertToHTML(this.state.docText)
}
)
)
),
React.createElement("div",
{className: "col-sm-5 col-offset-sm-1"},
React.createElement("div",
{className: "panel panel-info"},
React.createElement("div",
{className: "panel-heading"},
React.createElement("h4",
{
className: "panel-title"
},
"Raw"
)
),
React.createElement("div",
{
className: "panel-body",
dangerouslySetInnerHTML: this.convertToMarkdown(this.state.docText)
}
)
)
)
)
)
);
}
}
</script>
</head>
<body style="width: 600px">
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"
aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Contributing Helper</a>
</div>
<!--<div id="navbar" class="navbar-collapse collapse">-->
<!--<ul class="nav navbar-nav">-->
<!--<li class="active"><a href="#">Home</a></li>-->
<!--</ul>-->
<!--</div><!–/.nav-collapse –>-->
</div>
</nav>
<div id="root" class="container-fluid" role="main">
<div id="editor" class="container"></div>
</div>
<script type="text/babel">
ReactDOM.render(React.createElement(InteractiveEditor, null), document.getElementById('editor'));
</script>
</body>
</html>