teepee 0.15.0 → 0.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/teepee/command-parser.rb +11 -7
 - data/lib/teepee/commander.rb +5 -6
 - data/lib/teepee/paragraph-parser.rb +3 -2
 - data/lib/teepee/parser.rb +3 -1
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 4cf1667f856da637023b09ff20bea473e2a7afb5
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 71a0186abc1b1adf0addcd8e56fdef6a88455b67
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: d1947fa3ce5f652143f62689cd98c2c552af27d3539f4dc8dba878f26c81e6e0dfdef030c7b66ed04e495b20fb4864d6a47c50b63f9394b2832bb2aadc1cf363
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 0fb35c12ad54e037c4e4605cf190ebd1c59aeed99332ecfbc5ba1fc8a9c1efe4eccca0aedeb4ce0c51cf835309a01338093d14dc9ab0cc46fb7ba038fdf8787b
         
     | 
| 
         @@ -46,9 +46,11 @@ require 'teepee/actionable-commander' 
     | 
|
| 
       46 
46 
     | 
    
         | 
| 
       47 
47 
     | 
    
         
             
            module Teepee
         
     | 
| 
       48 
48 
     | 
    
         
             
              class CommandParser < ParserNode
         
     | 
| 
      
 49 
     | 
    
         
            +
                attr_accessor :parser
         
     | 
| 
       49 
50 
     | 
    
         
             
                attr_reader :command, :expressions
         
     | 
| 
       50 
51 
     | 
    
         | 
| 
       51 
     | 
    
         
            -
                def initialize(command, expressions)
         
     | 
| 
      
 52 
     | 
    
         
            +
                def initialize(parser, command, expressions)
         
     | 
| 
      
 53 
     | 
    
         
            +
                  @parser = parser
         
     | 
| 
       52 
54 
     | 
    
         
             
                  raise ArgumentError if not command.is_a? WordToken
         
     | 
| 
       53 
55 
     | 
    
         
             
                  @command = command
         
     | 
| 
       54 
56 
     | 
    
         
             
                  raise ArgumentError if not expressions.is_a? Array
         
     | 
| 
         @@ -67,7 +69,8 @@ module Teepee 
     | 
|
| 
       67 
69 
     | 
    
         
             
                end
         
     | 
| 
       68 
70 
     | 
    
         | 
| 
       69 
71 
     | 
    
         
             
                def to_html
         
     | 
| 
       70 
     | 
    
         
            -
                   
     | 
| 
      
 72 
     | 
    
         
            +
                  @@commander.parser = @parser
         
     | 
| 
      
 73 
     | 
    
         
            +
                  if @parser.variables.include? command.word
         
     | 
| 
       71 
74 
     | 
    
         
             
                    @@commander.get_operator command.word
         
     | 
| 
       72 
75 
     | 
    
         
             
                  else
         
     | 
| 
       73 
76 
     | 
    
         
             
                    builtins
         
     | 
| 
         @@ -472,7 +475,8 @@ module Teepee 
     | 
|
| 
       472 
475 
     | 
    
         
             
                  @@action_view = nil
         
     | 
| 
       473 
476 
     | 
    
         
             
                  @@controller = nil
         
     | 
| 
       474 
477 
     | 
    
         | 
| 
       475 
     | 
    
         
            -
                  def parse(tokens)
         
     | 
| 
      
 478 
     | 
    
         
            +
                  def parse(parser, tokens)
         
     | 
| 
      
 479 
     | 
    
         
            +
                    @parser = parser
         
     | 
| 
       476 
480 
     | 
    
         
             
                    expressions = []
         
     | 
| 
       477 
481 
     | 
    
         
             
                    rest = tokens
         
     | 
| 
       478 
482 
     | 
    
         
             
                    backslash, command, left_brace = rest.shift(3)
         
     | 
| 
         @@ -481,23 +485,23 @@ module Teepee 
     | 
|
| 
       481 
485 
     | 
    
         
             
                    raise ParseError if not command.is_a? WordToken
         
     | 
| 
       482 
486 
     | 
    
         
             
                    if not left_brace.is_a? LeftBraceToken # A command with no interior.
         
     | 
| 
       483 
487 
     | 
    
         
             
                      rest.unshift left_brace if not left_brace.is_a? WhitespaceToken
         
     | 
| 
       484 
     | 
    
         
            -
                      return [CommandParser.new(command, []), rest]
         
     | 
| 
      
 488 
     | 
    
         
            +
                      return [CommandParser.new(parser, command, []), rest]
         
     | 
| 
       485 
489 
     | 
    
         
             
                    end
         
     | 
| 
       486 
490 
     | 
    
         
             
                    while rest.length > 0
         
     | 
| 
       487 
491 
     | 
    
         
             
                      if rest.first.is_a? WordToken or rest.first.is_a? WhitespaceToken or rest.first.is_a? PipeToken
         
     | 
| 
       488 
492 
     | 
    
         
             
                        expressions << rest.shift
         
     | 
