musterb 1.0.0 → 1.0.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.
- data/lib/musterb.rb +0 -1
- data/lib/musterb/binding_extractor.rb +1 -1
- data/lib/musterb/extract_values.rb +1 -3
- data/lib/musterb/hash_extractor.rb +3 -3
- data/lib/musterb/instance_variable_extractor.rb +2 -2
- data/lib/musterb/null_extractor.rb +2 -2
- data/lib/musterb/object_extractor.rb +3 -3
- data/lib/musterb/rails_locals_extractor.rb +2 -2
- data/lib/musterb/template_handler.rb +3 -5
- data/lib/musterb/version.rb +1 -1
- data/spec/musterb/template_handler_spec.rb +2 -2
- metadata +1 -3
- data/lib/musterb/extractor.rb +0 -4
    
        data/lib/musterb.rb
    CHANGED
    
    | @@ -5,7 +5,6 @@ module Musterb | |
| 5 5 |  | 
| 6 6 | 
             
              autoload :ExtractValues,             "musterb/extract_values"
         | 
| 7 7 | 
             
              autoload :Musterbifier,              "musterb/musterbifier"
         | 
| 8 | 
            -
              autoload :Extractor,                 "musterb/extractor"
         | 
| 9 8 | 
             
              autoload :BindingExtractor,          "musterb/binding_extractor"
         | 
| 10 9 | 
             
              autoload :HashExtractor,             "musterb/hash_extractor"
         | 
| 11 10 | 
             
              autoload :ObjectExtractor,           "musterb/object_extractor"
         | 
| @@ -11,10 +11,8 @@ module Musterb::ExtractValues | |
| 11 11 | 
             
                Musterb::Chain.new self[symbol]
         | 
| 12 12 | 
             
              end
         | 
