Exemple #1
0
func makeInclude(in common.TagNode) common.TagNode {
	if len(in.Content) != 1 {
		return in
	}

	textNode, ok := in.Content[0].(common.TextNode)

	if !ok {
		return in
	}

	if strings.HasSuffix(textNode.Content, ".js") {
		in.Tag = "script"
		in.Attributes = append(in.Attributes, common.Attribute{"src", textNode.Content})
		in.Content = nil
	} else if strings.HasSuffix(textNode.Content, ".css") {
		in.Tag = "link"
		in.Attributes = append(in.Attributes, []common.Attribute{
			{"rel", "stylesheet"},
			{"href", textNode.Content},
		}...)
		in.Content = nil
	} else if strings.HasSuffix(textNode.Content, ".ico") {
		in.Tag = "link"
		in.Attributes = append(in.Attributes, []common.Attribute{
			{"rel", "shortcut icon"},
			{"href", textNode.Content},
		}...)
		in.Content = nil
	} else if strings.HasSuffix(textNode.Content, ".xml") {
		in.Tag = "link"
		in.Attributes = append(in.Attributes, []common.Attribute{
			{"rel", "alternate"},
			{"type", "application/rss+xml"},
			{"href", textNode.Content},
		}...)
		in.Content = nil
	} else if strings.HasSuffix(textNode.Content, ".atom") {
		in.Tag = "link"
		in.Attributes = append(in.Attributes, []common.Attribute{
			{"rel", "alternate"},
			{"type", "application/atom+xml"},
			{"href", textNode.Content},
		}...)
		in.Content = nil
	}

	return in
}
Exemple #2
0
func makeMeta(in common.TagNode) common.TagNode {
	if len(in.Attributes) != 1 {
		return in
	}

	if in.Attributes[0].Value != "" {
		return in
	}

	if len(in.Content) != 1 {
		return in
	}

	textNode, ok := in.Content[0].(common.TextNode)

	if !ok {
		return in
	}

	in.Attributes = []common.Attribute{
		{"name", in.Attributes[0].Name},
		{"content", textNode.Content},
	}

	in.Content = nil

	return in
}
Exemple #3
0
func makeFormControl(in common.TagNode) (out common.TagNode) {
	if in.Tag != "input" && in.Tag != "select" {
		panic("attempt to make a bootstrap from control out of a non-input")
	}

	out.Tag = "div"

	out.Classes = []string{"form-group"}

	in.Classes = append(in.Classes, "form-control")

	var attrs []common.Attribute

	for _, attr := range in.Attributes {
		include := true

		if attr.Name == "label" {
			labelNode := common.TagNode{
				Tag:     "label",
				Classes: []string{"control-label"},
				Content: []common.Node{
					common.TextNode{attr.Value},
				},
			}

			if in.Id != "" {
				labelNode.Attributes = []common.Attribute{
					{"for", in.Id},
				}
			}

			out.Content = append(out.Content, labelNode)

			include = false
		}

		if include {
			attrs = append(attrs, attr)
		}
	}

	in.Attributes = attrs

	if len(in.Content) == 1 {
		if textNode, ok := in.Content[0].(common.TextNode); ok {
			in.Attributes = append(in.Attributes, common.Attribute{"placeholder", textNode.Content})

			in.Content = nil
		}
	}

	out.Content = append(out.Content, in)

	return
}
Exemple #4
0
/*
HTML adds some convenience elements to save typing.

Examples:

	meta(a): b -> meta(name=a value=b)
	import: a -> link(rel=stylesheet href=a) or script(src=a): ""
*/
func HTML(in common.TagNode) common.TagNode {
	in.Content = translateHTMLNodes(in.Content)

	switch in.Tag {
	case "meta":
		return makeMeta(in)
	case "include":
		return makeInclude(in)
	default:
		return in
	}
}
Exemple #5
0
func Bootstrap(in common.TagNode) common.TagNode {
	in.Content = translateNodes(in.Content)

	switch in.Tag {
	case "panel":
		return makePanel(in)
	case "input", "select":
		return makeFormControl(in)
	case "row":
		return makeRow(in)
	case "col":
		return makeCol(in)
	case "icon":
		return makeIcon(in)
	default:
		return in
	}
}
Exemple #6
0
func makeIcon(in common.TagNode) common.TagNode {
	if in.Tag != "icon" {
		panic("attempt to make a bootstrap icon out of a non-icon")
	}

	if len(in.Content) != 1 {
		panic("bootstrap icon requires an icon name")
	}

	textNode, ok := in.Content[0].(common.TextNode)

	if !ok {
		panic("bootstrap icon requires an icon name")
	}

	in.Tag = "span"

	in.Classes = append(in.Classes, "glyphicon", "glyphicon-"+textNode.Content)

	in.Content = nil

	return in
}