rabl 0.5.5.c → 0.5.5.d

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 0.5.5.a-c
3
+ ## 0.5.5.a-d
4
4
 
5
5
  * Change engine to only instantiate one builder when rendering a collection
6
6
  * Alias to\_msgpack to to\_mpac
7
- * Cache template sources for faster partial lookups
7
+ * Cache template sources for faster partial lookups (thanks cj)
8
8
 
9
9
  ## 0.5.4
10
10
 
data/README.md CHANGED
@@ -97,7 +97,8 @@ RABL is intended to require little to no configuration to get working. This is t
97
97
  ```ruby
98
98
  # config/initializers/rabl_init.rb
99
99
  Rabl.configure do |config|
100
- # Commented as these are the defaults
100
+ # Commented as these are defaults
101
+ # config.cache_sources = false
101
102
  # config.json_engine = nil # Any multi\_json engines
102
103
  # config.msgpack_engine = nil # Defaults to ::MessagePack
103
104
  # config.include_json_root = true
@@ -108,9 +109,16 @@ Rabl.configure do |config|
108
109
  end
109
110
  ```
110
111
 
111
- Each option specifies behavior related to RABL's output. If `include_json_root` is disabled that removes the root node for each child in the output, and `enable_json_callbacks` enables support for 'jsonp' style callback output if the incoming request has a 'callback' parameter.
112
+ Each option specifies behavior related to RABL's output. If `include_json_root` is disabled that removes the
113
+ root node for each child in the output, and `enable_json_callbacks` enables support for 'jsonp' style callback
114
+ output if the incoming request has a 'callback' parameter.
112
115
 
113
- Note that the `json_engine` option uses the [multi_json](http://intridea.com/2010/6/14/multi-json-the-swappable-json-handler) intelligent engine defaults so in most cases you **don't need to configure this** directly. If you wish to use yajl as the primary JSON encoding engine simply add that to your Gemfile:
116
+ If `cache_sources` is set to `true`, template lookups will be cached for improved performance.
117
+ The cache can be reset manually by running `Rabl.reset_source_cache!` within your application.
118
+
119
+ Note that the `json_engine` option uses the [multi_json](http://intridea.com/2010/6/14/multi-json-the-swappable-json-handler) intelligent engine
120
+ defaults so in most cases you **don't need to configure this** directly. If you wish to use yajl as
121
+ the primary JSON encoding engine simply add that to your Gemfile:
114
122
 
115
123
  ```ruby
116
124
  # Gemfile
@@ -45,6 +45,8 @@ module Rabl
45
45
  # Used to cache the contents and paths to various rabl templates
46
46
  # source_cache("users/index", "path/to/view") { "/full/path/to/template/users/index" }
47
47
  def source_cache(file, view_path, &block)
48
+ return yield unless Rabl.configuration.cache_sources
49
+
48
50
  @_source_cache ||= {}
49
51
  cache_key = [file, view_path].compact.join(":")
50
52
  if cached_result = @_source_cache[cache_key]
@@ -16,6 +16,7 @@ module Rabl
16
16
  attr_accessor :enable_json_callbacks
17
17
  attr_writer :msgpack_engine
18
18
  attr_writer :xml_options
19
+ attr_accessor :cache_sources
19
20
 
20
21
  DEFAULT_XML_OPTIONS = { :dasherize => true, :skip_types => false }
21
22
 
@@ -27,6 +28,7 @@ module Rabl
27
28
  @json_engine = nil
28
29
  @msgpack_engine = nil
29
30
  @xml_options = {}
31
+ @cache_sources = false
30
32
  end
31
33
 
32
34
  # @param [Symbol, String, #encode] engine_name The name of a JSON engine,
@@ -7,21 +7,20 @@ module Rabl
7
7
  def initialize(source, options={})
8
8
  @_source = source
9
9
  @_options = options
10
- @_compiled = false
11
10
  end
12
11
 
13
12
  # Renders the representation based on source, object, scope and locals
14
13
  # Rabl::Engine.new("...source...", { :format => "xml" }).render(scope, { :foo => "bar", :object => @user })
15
14
  def render(scope, locals, &block)
15
+ clear_options!
16
16
  @_locals, @_scope = locals, scope
17
17
  self.copy_instance_variables_from(@_scope, [:@assigns, :@helpers])
18
- clear_compile_state
19
18
  @_options[:scope] = @_scope
20
19
  @_options[:format] ||= self.request_format
21
20
  @_data = locals[:object] || self.default_object
22
21
  if @_options[:source_location]
23
22
  instance_eval(@_source, @_options[:source_location]) if @_source.present?
24
- else
23
+ else # without source location
25
24
  instance_eval(@_source) if @_source.present?
26
25
  end
27
26
  instance_eval(&block) if block_given?
@@ -194,7 +193,7 @@ module Rabl
194
193
 
195
194
  private
196
195
 
197
- def clear_compile_state
196
+ def clear_options!
198
197
  @_options.delete(:extends)
199
198
  @_options.delete(:attributes)
200
199
  @_options.delete(:node)
@@ -6,5 +6,6 @@ module Rabl
6
6
  Rabl.register!
7
7
  end
8
8
  end
9
- end
10
- end
9
+
10
+ end # Railtie
11
+ end # Rabl
@@ -1,3 +1,3 @@
1
1
  module Rabl
2
- VERSION = "0.5.5.c"
2
+ VERSION = "0.5.5.d"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rabl
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 6
5
- version: 0.5.5.c
5
+ version: 0.5.5.d
6
6
  platform: ruby
7
7
  authors:
8
8
  - Nathan Esquenazi