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/sources.rb,
lib/rabl/tracker.rb,
lib/rabl/version.rb,
lib/rabl/digestor.rb,
lib/rabl/partials.rb,
lib/rabl/renderer.rb,
lib/rabl/cache_engine.rb,
lib/rabl/configuration.rb,
lib/rabl/multi_builder.rb

Overview

Defines the default cache engine for RABL when caching is invoked for a template. You can define your own caching engines by creating an object that responds to fetch and setting the configuration option:

config.cache_engine = AdvancedCacheEngine.new

Defined Under Namespace

Modules: Helpers, Partials, Sources Classes: Builder, CacheEngine, Configuration, Digestor, Engine, MultiBuilder, Railtie, Renderer, Tracker

Constant Summary collapse

VERSION =
"0.11.8"

Class Method Summary collapse

Class Method Details

.configurationObject

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



47
48
49
# File 'lib/rabl.rb', line 47

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:



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

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

.register!Object

Initialize RABL within an application Rabl.register!



31
32
33
# File 'lib/rabl.rb', line 31

def register!
  require 'rabl/template'
end

.render(object, source, options = {}) ⇒ Object

Renders an object using a specified template within an application. render(@post, ‘posts/show’, :view_path => “/path/to/app/views”)



76
77
78
# File 'lib/rabl.rb', line 76

def render(object, source, options = {})
  Rabl::Renderer.new(source, object, options).render
end

.reset_configuration!Object

Resets the RABL configuration back to the defaults.



52
53
54
# File 'lib/rabl.rb', line 52

def reset_configuration!
  @_configuration = nil
end

.reset_source_cache!Object

Resets the RABL source cache



70
71
72
# File 'lib/rabl.rb', line 70

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” }



59
60
61
62
63
64
65
66
67
# File 'lib/rabl.rb', line 59

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

  cache_key = [file, view_path].compact.join(":")

  @_source_cache ||= {}

  @_source_cache[cache_key] ||= yield
end