This repository was archived by the owner on Oct 19, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +48
-33
lines changed Expand file tree Collapse file tree 3 files changed +48
-33
lines changed Original file line number Diff line number Diff line change 1
1
< script type ="text/ruby ">
2
2
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
7
6
before_mount do
8
- state . code ! " I am the code "
7
+ state . output_code ! params . code
9
8
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} })`
16
19
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 }
25
23
end
26
24
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()`
31
27
end
28
+
32
29
end
33
30
34
31
class TestApp < React ::Component ::Base
Original file line number Diff line number Diff line change 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 >
2
11
3
- < form > < textarea id ="code " name ="code ">
12
+ <!-- < form><textarea id="code" name="code">
4
13
class TestApp < React::Component::Base
5
14
param :name
6
15
before_mount { @timer = every(1) { force_update! } }
@@ -11,17 +20,31 @@ class TestApp < React::Component::Base
11
20
end
12
21
end
13
22
end
14
- </ textarea > </ form>
23
+ </textarea></form> -->
24
+
25
+ <!-- <div id="code"> </div> -->
15
26
16
- < script >
27
+ <!-- < script>
17
28
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
18
29
mode: "text/x-ruby",
19
30
matchBrackets: true,
20
31
lineNumbers: true,
21
32
indentUnit: 2,
22
33
theme: 'github'
23
34
});
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
+
25
48
26
49
< br >
27
50
Original file line number Diff line number Diff line change 2
2
.CodeMirror {border-top : 1px solid black; border-bottom : 1px solid black;}
3
3
.cm-s-default span .cm-arrow { color : red; }
4
4
5
- /*table.rouge-table.tr {
6
- background-color: blue;
7
- border: 0px;
8
- }*/
9
-
10
5
11
6
.page-header {
12
7
color : # fff ;
You can’t perform that action at this time.
0 commit comments