abongo 1.0.7 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
1
  class Abongo
2
- VERSION = '1.0.7'
2
+ VERSION = '1.0.8'
3
3
  MAJOR_VERSION = '1'
4
4
  end
@@ -1,4 +1,4 @@
1
1
  class Abongo
2
- VERSION = '1.0.6'
2
+ VERSION = '1.0.7'
3
3
  MAJOR_VERSION = '1'
4
4
  end
@@ -71,7 +71,7 @@ class Abongo
71
71
  if (style == :prototype)
72
72
  script = "var a=Math.floor(Math.random()*11); var b=Math.floor(Math.random()*11);var x=new Ajax.Request('#{url}', {parameters:{a: a, b: b, c: a+b}})"
73
73
  elsif (style == :jquery)
74
- script = "var a=Math.floor(Math.random()*11); var b=Math.floor(Math.random()*11);var x=jQuery.post('#{url}', {a: a, b: b, c: a+b})"
74
+ script = "jQuery(document).ready(function(){var a=Math.floor(Math.random()*11); var b=Math.floor(Math.random()*11);var x=jQuery.post('#{url}', {a: a, b: b, c: a+b})});"
75
75
  end
76
76
  script.nil? ? "" : %Q|<script type="text/javascript">#{script}</script>|.html_safe
77
77
  end
@@ -0,0 +1,79 @@
1
+ #Gives you easy syntax to use ABongo in your views.
2
+
3
+ class Abongo
4
+ module ViewHelper
5
+
6
+ def ab_test(test_name, alternatives = nil, options = {}, &block)
7
+ @choices ||= {}
8
+ unless @choices[test_name]
9
+ if (Abongo.options[:enable_specification] && !params[test_name].nil?)
10
+ @choices[test_name] = params[test_name]
11
+ elsif (Abongo.options[:enable_override_in_session] && !session[test_name].nil?)
12
+ @choices[test_name] = session[test_name]
13
+ elsif (Abongo.options[:enable_selection] && !params[test_name].nil?)
14
+ @choices[test_name] = Abongo.parse_alternatives(alternatives)[params[test_name].to_i]
15
+ elsif (alternatives.nil?)
16
+ begin
17
+ @choices[test_name] = Abongo.flip(test_name, options)
18
+ rescue
19
+ if Abongo.options[:failsafe]
20
+ @choices[test_name] = true
21
+ else
22
+ raise
23
+ end
24
+ end
25
+ else
26
+ begin
27
+ @choices[test_name] = Abongo.test(test_name, alternatives, options)
28
+ rescue
29
+ if Abongo.options[:failsafe]
30
+ @choices[test_name] = Abongo.parse_alternatives(alternatives).first
31
+ else
32
+ raise
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ if block
39
+ content_tag = capture(@choices[test_name], &block)
40
+ Rails::VERSION::MAJOR <= 2 && block_called_from_erb?(block) ? concat(content_tag) : content_tag
41
+ else
42
+ @choices[test_name]
43
+ end
44
+ end
45
+
46
+ def bongo!(test_name, options = {})
47
+ begin
48
+ Abongo.bongo!(test_name, options)
49
+ rescue
50
+ if Abongo.options[:failsafe]
51
+ return
52
+ else
53
+ raise
54
+ end
55
+ end
56
+ end
57
+
58
+ #This causes an AJAX post against the URL. That URL should call Abongo.human!
59
+ #This guarantees that anyone calling Abongo.human! is capable of at least minimal Javascript execution, and thus is (probably) not a robot.
60
+ def include_humanizing_javascript(url = "/abongo_mark_human", style = :prototype)
61
+ begin
62
+ return if Abongo.is_human?
63
+ rescue
64
+ if Abongo.options[:failsafe]
65
+ else
66
+ raise
67
+ end
68
+ end
69
+
70
+ script = nil
71
+ if (style == :prototype)
72
+ script = "var a=Math.floor(Math.random()*11); var b=Math.floor(Math.random()*11);var x=new Ajax.Request('#{url}', {parameters:{a: a, b: b, c: a+b}})"
73
+ elsif (style == :jquery)
74
+ script = "var a=Math.floor(Math.random()*11); var b=Math.floor(Math.random()*11);var x=jQuery.post('#{url}', {a: a, b: b, c: a+b})"
75
+ end
76
+ script.nil? ? "" : %Q|<script type="text/javascript">#{script}</script>|.html_safe
77
+ end
78
+ end
79
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 7
9
- version: 1.0.7
8
+ - 8
9
+ version: 1.0.8
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michael Fairley
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-04-28 00:00:00 -07:00
17
+ date: 2011-05-20 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -59,6 +59,7 @@ files:
59
59
  - lib/abongo/version.rb
60
60
  - lib/abongo/version.rb~
61
61
  - lib/abongo/view_helper.rb
62
+ - lib/abongo/view_helper.rb~
62
63
  - lib/abongo/views/dashboard/_experiment.html.erb
63
64
  - lib/abongo/views/dashboard/_experiment.html.erb~
64
65
  - lib/abongo/views/dashboard/index.html.erb