Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Commit be7ddab

Browse files
author
Barrie Hadfield
committed
compiling on change
1 parent 87e6dd9 commit be7ddab

File tree

3 files changed

+48
-33
lines changed

3 files changed

+48
-33
lines changed

source/_components.html.erb

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
11
<script type="text/ruby">
22

3-
class CodeEditor < React::Component::Base
4-
5-
define_state :code, type: String
6-
3+
class CodeMirror < React::Component::Base
4+
param :code, type: String
5+
define_state :output_code
76
before_mount do
8-
state.code! "I am the code"
7+
state.output_code! params.code
98
end
10-
11-
render do
12-
div.row do
13-
div.col_md_6 { code_card }
14-
div.col_md_6 { result_card }
15-
end
9+
after_mount do
10+
@editor = `CodeMirror(document.getElementById("code"), {
11+
value: #{params.code},
12+
mode: "text/x-ruby",
13+
matchBrackets: true,
14+
lineNumbers: true,
15+
indentUnit: 2,
16+
theme: 'github'
17+
});`
18+
`#{@editor}.on('change', #{lambda {on_change} })`
1619
end
17-
18-
def code_card
19-
div.card_block do
20-
input(type: :text, value: state.code, placeholder: "placeholder"
21-
).on(:change) do |e|
22-
state.code! e.target.value
23-
end
24-
end
20+
render(DIV) do
21+
div(id: 'code')
22+
p { state.output_code }
2523
end
2624

27-
def result_card
28-
div.card_block do
29-
p { state.code }
30-
end
25+
def on_change
26+
state.output_code! Opal.compile `#{@editor}.getValue()`
3127
end
28+
3229
end
3330

3431
class TestApp < React::Component::Base

source/index.html.md.erb

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1-
<div data-reactrb-mount="CodeEditor"></div>
1+
<div data-reactrb-mount="CodeMirror" data-code="class TestApp < React::Component::Base
2+
param :name
3+
before_mount { @timer = every(1) { force_update! } }
4+
render(DIV) do
5+
h1 {'The current time is #{Time.now}'}
6+
h2 { 'here hello #{params.name}' }.on(:click) do
7+
alert 'you clicked'
8+
end
9+
end
10+
end"></div>
211

3-
<form><textarea id="code" name="code">
12+
<!-- <form><textarea id="code" name="code">
413
class TestApp < React::Component::Base
514
param :name
615
before_mount { @timer = every(1) { force_update! } }
@@ -11,17 +20,31 @@ class TestApp < React::Component::Base
1120
end
1221
end
1322
end
14-
</textarea></form>
23+
</textarea></form> -->
24+
25+
<!-- <div id="code"> </div> -->
1526

16-
<script>
27+
<!-- <script>
1728
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
1829
mode: "text/x-ruby",
1930
matchBrackets: true,
2031
lineNumbers: true,
2132
indentUnit: 2,
2233
theme: 'github'
2334
});
24-
</script>
35+
</script> -->
36+
37+
<!-- <script>
38+
var myCodeMirror = CodeMirror(document.getElementById("code"), {
39+
value: "puts 'hello'",
40+
mode: "text/x-ruby",
41+
matchBrackets: true,
42+
lineNumbers: true,
43+
indentUnit: 2,
44+
theme: 'github'
45+
});
46+
</script> -->
47+
2548

2649
<br>
2750

source/stylesheets/override.css

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
33
.cm-s-default span.cm-arrow { color: red; }
44

5-
/*table.rouge-table.tr {
6-
background-color: blue;
7-
border: 0px;
8-
}*/
9-
105

116
.page-header {
127
color: #fff;

0 commit comments

Comments
 (0)