mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-15 08:30:42 +08:00
🎨 Add template type column to Attribute View https://github.com/siyuan-note/siyuan/issues/8766
This commit is contained in:
parent
c0424caf67
commit
b69e8d3357
@ -354,6 +354,10 @@ type ValueTemplate struct {
|
|||||||
RenderedContent string `json:"renderedContent"`
|
RenderedContent string `json:"renderedContent"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *ValueTemplate) Render(blockID string, r func(blockID string) string) {
|
||||||
|
t.RenderedContent = r(blockID)
|
||||||
|
}
|
||||||
|
|
||||||
// View 描述了视图的结构。
|
// View 描述了视图的结构。
|
||||||
type View struct {
|
type View struct {
|
||||||
ID string `json:"id"` // 视图 ID
|
ID string `json:"id"` // 视图 ID
|
||||||
|
@ -17,12 +17,15 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
"github.com/88250/gulu"
|
"github.com/88250/gulu"
|
||||||
"github.com/88250/lute/ast"
|
"github.com/88250/lute/ast"
|
||||||
"github.com/88250/lute/parse"
|
"github.com/88250/lute/parse"
|
||||||
|
"github.com/Masterminds/sprig/v3"
|
||||||
"github.com/siyuan-note/logging"
|
"github.com/siyuan-note/logging"
|
||||||
"github.com/siyuan-note/siyuan/kernel/av"
|
"github.com/siyuan-note/siyuan/kernel/av"
|
||||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||||
@ -227,6 +230,27 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
|
|||||||
tableCell.Value.Number.FormatNumber()
|
tableCell.Value.Number.FormatNumber()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 渲染模板列
|
||||||
|
if av.KeyTypeTemplate == tableCell.ValueType && nil != tableCell.Value && nil != tableCell.Value.Template {
|
||||||
|
render := func(blockID string) string {
|
||||||
|
funcMap := sprig.TxtFuncMap()
|
||||||
|
goTpl := template.New("").Delims(".action{", "}")
|
||||||
|
tpl, tplErr := goTpl.Funcs(funcMap).Parse(tableCell.Value.Template.Content)
|
||||||
|
if nil != tplErr {
|
||||||
|
logging.LogWarnf("parse template [%s] failed: %s", tableCell.Value.Template.Content, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
buf := &bytes.Buffer{}
|
||||||
|
ial := GetBlockAttrs(blockID)
|
||||||
|
if err = tpl.Execute(buf, ial); nil != err {
|
||||||
|
logging.LogWarnf("execute template [%s] failed: %s", tableCell.Value.Template.Content, err)
|
||||||
|
}
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
tableCell.Value.Template.Render(tableCell.Value.BlockID, render)
|
||||||
|
}
|
||||||
|
|
||||||
tableRow.Cells = append(tableRow.Cells, tableCell)
|
tableRow.Cells = append(tableRow.Cells, tableCell)
|
||||||
}
|
}
|
||||||
ret.Rows = append(ret.Rows, &tableRow)
|
ret.Rows = append(ret.Rows, &tableRow)
|
||||||
|
Loading…
Reference in New Issue
Block a user