diff --git a/haml_interpret_test.go b/haml_interpret_test.go index 8cd6155..9959886 100644 --- a/haml_interpret_test.go +++ b/haml_interpret_test.go @@ -55,55 +55,55 @@ func TestForArrayRangeConstruct(t *testing.T) { type testObject struct{ Val int } func TestForArrayObjectRangeConstruct(t *testing.T) { - scope := make(map[string]interface{}) - scope["looper"] = [5]testObject{ - testObject{4}, - testObject{-128}, - testObject{38}, - testObject{99}, - testObject{1}, - } - - expected := "

\n" + - " 04\n" + - " 1-128\n" + - " 238\n" + - " 399\n" + - " 41\n" + - "

" - input := "%p\n - for i, v := range looper\n %span= i<\n %span= v.Val" - engine, _ := NewEngine(input) - output := engine.Render(scope) - - if output != expected { - t.Errorf("Expected\n%s\nbut got\n%s\n", expected, output) - } + scope := make(map[string]interface{}) + scope["looper"] = [5]testObject{ + testObject{4}, + testObject{-128}, + testObject{38}, + testObject{99}, + testObject{1}, + } + + expected := "

\n" + + " 04\n" + + " 1-128\n" + + " 238\n" + + " 399\n" + + " 41\n" + + "

" + input := "%p\n - for i, v := range looper\n %span= i<\n %span= v.Val" + engine, _ := NewEngine(input) + output := engine.Render(scope) + + if output != expected { + t.Errorf("Expected\n%s\nbut got\n%s\n", expected, output) + } } func TestForSliceObjectRangeConstruct(t *testing.T) { - scope := make(map[string]interface{}) - scope["looper"] = []testObject{ - testObject{4}, - testObject{-128}, - testObject{38}, - testObject{99}, - testObject{1}, - } - - expected := "

\n" + - " 04\n" + - " 1-128\n" + - " 238\n" + - " 399\n" + - " 41\n" + - "

" - input := "%p\n - for i, v := range looper\n %span= i<\n %span= v.Val" - engine, _ := NewEngine(input) - output := engine.Render(scope) - - if output != expected { - t.Errorf("Expected\n%s\nbut got\n%s\n", expected, output) - } + scope := make(map[string]interface{}) + scope["looper"] = []testObject{ + testObject{4}, + testObject{-128}, + testObject{38}, + testObject{99}, + testObject{1}, + } + + expected := "

\n" + + " 04\n" + + " 1-128\n" + + " 238\n" + + " 399\n" + + " 41\n" + + "

" + input := "%p\n - for i, v := range looper\n %span= i<\n %span= v.Val" + engine, _ := NewEngine(input) + output := engine.Render(scope) + + if output != expected { + t.Errorf("Expected\n%s\nbut got\n%s\n", expected, output) + } } func TestForMapRangeConstruct(t *testing.T) { diff --git a/haml_io_test.go b/haml_io_test.go index 51f2546..66c8814 100644 --- a/haml_io_test.go +++ b/haml_io_test.go @@ -67,6 +67,14 @@ var autoCloseTests = []testcase{ testcase{"%input{:type => \"checkbox\", cd => outputTrue}", ""}, testcase{"%one\n %two\n %three\n", "\n\t\n\t\t\n\t\n"}, testcase{"%one\n %two\n %three\n ", "\n\t\n\t\t\n\t\n"}, + testcase{"!!!", ""}, + testcase{"!!! Strict", ""}, + testcase{"!!! Frameset", ""}, + testcase{"!!! 5", ""}, + testcase{"!!! 1.1", ""}, + testcase{"!!! Basic", ""}, + testcase{"!!! Mobile", ""}, + testcase{"!!! RDFa", ""}, } func TestAutoCloseIO(t *testing.T) { diff --git a/parser.go b/parser.go index 49b91a8..1c5a226 100644 --- a/parser.go +++ b/parser.go @@ -71,6 +71,12 @@ func parseLeadingSpace(input string, lastSpaceChar rune, line int) (output inode node := new(node) for i, r := range input { switch { + case r == '!' && len(input) >= i+2 && input[i+1] == '!' && input[i+2] == '!': + if len(input) > i+2 { + output = parseDoctype(input[i+3:], node, line) + } else { + output = parseDoctype("", node, line) + } case r == '-': output = parseCode(input[i+1:], node, line) case r == '%': @@ -93,7 +99,6 @@ func parseLeadingSpace(input string, lastSpaceChar rune, line int) (output inode to = "space" } msg := fmt.Sprintf("Syntax error on line %d: Inconsistent spacing in document changed from %s to %s characters.\n", line, from, to) - //err = os.NewError(msg) err = errors.New(msg) } else { lastSpaceChar = r @@ -111,6 +116,15 @@ func parseLeadingSpace(input string, lastSpaceChar rune, line int) (output inode return } +func parseDoctype(input string, n *node, line int) (output inode) { + output = n + n._name = "doctype" + if len(input) > 0 { + output = parseRemainder(input, n, line) + } + return +} + func parseKey(input string, n *node, line int) (output inode) { if input[len(input)-1] == '<' { n = parseNoNewline("", n, line) @@ -125,7 +139,6 @@ func parseKey(input string, n *node, line int) (output inode) { func parseTag(input string, node *node, newTag bool, line int) (output inode, err error) { if 0 == len(input) && newTag { - //err = os.NewError(fmt.Sprintf("Syntax error on line %d: Invalid tag: %s.\n", line, input)) err = errors.New(fmt.Sprintf("Syntax error on line %d: Invalid tag: %s.\n", line, input)) return } diff --git a/tree.go b/tree.go index ae7a338..3beb721 100644 --- a/tree.go +++ b/tree.go @@ -2,7 +2,6 @@ package gohaml import ( "bytes" - //"container/vector" "fmt" "reflect" "strings" @@ -126,8 +125,26 @@ func (self tree) resolve(scope map[string]interface{}, indent string, autoclose func (self node) resolve(scope map[string]interface{}, buf *bytes.Buffer, curIndent string, indent string, autoclose bool) { remainder := self._remainder.resolve(scope) - //if self._attrs.Len() > 0 && len(remainder) > 0 { - if len(self._attrs) > 0 && len(remainder) > 0 { + if self._name == "doctype" { + buf.WriteString("") + } else if len(self._attrs) > 0 && len(remainder) > 0 { if len(self._name) == 0 { self._name = "div" }