...

Source file src/github.com/noirbizarre/gonja/nodes/sets.go

Documentation: github.com/noirbizarre/gonja/nodes

     1  package nodes
     2  
     3  import (
     4  	"github.com/pkg/errors"
     5  )
     6  
     7  type BlockSet map[string]*Wrapper
     8  
     9  // Exists returns true if the given block is already registered
    10  func (bs BlockSet) Exists(name string) bool {
    11  	_, existing := bs[name]
    12  	return existing
    13  }
    14  
    15  // Register registers a new block. If there's already a filter with the same
    16  // name, Register will panic. You usually want to call this
    17  // function in the filter's init() function:
    18  // http://golang.org/doc/effective_go.html#init
    19  //
    20  // See http://www.florian-schlachter.de/post/gonja/ for more about
    21  // writing filters and tags.
    22  func (bs *BlockSet) Register(name string, w *Wrapper) error {
    23  	if bs.Exists(name) {
    24  		return errors.Errorf("Block with name '%s' is already registered", name)
    25  	}
    26  	(*bs)[name] = w
    27  	return nil
    28  }
    29  
    30  // Replace replaces an already registered filter with a new implementation. Use this
    31  // function with caution since it allobs you to change existing filter behaviour.
    32  func (bs *BlockSet) Replace(name string, w *Wrapper) error {
    33  	if !bs.Exists(name) {
    34  		return errors.Errorf("Block with name '%s' does not exist (therefore cannot be overridden)", name)
    35  	}
    36  	(*bs)[name] = w
    37  	return nil
    38  }
    39  

View as plain text