Skip to content

Commit

Permalink
added go and rust type support
Browse files Browse the repository at this point in the history
  • Loading branch information
gunerhuseyin committed Feb 14, 2020
1 parent 31bf74a commit eb99bec
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
*.iml
*.ipr
*.playground
*.swp
vendor/
code-playground
8 changes: 5 additions & 3 deletions editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ const DefaultEditor = "vim"

type Editor struct {
File string
Type string
Content string
}

func NewEditor(file, content string) *Editor {
func NewEditor(file, t, content string) *Editor {
return &Editor{
File: file,
Type: t,
Content: content,
}
}
Expand Down Expand Up @@ -55,7 +57,7 @@ func (e *Editor) Open() (string, error) {

if len(e.File) > 0 {

e.File = e.File + ".playground"
e.File = e.File + ".playground" + e.Type

file, err = os.Open(e.File)

Expand Down Expand Up @@ -85,7 +87,7 @@ func (e *Editor) Open() (string, error) {

} else {

file, err = ioutil.TempFile(os.TempDir(), "play-*.playground")
file, err = ioutil.TempFile(os.TempDir(), "play-*.playground"+e.Type)

if err != nil {
return "", err
Expand Down
4 changes: 4 additions & 0 deletions go.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ type Go struct {
Code string
}

func (r *Go) Type() string {
return ".go"
}

func (g *Go) Init(code string) {
g.Code = code
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func main() {
init = playground.Import(path)
}

editor := NewEditor(file, init)
editor := NewEditor(file, playground.Type(), init)

code, err := editor.Open()

Expand Down
1 change: 1 addition & 0 deletions playground.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ type IPlayground interface {
Evaluate()
Share()
Default() string
Type() string
}
4 changes: 4 additions & 0 deletions rust.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ type Rust struct {
Code string
}

func (r *Rust) Type() string {
return ".rs"
}

func (r *Rust) Init(code string) {
r.Code = code
}
Expand Down

0 comments on commit eb99bec

Please sign in to comment.