| 
       489 
493 
     | 
    
         
             
                      elsif rest.first.is_a? BackslashToken
         
     | 
| 
       490 
     | 
    
         
            -
                        result, rest = CommandParser.parse(rest)
         
     | 
| 
      
 494 
     | 
    
         
            +
                        result, rest = CommandParser.parse(parser, rest)
         
     | 
| 
       491 
495 
     | 
    
         
             
                        expressions << result
         
     | 
| 
       492 
496 
     | 
    
         
             
                      elsif rest.first.is_a? RightBraceToken
         
     | 
| 
       493 
497 
     | 
    
         
             
                        right_brace = rest.shift
         
     | 
| 
       494 
     | 
    
         
            -
                        return [CommandParser.new(command, expressions), rest]
         
     | 
| 
      
 498 
     | 
    
         
            +
                        return [CommandParser.new(parser, command, expressions), rest]
         
     | 
| 
       495 
499 
     | 
    
         
             
                      else
         
     | 
| 
       496 
500 
     | 
    
         
             
                        raise ParseError
         
     | 
| 
       497 
501 
     | 
    
         
             
                      end
         
     | 
| 
       498 
502 
     | 
    
         
             
                    end
         
     | 
| 
       499 
503 
     | 
    
         
             
                    if right_brace.nil? # Allow a forgotten final right brace.
         
     | 
| 
       500 
     | 
    
         
            -
                      return [CommandParser.new(command, expressions), rest]
         
     | 
| 
      
 504 
     | 
    
         
            +
                      return [CommandParser.new(parser, command, expressions), rest]
         
     | 
| 
       501 
505 
     | 
    
         
             
                    end
         
     | 
| 
       502 
506 
     | 
    
         
             
                  end
         
     | 
| 
       503 
507 
     | 
    
         | 
    
        data/lib/teepee/commander.rb
    CHANGED
    
    | 
         @@ -37,11 +37,10 @@ 
     | 
|
| 
       37 
37 
     | 
    
         | 
| 
       38 
38 
     | 
    
         
             
            module Teepee
         
     | 
| 
       39 
39 
     | 
    
         
             
              class Commander
         
     | 
| 
       40 
     | 
    
         
            -
                 
     | 
| 
      
 40 
     | 
    
         
            +
                attr_accessor :parser
         
     | 
| 
       41 
41 
     | 
    
         | 
| 
       42 
42 
     | 
    
         
             
                def initialize params
         
     | 
| 
       43 
43 
     | 
    
         
             
                  # We don't use the params in the base class, but might in derived classes.
         
     | 
| 
       44 
     | 
    
         
            -
                  @variables = Hash.new
         
     | 
| 
       45 
44 
     | 
    
         
             
                end
         
     | 
| 
       46 
45 
     | 
    
         | 
| 
       47 
46 
     | 
    
         
             
                def valid_uri? uri
         
     | 
| 
         @@ -380,12 +379,12 @@ module Teepee 
     | 
|
| 
       380 
379 
     | 
    
         | 
| 
       381 
380 
     | 
    
         
             
                def define expressions
         
     | 
| 
       382 
381 
     | 
    
         
             
                  variable, _, value = expressions
         
     | 
| 
       383 
     | 
    
         
            -
                  @variables[variable.to_html] = value
         
     | 
| 
      
 382 
     | 
    
         
            +
                  @parser.variables[variable.to_html] = value
         
     | 
| 
       384 
383 
     | 
    
         
             
                  value.to_html
         
     | 
| 
       385 
384 
     | 
    
         
             
                end
         
     | 
| 
       386 
385 
     | 
    
         | 
| 
       387 
386 
     | 
    
         
             
                def defined? variables
         
     | 
| 
       388 
     | 
    
         
            -
                  if Set.new(variables.map(&:to_html)).subset? Set.new(@variables.keys)
         
     | 
| 
      
 387 
     | 
    
         
            +
                  if Set.new(variables.map(&:to_html)).subset? Set.new(@parser.variables.keys)
         
     | 
| 
       389 
388 
     | 
    
         
             
                    true_constant
         
     | 
| 
       390 
389 
     | 
    
         
             
                  else
         
     | 
| 
       391 
390 
     | 
    
         
             
                    false_constant
         
     | 
| 
         @@ -475,7 +474,7 @@ module Teepee 
     | 
|
| 
       475 
474 
     | 
    
         
             
                end
         
     | 
| 
       476 
475 
     | 
    
         | 
| 
       477 
476 
     | 
    
         
             
                def get_operator variable
         
     | 
| 
       478 
     | 
    
         
            -
                  @variables[variable.to_html].to_html
         
     | 
| 
      
 477 
     | 
    
         
            +
                  @parser.variables[variable.to_html].to_html
         
     | 
| 
       479 
478 
     | 
    
         
             
                end
         
     | 
| 
       480 
479 
     | 
    
         | 
| 
       481 
480 
     | 
    
         
             
                def greater_than numbers
         
     | 
