Class: Activr::Utils
- Inherits:
-
Object
- Object
- Activr::Utils
- Defined in:
- lib/activr/utils.rb
Overview
Utilities methods
Class Method Summary collapse
-
.class_for_kind(kind, suffix = nil) ⇒ Class
private
Returns class for given kind.
-
.compiled_mustache_template(tpl) ⇒ String
private
Get a compiled mustache template.
-
.kind_for_class(klass, suffix = nil) ⇒ String
private
Returns kind for given class.
-
.render_mustache(text, bindings) ⇒ String
private
Render a mustache template.
Class Method Details
.class_for_kind(kind, suffix = nil) ⇒ Class
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns class for given kind
31 32 33 34 |
# File 'lib/activr/utils.rb', line 31 def class_for_kind(kind, suffix = nil) str = suffix ? "#{kind}_#{suffix}" : kind str.camelize.constantize end |
.compiled_mustache_template(tpl) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get a compiled mustache template
47 48 49 50 51 52 53 54 55 |
# File 'lib/activr/utils.rb', line 47 def compiled_mustache_template(tpl) @compiled_mustache_templates ||= {} @compiled_mustache_templates[tpl] ||= begin view = Mustache.new view.raise_on_context_miss = true view.template = tpl # will compile and store template once for all view end end |
.kind_for_class(klass, suffix = nil) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns kind for given class
15 16 17 18 19 20 21 22 |
# File 'lib/activr/utils.rb', line 15 def kind_for_class(klass, suffix = nil) class_name = klass.to_s.split('::').last.underscore if suffix && (match_data = class_name.match(/(.+)_#{suffix}$/)) match_data[1] else class_name end end |
.render_mustache(text, bindings) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Render a mustache template
64 65 66 67 68 |
# File 'lib/activr/utils.rb', line 64 def render_mustache(text, bindings) tpl = self.compiled_mustache_template(text) tpl.raise_on_context_miss = true tpl.render(bindings) end |