opulent 1.8.1 → 1.8.2
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/CHANGELOG.md +4 -0
- data/lib/opulent/compiler.rb +3 -0
- data/lib/opulent/compiler/buffer.rb +12 -4
- data/lib/opulent/compiler/comment.rb +7 -1
- data/lib/opulent/compiler/define.rb +9 -1
- data/lib/opulent/compiler/node.rb +25 -12
- data/lib/opulent/compiler/text.rb +4 -2
- data/lib/opulent/version.rb +1 -1
- metadata +2 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: cd8db65730c87a9220e739b5863cc7b1054129f3
         | 
| 4 | 
            +
              data.tar.gz: 25c0887712f3ac678719b13487368781a2854c6b
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 61534b13b508dd60b494d3e5ddf7254f86830a6c2dbd223790e59c1fcdad3a8b9c11778ae18d96cb1f07110d49750287f8a1ea597da67b39f81cdea9f160faed
         | 
| 7 | 
            +
              data.tar.gz: a37b62028da6f5dfab4064899305b0492271c53eed205773c33b34d7680cee1d3f8d46e54cdedfe2815a03c93761af5e55f20b271a367711a662df43579d1ebb
         | 
    
        data/CHANGELOG.md
    ADDED
    
    
    
        data/lib/opulent/compiler.rb
    CHANGED
    
    
| @@ -64,12 +64,20 @@ module Opulent | |
| 64 64 | 
             
                # @param type [Symbol] Remove only if last buffer part is of this type
         | 
| 65 65 | 
             
                # @param n [Fixnum] Number of characters to be removed
         | 
| 66 66 | 
             
                #
         | 
| 67 | 
            -
                def  | 
| 67 | 
            +
                def buffer_remove_trailing_newline(type = :freeze)
         | 
| 68 68 | 
             
                  if @template[-1][0] == type
         | 
| 69 | 
            -
                     | 
| 70 | 
            -
             | 
| 69 | 
            +
                    @template[-1][1].gsub! /\s*\n+\s*$/, ''
         | 
| 70 | 
            +
                  end
         | 
| 71 | 
            +
                end
         | 
| 71 72 |  | 
| 72 | 
            -
             | 
| 73 | 
            +
                # Remove last n characters from the most recent template item
         | 
| 74 | 
            +
                #
         | 
| 75 | 
            +
                # @param type [Symbol] Remove only if last buffer part is of this type
         | 
| 76 | 
            +
                # @param n [Fixnum] Number of characters to be removed
         | 
| 77 | 
            +
                #
         | 
| 78 | 
            +
                def buffer_remove_trailing_whitespace(type = :freeze)
         | 
| 79 | 
            +
                  if @template[-1][0] == type
         | 
| 80 | 
            +
                    @template[-1][1].rstrip!
         | 
| 73 81 | 
             
                  end
         | 
| 74 82 | 
             
                end
         | 
| 75 83 |  | 
| @@ -9,7 +9,13 @@ module Opulent | |
| 9 9 | 
             
                #
         | 
| 10 10 | 
             
                def comment(node, indent)
         | 
| 11 11 | 
             
                  buffer_freeze "\n" if node[@options][:newline]
         | 
| 12 | 
            -
                   | 
| 12 | 
            +
                  if @settings[:pretty]
         | 
| 13 | 
            +
                    if @in_definition
         | 
| 14 | 
            +
                      buffer "' ' * (indent + #{indent})"
         | 
| 15 | 
            +
                    else
         | 
| 16 | 
            +
                      buffer_freeze " " * indent
         | 
| 17 | 
            +
                    end
         | 
| 18 | 
            +
                  end
         | 
| 13 19 | 
             
                  buffer_freeze '<!-- '
         | 
| 14 20 | 
             
                  buffer_split_by_interpolation node[@value].strip, false
         | 
| 15 21 | 
             
                  buffer_freeze ' -->'
         | 
| @@ -16,15 +16,18 @@ module Opulent | |
| 16 16 | 
             
                    parameters << "#{key} = #{value[@value]}"
         | 
| 17 17 | 
             
                  end
         | 
| 18 18 | 
             
                  parameters << 'attributes = {}'
         | 
| 19 | 
            +
                  parameters << 'indent'
         | 
| 19 20 | 
             
                  parameters << '&block'
         | 
| 20 21 | 
             
                  definition += '(' + parameters.join(', ') + ')'
         | 