| 13 13 |  | 
| 14 | 
            -
              def self.new_context(value, old_context =  | 
| 14 | 
            +
              def self.new_context(value, old_context = Musterb::NullExtractor.new)
         | 
| 15 15 | 
             
                case value
         | 
| 16 | 
            -
                when Musterb::Extractor
         | 
| 17 | 
            -
                  value
         | 
| 18 16 | 
             
                when Hash
         | 
| 19 17 | 
             
                  Musterb::HashExtractor.new(value, old_context)
         | 
| 20 18 | 
             
                when nil
         | 
| @@ -1,9 +1,9 @@ | |
| 1 1 | 
             
            require 'hashie'
         | 
| 2 2 |  | 
| 3 | 
            -
            class Musterb::HashExtractor | 
| 3 | 
            +
            class Musterb::HashExtractor
         | 
| 4 4 | 
             
              attr_reader :parent, :value
         | 
| 5 5 |  | 
| 6 | 
            -
              def initialize(value, parent)
         | 
| 6 | 
            +
              def initialize(value, parent)    
         | 
| 7 7 | 
             
                @value = to_string_access(value)
         | 
| 8 8 | 
             
                @parent = parent
         | 
| 9 9 | 
             
              end
         | 
| @@ -23,4 +23,4 @@ class Musterb::HashExtractor < Musterb::Extractor | |
| 23 23 | 
             
                  hash.hashie_stringify_keys!
         | 
| 24 24 | 
             
                end
         | 
| 25 25 | 
             
              end
         | 
| 26 | 
            -
            end
         | 
| 26 | 
            +
            end
         | 
| @@ -1,4 +1,4 @@ | |
| 1 | 
            -
            class Musterb::InstanceVariableExtractor | 
| 1 | 
            +
            class Musterb::InstanceVariableExtractor
         | 
| 2 2 | 
             
              attr_reader :parent, :value
         | 
| 3 3 |  | 
| 4 4 | 
             
              def initialize(value, parent)
         | 
| @@ -13,4 +13,4 @@ class Musterb::InstanceVariableExtractor < Musterb::Extractor | |
| 13 13 | 
             
                  @parent[symbol]
         | 
| 14 14 | 
             
                end
         | 
| 15 15 | 
             
              end
         | 
| 16 | 
            -
            end
         | 
| 16 | 
            +
            end
         | 
| @@ -1,4 +1,4 @@ | |
| 1 | 
            -
            class Musterb::ObjectExtractor | 
| 1 | 
            +
            class Musterb::ObjectExtractor
         | 
| 2 2 | 
             
              attr_reader :parent, :value
         | 
| 3 3 |  | 
| 4 4 | 
             
              def initialize(value, parent)
         | 
| @@ -6,11 +6,11 @@ class Musterb::ObjectExtractor < Musterb::Extractor | |
| 6 6 | 
             
                @parent = parent
         | 
| 7 7 | 
             
              end
         | 
| 8 8 |  | 
| 9 | 
            -
              def [](symbol)
         | 
| 9 | 
            +
              def [](symbol)    
         | 
| 10 10 | 
             
                if @value.respond_to? symbol
         | 
| 11 11 | 
             
                  @value.send(symbol)
         | 
| 12 12 | 
             
                else
         | 
| 13 13 | 
             
                  @parent[symbol]
         | 
| 14 14 | 
             
                end
         | 
| 15 15 | 
             
              end
         | 
| 16 | 
            -
            end
         | 
| 16 | 
            +
            end
         | 
| @@ -1,4 +1,4 @@ | |
| 1 | 
            -
            class Musterb::RailsLocalsExtractor | 
| 1 | 
            +
            class Musterb::RailsLocalsExtractor
         | 
| 2 2 | 
             
              attr_reader :parent, :value
         | 
| 3 3 |  | 
| 4 4 | 
             
              def initialize(locals, binding, parent)
         | 
| @@ -14,4 +14,4 @@ class Musterb::RailsLocalsExtractor < Musterb::Extractor | |
| 14 14 | 
             
                  parent[symbol]
         | 
| 15 15 | 
             
                end
         | 
| 16 16 | 
             
              end
         | 
| 17 | 
            -
            end
         | 
| 17 | 
            +
            end
         | 
| @@ -15,15 +15,13 @@ class Musterb::TemplateHandler < Musterb::Musterbifier | |
| 15 15 | 
             
              end
         | 
| 16 16 |  | 
| 17 17 | 
             
              def self.build_initial_context(locals)
         | 
| 18 | 
            +
                return "initial_context" if locals.include?("initial_context")
         | 
| 19 | 
            +
                return "Musterb::ExtractValues.new_context(mustache)" if locals.include?("mustache")
         | 
| 18 20 | 
             
                "Musterb::RailsLocalsExtractor.new(#{locals.inspect}, binding, Musterb::InstanceVariableExtractor.new(self, Musterb::NullExtractor.new))"
         | 
| 19 21 | 
             
              end
         | 
| 20 22 |  | 
| 21 | 
            -
              def self.initial_context(initial_context)
         | 
| 22 | 
            -
                Musterb::ExtractValues.new_context(initial_context)
         | 
| 23 | 
            -
              end
         | 
| 24 | 
            -
             | 
| 25 23 | 
             
              def self.call(template)
         | 
| 26 | 
            -
                initial_context =  | 
| 24 | 
            +
                initial_context = build_initial_context(template.locals.map(&:to_s))
         | 
| 27 25 | 
             
                erb = Musterb.to_erb(template.source, :musterbifier_klass => self, :initial_context => initial_context)
         | 
| 28 26 | 
             
                klass = ActionView::Template::Handlers::ERB
         | 
| 29 27 | 
             
                klass.erb_implementation.new(erb, :trim => (klass.erb_trim_mode == "-")).src
         | 
    
        data/lib/musterb/version.rb
    CHANGED
    
    
| @@ -47,7 +47,7 @@ describe Musterb::TemplateHandler do | |
| 47 47 | 
             
              end
         | 
| 48 48 |  | 
| 49 49 | 
             
              it "can set the initial context to a hash" do
         | 
| 50 | 
            -
                 | 
| 51 | 
            -
                evaluate("{{to_s}}", binding, :locals => [" | 
| 50 | 
            +
                mustache = 2
         | 
| 51 | 
            +
                evaluate("{{to_s}}", binding, :locals => ["mustache"]).should eq "2"
         | 
| 52 52 | 
             
              end
         | 
| 53 53 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: musterb
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.0. | 
| 4 | 
            +
              version: 1.0.1
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -121,8 +121,6 @@ files: | |
| 121 121 | 
             
              bGliL211c3RlcmIvZXZhbHVhdG9yLnJi
         | 
| 122 122 | 
             
            - !binary |-
         | 
| 123 123 | 
             
              bGliL211c3RlcmIvZXh0cmFjdF92YWx1ZXMucmI=
         | 
| 124 | 
            -
            - !binary |-
         | 
| 125 | 
            -
              bGliL211c3RlcmIvZXh0cmFjdG9yLnJi
         | 
| 126 124 | 
             
            - !binary |-
         | 
| 127 125 | 
             
              bGliL211c3RlcmIvaGFzaF9leHRyYWN0b3IucmI=
         | 
| 128 126 | 
             
            - !binary |-
         | 
    
        data/lib/musterb/extractor.rb
    DELETED