Skip to content

Commit

Permalink
Fixes issue #7.
Browse files Browse the repository at this point in the history
Removed the neccessary to have blocks in the root level. It is still disallowed to have two or more blocks with the same name. Added tests for inheritance (extends/block-tags).
  • Loading branch information
flosch committed Jul 6, 2014
1 parent cc4db26 commit d7a48dc
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
7 changes: 2 additions & 5 deletions tags_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ func (node *tagBlockNode) Execute(ctx *ExecutionContext) (string, error) {
}

func tagBlockParser(doc *Parser, start *Token, arguments *Parser) (INodeTag, error) {
if doc.template.level > 1 {
return nil, arguments.Error("The 'block' tag can only defined on root level (especially no nesting).", start)
}

// TODO: Add {% endblock <blockname> %}-support since Django supports this for better readability
wrapper, err := doc.WrapUntilTag("endblock")
if err != nil {
return nil, err
Expand All @@ -74,7 +71,7 @@ func tagBlockParser(doc *Parser, start *Token, arguments *Parser) (INodeTag, err
if !has_block {
tpl.blocks[name_token.Val] = wrapper
} else {
return nil, arguments.Error("Block already defined", nil)
return nil, arguments.Error(fmt.Sprintf("Block named '%s' already defined", name_token.Val), nil)
}

return &tagBlockNode{name: name_token.Val}, nil
Expand Down
3 changes: 3 additions & 0 deletions template_tests/extends.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% extends "inheritance/base.tpl" %}

{% block content %}Extends' content{% endblock %}
1 change: 1 addition & 0 deletions template_tests/extends.tpl.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Start#This is base's bodyExtends' content#End
3 changes: 3 additions & 0 deletions template_tests/inheritance/base.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% extends "inheritance2/skeleton.tpl" %}

{% block body %}This is base's body{% block content %}Default content{% endblock %}{% endblock %}
1 change: 1 addition & 0 deletions template_tests/inheritance/inheritance2/skeleton.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Start#{% block body %}Default body{% endblock %}#End

0 comments on commit d7a48dc

Please sign in to comment.