Module: Vanity::Rails::Helpers
- Defined in:
- lib/vanity/frameworks/rails.rb
Overview
Introduces ab_test helper (controllers and views). Similar to the generic ab_test method, with the ability to capture content (applicable to views, see examples).
Instance Method Summary collapse
-
#ab_test(name, &block) ⇒ Object
This method returns one of the alternative values in the named A/B test.
- #vanity_h(text) ⇒ Object
- #vanity_html_safe(text) ⇒ Object
- #vanity_simple_format(text, html_options = {}) ⇒ Object
Instance Method Details
#ab_test(name, &block) ⇒ Object
This method returns one of the alternative values in the named A/B test.
142 143 144 145 146 147 148 149 150 |
# File 'lib/vanity/frameworks/rails.rb', line 142 def ab_test(name, &block) value = Vanity.playground.experiment(name).choose if block content = capture(value, &block) block_called_from_erb?(block) ? concat(content) : content else value end end |
#vanity_h(text) ⇒ Object
152 153 154 |
# File 'lib/vanity/frameworks/rails.rb', line 152 def vanity_h(text) h(text) end |
#vanity_html_safe(text) ⇒ Object
156 157 158 159 160 161 162 |
# File 'lib/vanity/frameworks/rails.rb', line 156 def vanity_html_safe(text) if text.respond_to?(:html_safe) text.html_safe else text end end |
#vanity_simple_format(text, html_options = {}) ⇒ Object
164 165 166 |
# File 'lib/vanity/frameworks/rails.rb', line 164 def vanity_simple_format(text, ={}) vanity_html_safe(simple_format(text, )) end |