Example #1
0
File: fs.go Project: romanoff/ahc
func (self *Fs) readCss(component *component.Component, basePath string) error {
	filepath := basePath + ".css"
	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 css file: %v", filepath))
	}
	component.Css = string(content)
	matches := provideRe.FindSubmatch(content)
	if len(matches) == 2 {
		component.Namespace = string(matches[1])
	}
	matches = defaultParamRe.FindSubmatch(content)
	if len(matches) == 2 {
		component.DefaultParam = string(matches[1])
	}
	allMatches := requireRe.FindAllSubmatch(content, -1)
	for _, matches := range allMatches {
		if len(matches) == 2 {
			component.Requires = append(component.Requires, string(matches[1]))
		}
	}
	return nil
}
Example #2
0
File: fs.go Project: romanoff/ahc
func (self *Fs) readTemplate(c *component.Component, basePath string) error {
	filepath := basePath + ".tmpl"
	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 tmpl file: %v", filepath))
	}
	template := &component.Template{Content: stripClasses(string(content))}
	c.Template = template
	return nil
}
Example #3
0
File: fs.go Project: romanoff/ahc
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
}
Example #4
0
File: fs.go Project: romanoff/ahc
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
}