erbse 0.1.1 → 0.1.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/CHANGES.md +5 -0
- data/lib/erbse/parser.rb +4 -3
- data/lib/erbse/version.rb +1 -1
- data/test/erbse_test.rb +37 -2
- metadata +3 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 77e9086b4307a32040e9853a10a23bef166a0a70
         | 
| 4 | 
            +
              data.tar.gz: 584fb610b0bc9ada7d9a585be6c884b1556ba905
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 7da9ee8cc19f748691923be30243eaed954fa701be099e95d8c70648c4d94b810cbebde572f32fb5520d125529711342b6efc62afda130d5bbbea7bf0d27194a
         | 
| 7 | 
            +
              data.tar.gz: c40f64e244d4236e4c221ef5748a714d9096c5e8e3953fced3e434ed3c0a55065b025d1f025fd839d8e93e6d49791bc617f287324424db8def34a707dac400b3
         | 
    
        data/CHANGES.md
    CHANGED
    
    | @@ -1,3 +1,8 @@ | |
| 1 | 
            +
            # 0.1.2
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            * Postfix conditionals are now parsed properly: code such as `<% puts if true %>` now works, thanks to @aiomaster's work.
         | 
| 4 | 
            +
            * `<%@ code %>` now requires an explicit whitespace after the `@` for backward-compatibility.
         | 
| 5 | 
            +
             | 
| 1 6 | 
             
            # 0.1.1
         | 
| 2 7 |  | 
| 3 8 | 
             
            * Introduce the `<%@ %>` tag. This is a built-in capture mechanism. It will assign all block content to a local variable but *not* output it.
         | 
    
        data/lib/erbse/parser.rb
    CHANGED
    
    | @@ -1,9 +1,10 @@ | |
| 1 1 | 
             
            module Erbse
         | 
| 2 2 | 
             
              class Parser
         | 
| 3 3 | 
             
                # ERB_EXPR = /<%(=|\#)?(.*?)%>(\n)*/m # this is the desired pattern.
         | 
| 4 | 
            -
                ERB_EXPR = /<%( | 
| 4 | 
            +
                ERB_EXPR = /<%(=+|-|\#|@\s|%)?(.*?)[-=]?%>(\n)*/m # this is for backward-compatibility.
         | 
| 5 5 | 
             
                # BLOCK_EXPR     = /\s*((\s+|\))do|\{)(\s*\|[^|]*\|)?\s*\Z/
         | 
| 6 | 
            -
                BLOCK_EXPR = /\ | 
| 6 | 
            +
                BLOCK_EXPR = /\sdo\s*\z|\sdo\s+\|[^|]*\|\s*\z/
         | 
| 7 | 
            +
                BLOCK_EXEC = /\A\s*(if|unless)\b|#{BLOCK_EXPR}/
         | 
| 7 8 |  | 
| 8 9 | 
             
                # Parsing patterns
         | 
| 9 10 | 
             
                #
         | 
| @@ -48,7 +49,7 @@ module Erbse | |
| 48 49 | 
             
                      buffers.last << [:capture, :block, code, block = [:multi]] # picked up by our own BlockFilter. # TODO: merge with %= ?
         | 
| 49 50 | 
             
                      buffers << block
         | 
| 50 51 | 
             
                    else # <% %>
         | 
| 51 | 
            -
                      if code =~  | 
| 52 | 
            +
                      if code =~ BLOCK_EXEC
         | 
| 52 53 | 
             
                        buffers.last << [:block, code, block = [:multi]] # picked up by Temple's ControlFlow filter.
         | 
| 53 54 | 
             
                        buffers << block
         | 
| 54 55 | 
             
                      else
         | 
    
        data/lib/erbse/version.rb
    CHANGED
    
    
    
        data/test/erbse_test.rb
    CHANGED
    
    | @@ -125,6 +125,37 @@ blubb</b>} } | |
| 125 125 | 
             
                it { eval(Erbse::Engine.new.(str)).must_equal "1" }
         | 
| 126 126 | 
             
              end
         | 
| 127 127 |  | 
| 128 | 
            +
              describe "postfix conditional in expression tag" do
         | 
| 129 | 
            +
                let (:str) { %{<p><%= 'test' if true %></p>} }
         | 
| 130 | 
            +
                it { eval(Erbse::Engine.new.(str)).must_equal "<p>test</p>" }
         | 
| 131 | 
            +
              end
         | 
| 132 | 
            +
             | 
| 133 | 
            +
              describe "postfix conditional in execution tag" do
         | 
| 134 | 
            +
                let (:str) { %{<p><% foo = 'test' if true %><%= foo %></p>} }
         | 
