File: element.go

package info (click to toggle)
golang-github-yosssi-ace 0.0.4%2Bgit20160102.51.71afeb7-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 468 kB
  • ctags: 249
  • sloc: makefile: 3; sh: 1
file content (72 lines) | stat: -rw-r--r-- 2,378 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package ace

import (
	"fmt"
	"io"
)

// Helper method names
const (
	helperMethodNameConditionalComment = "conditionalComment"
	helperMethodNameContent            = "content"
	helperMethodNameCSS                = "css"
	helperMethodNameDoctype            = "doctype"
	helperMethodNameYield              = "yield"
	helperMethodNameInclude            = "include"
	helperMethodNameJavascript         = "javascript"
)

// element is an interface for storing an element.
type element interface {
	io.WriterTo
	AppendChild(child element)
	ContainPlainText() bool
	Base() *elementBase
	CanHaveChildren() bool
	InsertBr() bool
	SetLastChild(lastChild bool)
}

// newElement creates and returns an element.
func newElement(ln *line, rslt *result, src *source, parent element, opts *Options) (element, error) {
	var e element
	var err error

	switch {
	case parent != nil && parent.ContainPlainText():
		e = newPlainTextInner(ln, rslt, src, parent, parent.InsertBr(), opts)
	case ln.isEmpty():
		e = newEmptyElement(ln, rslt, src, parent, opts)
	case ln.isComment():
		e = newComment(ln, rslt, src, parent, opts)
	case ln.isHTMLComment():
		e = newHTMLComment(ln, rslt, src, parent, opts)
	case ln.isHelperMethod():
		switch {
		case ln.isHelperMethodOf(helperMethodNameConditionalComment):
			e, err = newHelperMethodConditionalComment(ln, rslt, src, parent, opts)
		case ln.isHelperMethodOf(helperMethodNameContent):
			e, err = newHelperMethodContent(ln, rslt, src, parent, opts)
		case ln.isHelperMethodOf(helperMethodNameCSS):
			e = newHelperMethodCSS(ln, rslt, src, parent, opts)
		case ln.isHelperMethodOf(helperMethodNameDoctype):
			e, err = newHelperMethodDoctype(ln, rslt, src, parent, opts)
		case ln.isHelperMethodOf(helperMethodNameInclude):
			e, err = newHelperMethodInclude(ln, rslt, src, parent, opts)
		case ln.isHelperMethodOf(helperMethodNameJavascript):
			e = newHelperMethodJavascript(ln, rslt, src, parent, opts)
		case ln.isHelperMethodOf(helperMethodNameYield):
			e, err = newHelperMethodYield(ln, rslt, src, parent, opts)
		default:
			err = fmt.Errorf("the helper method name is invalid [file: %s][line: %d]", ln.fileName(), ln.no)
		}
	case ln.isPlainText():
		e = newPlainText(ln, rslt, src, parent, opts)
	case ln.isAction():
		e = newAction(ln, rslt, src, parent, opts)
	default:
		e, err = newHTMLTag(ln, rslt, src, parent, opts)
	}

	return e, err
}