OLD | NEW |
---|---|
1 # Copyright 2012 Benjamin Kalman | 1 # Copyright 2012 Benjamin Kalman |
2 # | 2 # |
3 # Licensed under the Apache License, Version 2.0 (the "License"); | 3 # Licensed under the Apache License, Version 2.0 (the "License"); |
4 # you may not use this file except in compliance with the License. | 4 # you may not use this file except in compliance with the License. |
5 # You may obtain a copy of the License at | 5 # You may obtain a copy of the License at |
6 # | 6 # |
7 # http://www.apache.org/licenses/LICENSE-2.0 | 7 # http://www.apache.org/licenses/LICENSE-2.0 |
8 # | 8 # |
9 # Unless required by applicable law or agreed to in writing, software | 9 # Unless required by applicable law or agreed to in writing, software |
10 # distributed under the License is distributed on an "AS IS" BASIS, | 10 # distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
585 while self.nextToken == Token.CHARACTER and \ | 585 while self.nextToken == Token.CHARACTER and \ |
586 excluded.find(self.nextContents) == -1: | 586 excluded.find(self.nextContents) == -1: |
587 buf.append(self.nextContents) | 587 buf.append(self.nextContents) |
588 self.advance() | 588 self.advance() |
589 return buf.toString() | 589 return buf.toString() |
590 | 590 |
591 class Handlebar(object): | 591 class Handlebar(object): |
592 """ A handlebar template. | 592 """ A handlebar template. |
593 """ | 593 """ |
594 def __init__(self, template): | 594 def __init__(self, template): |
595 self.source = template | 595 self.source = unicode(template, 'utf-8') |
cduvall
2012/07/23 21:04:20
This fix makes it render the footer, but this migh
not at google - send to devlin
2012/07/24 01:23:31
Yeah; as discussed in IRC, let's fix this at the F
cduvall
2012/07/24 21:22:46
Done.
| |
596 tokens = TokenStream(template) | 596 tokens = TokenStream(self.source) |
597 self._topNode = self._parseSection(tokens) | 597 self._topNode = self._parseSection(tokens) |
598 if not self._topNode: | 598 if not self._topNode: |
599 raise ParseException("Template is empty", tokens.nextLine) | 599 raise ParseException("Template is empty", tokens.nextLine) |
600 if tokens.hasNext(): | 600 if tokens.hasNext(): |
601 raise ParseException("There are still tokens remaining, " | 601 raise ParseException("There are still tokens remaining, " |
602 "was there an end-section without a start-section:", | 602 "was there an end-section without a start-section:", |
603 tokens.nextLine) | 603 tokens.nextLine) |
604 | 604 |
605 def _parseSection(self, tokens): | 605 def _parseSection(self, tokens): |
606 nodes = [] | 606 nodes = [] |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
739 def render(self, *contexts): | 739 def render(self, *contexts): |
740 """ Renders this template given a variable number of "contexts" to read | 740 """ Renders this template given a variable number of "contexts" to read |
741 out values from (such as those appearing in {{foo}}). | 741 out values from (such as those appearing in {{foo}}). |
742 """ | 742 """ |
743 globalContexts = [] | 743 globalContexts = [] |
744 for context in contexts: | 744 for context in contexts: |
745 globalContexts.append(context) | 745 globalContexts.append(context) |
746 renderState = RenderState(globalContexts, []) | 746 renderState = RenderState(globalContexts, []) |
747 self._topNode.render(renderState) | 747 self._topNode.render(renderState) |
748 return renderState.getResult() | 748 return renderState.getResult() |
OLD | NEW |