| 135 | 
            +
                it { eval(Erbse::Engine.new.(str)).must_equal "<p>test</p>" }
         | 
| 136 | 
            +
              end
         | 
| 137 | 
            +
             | 
| 138 | 
            +
              describe "condition in multiline expression tag" do
         | 
| 139 | 
            +
                let (:str) { %{<p><%= if true
         | 
| 140 | 
            +
                                       'test'
         | 
| 141 | 
            +
                                      end %></p>} }
         | 
| 142 | 
            +
                it { eval(Erbse::Engine.new.(str)).must_equal "<p>test</p>" }
         | 
| 143 | 
            +
              end
         | 
| 144 | 
            +
             | 
| 145 | 
            +
              describe "multiline do-end-block in expression tag" do
         | 
| 146 | 
            +
                let (:str) { %{<%= [1,2].map do |i|
         | 
| 147 | 
            +
                             i+1
         | 
| 148 | 
            +
                           end.join %>} }
         | 
| 149 | 
            +
                it { eval(Erbse::Engine.new.(str)).must_equal "23" }
         | 
| 150 | 
            +
              end
         | 
| 151 | 
            +
             | 
| 152 | 
            +
              describe "multiline {}-block in expression tag" do
         | 
| 153 | 
            +
                let (:str) { %(<%= [3,1].map { |i|
         | 
| 154 | 
            +
                             i+1
         | 
| 155 | 
            +
                           }.join %>) }
         | 
| 156 | 
            +
                it { eval(Erbse::Engine.new.(str)).must_equal "42" }
         | 
| 157 | 
            +
              end
         | 
| 158 | 
            +
             | 
| 128 159 | 
             
              describe "<% \"string with do\" %>" do
         | 
| 129 160 | 
             
                it { Erbse::Parser.new.(%{<% var = "do 1" %><%= var %>}).must_equal [:multi, [:code, " var = \"do 1\" "], [:dynamic, " var "]] }
         | 
| 130 161 | 
             
                it { Erbse::Parser.new.(%{<% var = " do 1" %><%= var %>}).must_equal [:multi, [:code, " var = \" do 1\" "], [:dynamic, " var "]] }
         | 
| @@ -135,7 +166,7 @@ blubb</b>} } | |
| 135 166 | 
             
                it { Erbse::Parser.new.(%{<% form do |i| %>1<% end %>}).must_equal [:multi, [:block, " form do |i| ", [:multi, [:static, "1"]]]] }
         | 
| 136 167 | 
             
              end
         | 
| 137 168 |  | 
| 138 | 
            -
              describe " | 
| 169 | 
            +
              describe "<%@ %>" do
         | 
| 139 170 | 
             
                let (:str) { %{<%@ content = capture do %>
         | 
| 140 171 | 
             
              Yo!
         | 
| 141 172 | 
             
              <%= 1 %>
         | 
| @@ -143,8 +174,12 @@ blubb</b>} } | |
| 143 174 |  | 
| 144 175 | 
             
                it do
         | 
| 145 176 | 
             
                  ruby = Erbse::Engine.new.(str).gsub("\n", "@").gsub('\n', "@@")
         | 
| 146 | 
            -
                  code = %{_buf = []; | 
| 177 | 
            +
                  code = %{_buf = []; content = capture do ; _erbse_blockfilter1 = ''; @; _erbse_blockfilter1 << (\"  Yo!@@  \".freeze); _erbse_blockfilter1 << (( 1 ).to_s); @; _erbse_blockfilter1; end; _buf = _buf.join(\"\".freeze)}
         | 
| 147 178 | 
             
                  ruby.must_equal code
         | 
| 148 179 | 
             
                end
         | 
| 180 | 
            +
             | 
| 181 | 
            +
                it do
         | 
| 182 | 
            +
                  Erbse::Parser.new.(%{<%@content = capture do %><% end %>}).must_equal [:multi, [:block, "@content = capture do ", [:multi]]]
         | 
| 183 | 
            +
                end
         | 
| 149 184 | 
             
              end
         | 
| 150 185 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: erbse
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.1. | 
| 4 | 
            +
              version: 0.1.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Nick Sutterer
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2017-12-25 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: temple
         | 
| @@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 98 98 | 
             
                  version: '0'
         | 
| 99 99 | 
             
            requirements: []
         | 
| 100 100 | 
             
            rubyforge_project: 
         | 
| 101 | 
            -
            rubygems_version: 2. | 
| 101 | 
            +
            rubygems_version: 2.6.8
         | 
| 102 102 | 
             
            signing_key: 
         | 
| 103 103 | 
             
            specification_version: 4
         | 
| 104 104 | 
             
            summary: Updated Erubis.
         |