Skip to content

Commit 6099458

Browse files
committed
Added playground.
1 parent 49e0040 commit 6099458

5 files changed

Lines changed: 438 additions & 1 deletion

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/bin
22
/pkg
33
/src/code.google.com
4-
/node-syscall/build
4+
/src/playground/files.go
5+
/node-syscall/build

playground.html

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<!doctype html>
2+
<html ng-app="playground">
3+
<head>
4+
<title>GopherJS Playground</title>
5+
<style>
6+
html {
7+
height: 100%;
8+
}
9+
body {
10+
color: #000;
11+
height: 100%;
12+
margin: 0;
13+
padding: 0;
14+
width: 100%;
15+
}
16+
a {
17+
color: #009;
18+
}
19+
#wrap {
20+
background: #ffd;
21+
bottom: 25%;
22+
left: 0;
23+
margin: 0;
24+
padding: 5px;
25+
position: absolute;
26+
right: 0;
27+
top: 50px;
28+
}
29+
#code, #output, pre, .lines {
30+
font-family: Menlo,Courier\ New,monospace;
31+
font-size: 11pt;
32+
}
33+
#code {
34+
background: inherit;
35+
border: none;
36+
float: right;
37+
height: 100%;
38+
margin: 0;
39+
outline: none;
40+
padding: 0;
41+
resize: none;
42+
width: 100%;
43+
wrap: off;
44+
}
45+
#output {
46+
bottom: 0;
47+
left: 0;
48+
padding: 8px;
49+
position: absolute;
50+
right: 0;
51+
top: 75%;
52+
}
53+
#output .system,#output .loading {
54+
color: #999;
55+
M}
56+
#output .err {
57+
color: #900;
58+
}
59+
#output pre {
60+
margin: 0;
61+
}
62+
#banner {
63+
height: 50px;
64+
left: 0;
65+
position: absolute;
66+
right: 0;
67+
top: 0;
68+
}
69+
#head {
70+
float: left;
71+
font-family: Georgia,serif;
72+
font-size: 30px;
73+
padding: 8px;
74+
}
75+
#controls {
76+
float: left;
77+
padding: 10px;
78+
}
79+
input[type="button"] {
80+
background: #eee;
81+
border: 1px solid #ccc;
82+
color: #000;
83+
font-size: 20px;
84+
height: 30px;
85+
}
86+
input[type="button"]:hover {
87+
background: #666;
88+
color: #fff;
89+
}
90+
.lines {
91+
float: left;
92+
overflow: hidden;
93+
text-align: right;
94+
}
95+
.lines div {
96+
color: #d3d3d3;
97+
padding-right: 5px;
98+
}
99+
.lineerror {
100+
background: #fdd;
101+
color: red;
102+
}
103+
.exit {
104+
color: #d3d3d3;
105+
}
106+
</style>
107+
<script src="angular.js"></script>
108+
<script src="bin/playground.js"></script>
109+
</head>
110+
<body ng-controller="PlaygroundCtrl">
111+
<div id="banner">
112+
<div id="head" itemprop="name">GopherJS Playground</div>
113+
<div id="controls">
114+
<input type="button" value="Run" ng-click="run()">
115+
<input type="button" value="Format" ng-click="format()">
116+
</div>
117+
</div>
118+
<div id="wrap">
119+
<textarea ng-model="code" id="code" autocorrect="off" autocomplete="off" autocapitalize="off" spellcheck="false"></textarea>
120+
</div>
121+
<div id="output">
122+
<div ng-repeat="line in output" class="{{line.Type}}">{{line.Content}}</div>
123+
</div>
124+
</body>
125+
</html>

