Beispiel #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
}
Beispiel #2
0
func makeCol(in common.TagNode) common.TagNode {
	if in.Tag != "col" {
		panic("attempt to make a bootstrap col out of a non-col")
	}

	in.Tag = "div"

	var attrs []common.Attribute

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

		for _, size := range bsSizes {
			if attr.Name == size {
				in.Classes = append(in.Classes, "col-"+attr.Name+"-"+attr.Value)
				include = false
			}
		}

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

	in.Attributes = attrs

	return in
}
Beispiel #3
0
func makeRow(in common.TagNode) common.TagNode {
	if in.Tag != "row" {
		panic("attempt to make a bootstrap row out of a non-row")
	}

	in.Tag = "div"

	in.Classes = append(in.Classes, "row")

	return in
}
Beispiel #4
0
func newElement(input string) (common.TagNode, error) {
	var el common.TagNode

	match := elementRe.FindStringSubmatch(input)

	if match == nil {
		return el, fmt.Errorf("Badly-formatted wossname")
	}

	for i, name := range elementNames {
		switch name {
		case "tag":
			el.Tag = match[i]
		case "id":
			el.Id = match[i]
		case "classes":
			if match[i] == "" {
				continue
			}

			el.Classes = strings.Fields(match[i])
		case "attributes":
			if match[i] == "" {
				continue
			}

			var err error

			el.Attributes, err = parseAttributes(match[i])

			if err != nil {
				return el, err
			}
		}

	}

	return el, nil
}
Beispiel #5
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
}