rack-olark 0.0.4 → 0.0.5
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 +2 -4
- data/VERSION +1 -1
- data/lib/rack/olark.rb +13 -4
- metadata +3 -3
data/README.md
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
# Rack
|
1
|
+
# Rack::Olark
|
2
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
|
-
require 'rack/olark'
|
7
6
|
use Rack::Olark, :id => '1234-567-89-0123'
|
8
7
|
|
9
8
|
Most of the options you give Rack::Olark are passed along to Olark in the following format:
|
@@ -14,13 +13,12 @@ There are three special options: :id, :format, and :paths. :id is your Olark API
|
|
14
13
|
|
15
14
|
: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
15
|
|
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:
|
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:
|
18
17
|
|
19
18
|
/^#{Regexp.escape(your_original_path_entry)}$/
|
20
19
|
|
21
20
|
Example using options:
|
22
21
|
|
23
|
-
require 'rack/olark'
|
24
22
|
use Rack::Olark, :id => '1234-567-89-0123', :format => :xhtml, :paths => ['/', '/aboutus'], 'box.corner_position' => 'BL', 'box.start_hidden' => true
|
25
23
|
|
26
24
|
## Acknowledgements
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
data/lib/rack/olark.rb
CHANGED
@@ -10,10 +10,15 @@ 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
|
-
|
13
|
+
|
14
|
+
@paths = @paths.class.eql?(Array) ? @paths.map do |path|
|
15
|
+
path.class.eql?(Regexp) ? path : /^#{Regexp.escape(path.to_s)}$/
|
16
|
+
end : []
|
17
|
+
|
14
18
|
@option_js = "olark.identify('#{@id}');"
|
15
19
|
@options.each do |key, val|
|
16
|
-
|
20
|
+
val = [String, Symbol].include? val.class ? "'#{val.to_s}'" : val.to_s
|
21
|
+
@option_js << "olark.configure('#{key.to_s}', #{val});"
|
17
22
|
end
|
18
23
|
end
|
19
24
|
|
@@ -24,7 +29,10 @@ module Rack
|
|
24
29
|
def _call(env)
|
25
30
|
@status, @headers, @response = @app.call env
|
26
31
|
@request = Rack::Request.new env
|
27
|
-
|
32
|
+
|
33
|
+
valid_path = @paths.select {|path| @request.path_info =~ path}.length > 0
|
34
|
+
return [@status, @headers, @response] unless html? and (@paths.empty? or valid_path)
|
35
|
+
|
28
36
|
response = Rack::Response.new [], @status, @headers
|
29
37
|
@response.each {|fragment| response.write inject(fragment)}
|
30
38
|
response.finish
|
@@ -37,7 +45,8 @@ module Rack
|
|
37
45
|
end
|
38
46
|
|
39
47
|
def inject(response)
|
40
|
-
|
48
|
+
template_contents = ::File.read ::File.expand_path('../templates/olark.haml', __FILE__)
|
49
|
+
@template = Haml::Engine.new(template_contents, {:format => @format}).render self
|
41
50
|
response.gsub '</body>', @template
|
42
51
|
end
|
43
52
|
end
|
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.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Dan Poggi
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-09 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rack
|
@@ -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.8.
|
81
|
+
rubygems_version: 1.8.1
|
82
82
|
signing_key:
|
83
83
|
specification_version: 3
|
84
84
|
summary: Rack middleware for embedding Olark.
|