rabl-rails 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # CHANGELOG
2
+
3
+ ## 0.1.1
4
+
5
+ * Add CHANGELOG
6
+ * Remove unnused test in loop
7
+ * Speed up rendering by not double copying variable from context
8
+ * Rename private variable to avoid name conflict
9
+ * Remove sqlite3 development dependency
data/Gemfile.lock CHANGED
@@ -53,7 +53,6 @@ GEM
53
53
  hike (~> 1.2)
54
54
  rack (~> 1.0)
55
55
  tilt (~> 1.1, != 1.3.0)
56
- sqlite3 (1.3.6)
57
56
  thor (0.15.4)
58
57
  tilt (1.3.3)
59
58
  yajl-ruby (1.1.0)
@@ -65,5 +64,4 @@ DEPENDENCIES
65
64
  actionpack (~> 3.0)
66
65
  rabl-rails!
67
66
  rspec-mocks
68
- sqlite3
69
67
  yajl-ruby
@@ -3,11 +3,11 @@ module RablRails
3
3
  class PartialError < StandardError; end
4
4
 
5
5
  class Base
6
- attr_accessor :options
6
+ attr_accessor :_options
7
7
 
8
8
  def initialize(context) # :nodoc:
9
9
  @_context = context
10
- @options = {}
10
+ @_options = {}
11
11
  setup_render_context
12
12
  end
13
13
 
@@ -18,10 +18,10 @@ module RablRails
18
18
  # method defined by the renderer.
19
19
  #
20
20
  def render(template)
21
- collection_or_resource = @_context.instance_variable_get(template.data) if template.data
21
+ collection_or_resource = instance_variable_get(template.data) if template.data
22
22
  output_hash = collection_or_resource.respond_to?(:each) ? render_collection(collection_or_resource, template.source) :
23
23
  render_resource(collection_or_resource, template.source)
24
- options[:root_name] = template.root_name
24
+ _options[:root_name] = template.root_name
25
25
  format_output(output_hash)
26
26
  end
27
27
 
@@ -54,7 +54,7 @@ module RablRails
54
54
  when Hash
55
55
  current_value = value.dup
56
56
  data_symbol = current_value.delete(:_data)
57
- object = data_symbol.nil? ? data : data_symbol.to_s.start_with?('@') ? @_context.instance_variable_get(data_symbol) : data.send(data_symbol)
57
+ object = data_symbol.nil? ? data : data_symbol.to_s.start_with?('@') ? instance_variable_get(data_symbol) : data.send(data_symbol)
58
58
 
59
59
  if key.to_s.start_with?('_') # glue
