Ejemplo n.º 1
0
Archivo: css.go Proyecto: influx6/gu
// Stylesheet returns the provided styles using the binding as the argument for the
// provided css template.
func (r *Rule) Stylesheet(bind interface{}, parentNode string) (*bcss.Stylesheet, error) {
	var stylesheet bcss.Stylesheet

	for _, rule := range r.depends {
		sheet, err := rule.Stylesheet(bind, parentNode)
		if err != nil {
			return nil, err
		}

		stylesheet.Rules = append(stylesheet.Rules, sheet.Rules...)
	}

	var content bytes.Buffer
	if err := r.template.Execute(&content, bind); err != nil {
		return nil, err
	}

	sheet, err := parser.Parse(content.String())
	if err != nil {
		return nil, err
	}

	for _, rule := range sheet.Rules {
		r.morphRule(rule, parentNode)
	}

	stylesheet.Rules = append(stylesheet.Rules, sheet.Rules...)

	return &stylesheet, nil
}
Ejemplo n.º 2
0
// parse and display CSS file
func parseCSS(filePath string) {
	input := readFile(filePath)

	stylesheet, err := parser.Parse(string(input))
	if err != nil {
		fmt.Println("Parsing error: ", err)
		os.Exit(1)
	}

	fmt.Println(stylesheet.String())
}
Ejemplo n.º 3
0
// Parses and removes stylesheets from HTML document
func (inliner *Inliner) parseStylesheets() error {
	var result error

	inliner.doc.Find("style").EachWithBreak(func(i int, s *goquery.Selection) bool {
		stylesheet, err := parser.Parse(s.Text())
		if err != nil {
			result = err
			return false
		}

		inliner.stylesheets = append(inliner.stylesheets, stylesheet)

		// removes parsed stylesheet
		s.Remove()

		return true
	})

	return result
}
Ejemplo n.º 4
0
// LoadHTML - load the html/css code into the container
func LoadHTML(container *Container, htmlInput, cssInput io.Reader, assets HtmlAssets) ([]Activatable, error) {
	document, err := html.Parse(htmlInput)
	if err != nil {
		log.Printf("Error parsing html: %v", err)
		return []Activatable{}, err
	}

	css, err := ioutil.ReadAll(cssInput)
	if err != nil {
		log.Printf("Error reading css: %v", err)
		return []Activatable{}, err
	}

	styles, err := parser.Parse(string(css))
	if err != nil {
		log.Printf("Error parsing css: %v", err)
		return []Activatable{}, err
	}

	activatables := renderNode(container, document.FirstChild, styles, assets)

	return activatables, nil
}