| 21 22 |  | 
| 22 23 | 
             
                  buffer_eval 'instance_eval do'
         | 
| 23 24 | 
             
                  buffer_eval definition
         | 
| 24 25 |  | 
| 26 | 
            +
                  @in_definition = true
         | 
| 25 27 | 
             
                  node[@children].each do |child|
         | 
| 26 28 | 
             
                    root child, 0
         | 
| 27 29 | 
             
                  end
         | 
| 30 | 
            +
                  @in_definition = false
         | 
| 28 31 |  | 
| 29 32 | 
             
                  buffer_eval 'end'
         | 
| 30 33 | 
             
                  buffer_eval 'end'
         | 
| @@ -56,6 +59,11 @@ module Opulent | |
| 56 59 | 
             
                    end
         | 
| 57 60 | 
             
                    arguments << '{}'
         | 
| 58 61 |  | 
| 62 | 
            +
                    if @in_definition
         | 
| 63 | 
            +
                      arguments << "(indent ? indent + #{indent} : #{indent})"
         | 
| 64 | 
            +
                    else
         | 
| 65 | 
            +
                      arguments << indent
         | 
| 66 | 
            +
                    end
         | 
| 59 67 | 
             
                    method_call += '(' + arguments.join(', ') + ')'
         | 
| 60 68 | 
             
                    method_call += ' do' unless node[@children].empty?
         | 
| 61 69 |  | 
| @@ -105,7 +113,7 @@ module Opulent | |
| 105 113 |  | 
| 106 114 | 
             
                    arguments << call_attributes
         | 
| 107 115 |  | 
| 108 | 
            -
                    call = "#{key}(#{arguments.join ', '})"
         | 
| 116 | 
            +
                    call = "#{key}(#{arguments.join ', '}, #{indent})"
         | 
| 109 117 | 
             
                    call += ' do' unless node[@children].empty?
         | 
| 110 118 |  | 
| 111 119 | 
             
                    buffer_eval call
         | 
| @@ -14,18 +14,30 @@ module Opulent | |
| 14 14 | 
             
                    indentation = ' ' * indent
         | 
| 15 15 | 
             
                    inline = Settings::INLINE_NODE.include? node[@value]
         | 
| 16 16 |  | 
| 17 | 
            +
                    indentate = proc do
         | 
| 18 | 
            +
                      if @in_definition
         | 
| 19 | 
            +
                        buffer "' ' * (indent + #{indent})"
         | 
| 20 | 
            +
                      else
         | 
| 21 | 
            +
                        buffer_freeze indentation
         | 
| 22 | 
            +
                      end
         | 
| 23 | 
            +
                    end
         | 
| 24 | 
            +
             | 
| 17 25 | 
             
                    if inline
         | 
| 26 | 
            +
                      inline_last_sibling = @sibling_stack[-1][-1] ? Settings::INLINE_NODE.include?(@sibling_stack[-1][-1][1]) : true
         | 
| 27 | 
            +
             | 
| 18 28 | 
             
                      if @sibling_stack[-1][-1] && @sibling_stack[-1][-1][0] == :plain
         | 
| 19 | 
            -
                         | 
| 20 | 
            -
                       | 
| 21 | 
            -
             | 
| 29 | 
            +
                        buffer_remove_trailing_newline
         | 
| 30 | 
            +
                      end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                      if @in_definition || @sibling_stack[-1].length == 1 || !inline_last_sibling
         | 
| 33 | 
            +
                        indentate[]
         | 
| 22 34 | 
             
                      end
         | 
| 23 35 | 
             
                    else
         | 
| 24 | 
            -
                       | 
| 36 | 
            +
                      indentate[]
         | 
| 25 37 | 
             
                    end
         | 
| 26 38 |  | 
| 27 39 | 
             
                    @sibling_stack[-1] << [node[@type], node[@value]]
         | 