60
60
  current_value.each_pair { |k, v|
@@ -108,7 +108,7 @@ module RablRails
108
108
  #
109
109
  def setup_render_context
110
110
  @_context.instance_variable_get(:@_assigns).each_pair { |k, v|
111
- instance_variable_set("@#{k}", v) unless k.start_with?('_') || k == @data
111
+ instance_variable_set("@#{k}", v) unless k.start_with?('_')
112
112
  }
113
113
  end
114
114
  end
@@ -2,7 +2,7 @@ module RablRails
2
2
  module Renderers
3
3
  class JSON < Base
4
4
  def format_output(hash)
5
- hash = { options[:root_name] => hash } if options[:root_name] && RablRails.include_json_root
5
+ hash = { _options[:root_name] => hash } if _options[:root_name] && RablRails.include_json_root
6
6
  MultiJson.encode(hash)
7
7
  end
8
8
  end
@@ -1,3 +1,3 @@
1
1
  module RablRails
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
data/rabl-rails.gemspec CHANGED
@@ -18,6 +18,5 @@ Gem::Specification.new do |s|
18
18
  s.add_dependency "activesupport", "~> 3.0"
19
19
  s.add_dependency "railties", "~> 3.0"
20
20
 
21
- s.add_development_dependency "sqlite3"
22
21
  s.add_development_dependency "actionpack", "~> 3.0"
23
22
  end
@@ -22,9 +22,8 @@ class DeepNestingTest < ActiveSupport::TestCase
22
22
  @user.stub(:respond_to?).with(:each).and_return(false)
23
23
 
24
24
  @context = Context.new
25
- @context.stub(:instance_variable_get).with(:@user).and_return(@user)
26
- @context.stub(:instance_variable_get).with(:@virtual_path).and_return('users/show')
27
- @context.stub(:instance_variable_get).with(:@_assigns).and_return({})
25
+ @context.assigns['user'] = @user
26
+ @context.virtual_path = 'users/show'
28
27
  @context.stub(:lookup_context).and_return(mock(:find_template => mock(:source => %{ object :@comment\n attribute :content })))
29
28
  end
30
29
 
@@ -7,8 +7,7 @@ class TestJsonRenderer < ActiveSupport::TestCase
7
7
  @data.stub(:respond_to?).with(:each).and_return(false)
8
8
 
9
9
  @context = Context.new
10
- @context.stub(:instance_variable_get).with(:@data).and_return(@data)
11
- @context.stub(:instance_variable_get).with(:@_assigns).and_return({})
10
+ @context.assigns['data'] = @data
12
11
 
13
12
  @template = RablRails::CompiledTemplate.new
14
13
  @template.data = :@data
@@ -24,7 +23,7 @@ class TestJsonRenderer < ActiveSupport::TestCase
24
23
  end
25
24
 
26
25
  test "render collection with empty template" do
27
- @context.stub(:instance_variable_get).with(:@data).and_return([@data])
26
+ @context.assigns['data'] = [@data]
28
27
  @template.source = {}
29
28
  assert_equal %q([{}]), render_json_output
30
29
  end
@@ -52,7 +51,7 @@ class TestJsonRenderer < ActiveSupport::TestCase
52
51
 
53
52
  test "render collection with attributes" do
54
53
  @data = [User.new(1, 'foo', 'male'), User.new(2, 'bar', 'female')]
55
- @context.stub(:instance_variable_get).with(:@data).and_return(@data)
54
+ @context.assigns['data'] = @data
56
55
  @template.source = { :uid => :id, :name => :name, :gender => :sex }
57
56
  assert_equal %q([{"uid":1,"name":"foo","gender":"male"},{"uid":2,"name":"bar","gender":"female"}]), render_json_output
58
57
  end
@@ -87,8 +86,8 @@ class TestJsonRenderer < ActiveSupport::TestCase
87
86
 
88
87
  test "partial should be evaluated at rendering time" do
89
88
  # Set assigns
90
- @context.stub(:instance_variable_get).with(:@_assigns).and_return({'user' => @data})
91
89
  @data.stub(:respond_to?).with(:empty?).and_return(false)
90
+ @context.assigns['user'] = @data
92
91
 
93
92
  # Stub Library#get
94
93
  t = RablRails::CompiledTemplate.new
data/test/test_helper.rb CHANGED
@@ -31,10 +31,15 @@ module ActiveSupport
31
31
  end
32
32
 
33
33
  class Context
34
- attr_accessor :virtual_path
35
-
34
+ attr_writer :virtual_path
35
+
36
36
  def initialize
37
37
  @_assigns = {}
38
+ @virtual_path = nil
39
+ end
40
+
41
+ def assigns
42
+ @_assigns
38
43
  end
39
44
 
40
45
  def params
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rabl-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-24 00:00:00.000000000 Z
12
+ date: 2012-07-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -43,22 +43,6 @@ dependencies:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
45
  version: '3.0'
46
- - !ruby/object:Gem::Dependency
47
- name: sqlite3
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
46
  - !ruby/object:Gem::Dependency
63
47
  name: actionpack
64
48
  requirement: !ruby/object:Gem::Requirement
@@ -83,6 +67,7 @@ extensions: []
83
67
  extra_rdoc_files: []
84
68
  files:
85
69
  - .gitignore
70
+ - CHANGELOG.md
86
71
  - Gemfile
87
72
  - Gemfile.lock
88
73
  - MIT-LICENSE
@@ -126,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
111
  version: '0'
127
112
  requirements: []
128
113
  rubyforge_project:
129
- rubygems_version: 1.8.21
114
+ rubygems_version: 1.8.22
130
115
  signing_key:
131
116
  specification_version: 3
132
117
  summary: Fast Rails 3+ templating system with JSON and XML support