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/renderer.rb,
lib/rabl/configuration.rb
Overview
Rabl.register!
Defined Under Namespace
Modules: Helpers, Partials Classes: Builder, Configuration, Engine, Railtie, Renderer
Constant Summary collapse
- VERSION =
"0.6.10"
Class Method Summary collapse
-
.configuration ⇒ Object
Returns the configuration options set for RABL Rabl.configuration.include_json_root => false.
-
.configure {|configuration| ... } ⇒ Object
Yields a RABL configuration block Rabl.configure do |config| config.include_json_root = false config.enable_json_callbacks = true end.
-
.register! ⇒ Object
Initialize RABL within an application Rabl.register!.
-
.render(object, source, options = {}) ⇒ Object
Renders an object using a specified template within an application.
-
.reset_configuration! ⇒ Object
Resets the RABL configuration back to the defaults.
-
.reset_source_cache! ⇒ Object
Resets the RABL source cache.
-
.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” }.
Class Method Details
.configuration ⇒ Object
Returns the configuration options set for RABL Rabl.configuration.include_json_root => false
38 39 40 |
# File 'lib/rabl.rb', line 38 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
31 32 33 34 |
# File 'lib/rabl.rb', line 31 def configure(&block) yield(configuration) configuration end |
.register! ⇒ Object
Initialize RABL within an application Rabl.register!
22 23 24 |
# File 'lib/rabl.rb', line 22 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”)
69 70 71 |
# File 'lib/rabl.rb', line 69 def render(object, source, = {}) Rabl::Renderer.new(source, object, ).render end |
.reset_configuration! ⇒ Object
Resets the RABL configuration back to the defaults.
43 44 45 |
# File 'lib/rabl.rb', line 43 def reset_configuration! @_configuration = nil end |
.reset_source_cache! ⇒ Object
Resets the RABL source cache
63 64 65 |
# File 'lib/rabl.rb', line 63 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” }
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rabl.rb', line 50 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 |