コード例 #1
0
ファイル: person.go プロジェクト: influx6/examples
func init() {
	if detect.IsServer() {
		pool = zoom.NewPool(nil)
		var err error
		People, err = pool.Register(&Person{})
		if err != nil {
			log.Fatal(err)
		}
		if err := CreateInitialPeople(); err != nil {
			log.Fatal(err)
		}
	}
}
コード例 #2
0
ファイル: printer.go プロジェクト: influx6/gu
// Print returns the string representation of the element
func (m *ElementWriter) Print(e *Markup) string {
	if detect.IsServer() {

		// if we are on the server && is this element marked as removed,
		// if so we skip and return an empty string
		if e.Removed() && GetMode() < Debugging {
			return ""
		}

	}

	//if we are dealing with a text type just return the content
	if e.Name() == "text" {
		return m.text.Print(e)
	}

	//management attributes
	var mido []Property

	//collect uid and hash of the element so we can write them along
	if GetMode() < Testing {
		hash := &Attribute{Name: "hash", Value: e.Hash()}
		uid := &Attribute{Name: "uid", Value: e.UID()}
		mido = append(mido, hash, uid)
	}

	// id, err := GetAttr(e, "id")
	// if err != nil {
	// 	id = Property(NewAttr("id", e.tagname+"-"+e.uid))
	// 	id.Apply(e)
	// }

	//write out the hash and uid as attributes
	hashes := m.attrWriter.Print(mido)

	//write out the elements attributes using the AttrWriter
	attrs := m.attrWriter.Print(e.Attributes())

	//write out the elements inline-styles using the StyleWriter
	style := m.styleWriter.Print(e.Styles())

	var closer string
	var beginbrack string

	if e.AutoClosed() {
		closer = "/>"
	} else {
		beginbrack = ">"
		closer = fmt.Sprintf("</%s>", e.Name())
	}

	var children = []string{}

	for _, ch := range e.Children() {
		if ch.UID() == e.UID() {
			continue
		}

		children = append(children, m.Print(ch))
	}

	//lets create the elements markup now
	return strings.Join([]string{
		fmt.Sprintf("<%s", e.Name()),
		hashes,
		attrs,
		(func() string {
			if len(style) != 0 {
				return fmt.Sprintf(` style="%s"`, style)
			}
			return ""
		}()),
		beginbrack,
		e.TextContent(),
		strings.Join(children, ""),
		closer,
	}, "")
}
コード例 #3
0
ファイル: printer.go プロジェクト: influx6/haiku-deprecated
// Print returns the string representation of the element
func (m *ElementWriter) Print(e *Element) string {
	// if we are on the server && is this element marked as removed, if so we skip and return an empty string
	if detect.IsServer() {
		if e.Removed() && !m.allowRemoved {
			return ""
		}
	}

	//if we are dealing with a text type just return the content
	if e.Name() == "text" {
		return m.text.Print(e)
	}

	//collect uid and hash of the element so we can write them along
	hash := &Attribute{"hash", e.Hash()}
	uid := &Attribute{"uid", e.UID()}

	//management attributes
	mido := []*Attribute{hash, uid}

	// if e.Removed() {
	// 	mido = append(mido, &Attribute{"haikuRemoved", ""})
	// }

	//write out the hash and uid as attributes
	hashes := m.attrWriter.Print(mido)

	//write out the elements attributes using the AttrWriter
	attrs := m.attrWriter.Print(e.Attributes())

	//write out the elements inline-styles using the StyleWriter
	style := m.styleWriter.Print(e.Styles())

	var closer string
	var beginbrack string

	if e.AutoClosed() {
		closer = "/>"
	} else {
		beginbrack = ">"
		closer = fmt.Sprintf("</%s>", e.Name())
	}

	var children = []string{}

	for _, ch := range e.Children() {
		// if ch.Name() == "text" {
		// 	children = append(children, m.text.Print(ch))
		// 	continue
		// }
		if ech, ok := ch.(*Element); ok {
			if ech == e {
				continue
			}
			children = append(children, m.Print(ech))
		}
	}

	//lets create the elements markup now
	return strings.Join([]string{
		fmt.Sprintf("<%s", e.Name()),
		hashes,
		attrs,
		fmt.Sprintf(` style="%s"`, style),
		beginbrack,
		e.textContent,
		strings.Join(children, ""),
		closer,
	}, "")
}