Skip to content

Commit c61f234

Browse files
author
Michael Mazyar
committed
initial
0 parents  commit c61f234

17 files changed

+347
-0
lines changed

.document

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
README.rdoc
2+
lib/**/*.rb
3+
bin/*
4+
features/**/*.feature
5+
LICENSE

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.sw?
2+
.DS_Store
3+
coverage
4+
rdoc
5+
pkg

LICENSE

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2009 Michael Mazyar
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.rdoc

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
= clicktale
2+
3+
== Summary
4+
5+
This gem allows easys integration with Clicktale service (http://clicktale.com)
6+
Clicktale records user sessions, clicks, form input etc and plays them back later for usability review.
7+
8+
== Installation
9+
10+
* install the plugin
11+
12+
> ./script/plugin install git://github.com/astrails/clicktale.git
13+
14+
OR
15+
16+
> gem install astrails-clicktale --source http://gems.github.com/
17+
and then
18+
> clicktailize YOUR_RAILS_DIR
19+
20+
* edit the autogenerated config/clicktale.yml and replace CLICKTALE_PROJECT_ID with your clicktale project id
21+
22+
* add partials into layout inside the 'body' tag
23+
24+
<body>
25+
<%= clicktale_top %>
26+
...
27+
<%= yield %>
28+
...
29+
<%= clicktale_bottom %>
30+
</body>
31+
32+
Note: The plugin works by leveraging rails caching mechanism, which is by default only enabled in production environment.
33+
To enable the plugin in the development environment do the following:
34+
35+
* set enabled=true in config/clicktale.yml (development section)
36+
* set config.action_controller.perform_caching=true in config/environments/development.rb
37+
38+
== Copyright
39+
40+
Copyright (c) 2009 Michael Mazyar. See LICENSE for details.

Rakefile

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
require 'rubygems'
2+
require 'rake'
3+
4+
begin
5+
require 'jeweler'
6+
Jeweler::Tasks.new do |gem|
7+
gem.name = "clicktale"
8+
gem.summary = %Q{TODO}
9+
gem.email = "[email protected]"
10+
gem.homepage = "http://github.com/astrails/clicktale"
11+
gem.authors = ["Michael Mazyar"]
12+
gem.files = FileList["[A-Z]*.*", "{bin,app,examples,generators,lib,rails,templates,config}/**/*", 'Rakefile', 'LICENSE*']
13+
14+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15+
end
16+
rescue LoadError
17+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
18+
end
19+
20+
require 'spec/rake/spectask'
21+
Spec::Rake::SpecTask.new(:spec) do |spec|
22+
spec.libs << 'lib' << 'spec'
23+
spec.spec_files = FileList['spec/**/*_spec.rb']
24+
end
25+
26+
Spec::Rake::SpecTask.new(:rcov) do |spec|
27+
spec.libs << 'lib' << 'spec'
28+
spec.pattern = 'spec/**/*_spec.rb'
29+
spec.rcov = true
30+
end
31+
32+
33+
task :default => :spec
34+
35+
require 'rake/rdoctask'
36+
Rake::RDocTask.new do |rdoc|
37+
if File.exist?('VERSION.yml')
38+
config = YAML.load(File.read('VERSION.yml'))
39+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
40+
else
41+
version = ""
42+
end
43+
44+
rdoc.rdoc_dir = 'rdoc'
45+
rdoc.title = "clicktale #{version}"
46+
rdoc.rdoc_files.include('README*')
47+
rdoc.rdoc_files.include('lib/**/*.rb')
48+
end
49+

VERSION.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
:major: 0
3+
:minor: 0
4+
:patch: 1

WRb.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/views/clicktale/_bottom.html.erb

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<div id="ClickTaleDiv" style="display: none;" />
2+
3+
<%= javascript_include_tag "WRb.js" %>
4+
<script type="text/javascript">
5+
if(typeof ClickTale == 'function') {
6+
<%- if request.ssl? -%>
7+
var ClickTaleSSL = 1;
8+
<%- end -%>
9+
<%- if tag -%>
10+
ClickTaleTag('<%= tag %>');
11+
<%- end -%>
12+
var ClickTaleFetchFrom = '<%= path %>';
13+
ClickTale(<%= project_id %>, <%= ratio %>);
14+
}
15+
</script>

app/views/clicktale/_top.html.erb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<script type="text/javascript">
2+
var WRInitTime=(new Date()).getTime();
3+
</script>

bin/clicktaleize

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'fileutils'
4+
5+
# check arguments
6+
root = ARGV.shift
7+
unless ARGV.empty? && root && File.directory?(root)
8+
abort "Usage: clicktaleize PATH_TO_YOUR_RAILS_APP"
9+
end
10+
11+
# create plugin dir and init.rb
12+
clicktale_dir = File.join(root, "vendor/plugins/clicktale")
13+
FileUtils.mkdir_p(clicktale_dir)
14+
File.open(File.join(clicktale_dir, "init.rb"), "w") do |file|
15+
file.write <<-INIT
16+
require 'astrails/clicktale'
17+
Astrails::Clicktale.init
18+
INIT
19+
end
20+
21+
# copy clicktale .js
22+
js_src = File.join(File.dirname(__FILE__), "../WRb.js")
23+
js_dst = File.join(root, "public/javascripts/WRb.js")
24+
unless File.exists?(js_dst)
25+
FileUtils.cp js_src, js_dst
26+
end
27+
28+
# create config file if needed
29+
conf_src = File.join(File.dirname(__FILE__), "../config/clicktale.yml")
30+
conf_dst = File.join(root, "config/clicktale.yml")
31+
if File.exists?(conf_dst)
32+
STDERR.puts <<-END
33+
Config file #{conf_dst} already exists.
34+
END
35+
else
36+
FileUtils.cp conf_src, conf_dst
37+
puts File.read(File.join(File.dirname(__FILE__), '../README.rdoc'))
38+
puts <<-END
39+
40+
-------------------------------------------------------------
41+
Installed clicktale configuration file at #{conf_dst}.
42+
You need to provide project_id for this plugin to work.
43+
You can get clicktale project_id from your clicktale account.
44+
-------------------------------------------------------------
45+
END
46+
end
47+

clicktale.gemspec

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# -*- encoding: utf-8 -*-
2+
3+
Gem::Specification.new do |s|
4+
s.name = %q{clicktale}
5+
s.version = "0.0.1"
6+
7+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8+
s.authors = ["Michael Mazyar"]
9+
s.date = %q{2009-05-06}
10+
s.default_executable = %q{clicktaleize}
11+
s.email = %q{[email protected]}
12+
s.executables = ["clicktaleize"]
13+
s.extra_rdoc_files = ["README.rdoc", "LICENSE"]
14+
s.files = ["README.rdoc", "VERSION.yml", "WRb.js", "bin/clicktaleize", "app/views", "app/views/clicktale", "app/views/clicktale/_bottom.html.erb", "app/views/clicktale/_top.html.erb", "lib/astrails", "lib/astrails/clicktale", "lib/astrails/clicktale/controller.rb", "lib/astrails/clicktale/helper.rb", "lib/astrails/clicktale.rb", "config/clicktale.yml", "Rakefile", "LICENSE"]
15+
s.has_rdoc = true
16+
s.homepage = %q{http://github.com/astrails/clicktale}
17+
s.rdoc_options = ["--inline-source", "--charset=UTF-8"]
18+
s.require_paths = ["lib"]
19+
s.rubygems_version = %q{1.3.1}
20+
s.summary = %q{TODO}
21+
22+
if s.respond_to? :specification_version then
23+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24+
s.specification_version = 2
25+
26+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27+
else
28+
end
29+
else
30+
end
31+
end

config/clicktale.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
default: &default
2+
project_id: CLICKTALE_PROJECT_ID
3+
ratio: 1
4+
5+
production:
6+
<<: *default
7+
enabled: true
8+
9+
development:
10+
<<: *default
11+
enabled: false
12+
13+
test:
14+
<<: *default
15+
enabled: false

init.rb

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require 'astrails/clicktale'
2+
Astrails::Clicktale.init

install.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require 'fileutils'
2+
3+
system '/usr/bin/env', 'ruby', File.join(File.dirname(__FILE__), "bin/clicktaleize"), RAILS_ROOT

lib/astrails/clicktale.rb

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
require 'activesupport'
2+
require 'astrails/clicktale/controller'
3+
require 'astrails/clicktale/helper'
4+
5+
module Astrails
6+
module Clicktale
7+
8+
def self.init
9+
ActionController::Base.append_view_path(File.dirname(__FILE__) + "/../../app/views") if ActionController::Base.respond_to?(:append_view_path)
10+
ActionController::Base.send(:include, Astrails::Clicktale::Controller)
11+
ActionView::Base.send(:include, Astrails::Clicktale::Helper)
12+
end
13+
14+
CONFIG = HashWithIndifferentAccess.new
15+
begin
16+
conffile = File.join(RAILS_ROOT, "config", "clicktale.yml")
17+
conf = YAML.load(File.read(conffile))
18+
CONFIG.merge!(conf[RAILS_ENV])
19+
rescue
20+
puts "*" * 50
21+
puts "#{conffile} can not be loaded:"
22+
puts $!
23+
puts "*" * 50
24+
end
25+
26+
end
27+
end

lib/astrails/clicktale/controller.rb

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
module Astrails
2+
module Clicktale
3+
module Controller
4+
5+
def self.included(base)
6+
base.class_eval do
7+
@@clicktale_options = {}
8+
around_filter :clicktaleize
9+
helper_method :clicktale_enabled?
10+
helper_method :clicktale_config
11+
helper_method :clicktale_path
12+
helper_method :clicktale_url
13+
end
14+
base.send(:extend, ClassMethods)
15+
end
16+
17+
module ClassMethods
18+
def clicktale(opts = {})
19+
@@clicktale_options = opts
20+
end
21+
end
22+
23+
def clicktale(opts = {})
24+
@clicktale_options = opts
25+
end
26+
27+
def clicktaleize
28+
returning(yield) do
29+
cache_page(nil, "/clicktale/#{clicktale_cache_token}") if clicktale_enabled?
30+
end
31+
end
32+
33+
def clicktale_enabled?
34+
@clicktale_enabled ||= clicktale_config[:enabled] && request.format.html? && request.get?
35+
end
36+
37+
def clicktale_config
38+
@clicktale_config ||= Astrails::Clicktale::CONFIG.merge(@@clicktale_options || {}).merge(@clicktale_options || {})
39+
end
40+
41+
42+
protected
43+
44+
def clicktale_cache_token(extra = "")
45+
@clicktale_cache_token ||= Digest::SHA1.hexdigest(Time.now.to_s.split(//).sort_by {rand}.join + extra)
46+
end
47+
48+
def clicktale_path
49+
@clicktale_path ||= "/clicktale/#{clicktale_cache_token}.html"
50+
end
51+
52+
def clicktale_url
53+
@clicktale_url ||= "#{request.protocol}#{request.host_with_port}#{clicktale_path}"
54+
end
55+
56+
end
57+
end
58+
end

lib/astrails/clicktale/helper.rb

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module Astrails
2+
module Clicktale
3+
module Helper
4+
def clicktale_top
5+
return unless clicktale_enabled?
6+
render :partial => "clicktale/top"
7+
end
8+
9+
def clicktale_bottom
10+
return unless clicktale_enabled?
11+
12+
render :partial => "clicktale/bottom", :locals => {
13+
:project_id => clicktale_config[:project_id],
14+
:path => clicktale_url,
15+
:ratio => clicktale_config[:ratio] || 1,
16+
:tag => clicktale_config[:tag]
17+
}
18+
end
19+
end
20+
end
21+
end
22+

0 commit comments

Comments
 (0)