voidtools 0.2.3 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- data/Readme.md +15 -1
- data/lib/voidtools.rb +13 -6
- data/lib/voidtools/dm/datamapper.rb +3 -0
- data/lib/voidtools/dm/paginable.rb +33 -1
- data/lib/voidtools/sinatra/sinatra.rb +10 -1
- data/lib/voidtools/sinatra/tracking.rb +88 -0
- data/lib/voidtools/sinatra/view_helpers.rb +10 -0
- data/lib/voidtools/version.rb +1 -1
- metadata +23 -31
data/Readme.md
CHANGED
@@ -3,6 +3,11 @@
|
|
3
3
|
|
4
4
|
---
|
5
5
|
|
6
|
+
### Install from RubyGems
|
7
|
+
|
8
|
+
gem i voidtools
|
9
|
+
|
10
|
+
|
6
11
|
### DataMapper
|
7
12
|
- form helpers: error_messages_for
|
8
13
|
- name url
|
@@ -29,4 +34,13 @@ or
|
|
29
34
|
|
30
35
|
### Build & install
|
31
36
|
|
32
|
-
|
37
|
+
|
38
|
+
git clone git://github.com/makevoid/voidtools.git
|
39
|
+
cd voidtools;
|
40
|
+
gem build voidtools.gemspec; gem install voidtools-x.x.x.gem
|
41
|
+
|
42
|
+
|
43
|
+
### Changelog
|
44
|
+
|
45
|
+
v0.2.9 - added datamapper module autoload if DataMapper is defined
|
46
|
+
v0.2.3 - first stable version, autoloads modules for sinatra and rails
|
data/lib/voidtools.rb
CHANGED
@@ -1,23 +1,25 @@
|
|
1
1
|
module Voidtools
|
2
|
-
|
2
|
+
|
3
3
|
# namespace our plugin and inherit from Rails::Railtie
|
4
4
|
# to get our plugin into the initialization process
|
5
5
|
if defined?(Rails)
|
6
6
|
class Railtie < Rails::Railtie
|
7
|
-
|
7
|
+
|
8
8
|
# configure our plugin on boot. other extension points such
|
9
9
|
# as configuration, rake tasks, etc, are also available
|
10
10
|
initializer "voidtools.initialize" do |app|
|
11
|
-
|
11
|
+
|
12
12
|
# subscribe to all rails notifications: controllers, AR, etc.
|
13
13
|
# ActiveSupport::Notifications.subscribe do |*args|
|
14
14
|
# event = ActiveSupport::Notifications::Event.new(*args)
|
15
15
|
# puts "Voidrails - got notification: #{event.inspect}"
|
16
16
|
# end
|
17
17
|
require 'voidtools/dm/form_helpers'
|
18
|
+
require 'voidtools/sinatra/tracking'
|
18
19
|
ActiveSupport.on_load(:action_view) do
|
19
20
|
module ApplicationHelper
|
20
21
|
include Voidtools::FormHelpers
|
22
|
+
include Voidtools::Tracking
|
21
23
|
end
|
22
24
|
end
|
23
25
|
# require 'voidtools/dm/name_url'
|
@@ -25,9 +27,14 @@ module Voidtools
|
|
25
27
|
end
|
26
28
|
end
|
27
29
|
end
|
28
|
-
|
30
|
+
|
31
|
+
@@path = File.expand_path "../", __FILE__
|
32
|
+
|
29
33
|
if defined?(Sinatra)
|
30
|
-
|
31
|
-
|
34
|
+
require "#{@@path}/voidtools/sinatra/sinatra"
|
35
|
+
end
|
36
|
+
|
37
|
+
if defined?(DataMapper)
|
38
|
+
require "#{@@path}/voidtools/dm/datamapper"
|
32
39
|
end
|
33
40
|
end
|
@@ -1,3 +1,35 @@
|
|
1
|
+
# Paginable
|
2
|
+
#
|
3
|
+
# Usage:
|
4
|
+
#
|
5
|
+
# in your model add:
|
6
|
+
# require 'voidtools/dm/paginable'
|
7
|
+
# include Voidtools::Paginable
|
8
|
+
#
|
9
|
+
# in a controller (or similar):
|
10
|
+
# Model.paginate(page: params[:page])
|
11
|
+
#
|
12
|
+
# in your view:
|
13
|
+
# .pagination
|
14
|
+
# pag:
|
15
|
+
# - Model.pages.times do |i|
|
16
|
+
# %a{ :href => "/path?page=#{i}" }= i+1
|
17
|
+
#
|
18
|
+
# (optional) in your model:
|
19
|
+
# def self.per_page
|
20
|
+
# 20
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# sass:
|
24
|
+
#
|
25
|
+
# .pagination
|
26
|
+
# margin: 10px 20px
|
27
|
+
# a
|
28
|
+
# padding: 3px 6px
|
29
|
+
# background: #DDD
|
30
|
+
# a:hover
|
31
|
+
# background: #FFF
|
32
|
+
|
1
33
|
module Voidtools
|
2
34
|
|
3
35
|
module Paginable
|
@@ -18,7 +50,7 @@ module Voidtools
|
|
18
50
|
end
|
19
51
|
|
20
52
|
def pages
|
21
|
-
all.count/x_page
|
53
|
+
(all.count.to_f/x_page).ceil
|
22
54
|
end
|
23
55
|
end
|
24
56
|
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# Voidtools::Tracking
|
2
|
+
# ---------------------------------------------
|
3
|
+
|
4
|
+
# Setup:
|
5
|
+
#
|
6
|
+
# put these lines in your app_helper.rb:
|
7
|
+
#
|
8
|
+
# require 'voidtools/sinatra/tracking'
|
9
|
+
# include Voidtools::Tracking
|
10
|
+
|
11
|
+
|
12
|
+
# Usage:
|
13
|
+
#
|
14
|
+
# :javascript
|
15
|
+
# #{crazyegg}
|
16
|
+
# #{gauges("id")}
|
17
|
+
|
18
|
+
|
19
|
+
module Voidtools
|
20
|
+
module Tracking
|
21
|
+
|
22
|
+
def track_run(&block)
|
23
|
+
if defined?(Rails)
|
24
|
+
yield if Rails.env != "development"
|
25
|
+
else
|
26
|
+
yield if ENV["RACK_ENV"] != "development"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def analytics(id, *domains) # before the end of head tag
|
31
|
+
# FIXME: try with multiple domains
|
32
|
+
# TODO: test case
|
33
|
+
track_run do
|
34
|
+
out = <<-FUN
|
35
|
+
var _gaq = _gaq || [];
|
36
|
+
_gaq.push(['_setAccount', '#{id}']);FUN
|
37
|
+
domains.each do |domain|
|
38
|
+
out << " _gaq.push(['_setDomainName', '.#{domain}']);"
|
39
|
+
end
|
40
|
+
<<-FUN
|
41
|
+
_gaq.push(['_trackPageview']);
|
42
|
+
|
43
|
+
(function() {
|
44
|
+
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
45
|
+
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
46
|
+
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
47
|
+
})();
|
48
|
+
FUN
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def mixpanel
|
53
|
+
track_run do
|
54
|
+
# ...
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def crazyegg # before the end of body tag
|
59
|
+
|
60
|
+
track_run do
|
61
|
+
<<-FUN
|
62
|
+
setTimeout(function(){var a=document.createElement("script");
|
63
|
+
var b=document.getElementsByTagName('script')[0];
|
64
|
+
a.src=document.location.protocol+"//dnn506yrbagrg.cloudfront.net/pages/scripts/0011/5433.js";
|
65
|
+
a.async=true;a.type="text/javascript";b.parentNode.insertBefore(a,b)}, 1);
|
66
|
+
FUN
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
def gauges(id) # before the end of body tag
|
72
|
+
track_run do
|
73
|
+
<<-FUN
|
74
|
+
(function() {
|
75
|
+
var t = document.createElement('script');
|
76
|
+
t.type = 'text/javascript';
|
77
|
+
t.async = true;
|
78
|
+
t.id = 'gauges-tracker';
|
79
|
+
t.setAttribute('data-site-id', '#{id}');
|
80
|
+
t.src = '//secure.gaug.es/track.js';
|
81
|
+
var s = document.getElementsByTagName('script')[0];
|
82
|
+
s.parentNode.insertBefore(t, s);
|
83
|
+
})();
|
84
|
+
FUN
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -1,6 +1,10 @@
|
|
1
1
|
module Voidtools
|
2
2
|
module Sinatra
|
3
3
|
module ViewHelpers
|
4
|
+
|
5
|
+
# require 'voidtools/sinatra/tracking'
|
6
|
+
# include Voidtools::Tracking
|
7
|
+
|
4
8
|
def link_to(label, path="javascript:void(0)", options={})
|
5
9
|
# haml_tag :a, { href: path } do
|
6
10
|
# haml_concat label
|
@@ -35,6 +39,12 @@ module Voidtools
|
|
35
39
|
def include_css(assets)
|
36
40
|
include_assets "css", assets
|
37
41
|
end
|
42
|
+
|
43
|
+
def body_class
|
44
|
+
path = request.path.split("/")[1..2]
|
45
|
+
path = path.join(" ") unless path.nil?
|
46
|
+
request.path == "/" ? "home" : path
|
47
|
+
end
|
38
48
|
end
|
39
49
|
end
|
40
50
|
end
|
data/lib/voidtools/version.rb
CHANGED
metadata
CHANGED
@@ -1,65 +1,57 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: voidtools
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.9
|
4
5
|
prerelease:
|
5
|
-
version: 0.2.3
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Francesco 'makevoid' Canessa
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
date: 2011-06-07 00:00:00 +02:00
|
14
|
-
default_executable:
|
12
|
+
date: 2012-02-26 00:00:00.000000000 Z
|
15
13
|
dependencies: []
|
16
|
-
|
17
|
-
|
14
|
+
description: ! 'handy toolset for sinatra and datamapper - sinatra modules: tracking,
|
15
|
+
view_helpers - datamapper modules: form_helpers, name_url, paginable'
|
18
16
|
email: makevoid@gmail.com
|
19
17
|
executables: []
|
20
|
-
|
21
18
|
extensions: []
|
22
|
-
|
23
19
|
extra_rdoc_files: []
|
24
|
-
|
25
|
-
files:
|
20
|
+
files:
|
26
21
|
- Readme.md
|
27
22
|
- lib/voidtools/cap/deploy.rb
|
23
|
+
- lib/voidtools/dm/datamapper.rb
|
28
24
|
- lib/voidtools/dm/form_helpers.rb
|
29
25
|
- lib/voidtools/dm/name_url.rb
|
30
26
|
- lib/voidtools/dm/paginable.rb
|
31
27
|
- lib/voidtools/rails/app_mixin.rb
|
32
28
|
- lib/voidtools/sinatra/sinatra.rb
|
29
|
+
- lib/voidtools/sinatra/tracking.rb
|
33
30
|
- lib/voidtools/sinatra/view_helpers.rb
|
34
31
|
- lib/voidtools/version.rb
|
35
32
|
- lib/voidtools.rb
|
36
|
-
has_rdoc: true
|
37
33
|
homepage: http://www.makevoid.com
|
38
34
|
licenses: []
|
39
|
-
|
40
35
|
post_install_message:
|
41
36
|
rdoc_options: []
|
42
|
-
|
43
|
-
require_paths:
|
37
|
+
require_paths:
|
44
38
|
- lib
|
45
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
40
|
none: false
|
47
|
-
requirements:
|
48
|
-
- -
|
49
|
-
- !ruby/object:Gem::Version
|
50
|
-
version:
|
51
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
46
|
none: false
|
53
|
-
requirements:
|
54
|
-
- -
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version:
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
57
51
|
requirements: []
|
58
|
-
|
59
52
|
rubyforge_project: voidtools
|
60
|
-
rubygems_version: 1.
|
53
|
+
rubygems_version: 1.8.10
|
61
54
|
signing_key:
|
62
55
|
specification_version: 3
|
63
|
-
summary:
|
56
|
+
summary: handy toolset for sinatra and datamapper
|
64
57
|
test_files: []
|
65
|
-
|