Exemple #1
0
func (self *Fs) readHtml(c *component.Component, basePath string) error {
	filepath := basePath + ".html"
	if _, err := os.Stat(filepath); err != nil {
		return nil
	}
	content, err := ioutil.ReadFile(filepath)
	document := xmlx.New()
	document.LoadBytes(content, nil)
	html := document.Root.Children[0]
	for _, attr := range html.Attributes {
		if attr.Name.Local == "namespace" {
			c.Namespace = attr.Value
		}
		if attr.Name.Local == "default_param" {
			c.DefaultParam = attr.Value
		}
		if attr.Name.Local == "require" {
			c.Requires = []string{attr.Value}
		}
	}
	for _, node := range html.Children {
		if node.Type != xmlx.NT_ELEMENT {
			continue
		}
		if node.Name.Local == "style" {
			c.Css = getXmlNodesContent(node.Children)
		}
		if node.Name.Local == "schema" {
			content := getXmlNodesContent(node.Children)
			lines := strings.Split(content, "\n")
			schemaContent := []byte{}
			for _, line := range lines {
				schemaContent = append(schemaContent, []byte(strings.Replace(line, "    ", "", 1))...)
			}
			schema, err := self.ParseSchema(schemaContent, filepath)
			if err != nil {
				return err
			}
			c.Schema = schema
		}
		if node.Name.Local == "template" {
			c.Template = &component.Template{Content: stripClasses(getXmlNodesContent(node.Children))}
		}
	}
	if err != nil {
		return errors.New(fmt.Sprintf("Error while reading html file: %v", filepath))
	}
	return nil
}
Exemple #2
0
func (self *Fs) readSchema(c *component.Component, basePath string) error {
	filepath := basePath + ".schema"
	if _, err := os.Stat(filepath); err != nil {
		return nil
	}
	content, err := ioutil.ReadFile(filepath)
	if err != nil {
		return errors.New(fmt.Sprintf("Error while reading schema file: %v", filepath))
	}
	schema, err := self.ParseSchema(content, filepath)
	if err != nil {
		return err
	}
	c.Schema = schema
	return nil
}