Add proper elements <element name="head"> will now be treated as <head>. WARNING: I WAS A STUPID NINCOMPOOP AND BROKE NESTING ELEMENTS!!!
This commit is contained in:
parent
cb7a238c80
commit
89fff8112f
8 changed files with 111 additions and 26 deletions
|
@ -15,7 +15,7 @@ type Element struct {
|
|||
FilePath string
|
||||
}
|
||||
|
||||
func ParseFile(filename string) ([]string error) {
|
||||
func ParseFile(filename string) ([]Element, error) {
|
||||
// Hey, does the file we're trying to parse actually exist?
|
||||
data, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
|
@ -38,11 +38,11 @@ func ParseFile(filename string) ([]string error) {
|
|||
content = content[start+len("<hylia>") : end]
|
||||
|
||||
// Extract the custom elements, which are wrapped in <element> tags and handle imports
|
||||
elements := []string{}
|
||||
elements := []Element{}
|
||||
lines := strings.Split(content, "\n")
|
||||
for _, line := range lines {
|
||||
line = strings.TrimSpace(line)
|
||||
if strings.HasPrefix(line, <"element") {
|
||||
if strings.HasPrefix(line, "<element") {
|
||||
// Extract the element name
|
||||
name := extractAttributeValue(line, "name")
|
||||
if name == "" {
|
||||
|
@ -54,7 +54,7 @@ func ParseFile(filename string) ([]string error) {
|
|||
}
|
||||
elements = append(elements, Element{Name: name, Content: content, FilePath: filename})
|
||||
} else if strings.HasPrefix(line, "<import") {
|
||||
filePath := extractAttributeValue(line, file)
|
||||
filePath := extractAttributeValue(line, "file")
|
||||
if filePath == "" {
|
||||
return nil, errors.New("<import> tag is missing a file ('file' attribute)")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue