elm

package module
v0.0.0-...-721ebaa Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2017 License: MIT Imports: 5 Imported by: 0

README

elm

简单的Golang Template

example

package main

import (
	"net/http"

	"git.oschina.net/jinzm/elm"

	"github.com/labstack/echo"
)

//使用echo框架时的例子
func main() {
	e := echo.New()
	e.GET("/", func(c echo.Context) error {
		doc := elm.NewDoc("index.html")
        //...         你可以在此处理网页文件的内容
		return c.HTML(http.StatusOK, doc.String())
	})

	e.Start(":80")

}

api

/*************************\\
||       struct DOC       ||
\\************************/
//读取html文件
func NewDoc (file string) Doc
//输出html内容
func (d *Doc) String() string

//Find 查找子元素
func (d *Doc) Find(query string) []*Elm
//FindFirst 查找匹配的第一个子元素
func (d *Doc) FindFirst(query string) *Elm 
//FindEach 查找子元素并输出
func (d *Doc) FindEach(query string, f func(node *Elm))


/*************************\\
||       struct Elm       ||
\\************************/
//NewElm 从字符串创建*Elm
//必须是只有一个源的树形结构 否则只能获取到第一个源
func NewElm(str string) *Elm 
//NewElmFromFile 从文件创建*Elm
//必须是只有一个源的树形结构 否则只能获取到第一个源
func NewElmFromFile(file string) *Elm
//Attr 设置或返回attr的值
func (e *Elm) Attr(key string, val ...interface{}) string 
//Text 设置或返回text的值
func (e *Elm) Text(text ...string) string 
//Each 遍历elm所有子、孙元素
func (e *Elm) Each(f func(node *Elm))
//Find 查找子元素
func (e *Elm) Find(query string) []*Elm
//FindFirst 查找匹配的第一个子元素
func (e *Elm) FindFirst(query string) *Elm
//FindEach 查找子元素并输出
func (e *Elm) FindEach(query string, f func(node *Elm))
//AppendChild 添加子元素
func (e *Elm) Append(node *Elm)
//RemoveChild 移除子元素
func (e *Elm) RemoveChild(node *Elm)
//Copy 复制元素元素
func (e *Elm) Copy() *Elm
//Repace 替换掉元素
func (e *Elm) Repace(node *Elm)
//Remove 移除元素
func (e *Elm) Remove()
//InsertBefore 在当前元素前插入元素
func (e *Elm) Before(node *Elm)
//InsertAfter 在当前元素后插入元素
func (e *Elm) After(node *Elm) 

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Doc

type Doc struct {
	// contains filtered or unexported fields
}

Doc struct

func NewDoc

func NewDoc(path string) *Doc

NewDoc func

func (*Doc) Find

func (d *Doc) Find(query string) []*Elm

Find 查找子元素

func (*Doc) FindEach

func (d *Doc) FindEach(query string, f func(node *Elm))

FindEach 查找子元素并输出

func (*Doc) FindFirst

func (d *Doc) FindFirst(query string) *Elm

FindFirst 查找匹配的第一个子元素

func (*Doc) String

func (d *Doc) String() string

type Elm

type Elm struct {
	// contains filtered or unexported fields
}

Elm struct

func NewElm

func NewElm(str string) *Elm

NewElm 从字符串创建*Elm 必须是只有一个根的树形结构 否则只能获取到第一个根

func NewElmFromFile

func NewElmFromFile(file string) *Elm

NewElmFromFile 从文件创建*Elm 必须是只有一个根的树形结构 否则只能获取到第一个根

func (*Elm) After

func (e *Elm) After(node *Elm)

After 在当前元素后插入元素

func (*Elm) Attr

func (e *Elm) Attr(key string, val ...interface{}) string

Attr 设置或返回attr的值

func (*Elm) Before

func (e *Elm) Before(node *Elm)

Before 在当前元素前插入元素

func (*Elm) Child

func (e *Elm) Child(query ...interface{}) []*Elm

Child 获取子元素

func (*Elm) ChildAppend

func (e *Elm) ChildAppend(node *Elm)

ChildAppend 添加子元素

func (*Elm) ChildRemove

func (e *Elm) ChildRemove(node ...interface{})

ChildRemove 移除子元素 可以是选择器,可以是*Elm或[]*Elm,node为空时全部移除

func (*Elm) Copy

func (e *Elm) Copy() *Elm

Copy 复制元素元素

func (*Elm) Each

func (e *Elm) Each(f func(node *Elm))

Each 遍历elm所有子、孙元素

func (*Elm) Find

func (e *Elm) Find(query string) []*Elm

Find 查找子元素

func (*Elm) FindEach

func (e *Elm) FindEach(query string, f func(node *Elm))

FindEach 查找子元素并输出

func (*Elm) FindFirst

func (e *Elm) FindFirst(query string) *Elm

FindFirst 查找匹配的第一个子元素

func (*Elm) Parent

func (e *Elm) Parent() *Elm

Parent 获取父元素

func (*Elm) Remove

func (e *Elm) Remove()

Remove 移除元素

func (*Elm) Repace

func (e *Elm) Repace(node *Elm)

Repace 替换掉元素

func (*Elm) String

func (e *Elm) String() string

String 以文本输出

func (*Elm) Text

func (e *Elm) Text(text ...string) string

Text 设置或返回text的值

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL