コード例 #1
0
ファイル: fs.go プロジェクト: 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
}
コード例 #2
0
ファイル: fs.go プロジェクト: 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
}