Skip to content

Commit

Permalink
Moving view tests back to backend closes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
zoli committed Jul 27, 2016
1 parent 16770b8 commit 276f107
Show file tree
Hide file tree
Showing 13 changed files with 573 additions and 6,086 deletions.
35 changes: 35 additions & 0 deletions colorscheme.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2016 The lime Authors.
// Use of this source code is governed by a 2-clause
// BSD-style license that can be found in the LICENSE file.

package sublime

import (
"path/filepath"

"github.com/limetext/sublime/textmate/theme"
)

// wrapper arount Theme implements backend.ColorScheme
type colorScheme struct {
*theme.Theme
}

func newColorScheme(path string) (*colorScheme, error) {
if tm, err := theme.Load(path); err != nil {
return nil, err
} else {
return &colorScheme{tm}, nil
}
}

func (c *colorScheme) Name() string {
return c.Theme.Name
}

func isColorScheme(path string) bool {
if filepath.Ext(path) == ".tmTheme" {
return true
}
return false
}
50 changes: 15 additions & 35 deletions package.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,23 @@ import (
"github.com/limetext/backend/log"
"github.com/limetext/backend/packages"
_ "github.com/limetext/sublime/api"
"github.com/limetext/sublime/textmate/theme"
"github.com/limetext/text"
)

type (
// Represents a sublime package
// TODO: iss#71
pkg struct {
dir string
name string
text.HasSettings
keys.HasKeyBindings
platformSettings *text.HasSettings
defaultSettings *text.HasSettings
defaultKB *keys.HasKeyBindings
plugins map[string]*plugin
syntaxes map[string]*syntax
colorSchemes map[string]*colorScheme
}

// wrapper arount Theme implements backend.ColorScheme
colorScheme struct {
*theme.Theme
}
)
// Represents a sublime package
// TODO: iss#71
type pkg struct {
dir string
name string
text.HasSettings
keys.HasKeyBindings
platformSettings *text.HasSettings
defaultSettings *text.HasSettings
defaultKB *keys.HasKeyBindings
plugins map[string]*plugin
syntaxes map[string]*syntax
colorSchemes map[string]*colorScheme
}

func newPKG(dir string) packages.Package {
p := &pkg{
Expand Down Expand Up @@ -126,13 +118,12 @@ func (p *pkg) loadPlugin(path string) {

func (p *pkg) loadColorScheme(path string) {
log.Fine("Loading %s package color scheme %s", p.Name(), path)
tm, err := theme.Load(path)
cs, err := newColorScheme(path)
if err != nil {
log.Warn("Error loading %s color scheme %s: %s", p.Name(), path, err)
return
}

cs := &colorScheme{tm}
p.colorSchemes[path] = cs
backend.GetEditor().AddColorScheme(path, cs)
}
Expand Down Expand Up @@ -195,17 +186,6 @@ func (p *pkg) scan(path string, info os.FileInfo, err error) error {
return nil
}

func (c *colorScheme) Name() string {
return c.Theme.Name
}

func isColorScheme(path string) bool {
if filepath.Ext(path) == ".tmTheme" {
return true
}
return false
}

func pkgName(dir string) string {
return filepath.Base(dir)
}
Expand Down
2 changes: 1 addition & 1 deletion package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var (
pkgPath = filepath.Join("testdata", "package")
pluginPath = filepath.Join("testdata", "package", "plugin.py")
synPath = filepath.Join(pkgPath, "Go.tmLanguage")
csPath = filepath.Join(pkgPath, "Monokai.tmTheme")
csPath = filepath.Join(pkgPath, "Twilight.tmTheme")
)

func TestLoadPlugin(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions syntax.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ type syntax struct {
}

func newSyntax(path string) (*syntax, error) {
l, err := language.Load(path)
if err != nil {
if l, err := language.Load(path); err != nil {
return nil, err
} else {
return &syntax{l: l}, nil
}
return &syntax{l: l}, nil
}

func (s *syntax) Parser(data string) (parser.Parser, error) {
Expand Down
Loading

0 comments on commit 276f107

Please sign in to comment.