musterb 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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"
@@ -1,4 +1,4 @@
1
- class Musterb::BindingExtractor < Musterb::Extractor
1
+ class Musterb::BindingExtractor
2
2
  attr_reader :value, :parent
3
3
 
4
4
  def initialize(_binding, parent)
@@ -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 = @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 < Musterb::Extractor
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 < Musterb::Extractor
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::NullExtractor < Musterb::Extractor
1
+ class Musterb::NullExtractor
2
2
  attr_reader :value, :parent
3
3
 
4
4
  def initialize(parent = nil)
@@ -8,4 +8,4 @@ class Musterb::NullExtractor < Musterb::Extractor
8
8
  def [](value)
9
9
  nil
10
10
  end
11
- end
11
+ end
@@ -1,4 +1,4 @@
1
- class Musterb::ObjectExtractor < Musterb::Extractor
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 < Musterb::Extractor
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 = template.locals.include?("initial_context") ? "Musterb::TemplateHandler.initial_context(initial_context)" : build_initial_context(template.locals.map(&:to_s))
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
@@ -1,3 +1,3 @@
1
1
  module Musterb
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -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
- initial_context = 2
51
- evaluate("{{to_s}}", binding, :locals => ["initial_context"]).should eq "2"
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.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 |-
@@ -1,4 +0,0 @@
1
- # Does nothing, but is a super class for other extractors
2
- class Musterb::Extractor
3
-
4
- end