Skip to content

Commit

Permalink
Add rails gem init and change namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
Cory Fabre committed Sep 28, 2011
1 parent 67e35a9 commit ae409cf
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 91 deletions.
4 changes: 2 additions & 2 deletions Rakefile
Expand Up @@ -6,8 +6,8 @@ begin
Jeweler::Tasks.new do |gem|
gem.name = "clicktale"
gem.summary = %Q{TODO}
gem.email = "michael@astrails.com"
gem.homepage = "http://github.com/astrails/clicktale"
gem.email = "cory@voteit.com"
gem.homepage = "http://github.com/coryf/clicktale"
gem.authors = ["Michael Mazyar"]
gem.files = FileList["[A-Z]*.*", "{bin,app,examples,generators,lib,rails,templates,config}/**/*", 'Rakefile', 'LICENSE*']

Expand Down
4 changes: 2 additions & 2 deletions bin/clicktaleize
Expand Up @@ -13,8 +13,8 @@ clicktale_dir = File.join(root, "vendor/plugins/clicktale")
FileUtils.mkdir_p(clicktale_dir)
File.open(File.join(clicktale_dir, "init.rb"), "w") do |file|
file.write <<-INIT
require 'astrails/clicktale'
Astrails::Clicktale.init
require 'clicktale'
Clicktale.init
INIT
end

Expand Down
8 changes: 4 additions & 4 deletions clicktale.gemspec
Expand Up @@ -2,18 +2,18 @@

Gem::Specification.new do |s|
s.name = %q{clicktale}
s.version = "0.0.1"
s.version = "0.0.2"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Michael Mazyar"]
s.authors = ["Michael Mazyar", "Cory Fabre"]
s.date = %q{2009-05-06}
s.default_executable = %q{clicktaleize}
s.email = %q{michael@astrails.com}
s.email = %q{cory@voteit.com}
s.executables = ["clicktaleize"]
s.extra_rdoc_files = ["README.rdoc", "LICENSE"]
s.files = ["README.rdoc", "VERSION.yml", "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"]
s.has_rdoc = true
s.homepage = %q{http://github.com/astrails/clicktale}
s.homepage = %q{http://github.com/coryf/clicktale}
s.rdoc_options = ["--inline-source", "--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.1}
Expand Down
3 changes: 1 addition & 2 deletions init.rb
@@ -1,2 +1 @@
require 'astrails/clicktale'
Astrails::Clicktale.init
require File.join(File.dirname(__FILE__), 'rails', 'init')
40 changes: 19 additions & 21 deletions lib/astrails/clicktale.rb
@@ -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
82 changes: 40 additions & 42 deletions lib/astrails/clicktale/controller.rb
@@ -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
33 changes: 15 additions & 18 deletions lib/astrails/clicktale/helper.rb
@@ -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

2 changes: 2 additions & 0 deletions rails/init.rb
@@ -0,0 +1,2 @@
require 'clicktale'
Clicktale.init

0 comments on commit ae409cf

Please sign in to comment.