Skip to content

Commit 59b8140

Browse files
committed
add some endpoint helpers
1 parent b48e32c commit 59b8140

7 files changed

Lines changed: 59 additions & 12 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.DS_Store
2+
public/v1

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Heroku 10 seconds setup
2+
3+
heroku create myapp
4+
heroku addons:add mongohq:sandbox
5+
git push heroku master
6+
heroku open

Rakefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace :assets do
2+
task :precompile do
3+
require 'fileutils'
4+
require './app'
5+
6+
FileUtils.mkdir_p(settings.root + '/public/v1')
7+
File.open(settings.root + '/public/v1/abba.js', 'w+') do |file|
8+
file.write settings.sprockets['client/index'].to_s
9+
end
10+
end
11+
end

app.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
}, settings.environment.to_s)
1818

1919
set :sprockets, Sprockets::Environment.new
20-
settings.sprockets.append_path 'app/assets/javascripts'
20+
settings.sprockets.append_path(settings.root + '/app/assets/javascripts')
2121
end
2222

2323
helpers do

app/assets/javascripts/client/index.coffee

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class @Abba
2-
@endpoint: 'http://localhost:4050'
2+
@endpoint: 'http://localhost:4567'
33

44
constructor: (name, options = {}) ->
55
unless name
@@ -111,4 +111,17 @@ class @Abba
111111
key = decodeURIComponent(cookie.substr(0, index))
112112
value = decodeURIComponent(cookie.substr(index + 1))
113113
return value if key is name
114-
null
114+
null
115+
116+
do ->
117+
host = (url) ->
118+
# IE6 only resolves resolves hrefs using innerHTML
119+
parent = document.createElement('div')
120+
parent.innerHTML = "<a href=\"#{url}\">x</a>"
121+
parser = parent.firstChild
122+
"#{parser.host}"
123+
124+
# Find Abba's endpoint from the script tag
125+
scripts = document.getElementsByTagName('script')
126+
scripts = (script.src for script in scripts when /abba\.js$/.test(script.src))
127+
Abba.endpoint = "//#{host(scripts[0])}" if scripts[0]

public/test/complete.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<script src="/v1/abba.js" type="text/javascript" charset="utf-8"></script>
22

33
<script type="text/javascript" charset="utf-8">
4-
Abba('alert test').complete();
5-
</script>
4+
Abba('My Checkout').complete();
5+
</script>
6+
7+
<h1>Test complete!</h1>

public/test/start.html

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
<script src="/v1/abba.js" type="text/javascript" charset="utf-8"></script>
2+
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
3+
4+
<div id="tests">
5+
<div id="control"><h1>The control was chosen!</h1></div>
6+
<div id="variant1"><h1>&#x27;Variant 1&#x27; was chosen!</h1></div>
7+
<div id="variant2"><h1>&#x27;Variant 2&#x27; was chosen!</h1></div>
8+
</div>
29

310
<script type="text/javascript" charset="utf-8">
4-
Abba('alert test')
11+
$('#tests').children().hide()
12+
13+
Abba('My Checkout')
514
.control(function(){
6-
alert('control');
15+
$('#control').show();
716
})
8-
.a(function(){
9-
alert('a');
17+
.variant('Variant 1', function(){
18+
$('#variant1').show();
1019
})
11-
.b(function(){
12-
alert('b');
20+
.variant('Variant 2', function(){
21+
$('#variant2').show();
1322
})
1423
.start();
15-
</script>
24+
</script>
25+
26+
<p>
27+
<a href="complete.html">Now complete the test.</a>
28+
</p>

0 commit comments

Comments
 (0)