Documentation ¶
Index ¶
- Variables
- func NicePrintStatement(st Statement, lev int) string
- func ParseHtmlToStatement(tpl string, options *parser.ParseVueNodeOptions) (Statement, *SlotsC, error)
- func ShouldLookInterface(data interface{}, keys ...string) (desc interface{}, rootExist bool, exist bool)
- type AttrWay
- type ChanSpan
- type Class
- type ComponentStatement
- type ComponentStruct
- type Directive
- type DirectivesBinding
- type EmptyStatement
- type ExecSlotOptions
- type FuncStatement
- type Function
- type ListWriter
- type MapStore
- type NodeData
- type Options
- type Prop
- type PropKeys
- type Props
- func (r *Props) Append(k string, v interface{})
- func (r *Props) AppendAttr(k, v string)
- func (r *Props) AppendClass(c ...string)
- func (r *Props) AppendMap(mp map[string]interface{})
- func (r *Props) AppendStyle(st map[string]string)
- func (r *Props) ForEach(cb func(index int, k *PropKeys, v interface{}))
- func (r *Props) Get(key string) (interface{}, bool)
- func (r *Props) ToMap() map[string]interface{}
- type RenderCtx
- type RenderParam
- type Scope
- type Slot
- type SlotC
- type Slots
- type SlotsC
- type Span
- type Statement
- type StatementCtx
- type StatementOptions
- type Store
- type StrStatement
- type StringSpan
- type Styles
- type Vpl
- func (v *Vpl) Component(name string, c Statement) (err error)
- func (v *Vpl) ComponentFile(name string, path string) (err error)
- func (v *Vpl) ComponentTxt(name string, txt string) (err error)
- func (v *Vpl) Directive(name string, val Directive)
- func (v *Vpl) Function(name string, val Function)
- func (v *Vpl) Global(name string, val interface{})
- func (v *Vpl) NewScope() *Scope
- func (v *Vpl) RenderComponent(component string, p *RenderParam) (html string, err error)
- func (v *Vpl) RenderTpl(tpl string, p *RenderParam) (html string, err error)
- type Writer
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func ParseHtmlToStatement ¶
func ShouldLookInterface ¶
func ShouldLookInterface(data interface{}, keys ...string) (desc interface{}, rootExist bool, exist bool)
shouldLookInterface会返回interface(map[string]interface{})中指定的keys路径的值
Types ¶
type ChanSpan ¶
type ChanSpan struct {
// contains filtered or unexported fields
}
func NewChanSpan ¶
func NewChanSpan() *ChanSpan
type ComponentStatement ¶
type ComponentStatement struct { ComponentKey string ComponentStruct ComponentStruct }
调用组件
func (*ComponentStatement) Exec ¶
func (c *ComponentStatement) Exec(ctx *StatementCtx, o *StatementOptions) error
调用组件语句 o是上层options. 根据组件attr拼接出新的scope, 再执行组件 处理slot作用域
type ComponentStruct ¶
type ComponentStruct struct { // Props: 无论动态还是静态, 都是Props // // 如: <Menu :data="data" id="abc" :style="{left: '1px'}"> // 其中 Props 值为: data, id // 其中 PropStyle 值为: style Props propsC // PropClass指动态class // 如 <Menu :class="['a','b']" class="c"> // 那么PropClass的值是: ['a', 'b'] VBind *vBindC Directives directivesC // 传递给这个组件的Slots Slots *SlotsC }
组件的属性
type Directive ¶
type Directive func(ctx *RenderCtx, nodeData *NodeData, binding *DirectivesBinding)
type DirectivesBinding ¶
type EmptyStatement ¶
type EmptyStatement struct { }
func (*EmptyStatement) Exec ¶
func (s *EmptyStatement) Exec(_ *StatementCtx, _ *StatementOptions) error
type ExecSlotOptions ¶
type ExecSlotOptions struct { // <slot :abc="abc"> 语法传递的slot props. SlotProps *Props }
type FuncStatement ¶
type FuncStatement func(*StatementCtx, *StatementOptions) error
func (FuncStatement) Exec ¶
func (f FuncStatement) Exec(ctx *StatementCtx, o *StatementOptions) error
type ListWriter ¶
type ListWriter struct {
// contains filtered or unexported fields
}
支持同时写Span和string的Write 优化多个字符串拼接
func NewListWriter ¶
func NewListWriter() *ListWriter
func (*ListWriter) Result ¶
func (p *ListWriter) Result() string
func (*ListWriter) WriteSpan ¶
func (p *ListWriter) WriteSpan(span Span)
func (*ListWriter) WriteString ¶
func (p *ListWriter) WriteString(s string)
type PropKeys ¶
type Props ¶
type Props struct {
// contains filtered or unexported fields
}
func (*Props) AppendClass ¶
func (*Props) AppendStyle ¶
type RenderCtx ¶
type RenderCtx struct { Scope *Scope // 当前作用域, 用于向当前作用域声明一个值 Store Store // 用于共享数据, 此Store是RenderParam中传递的Store }
在渲染中的上下文, 用在function和directive
type RenderParam ¶
type RenderParam struct { // 声明本次渲染的全局变量, 和vpl.Global()功能类似, 在所有组件中都有效. // 可以用来存放诸如版本号/作者等全部组件都可能需要访问的数据, 还可以存放方法. // Global设置的值会覆盖vpl.Global()设置的值. // // Q: 如何区分应该使用RenderParam.Global设置全局变量还是vpl.Global()设置全局变量? // A: // 根据这个"全局"变量的真正范围而定. // 如果这个变量是"整个程序"的全局变量, 如一个全局方法, 那么它应该使用vpl.Global()设置 // 如果这个变量是"这一次渲染过程中"的全局变量, 如在渲染每个页面时的页面ID, 那么它应该使用RenderParam.Global设置. Global map[string]interface{} // 用于在整个运行环境共享变量, 如在一个方法/指令中读取另一个方法/指令里存储的数据 Store Store // unused so far Ctx context.Context Props *Props // 渲染组件时给组件传递slots Slots *SlotsC }
type Slot ¶
type Slot struct { *SlotC // 在运行时被赋值 // Declarer 存储在当slot声明时的组件数据 Declarer *StatementOptions }
Slot的运行时
func (*Slot) Exec ¶
func (s *Slot) Exec(ctx *StatementCtx, o *StatementOptions) error
type Slots ¶
type SlotsC ¶
https://cn.vuejs.org/v2/guide/components-slots.html SlotsC 存放传递给组件的所有Slot(默认与具名)(编译时), vue语法: <h1 v-slot:default="xxx"></h1>
func (*SlotsC) WrapScope ¶
func (s *SlotsC) WrapScope(o *StatementOptions) (sr *Slots)
WrapScope 设置在slot声明时的scope, 用于在运行slot时使用声明slot时的scope
type Statement ¶
type Statement interface {
Exec(ctx *StatementCtx, o *StatementOptions) error
}
vue语法会被编译成一组Statement 为了避免多次运行造成副作用, 所有的 运行时代码 都不应该修改 编译时
type StatementCtx ¶
type StatementCtx struct { Global *Scope Store Store Ctx context.Context W Writer Components map[string]Statement Directives map[string]Directive CanBeAttrsKey func(k string) bool }
整个渲染期间的上下文. Ctx贯穿整个渲染流程, 意味着每一个组件/方法/指令都可以拿到同一个ctx, 只有其中的值会变化.
func (*StatementCtx) Clone ¶
func (c *StatementCtx) Clone() *StatementCtx
func (*StatementCtx) Get ¶
func (c *StatementCtx) Get(k string) (v interface{}, exist bool)
func (*StatementCtx) NewScope ¶
func (c *StatementCtx) NewScope() *Scope
func (*StatementCtx) Set ¶
func (c *StatementCtx) Set(k string, v interface{})
type StatementOptions ¶
type StatementOptions struct { Slots *Slots // 渲染组件时, 组件上的props // 如 // <Menu :data="data"> // <slot name="default"> Props *Props // 如果是渲染tag, scope是当前组件的scope(如果在For语句中, 则也有For的scope). // 如果渲染其他组件, scope也是当前组件的scope. Scope *Scope // 上一层参数, 用于: // - 渲染slot时获取声明slot时的scope. // - 渲染slot时获取上一层的slots, 从中取出slot渲染. (slot组件自己的slot是备选内容) Parent *StatementOptions }
执行语句(组件/Tag)所需的参数
type StrStatement ¶
type StrStatement struct {
Str string
}
静态字符串块
func (*StrStatement) Exec ¶
func (s *StrStatement) Exec(ctx *StatementCtx, _ *StatementOptions) error
type StringSpan ¶
type StringSpan struct {
// contains filtered or unexported fields
}
func (*StringSpan) Result ¶
func (s *StringSpan) Result() string
type Vpl ¶
type Vpl struct {
// contains filtered or unexported fields
}
常驻实例, 一个程序只应该有一个实例. 在运行期间是无副作用的
func New ¶
New return a Vpl instance, This instance should be shared in multiple renderings. The recommended practice is to have only one Vpl instance for the whole program.
func (*Vpl) ComponentFile ¶
Declare a component by file
func (*Vpl) ComponentTxt ¶
Declare a component by txt
func (*Vpl) RenderComponent ¶
func (v *Vpl) RenderComponent(component string, p *RenderParam) (html string, err error)
渲染一个已经编译好的组件