| 28 | 
            -
                    @sibling_stack << [ | 
| 40 | 
            +
                    @sibling_stack << [[node[@type], node[@value]]]
         | 
| 29 41 | 
             
                  end
         | 
| 30 42 |  | 
| 31 43 | 
             
                  # Add the tag opening, with leading whitespace to the code buffer
         | 
| @@ -80,17 +92,18 @@ module Opulent | |
| 80 92 | 
             
                      root child, indent + @settings[:indent]
         | 
| 81 93 | 
             
                    end
         | 
| 82 94 |  | 
| 95 | 
            +
                    inline_last_child = @sibling_stack[-1][-2] &&
         | 
| 96 | 
            +
                                        (@sibling_stack[-1][-2][0] == :plain ||
         | 
| 97 | 
            +
                                          Settings::INLINE_NODE.include?(@sibling_stack[-1][-2][1]))
         | 
| 98 | 
            +
             | 
| 83 99 | 
             
                    # Pretty print
         | 
| 84 100 | 
             
                    if @settings[:pretty]
         | 
| 85 | 
            -
                      if node[@children].length > 1 &&
         | 
| 86 | 
            -
                        @sibling_stack[-1][-1] &&
         | 
| 87 | 
            -
                        (@sibling_stack[-1][-1][0] == :plain ||
         | 
| 88 | 
            -
                          Settings::INLINE_NODE.include?(@sibling_stack[-1][-1][1]))
         | 
| 101 | 
            +
                      if node[@children].length > 1 && inline_last_child
         | 
| 89 102 | 
             
                        buffer_freeze "\n"
         | 
| 90 103 | 
             
                      end
         | 
| 91 104 |  | 
| 92 | 
            -
                      if node[@children].size > 0  | 
| 93 | 
            -
                         | 
| 105 | 
            +
                      if node[@children].size > 0 && !inline
         | 
| 106 | 
            +
                        indentate[]
         | 
| 94 107 | 
             
                      end
         | 
| 95 108 | 
             
                    end
         | 
| 96 109 |  | 
| @@ -100,7 +113,7 @@ module Opulent | |
| 100 113 |  | 
| 101 114 | 
             
                    # Pretty print
         | 
| 102 115 | 
             
                    if @settings[:pretty]
         | 
| 103 | 
            -
                      buffer_freeze "\n"  | 
| 116 | 
            +
                      buffer_freeze "\n" if !inline || @in_definition
         | 
| 104 117 | 
             
                    end
         | 
| 105 118 | 
             
                  end
         | 
| 106 119 |  | 
| @@ -15,7 +15,8 @@ module Opulent | |
| 15 15 | 
             
                  if @settings[:pretty]
         | 
| 16 16 | 
             
                    indentation = ' ' * indent
         | 
| 17 17 |  | 
| 18 | 
            -
                    inline = @sibling_stack[-1][-1] && | 
| 18 | 
            +
                    inline = @sibling_stack[-1][-1] &&
         | 
| 19 | 
            +
                             @sibling_stack[-1][-1][0] == :node &&
         | 
| 19 20 | 
             
                             Settings::INLINE_NODE.include?(@sibling_stack[-1][-1][1])
         | 
| 20 21 |  | 
| 21 22 | 
             
                    # Add current node to the siblings stack
         | 
| @@ -27,6 +28,7 @@ module Opulent | |
| 27 28 | 
             
                      if !inline
         | 
| 28 29 | 
             
                        value.gsub!(/^(?!$)/, indentation)
         | 
| 29 30 | 
             
                      else
         | 
| 31 | 
            +
                        buffer_remove_trailing_whitespace
         | 
| 30 32 | 
             
                        value.strip!
         | 
| 31 33 | 
             
                      end
         | 
| 32 34 | 
             
                    else
         | 
| @@ -50,7 +52,7 @@ module Opulent | |
| 50 52 |  | 
| 51 53 | 
             
                  # Pretty print
         | 
| 52 54 | 
             
                  if @settings[:pretty]
         | 
| 53 | 
            -
                    buffer_freeze "\n"  | 
| 55 | 
            +
                    buffer_freeze "\n" if !inline or node[@value] == :print
         | 
| 54 56 | 
             
                  end
         | 
| 55 57 | 
             
                end
         | 
| 56 58 | 
             
              end
         | 
    
        data/lib/opulent/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: opulent
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.8. | 
| 4 | 
            +
              version: 1.8.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Alex Grozav
         | 
| @@ -91,6 +91,7 @@ extra_rdoc_files: [] | |
| 91 91 | 
             
            files:
         | 
| 92 92 | 
             
            - ".gitignore"
         | 
| 93 93 | 
             
            - ".travis.yml"
         | 
| 94 | 
            +
            - CHANGELOG.md
         | 
| 94 95 | 
             
            - CODE_OF_CONDUCT.md
         | 
| 95 96 | 
             
            - Gemfile
         | 
| 96 97 | 
             
            - LICENSE.md
         |