| 
         @@ -814,7 +813,7 @@ module Teepee 
     | 
|
| 
       814 
813 
     | 
    
         | 
| 
       815 
814 
     | 
    
         
             
                def undefine expressions
         
     | 
| 
       816 
815 
     | 
    
         
             
                  expressions.each do |expression|
         
     | 
| 
       817 
     | 
    
         
            -
                    @variables.delete expression.to_html
         
     | 
| 
      
 816 
     | 
    
         
            +
                    @parser.variables.delete expression.to_html
         
     | 
| 
       818 
817 
     | 
    
         
             
                  end
         
     | 
| 
       819 
818 
     | 
    
         
             
                  ""
         
     | 
| 
       820 
819 
     | 
    
         
             
                end
         
     | 
| 
         @@ -49,7 +49,8 @@ module Teepee 
     | 
|
| 
       49 
49 
     | 
    
         
             
              class ParagraphParser < ParserNode
         
     | 
| 
       50 
50 
     | 
    
         
             
                attr_reader :expressions, :tokens
         
     | 
| 
       51 
51 
     | 
    
         | 
| 
       52 
     | 
    
         
            -
                def initialize(tokens)
         
     | 
| 
      
 52 
     | 
    
         
            +
                def initialize(parser, tokens)
         
     | 
| 
      
 53 
     | 
    
         
            +
                  @parser = parser
         
     | 
| 
       53 
54 
     | 
    
         
             
                  raise ArgumentError if not tokens.is_a? Array
         
     | 
| 
       54 
55 
     | 
    
         
             
                  tokens.each {|token| raise ArgumentError if not token.kind_of? ParserNode}
         
     | 
| 
       55 
56 
     | 
    
         
             
                  @tokens = tokens
         
     | 
| 
         @@ -65,7 +66,7 @@ module Teepee 
     | 
|
| 
       65 
66 
     | 
    
         
             
                    elsif rest.first.is_a? WhitespaceToken
         
     | 
| 
       66 
67 
     | 
    
         
             
                      @expressions << rest.shift
         
     | 
| 
       67 
68 
     | 
    
         
             
                    elsif rest.first.is_a? BackslashToken
         
     | 
| 
       68 
     | 
    
         
            -
                      command, rest = CommandParser.parse(rest)
         
     | 
| 
      
 69 
     | 
    
         
            +
                      command, rest = CommandParser.parse(@parser, rest)
         
     | 
| 
       69 
70 
     | 
    
         
             
                      @expressions << command
         
     | 
| 
       70 
71 
     | 
    
         
             
                    else
         
     | 
| 
       71 
72 
     | 
    
         
             
                      return self
         
     | 
    
        data/lib/teepee/parser.rb
    CHANGED
    
    | 
         @@ -53,6 +53,7 @@ require 'teepee/paragraph-parser' 
     | 
|
| 
       53 
53 
     | 
    
         | 
| 
       54 
54 
     | 
    
         
             
            module Teepee
         
     | 
| 
       55 
55 
     | 
    
         
             
              class Parser < ParserNode
         
     | 
| 
      
 56 
     | 
    
         
            +
                attr_accessor :variables
         
     | 
| 
       56 
57 
     | 
    
         
             
                attr_reader :paragraphs, :split_tokens, :text, :tokenizer
         
     | 
| 
       57 
58 
     | 
    
         | 
| 
       58 
59 
     | 
    
         
             
                def tokens
         
     | 
| 
         @@ -60,6 +61,7 @@ module Teepee 
     | 
|
| 
       60 
61 
     | 
    
         
             
                end
         
     | 
| 
       61 
62 
     | 
    
         | 
| 
       62 
63 
     | 
    
         
             
                def initialize(text)
         
     | 
| 
      
 64 
     | 
    
         
            +
                  @variables = Hash.new
         
     | 
| 
       63 
65 
     | 
    
         
             
                  @text = text
         
     | 
| 
       64 
66 
     | 
    
         
             
                  @tokenizer = Tokenizer.new text
         
     | 
| 
       65 
67 
     | 
    
         
             
                  parse
         
     | 
| 
         @@ -67,7 +69,7 @@ module Teepee 
     | 
|
| 
       67 
69 
     | 
    
         | 
| 
       68 
70 
     | 
    
         
             
                def parse
         
     | 
| 
       69 
71 
     | 
    
         
             
                  @split_tokens = tokens.split {|token| token.class == EmptyNewlinesToken}
         
     | 
| 
       70 
     | 
    
         
            -
                  @paragraphs = @split_tokens.map {|split_tokens| ParagraphParser.new split_tokens}
         
     | 
| 
      
 72 
     | 
    
         
            +
                  @paragraphs = @split_tokens.map {|split_tokens| ParagraphParser.new(self, split_tokens)}
         
     | 
| 
       71 
73 
     | 
    
         
             
                end
         
     | 
| 
       72 
74 
     | 
    
         | 
| 
       73 
75 
     | 
    
         
             
                def to_html
         
     |