rack-olark 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.DS_Store
2
+ *.gem
3
+ .bundle
4
+ Gemfile.lock
5
+ pkg/*
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use --create ruby-1.9.2-p180@rack-olark
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org/'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ Copyright 2011 Dan Poggi. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are
4
+ permitted provided that the following conditions are met:
5
+
6
+ 1. Redistributions of source code must retain the above copyright notice, this list of
7
+ conditions and the following disclaimer.
8
+
9
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list
10
+ of conditions and the following disclaimer in the documentation and/or other materials
11
+ provided with the distribution.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND ANY EXPRESS OR IMPLIED
14
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
15
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR
16
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
17
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
18
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
20
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
21
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+
23
+ The views and conclusions contained in the software and documentation are those of the
24
+ authors and should not be interpreted as representing official policies, either expressed
25
+ or implied, of Dan Poggi.
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # Rack Olark
2
+ Rack middleware which injects the Olark JavaScript code before the end of the body of any HTML document being sent to the client. Code from rack/google-analytics has been used liberally and expanded/trimmed down where needed. Mucho thanks to Lee Hambley and other cool rack/google-analytics bros.
3
+
4
+ ## Usage
5
+
6
+ require 'rack/olark'
7
+ use Rack::Olark, :id => '1234-567-89-0123', :options => 'like', :this => true, :orthis => 45
8
+
9
+ Options become this line of JavaScript:
10
+
11
+ olark.configure('key', value);
12
+
13
+ Strings are quoted for you, you needn't worry about that.
14
+
15
+ ## Copyright
16
+
17
+ Copyright (c) 2011 Dan Poggi. License is 2-clause BSD, see LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/lib/rack/olark.rb ADDED
@@ -0,0 +1,41 @@
1
+ require 'rack'
2
+ require 'haml'
3
+
4
+ module Rack
5
+ class Olark
6
+ Defaults = {:format => :html5}
7
+
8
+ def initialize(app, options = {})
9
+ raise ArgumentError, "Need a valid Olark ID!" unless options[:id] and options[:id].length.eql? 16
10
+ @app, @options = app, Defaults.merge(options)
11
+ @id, @format = [@options.delete(:id), @options.delete(:format)]
12
+ @option_js = "olark.identify('#{@id}');"
13
+ @options.each do |key, val|
14
+ @option_js << "olark.configure('#{key.to_s}', #{[String, Symbol].include? val.class ? "'#{val.to_s}'" : val.to_s});"
15
+ end
16
+ end
17
+
18
+ def call(env)
19
+ dup._call(env)
20
+ end
21
+
22
+ def _call(env)
23
+ @status, @headers, @response = @app.call(env)
24
+ return [@status, @headers, @response] unless html?
25
+ response = Rack::Response.new [], @status, @headers
26
+ @response.each {|fragment| response.write inject(fragment)}
27
+ response.finish
28
+ end
29
+
30
+ private
31
+
32
+ def html?
33
+ @headers['Content-Type'] =~ /html/
34
+ end
35
+
36
+ def inject(response)
37
+ @template = Haml::Engine.new(::File.read(::File.expand_path('../templates/olark.haml', __FILE__)), {:format => @format}).render self
38
+ response.gsub '</body>', @template + '</body>'
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,6 @@
1
+ / Begin Olark code
2
+ :javascript
3
+ window.olark||(function(i){var e=window,h=document,a=e.location.protocol=="https:"?"https:":"http:",g=i.name,b="load";(function(){e[g]=function(){(c.s=c.s||[]).push(arguments)};var c=e[g]._={},f=i.methods.length; while(f--){(function(j){e[g][j]=function(){e[g]("call",j,arguments)}})(i.methods[f])} c.l=i.loader;c.i=arguments.callee;c.f=setTimeout(function(){if(c.f){(new Image).src=a+"//"+c.l.replace(".js",".png")+"&"+escape(e.location.href)}c.f=null},20000);c.p={0:+new Date};c.P=function(j){c.p[j]=new Date-c.p[0]};function d(){c.P(b);e[g](b)}e.addEventListener?e.addEventListener(b,d,false):e.attachEvent("on"+b,d); (function(){function l(j){j="head";return["<",j,"></",j,"><",z,' onload="var d=',B,";d.getElementsByTagName('head')[0].",y,"(d.",A,"('script')).",u,"='",a,"//",c.l,"'",'"',"></",z,">"].join("")}var z="body",s=h[z];if(!s){return setTimeout(arguments.callee,100)}c.P(1);var y="appendChild",A="createElement",u="src",r=h[A]("div"),G=r[y](h[A](g)),D=h[A]("iframe"),B="document",C="domain",q;r.style.display="none";s.insertBefore(r,s.firstChild).id=g;D.frameBorder="0";D.id=g+"-loader";if(/MSIE[ ]+6/.test(navigator.userAgent)){D.src="javascript:false"} D.allowTransparency="true";G[y](D);try{D.contentWindow[B].open()}catch(F){i[C]=h[C];q="javascript:var d="+B+".open();d.domain='"+h.domain+"';";D[u]=q+"void(0);"}try{var H=D.contentWindow[B];H.write(l());H.close()}catch(E){D[u]=q+'d.write("'+l().replace(/"/g,String.fromCharCode(92)+'"')+'");d.close();'}c.P(2)})()})()})({loader:(function(a){return "static.olark.com/jsclient/loader0.js?ts="+(a?a[1]:(+new Date))})(document.cookie.match(/olarkld=([0-9]+)/)),name:"olark",methods:["configure","extend","declare","identify"]});
4
+ #{@option_js}
5
+
6
+ / End Olark code
@@ -0,0 +1,19 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "rack-olark"
3
+ s.version = ::File.read(::File.expand_path('../VERSION', __FILE__)).strip
4
+ s.date = ::Date.today.to_s
5
+ s.platform = Gem::Platform::RUBY
6
+ s.authors = ["Dan Poggi"]
7
+ s.email = ["dan.poggi@gmail.com"]
8
+ s.homepage = "https://github.com/dpoggi/rack-olark"
9
+ s.summary = %q{Rack middleware for embedding Olark.}
10
+ s.description = %q{Rack middleware which injects the Olark JavaScript code before the end of the body of any HTML document being sent to the client. Code from rack/google-analytics has been used liberally and expanded/trimmed down where needed. Mucho thanks to Lee Hambley and other cool rack/google-analytics bros.}
11
+
12
+ s.rubyforge_project = "rack-olark"
13
+
14
+ s.add_dependency('rack', ['>= 1.2.2'])
15
+ s.add_dependency('haml', ['>= 3.1.1'])
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.require_paths = ["lib"]
19
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-olark
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Dan Poggi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-04 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rack
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.2
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: haml
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 3.1.1
35
+ type: :runtime
36
+ version_requirements: *id002
37
+ description: Rack middleware which injects the Olark JavaScript code before the end of the body of any HTML document being sent to the client. Code from rack/google-analytics has been used liberally and expanded/trimmed down where needed. Mucho thanks to Lee Hambley and other cool rack/google-analytics bros.
38
+ email:
39
+ - dan.poggi@gmail.com
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - .gitignore
48
+ - .rvmrc
49
+ - Gemfile
50
+ - LICENSE
51
+ - README.md
52
+ - Rakefile
53
+ - VERSION
54
+ - lib/rack/olark.rb
55
+ - lib/rack/templates/olark.haml
56
+ - rack-olark.gemspec
57
+ homepage: https://github.com/dpoggi/rack-olark
58
+ licenses: []
59
+
60
+ post_install_message:
61
+ rdoc_options: []
62
+
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ requirements: []
78
+
79
+ rubyforge_project: rack-olark
80
+ rubygems_version: 1.7.2
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Rack middleware for embedding Olark.
84
+ test_files: []
85
+