Skip to content

Commit

Permalink
Merge branch 'beta'
Browse files Browse the repository at this point in the history
  • Loading branch information
gentee committed Dec 6, 2020
2 parents 41d5396 + 6a4b390 commit 777450a
Show file tree
Hide file tree
Showing 9 changed files with 605 additions and 370 deletions.
701 changes: 459 additions & 242 deletions assets.go

Large diffs are not rendered by default.

3 changes: 2 additions & 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.6.0"
Version = "1.7.0"
// DefPort is the default web-server port
DefPort = 3234
// DefTheme is the default web-server theme
Expand All @@ -29,6 +29,7 @@ const (
TimeFormat = `2006/01/02 15:04:05`
TimeoutOpen = 4000
SourceCode = `source-code`
Return = `return.eonza`
DefLang = 0
// ConsolePrefix is the prefix of eonza console version
ConsolePrefix = `ez`
Expand Down
55 changes: 36 additions & 19 deletions gensource.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (src *Source) getTypeValue(script *Script, par es.ScriptParam, value string
!(strings.HasPrefix(value, `bool(`) && strings.HasSuffix(value, `)`)) {
value = src.Value(value) + `?`
}
case es.PTextarea, es.PSingleText:
case es.PTextarea, es.PSingleText, es.PPassword:
if script.Settings.Name != SourceCode {
value = src.Value(value)
}
Expand Down Expand Up @@ -196,7 +196,7 @@ func (src *Source) ScriptValues(script *Script, node scriptTree) ([]Param, []Par
isEmpty := len(value) == 0
ptype, value = src.getTypeValue(script, par, value)
switch par.Type {
case es.PTextarea, es.PSingleText, es.PNumber:
case es.PTextarea, es.PSingleText, es.PNumber, es.PPassword:
if isEmpty && par.Options.Required && len(node.Name) != 0 {
return nil, nil, errField(par.Title)
}
Expand Down Expand Up @@ -246,11 +246,13 @@ func (src *Source) Predefined(script *Script) (ret string, err error) {
}
}
}
data, err = yaml.Marshal(predef)
if err != nil {
return
if len(predef) > 0 {
data, err = yaml.Marshal(predef)
if err != nil {
return
}
ret = `SetYamlVars(` + src.FindStrConst(string(data)) + ")\r\n"
}
ret = `SetYamlVars(` + src.FindStrConst(string(data)) + ")\r\n"
}
return
}
Expand Down Expand Up @@ -309,20 +311,21 @@ func (src *Source) Script(node scriptTree) (string, error) {
ifcond, _ = ifraw.(string)
ifcond = processIf(ifcond)
}
var params []string
var (
params []string
predef string
)
if predef, err = src.Predefined(script); err != nil {
return ``, err
}
if !src.Linked[idname] || script.Settings.Name == SourceCode || len(node.Children) > 0 {
src.Linked[idname] = true

tmp, err := src.Tree(node.Children)
if err != nil {
return ``, err
}
var (
code, predef string
)
if predef, err = src.Predefined(script); err != nil {
return ``, err
}
var code string
if script.Settings.Name == SourceCode {
code = values[1].Value
} else {
Expand Down Expand Up @@ -365,12 +368,18 @@ func (src *Source) Script(node scriptTree) (string, error) {
}
if len(script.Tree) > 0 {
code += "\r\ninit(" + strings.Join(vars, `,`) + ")\r\n" + predef
code += "try {\r\n"
tmp, err = src.Tree(script.Tree)
if err != nil {
return ``, err
}
code += "\r\n" + tmp
code += "\r\ndeinit()"
code += `
} // try
catch err {
if ErrID(err) == RETURN : recover
}
deinit()`
}
}
if script.Settings.LogLevel < es.LOG_INHERIT {
Expand All @@ -382,10 +391,9 @@ func (src *Source) Script(node scriptTree) (string, error) {
name = `*` + name
}
initcmd = fmt.Sprintf("initcmd(`%s`%s)\r\n", name, parNames)
/* if len(script.Tree) > 0 || len(predef) > 0 {
initcmd += "init()\r\n" + predef
code += "\r\ndeinit()"
}*/
if len(script.Tree) == 0 || len(predef) > 0 {
initcmd += "\r\n" + predef
}
code = initcmd + code
src.Funcs += fmt.Sprintf("func %s(%s) {\r\n", idname, strings.Join(params, `,`)) +
prefix + code + suffix + "\r\n}\r\n"
Expand All @@ -400,9 +408,12 @@ func (src *Source) Script(node scriptTree) (string, error) {
}
}
out := fmt.Sprintf(" %s(%s)\r\n", idname, strings.Join(params, `,`))
/* if script.Settings.Name == Return {
out += " deinit();return\r\n"
}*/
if len(ifcond) > 0 {
out = fmt.Sprintf(` if %s {
%s }`, ifcond, out)
%s }`+"\r\n", ifcond, out)
}
return out, nil
}
Expand Down Expand Up @@ -507,11 +518,16 @@ func GenSource(script *Script, header *es.Header) (string, error) {
}
}
code = strings.Join(params, "\r\n")
code += "\r\ntry {"
body, err := src.Tree(script.Tree)
if err != nil {
return ``, err
}
body = strings.TrimSpace(strings.ReplaceAll(script.Code, `%body%`, ``)) + "\r\n" + body
body += `
} catch err {
if ErrID(err) == RETURN : recover
}`

var constStr string
if len(src.Strings) > 0 {
Expand All @@ -523,6 +539,7 @@ func GenSource(script *Script, header *es.Header) (string, error) {
}
constStr += `const IOTA { LOG_DISABLE
LOG_ERROR LOG_WARN LOG_FORM LOG_INFO LOG_DEBUG }
const IOTA+500 : RETURN ASSERT
`
return fmt.Sprintf("%s%s\r\nrun {\r\n%s\r\n%s\r\ndeinit()}", constStr, src.Funcs,
code, body), nil
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ module eonza
go 1.15

require (
github.com/alecthomas/chroma v0.8.1
github.com/alecthomas/chroma v0.8.2
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/gentee/gentee v1.17.0
github.com/gentee/gentee v1.19.0
github.com/gorilla/websocket v1.4.2
github.com/kataras/golog v0.1.5
github.com/labstack/echo/v4 v4.1.17
github.com/yuin/goldmark v1.2.1
github.com/yuin/goldmark-highlighting v0.0.0-20200307114337-60d527fdb691
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897
gopkg.in/yaml.v2 v2.3.0
golang.org/x/crypto v0.0.0-20201124201722-c8d3bf9c5392
gopkg.in/yaml.v2 v2.4.0
)
Loading

0 comments on commit 777450a

Please sign in to comment.