rack-olark 0.0.6 → 0.0.7
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/Gemfile +1 -2
- data/LICENSE +4 -22
- data/README.md +8 -6
- data/Rakefile +1 -2
- data/VERSION +1 -1
- data/lib/rack/olark.rb +35 -29
- data/lib/rack/templates/olark.erb +7 -0
- data/rack-olark.gemspec +3 -4
- metadata +21 -17
- data/lib/rack/templates/olark.haml +0 -7
data/Gemfile
CHANGED
data/LICENSE
CHANGED
@@ -1,25 +1,7 @@
|
|
1
|
-
Copyright
|
1
|
+
Copyright (C) 2012 Dan Poggi
|
2
2
|
|
3
|
-
|
4
|
-
permitted provided that the following conditions are met:
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
5
4
|
|
6
|
-
|
7
|
-
conditions and the following disclaimer.
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
6
|
|
9
|
-
|
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.
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -3,23 +3,25 @@ Rack middleware which injects the Olark JavaScript code before the end of the bo
|
|
3
3
|
|
4
4
|
## Usage
|
5
5
|
|
6
|
-
use Rack::Olark, :
|
6
|
+
use Rack::Olark, id: '1234-567-89-0123'
|
7
7
|
|
8
8
|
Most of the options you give Rack::Olark are passed along to Olark in the following format:
|
9
9
|
|
10
10
|
olark.configure('key', value);
|
11
11
|
|
12
|
-
There are three special options:
|
12
|
+
There are three special options: id, tag, and paths. id is your Olark API ID, and the middleware won't let your Rack app boot without it.
|
13
13
|
|
14
|
-
|
14
|
+
tag is a custom <script> tag to be used at the beginning of the Olark code. Most people shouldn't need this, and it will default to just <script> (HTML5-style).
|
15
15
|
|
16
|
-
|
16
|
+
paths decides which routes in your application will display the Olark chat box. It takes an array of routes, and you need to include the leading slash (/). If you don't give an array for paths, it is empty by default, and this will cause the Olark code to be inserted on every route. As of version 0.0.4, you can now describe routes in the paths array with a Regexp as well, and any non-Regexp entries will be handled like this:
|
17
17
|
|
18
18
|
/^#{Regexp.escape(your_original_path_entry)}$/
|
19
19
|
|
20
20
|
Example using options:
|
21
21
|
|
22
|
-
use Rack::Olark, :
|
22
|
+
use Rack::Olark, id: '1234-567-89-0123',
|
23
|
+
tag: '<script type="text/javascript">',
|
24
|
+
paths: ['/', '/aboutus']
|
23
25
|
|
24
26
|
## Acknowledgements
|
25
27
|
|
@@ -27,4 +29,4 @@ Code from rack/google-analytics has been used liberally and expanded/trimmed dow
|
|
27
29
|
|
28
30
|
## Copyright
|
29
31
|
|
30
|
-
Copyright (
|
32
|
+
Copyright (C) 2012 Dan Poggi. MIT License, see LICENSE for details.
|
data/Rakefile
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
require 'bundler'
|
2
|
-
Bundler::GemHelper.install_tasks
|
1
|
+
require 'bundler/gem_tasks'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.7
|
data/lib/rack/olark.rb
CHANGED
@@ -1,53 +1,59 @@
|
|
1
1
|
require 'rack'
|
2
2
|
require 'rack/request'
|
3
|
-
require '
|
3
|
+
require 'erb'
|
4
4
|
|
5
5
|
module Rack
|
6
6
|
class Olark
|
7
|
-
|
7
|
+
DEFAULTS = {
|
8
|
+
tag: '<script>',
|
9
|
+
paths: []
|
10
|
+
}
|
8
11
|
|
9
12
|
def initialize(app, options = {})
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
@paths = @
|
15
|
-
|
16
|
-
|
13
|
+
unless options[:id] && options[:id].length == 16
|
14
|
+
raise ArgumentError, 'Need a valid Olark ID!'
|
15
|
+
end
|
16
|
+
@app, @options = app, DEFAULTS.merge(options)
|
17
|
+
@id, @tag, @paths = [@options.delete(:id),
|
18
|
+
@options.delete(:tag),
|
19
|
+
@options.delete(:paths)]
|
20
|
+
|
21
|
+
if @paths.is_a?(Array)
|
22
|
+
@paths.map! { |path| path.is_a?(Regexp) ? path : /^#{Regexp.escape(path.to_s)}$/ }
|
23
|
+
else
|
24
|
+
@paths = []
|
25
|
+
end
|
17
26
|
|
18
27
|
@option_js = "olark.identify('#{@id}');"
|
19
28
|
@options.each do |key, val|
|
20
|
-
val = [String, Symbol].include?
|
29
|
+
val = [String, Symbol].include?(val.class) ? "'#{val.to_s}'" : val.to_s
|
21
30
|
@option_js << "olark.configure('#{key.to_s}', #{val});"
|
22
31
|
end
|
23
32
|
end
|
24
33
|
|
25
|
-
def call(env)
|
26
|
-
dup._call(env)
|
27
|
-
end
|
34
|
+
def call(env); dup._call(env); end
|
28
35
|
|
29
36
|
def _call(env)
|
30
|
-
@status, @headers, @response = @app.call
|
31
|
-
@request = Rack::Request.new
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
@status, @headers, @response = @app.call(env)
|
38
|
+
@request = Rack::Request.new(env)
|
39
|
+
valid_path = @paths.select { |path| @request.path_info =~ path }.length > 0
|
40
|
+
|
41
|
+
if html? && (@paths.empty? || valid_path)
|
42
|
+
response = Rack::Response.new([], @status, @headers)
|
43
|
+
@response.each { |fragment| response.write(inject(fragment)) }
|
44
|
+
response.finish
|
45
|
+
else
|
46
|
+
[@status, @headers, @response]
|
47
|
+
end
|
39
48
|
end
|
40
49
|
|
41
50
|
private
|
42
|
-
|
43
|
-
def html?
|
44
|
-
@headers['Content-Type'] =~ /html/
|
45
|
-
end
|
51
|
+
def html?; @headers['Content-Type'] =~ /html/; end
|
46
52
|
|
47
53
|
def inject(response)
|
48
|
-
|
49
|
-
@template =
|
50
|
-
response.gsub
|
54
|
+
template_file = ::File.read(::File.expand_path('../templates/olark.erb', __FILE__))
|
55
|
+
@template = ERB.new(template_file).result(binding)
|
56
|
+
response.gsub('</body>', @template)
|
51
57
|
end
|
52
58
|
end
|
53
59
|
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
<!-- Begin Olark code -->
|
2
|
+
<%= @tag %>
|
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
|
+
</script>
|
6
|
+
<!-- End Olark code -->
|
7
|
+
</body>
|
data/rack-olark.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
|
-
s.name =
|
3
|
-
s.version =
|
4
|
-
s.date =
|
2
|
+
s.name = 'rack-olark'
|
3
|
+
s.version = File.read(File.expand_path('../VERSION', __FILE__)).strip
|
4
|
+
s.date = Date.today.to_s
|
5
5
|
s.platform = Gem::Platform::RUBY
|
6
6
|
s.authors = ['Dan Poggi']
|
7
7
|
s.email = ['dan.poggi@gmail.com']
|
@@ -12,7 +12,6 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.rubyforge_project = "rack-olark"
|
13
13
|
|
14
14
|
s.add_dependency 'rack', ['>= 1.2']
|
15
|
-
s.add_dependency 'haml', ['>= 2.2.0']
|
16
15
|
|
17
16
|
s.add_development_dependency 'rake'
|
18
17
|
s.add_development_dependency 'bundler'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-olark
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-08-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,21 +21,15 @@ dependencies:
|
|
21
21
|
version: '1.2'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: haml
|
27
|
-
requirement: &2153883840 !ruby/object:Gem::Requirement
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
25
|
none: false
|
29
26
|
requirements:
|
30
27
|
- - ! '>='
|
31
28
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
33
|
-
type: :runtime
|
34
|
-
prerelease: false
|
35
|
-
version_requirements: *2153883840
|
29
|
+
version: '1.2'
|
36
30
|
- !ruby/object:Gem::Dependency
|
37
31
|
name: rake
|
38
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
39
33
|
none: false
|
40
34
|
requirements:
|
41
35
|
- - ! '>='
|
@@ -43,10 +37,15 @@ dependencies:
|
|
43
37
|
version: '0'
|
44
38
|
type: :development
|
45
39
|
prerelease: false
|
46
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
47
46
|
- !ruby/object:Gem::Dependency
|
48
47
|
name: bundler
|
49
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
50
49
|
none: false
|
51
50
|
requirements:
|
52
51
|
- - ! '>='
|
@@ -54,7 +53,12 @@ dependencies:
|
|
54
53
|
version: '0'
|
55
54
|
type: :development
|
56
55
|
prerelease: false
|
57
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
58
62
|
description: Rack middleware which injects the Olark JavaScript code before the end
|
59
63
|
of the body of any HTML document being sent to the client. See README.md for details.
|
60
64
|
email:
|
@@ -71,7 +75,7 @@ files:
|
|
71
75
|
- VERSION
|
72
76
|
- lib/rack-olark.rb
|
73
77
|
- lib/rack/olark.rb
|
74
|
-
- lib/rack/templates/olark.
|
78
|
+
- lib/rack/templates/olark.erb
|
75
79
|
- rack-olark.gemspec
|
76
80
|
homepage: https://github.com/dpoggi/rack-olark
|
77
81
|
licenses: []
|
@@ -93,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
97
|
version: '0'
|
94
98
|
requirements: []
|
95
99
|
rubyforge_project: rack-olark
|
96
|
-
rubygems_version: 1.8.
|
100
|
+
rubygems_version: 1.8.23
|
97
101
|
signing_key:
|
98
102
|
specification_version: 3
|
99
103
|
summary: Rack middleware for embedding Olark.
|
@@ -1,7 +0,0 @@
|
|
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
|
7
|
-
</body>
|