forked from astrails/clicktale
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rails gem init and change namespace
- Loading branch information
Cory Fabre
committed
Sep 28, 2011
1 parent
67e35a9
commit ae409cf
Showing
8 changed files
with
85 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
require 'astrails/clicktale' | ||
Astrails::Clicktale.init | ||
require File.join(File.dirname(__FILE__), 'rails', 'init') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,25 @@ | ||
require 'activesupport' | ||
require 'astrails/clicktale/controller' | ||
require 'astrails/clicktale/helper' | ||
require 'clicktale/controller' | ||
require 'clicktale/helper' | ||
|
||
module Astrails | ||
module Clicktale | ||
module Clicktale | ||
|
||
def self.init | ||
ActionController::Base.append_view_path(File.dirname(__FILE__) + "/../../app/views") if ActionController::Base.respond_to?(:append_view_path) | ||
ActionController::Base.send(:include, Astrails::Clicktale::Controller) | ||
ActionView::Base.send(:include, Astrails::Clicktale::Helper) | ||
end | ||
|
||
CONFIG = HashWithIndifferentAccess.new | ||
begin | ||
conffile = File.join(RAILS_ROOT, "config", "clicktale.yml") | ||
conf = YAML.load(File.read(conffile)) | ||
CONFIG.merge!(conf[RAILS_ENV]) | ||
rescue | ||
puts "*" * 50 | ||
puts "#{conffile} can not be loaded:" | ||
puts $! | ||
puts "*" * 50 | ||
end | ||
def self.init | ||
ActionController::Base.append_view_path(File.dirname(__FILE__) + "/../../app/views") if ActionController::Base.respond_to?(:append_view_path) | ||
ActionController::Base.send(:include, Clicktale::Controller) | ||
ActionView::Base.send(:include, Clicktale::Helper) | ||
end | ||
|
||
CONFIG = HashWithIndifferentAccess.new | ||
begin | ||
conffile = File.join(RAILS_ROOT, "config", "clicktale.yml") | ||
conf = YAML.load(File.read(conffile)) | ||
CONFIG.merge!(conf[RAILS_ENV]) | ||
rescue | ||
puts "*" * 50 | ||
puts "#{conffile} can not be loaded:" | ||
puts $! | ||
puts "*" * 50 | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,56 @@ | ||
module Astrails | ||
module Clicktale | ||
module Controller | ||
|
||
def self.included(base) | ||
base.class_eval do | ||
@@clicktale_options = {} | ||
around_filter :clicktaleize | ||
helper_method :clicktale_enabled? | ||
helper_method :clicktale_config | ||
helper_method :clicktale_path | ||
helper_method :clicktale_url | ||
end | ||
base.send(:extend, ClassMethods) | ||
end | ||
|
||
module ClassMethods | ||
def clicktale(opts = {}) | ||
@@clicktale_options = opts | ||
end | ||
end | ||
module Clicktale | ||
module Controller | ||
|
||
def self.included(base) | ||
base.class_eval do | ||
@@clicktale_options = {} | ||
around_filter :clicktaleize | ||
helper_method :clicktale_enabled? | ||
helper_method :clicktale_config | ||
helper_method :clicktale_path | ||
helper_method :clicktale_url | ||
end | ||
base.send(:extend, ClassMethods) | ||
end | ||
|
||
module ClassMethods | ||
def clicktale(opts = {}) | ||
@clicktale_options = opts | ||
@@clicktale_options = opts | ||
end | ||
end | ||
|
||
def clicktaleize | ||
returning(yield) do | ||
cache_page(nil, "/clicktale/#{clicktale_cache_token}") if clicktale_enabled? | ||
end | ||
end | ||
def clicktale(opts = {}) | ||
@clicktale_options = opts | ||
end | ||
|
||
def clicktale_enabled? | ||
@clicktale_enabled ||= clicktale_config[:enabled] && request.format.try(:html?) && request.get? | ||
def clicktaleize | ||
returning(yield) do | ||
cache_page(nil, "/clicktale/#{clicktale_cache_token}") if clicktale_enabled? | ||
end | ||
end | ||
|
||
def clicktale_config | ||
@clicktale_config ||= Astrails::Clicktale::CONFIG.merge(@@clicktale_options || {}).merge(@clicktale_options || {}) | ||
end | ||
def clicktale_enabled? | ||
@clicktale_enabled ||= clicktale_config[:enabled] && request.format.try(:html?) && request.get? | ||
end | ||
|
||
def clicktale_config | ||
@clicktale_config ||= Clicktale::CONFIG.merge(@@clicktale_options || {}).merge(@clicktale_options || {}) | ||
end | ||
|
||
protected | ||
|
||
def clicktale_cache_token(extra = "") | ||
@clicktale_cache_token ||= Digest::SHA1.hexdigest(Time.now.to_s.split(//).sort_by {rand}.join + extra) | ||
end | ||
protected | ||
|
||
def clicktale_path | ||
@clicktale_path ||= "/clicktale/#{clicktale_cache_token}.html" | ||
end | ||
def clicktale_cache_token(extra = "") | ||
@clicktale_cache_token ||= Digest::SHA1.hexdigest(Time.now.to_s.split(//).sort_by {rand}.join + extra) | ||
end | ||
|
||
def clicktale_url | ||
@clicktale_url ||= "#{request.protocol}#{request.host_with_port}#{clicktale_path}" | ||
end | ||
def clicktale_path | ||
@clicktale_path ||= "/clicktale/#{clicktale_cache_token}.html" | ||
end | ||
|
||
def clicktale_url | ||
@clicktale_url ||= "#{request.protocol}#{request.host_with_port}#{clicktale_path}" | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,20 @@ | ||
module Astrails | ||
module Clicktale | ||
module Helper | ||
def clicktale_top | ||
return unless clicktale_enabled? | ||
render :partial => "clicktale/top.html.erb" | ||
end | ||
module Clicktale | ||
module Helper | ||
def clicktale_top | ||
return unless clicktale_enabled? | ||
render :partial => "clicktale/top.html.erb" | ||
end | ||
|
||
def clicktale_bottom | ||
return unless clicktale_enabled? | ||
def clicktale_bottom | ||
return unless clicktale_enabled? | ||
|
||
render :partial => "clicktale/bottom.html.erb", :locals => { | ||
:project_id => clicktale_config[:project_id], | ||
:path => clicktale_url, | ||
:ratio => clicktale_config[:ratio] || 1, | ||
:tag => clicktale_config[:tag], | ||
:param => clicktale_config[:param] | ||
} | ||
end | ||
render :partial => "clicktale/bottom.html.erb", :locals => { | ||
:project_id => clicktale_config[:project_id], | ||
:path => clicktale_url, | ||
:ratio => clicktale_config[:ratio] || 1, | ||
:tag => clicktale_config[:tag], | ||
:param => clicktale_config[:param] | ||
} | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'clicktale' | ||
Clicktale.init |