Beispiel #1
0
func (c *Component) blend_js() string {

	filename := "./" + c.Location.Filename + ".js"
	bytes, _ := c.Storage.ReadFileString(c.Location.Navigate(filename))
	parse_js := gotreescript.Parse(bytes)

	js := ""
	for _, token := range *parse_js {
		if gotreescript.TEXT == token.Type {
			js += token.Partial
		} else if gotreescript.TAG == token.Type {
			n := strings.ToLower(token.Name)

			if "include" == n {
				c.tag_include(token)
			} else if "base64" == n {
				js += c.tag_base64(token)
			} else if "content" == n {
				js += c.tag_content(token)
			} else if "path" == n {
				js += c.tag_path(token)
			} else if "link" == n {
				js += c.tag_link(token)
			} else if "todo:" == n {
				js += c.tag_todo(token)
			} else {
				js += c.tag_else(token)
			}
		}
	}

	return js
}
Beispiel #2
0
func (c *Component) blend_html() {

	filename := "./" + c.Location.Filename + ".html"
	bytes, _ := c.Storage.ReadFileString(c.Location.Navigate(filename))
	parse_html := gotreescript.Parse(bytes)

	// Traverse ONLY includes
	for _, token := range *parse_html {
		if gotreescript.TAG == token.Type {
			n := strings.ToLower(token.Name)
			if "include" == n {
				c.require(token)
				// } else if "content" == n {
				// 	c.tag_content(token)
			}
		}
	}

	// The order is very important! First js dependencies and Last css
	// dependencies (more priority)
	js := c.blend_js()
	css := c.blend_css()

	*c.Js += js
	*c.Css += css

	dst := c.Location.Navigate("./" + c.Location.Filename).Canonical()
	dst = strings.Replace(dst, "/", "_", -1)

	c.TagsCss = append(c.TagsCss, dst+".css")
	c.TagsJs = append(c.TagsJs, dst+".js")

	for _, token := range *parse_html {
		if gotreescript.TEXT == token.Type {
			*c.Html += token.Partial
		} else if gotreescript.TAG == token.Type {
			n := strings.ToLower(token.Name)

			if "include" == n {
				*c.Html += c.tag_include(token)
			} else if "base64" == n {
				*c.Html += c.tag_base64(token)
			} else if "content" == n {
				*c.Html += c.tag_content(token)
			} else if "path" == n {
				*c.Html += c.tag_path(token)
			} else if "link" == n {
				*c.Html += c.tag_link(token)
			} else if "css-tags" == n {
				*c.Html += c.tag_csstags(token)
			} else if "js-tags" == n {
				*c.Html += c.tag_jstags(token)
			} else if "todo:" == n {
				*c.Html += c.tag_todo(token)
			} else {
				*c.Html += c.tag_else(token)
			}
		}
	}

}