rack-olark 0.0.3 → 0.0.4
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/README.md +19 -4
- data/VERSION +1 -1
- data/lib/rack/olark.rb +4 -3
- data/rack-olark.gemspec +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -1,16 +1,31 @@
|
|
1
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.
|
2
|
+
Rack middleware which injects the Olark JavaScript code before the end of the body of any HTML document being sent to the client.
|
3
3
|
|
4
4
|
## Usage
|
5
5
|
|
6
6
|
require 'rack/olark'
|
7
|
-
use Rack::Olark, :id => '1234-567-89-0123'
|
7
|
+
use Rack::Olark, :id => '1234-567-89-0123'
|
8
8
|
|
9
|
-
|
9
|
+
Most of the options you give Rack::Olark are passed along to Olark in the following format:
|
10
10
|
|
11
11
|
olark.configure('key', value);
|
12
12
|
|
13
|
-
|
13
|
+
There are three special options: :id, :format, and :paths. :id is your Olark API ID, and the middleware won't let your Rack app boot without it.
|
14
|
+
|
15
|
+
:format is my (possibly lame) justification for using Haml in this project - this option is passed directly to Haml::Engine, and determines the form of the script tags that are inserted into your pages. Choices are :html4, :xhtml, and :html5, with a default of :html5.
|
16
|
+
|
17
|
+
: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 (/). 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:
|
18
|
+
|
19
|
+
/^#{Regexp.escape(your_original_path_entry)}$/
|
20
|
+
|
21
|
+
Example using options:
|
22
|
+
|
23
|
+
require 'rack/olark'
|
24
|
+
use Rack::Olark, :id => '1234-567-89-0123', :format => :xhtml, :paths => ['/', '/aboutus'], 'box.corner_position' => 'BL', 'box.start_hidden' => true
|
25
|
+
|
26
|
+
## Acknowledgements
|
27
|
+
|
28
|
+
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.
|
14
29
|
|
15
30
|
## Copyright
|
16
31
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/lib/rack/olark.rb
CHANGED
@@ -10,7 +10,7 @@ module Rack
|
|
10
10
|
raise ArgumentError, "Need a valid Olark ID!" unless options[:id] and options[:id].length.eql? 16
|
11
11
|
@app, @options = app, Defaults.merge(options)
|
12
12
|
@id, @format, @paths = [@options.delete(:id), @options.delete(:format), @options.delete(:paths)]
|
13
|
-
@paths =
|
13
|
+
@paths = @paths.class.eql?(Array) ? @paths.map {|path| path.class.eql?(Regexp) ? path : /^#{Regexp.escape(path.to_s)}$/} : []
|
14
14
|
@option_js = "olark.identify('#{@id}');"
|
15
15
|
@options.each do |key, val|
|
16
16
|
@option_js << "olark.configure('#{key.to_s}', #{[String, Symbol].include? val.class ? "'#{val.to_s}'" : val.to_s});"
|
@@ -22,8 +22,9 @@ module Rack
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def _call(env)
|
25
|
-
@status, @headers, @response = @app.call
|
26
|
-
|
25
|
+
@status, @headers, @response = @app.call env
|
26
|
+
@request = Rack::Request.new env
|
27
|
+
return [@status, @headers, @response] unless html? and (@paths.empty? or @paths.select {|path| @request.path_info =~ path}.length > 0)
|
27
28
|
response = Rack::Response.new [], @status, @headers
|
28
29
|
@response.each {|fragment| response.write inject(fragment)}
|
29
30
|
response.finish
|
data/rack-olark.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.email = ["dan.poggi@gmail.com"]
|
8
8
|
s.homepage = "https://github.com/dpoggi/rack-olark"
|
9
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.
|
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. See README.md for details.}
|
11
11
|
|
12
12
|
s.rubyforge_project = "rack-olark"
|
13
13
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: rack-olark
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Dan Poggi
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
version: 3.1.1
|
35
35
|
type: :runtime
|
36
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.
|
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. See README.md for details.
|
38
38
|
email:
|
39
39
|
- dan.poggi@gmail.com
|
40
40
|
executables: []
|
@@ -78,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
78
|
requirements: []
|
79
79
|
|
80
80
|
rubyforge_project: rack-olark
|
81
|
-
rubygems_version: 1.
|
81
|
+
rubygems_version: 1.8.0
|
82
82
|
signing_key:
|
83
83
|
specification_version: 3
|
84
84
|
summary: Rack middleware for embedding Olark.
|