Skip to content

Commit

Permalink
make example trigger more changes in stages
Browse files Browse the repository at this point in the history
Not sure it's the best example logic-wise, but it lights up more stages now.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
  • Loading branch information
srenatus committed Nov 23, 2022
1 parent 091f2fd commit 0b2a14e
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions cmd/explorer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@ import (
const exampleCode = `package test
import future.keywords.if
import future.keywords.in
allow if "admin" in input.roles
import input.roles
# METADATA
# entrypoint: true
allow := "admin" in roles if {
print(roles)
some x in roles
x == "janitor"
}
`

var tpl = template.Must(template.New("main").Parse(`
Expand All @@ -30,7 +37,7 @@ var tpl = template.Must(template.New("main").Parse(`
hx-get="/?tmpl=output"
hx-trigger="keyup changed delay:500ms"
hx-target="#output"
style="height: 200px"
style="height: 300px"
class="flex-grow:1 monospace"
>{{ .Code }}</textarea>
</div>
Expand Down Expand Up @@ -112,7 +119,7 @@ func CompilerStages(rego string) []CompileResult {
result = append(result, CompileResult{
Stage: "ParseModule",
})
mod, err := ast.ParseModule("a.rego", rego)
mod, err := ast.ParseModuleWithOpts("a.rego", rego, ast.ParserOptions{ProcessAnnotation: true})
if err != nil {
result[0].Error = err.Error()
return result
Expand Down Expand Up @@ -179,12 +186,7 @@ func main() {
} else {
st.Result[i].Output = cs[i].Result.String()
}
switch i {
case 0:
st.Result[i].Show = len(cs) == 1
default:
st.Result[i].Show = st.Result[i-1].Output != st.Result[i].Output
}
st.Result[i].Show = i == 0 || st.Result[i-1].Output != st.Result[i].Output
if st.Result[i].Class == "" {
if st.Result[i].Show {
st.Result[i].Class = "ok"
Expand Down

0 comments on commit 0b2a14e

Please sign in to comment.