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_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.
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/vanity/frameworks/rails.rb', line 184 def ab_test(name, &block) if Vanity.playground.using_js? @_vanity_experiments ||= {} @_vanity_experiments[name] ||= Vanity.playground.experiment(name.to_sym).choose value = @_vanity_experiments[name].value else value = Vanity.playground.experiment(name.to_sym).choose.value end 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_h(text) ⇒ Object
224 225 226 |
# File 'lib/vanity/frameworks/rails.rb', line 224 def vanity_h(text) h(text) end |
#vanity_html_safe(text) ⇒ Object
228 229 230 231 232 233 234 |
# File 'lib/vanity/frameworks/rails.rb', line 228 def vanity_html_safe(text) if text.respond_to?(:html_safe) text.html_safe else text end end |
#vanity_js ⇒ Object
217 218 219 220 221 222 |
# File 'lib/vanity/frameworks/rails.rb', line 217 def vanity_js return if @_vanity_experiments.nil? javascript_tag do render :file => Vanity.template("_vanity.js.erb") end end |
#vanity_simple_format(text, html_options = {}) ⇒ Object
236 237 238 |
# File 'lib/vanity/frameworks/rails.rb', line 236 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
206 207 208 209 |
# File 'lib/vanity/frameworks/rails.rb', line 206 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
212 213 214 215 |
# File 'lib/vanity/frameworks/rails.rb', line 212 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 |