src/angularjs/angularjs.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package angularjs
2+
3+
func NewModule(name string, requires []string, configFn func()) *Module { return nil }
4+
5+
const js_NewModule = `
6+
requires = requires ? requires.Go$toArray() : [];
7+
return new Module(angular.module(name, requires, configFn));
8+
`
9+
10+
type Module struct {
11+
native interface{}
12+
SCE *SCE
13+
}
14+
15+
func (m *Module) NewController(name string, constructor func(scope *Scope)) {}
16+
17+
const js_Module_NewController = `
18+
this.native.controller(name, function($scope, $sce) {
19+
constructor(new Scope($scope, new SCE($sce)));
20+
});
21+
`
22+
23+
func (m *Module) NewFilter(name string, fn func(text string, arguments []string) string) {}
24+
25+
const js_Module_NewFilter = `
26+
this.native.filter(name, function() {
27+
return function(text) {
28+
return fn(text, new Go$Slice(Array.prototype.slice.call(arguments, 1)));
29+
};
30+
});
31+
`
32+
33+
type Scope struct {
34+
native interface{}
35+
}
36+
37+
func (s *Scope) GetString(key string) string { return "" }
38+
39+
const js_Scope_GetString = `
40+
return String(this.native[key]);
41+
`
42+
43+
func (s *Scope) GetInt(key string) int { return 0 }
44+
45+
const js_Scope_GetInt = `
46+
return parseInt(this.native[key]);
47+
`
48+
49+
func (s *Scope) GetFloat(key string) float64 { return 0 }
50+
51+
const js_Scope_GetFloat = `
52+
return parseFloat(this.native[key]);
53+
`
54+
55+
func (s *Scope) GetSlice(key string) []interface{} { return nil }
56+
57+
const js_Scope_GetSlice = `
58+
return new Go$Slice(this.native[key]);
59+
`
60+
61+
func (s *Scope) Set(key string, value interface{}) {}
62+
63+
const js_Scope_Set = `
64+
if (value.constructor === Go$Slice) {
65+
value = value.Go$toArray();
66+
}
67+
this.native[key] = value.v !== undefined ? value.v : value;
68+
`
69+
70+
type SCE struct {
71+
native interface{}
72+
}

src/playground/binfs/binfs.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"go/build"
6+
"io/ioutil"
7+
"os"
8+
"path/filepath"
9+
"strings"
10+
)
11+
12+
func main() {
13+
dirs := make(map[string][]os.FileInfo)
14+
files := make(map[string]string)
15+
readDir := func(dir string) {
16+
err := filepath.Walk(dir+"/pkg/darwin_amd64_js/", func(path string, info os.FileInfo, err error) error {
17+
if info.IsDir() {
18+
var err error
19+
dirs[path[len(dir):]], err = ioutil.ReadDir(path)
20+
return err
21+
}
22+
23+
in, err := ioutil.ReadFile(path)
24+
if err != nil {
25+
return err
26+
}
27+
files[path[len(dir):]] = string(in)
28+
return nil
29+
})
30+
if err != nil {
31+
panic(err)
32+
}
33+
}
34+
35+
readDir(build.Default.GOROOT)
36+
readDir(build.Default.GOPATH)
37+
38+
out, err := os.Create("src/playground/files.go")
39+
if err != nil {
40+
panic(err)
41+
}
42+
out.WriteString("package main\n\nimport \"os\"\n\nvar dirs = map[string][]os.FileInfo {\n")
43+
for name, content := range dirs {
44+
entries := make([]string, len(content))
45+
for i, entry := range content {
46+
entries[i] = fmt.Sprintf(`&FileEntry{ name: "%s", mode: %d }`, entry.Name(), entry.Mode())
47+
}
48+
fmt.Fprintf(out, "\t\"%s\": []os.FileInfo{ %s },\n", name, strings.Join(entries, ", "))
49+
}
50+
out.WriteString("}\n\nvar files = map[string]string {\n")
51+
for name, content := range files {
52+
fmt.Fprintf(out, "\t\"%s\": %#v,\n", name, content)
53+
}
54+
out.WriteString("}\n")
55+
out.Close()
56+
}

0 commit comments

Comments
 (0)