Module: Rabl

Defined in:
lib/rabl.rb,
lib/rabl/engine.rb,
lib/rabl/builder.rb,
lib/rabl/helpers.rb,
lib/rabl/railtie.rb,
lib/rabl/version.rb,
lib/rabl/partials.rb,
lib/rabl/configuration.rb

Overview

Rabl.register!

Defined Under Namespace

Modules: Helpers, Partials Classes: Builder, Configuration, Engine, Railtie

Constant Summary collapse

VERSION =
"0.6.7"

Class Method Summary collapse

Class Method Details

.configurationObject

Returns the configuration options set for RABL Rabl.configuration.include_json_root => false



35
36
37
# File 'lib/rabl.rb', line 35

def configuration
  @_configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields a RABL configuration block Rabl.configure do |config|

config.include_json_root     = false
config.enable_json_callbacks = true

end

Yields:



28
29
30
31
# File 'lib/rabl.rb', line 28

def configure(&block)
  yield(configuration)
  configuration
end

.register!Object



19
20
21
# File 'lib/rabl.rb', line 19

def register!
  require 'rabl/template'
end

.reset_configuration!Object

Resets the RABL configuration back to the defaults.



40
41
42
# File 'lib/rabl.rb', line 40

def reset_configuration!
  @_configuration = nil
end

.reset_source_cache!Object

Resets the RABL source cache



60
61
62
# File 'lib/rabl.rb', line 60

def reset_source_cache!
  @_source_cache = {}
end

.source_cache(file, view_path, &block) ⇒ Object

Fetches from the source_cache, stores block result in cache if nil Used to cache the contents and paths to various rabl templates source_cache(“users/index”, “path/to/view”) { “/full/path/to/template/users/index” }



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rabl.rb', line 47

def source_cache(file, view_path, &block)
  return yield unless Rabl.configuration.cache_sources

  @_source_cache ||= {}
  cache_key = [file, view_path].compact.join(":")
  if cached_result = @_source_cache[cache_key]
    cached_result
  else # store result of block
    @_source_cache[cache_key] = yield
  end
end