Skip to content

Commit

Permalink
Merge branch 'beta'
Browse files Browse the repository at this point in the history
  • Loading branch information
gentee committed Jan 6, 2021
2 parents 9990f5c + 1bf91f2 commit 5874748
Show file tree
Hide file tree
Showing 6 changed files with 705 additions and 456 deletions.
1,062 changes: 611 additions & 451 deletions assets.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion const.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package main

const (
// Version of the application
Version = "1.9.0"
Version = "1.10.0"
// DefPort is the default web-server port
DefPort = 3234
// DefTheme is the default web-server theme
Expand Down
12 changes: 12 additions & 0 deletions languages.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
package main

import (
es "eonza/script"
"fmt"
"strings"

"github.com/kataras/golog"
"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -136,3 +138,13 @@ func RenderLang(input []rune, idLang int) string {
}
return string(result)
}

func ScriptLang(script *Script, langCode, text string) string {
if strings.Contains(text, `#`) {
text = es.ReplaceVars(text, script.Langs[langCode], &langRes[langsId[langCode]])
if langCode != LangDefCode && strings.Contains(text, `#`) {
text = es.ReplaceVars(text, script.Langs[LangDefCode], &langRes[langsId[LangDefCode]])
}
}
return text
}
15 changes: 12 additions & 3 deletions script/embedded.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ var (
{Prototype: `GetVarObj(str) obj`, Object: GetVarObj},
// For gentee
{Prototype: `YamlToMap(str) map`, Object: YamlToMap},
{Prototype: `Subbuf(buf,int,int) buf`, Object: Subbuf},
// {Prototype: `Subbuf(buf,int,int) buf`, Object: Subbuf},
{Prototype: `CopyName(str) str`, Object: CopyName},
{Prototype: `CloseLines(handle)`, Object: CloseLines},
{Prototype: `GetLine(handle) str`, Object: GetLine},
{Prototype: `ReadLines(str) handle`, Object: ReadLines},
{Prototype: `ScanLines(handle) bool`, Object: ScanLines},
}
)

Expand Down Expand Up @@ -319,11 +324,15 @@ func Init(pars ...interface{}) {
func InitCmd(name string, pars ...interface{}) bool {
params := make([]string, len(pars))
for i, par := range pars {
val := fmt.Sprint(par)
if len(val) > 64 {
val = val[:64] + `...`
}
switch par.(type) {
case string:
params[i] = `"` + fmt.Sprint(par) + `"`
params[i] = `"` + val + `"`
default:
params[i] = fmt.Sprint(par)
params[i] = val
}
}
level := int64(LOG_DEBUG)
Expand Down
68 changes: 68 additions & 0 deletions script/gentee.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,23 @@
package script

import (
"bufio"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/gentee/gentee"
"github.com/gentee/gentee/core"
"github.com/gentee/gentee/vm"
"gopkg.in/yaml.v2"
)

type FileLines struct {
File *os.File
Scanner *bufio.Scanner
}

func YamlToMap(in string) (*core.Map, error) {
var (
tmp map[string]string
Expand All @@ -29,6 +38,64 @@ func YamlToMap(in string) (*core.Map, error) {
return ret.(*core.Map), nil
}

func CopyName(rt *vm.Runtime, fname string) (string, error) {
var (
err error
i int
)
if !filepath.IsAbs(fname) {
fname, err = filepath.Abs(fname)
if err != nil {
return ``, err
}
}
dir := filepath.Dir(fname)
base := strings.SplitN(filepath.Base(fname), `.`, 2)
if len(base) == 1 {
base = append(base, ``)
} else {
base[1] = `.` + base[1]
}
for {
i++
exist, err := vm.ExistFile(rt, fname)
if err != nil {
return ``, err
}
if exist == 0 {
break
}
fname = filepath.Join(dir, fmt.Sprintf("%s (%d)%s", base[0], i, base[1]))
}
return fname, nil
}

func CloseLines(flines *FileLines) error {
return flines.File.Close()
}

func GetLine(flines *FileLines) string {
return flines.Scanner.Text()
}

func ReadLines(filename string) (*FileLines, error) {
file, err := os.Open(filename)
if err != nil {
return nil, err
}
scanner := bufio.NewScanner(file)
scanner.Split(bufio.ScanLines)
return &FileLines{File: file, Scanner: scanner}, nil
}

func ScanLines(flines *FileLines) int64 {
if flines.Scanner.Scan() {
return 1
}
return 0
}

/*
// Subbuf(buf, int, int) buf
func Subbuf(buf *core.Buffer, off int64, size int64) (*core.Buffer, error) {
if off < 0 || off+size > int64(len(buf.Data)) {
Expand All @@ -38,3 +105,4 @@ func Subbuf(buf *core.Buffer, off int64, size int64) (*core.Buffer, error) {
ret.Data = append(ret.Data, buf.Data[off:off+size]...)
return ret, nil
}
*/
2 changes: 1 addition & 1 deletion showtask..go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func showTaskHandle(c echo.Context) error {
return jsonError(c, fmt.Errorf(`task %d has not been found`, idtask))
}
if item := getScript(ptask.Name); item != nil {
c.Set(`Title`, item.Settings.Title)
c.Set(`Title`, ScriptLang(item, GetLangCode(c.(*Auth).User), item.Settings.Title))
} else {
c.Set(`Title`, ptask.Name)
}
Expand Down

0 comments on commit 5874748

Please sign in to comment.