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_experiments ⇒ Object
Return a copy of the active experiments on a page.
- #vanity_h(text) ⇒ Object
- #vanity_html_safe(text) ⇒ Object
- #vanity_js ⇒ Object
- #vanity_simple_format(text, html_options = {}) ⇒ Object
-
#vanity_track_url_for(identity, metric, options = {}) ⇒ Object
Generate url with the identity of the current user and the metric to track on click.
-
#vanity_tracking_image(identity, metric, options = {}) ⇒ Object
Generate url with the fingerprint for the current Vanity experiment.
Instance Method Details
#ab_test(name, &block) ⇒ Object
This method returns one of the alternative values in the named A/B test.
226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/vanity/frameworks/rails.rb', line 226 def ab_test(name, &block) value = setup_experiment(name) if block content = capture(value, &block) if defined?(block_called_from_erb?) && block_called_from_erb?(block) concat(content) else content end else value end end |
#vanity_experiments ⇒ Object
Return a copy of the active experiments on a page
293 294 295 296 297 298 299 300 301 302 |
# File 'lib/vanity/frameworks/rails.rb', line 293 def vanity_experiments @_vanity_experiments ||= {} experiments = {} @_vanity_experiments.each do |name, alternative| experiments[name] = alternative.clone end experiments end |
#vanity_h(text) ⇒ Object
260 261 262 |
# File 'lib/vanity/frameworks/rails.rb', line 260 def vanity_h(text) h(text) end |
#vanity_html_safe(text) ⇒ Object
264 265 266 267 268 269 270 |
# File 'lib/vanity/frameworks/rails.rb', line 264 def vanity_html_safe(text) if text.respond_to?(:html_safe) text.html_safe else text end end |
#vanity_js ⇒ Object
253 254 255 256 257 258 |
# File 'lib/vanity/frameworks/rails.rb', line 253 def vanity_js return if @_vanity_experiments.nil? || @_vanity_experiments.empty? javascript_tag do render :file => Vanity.template("_vanity"), :formats => [:js] end end |
#vanity_simple_format(text, html_options = {}) ⇒ Object
272 273 274 |
# File 'lib/vanity/frameworks/rails.rb', line 272 def vanity_simple_format(text, ={}) vanity_html_safe(simple_format(text, )) end |
#vanity_track_url_for(identity, metric, options = {}) ⇒ Object
Generate url with the identity of the current user and the metric to track on click
242 243 244 245 |
# File 'lib/vanity/frameworks/rails.rb', line 242 def vanity_track_url_for(identity, metric, = {}) = .merge(:_identity => identity, :_track => metric) url_for() end |
#vanity_tracking_image(identity, metric, options = {}) ⇒ Object
Generate url with the fingerprint for the current Vanity experiment
248 249 250 251 |
# File 'lib/vanity/frameworks/rails.rb', line 248 def vanity_tracking_image(identity, metric, = {}) = .merge(:controller => :vanity, :action => :image, :_identity => identity, :_track => metric) image_tag(url_for(), :width => "1px", :height => "1px", :alt => "") end |