clickmap 0.0.2
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.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +43 -0
- data/Rakefile +16 -0
- data/clickmap.gemspec +25 -0
- data/lib/clickmap.rb +3 -0
- data/lib/clickmap/base.rb +52 -0
- data/lib/clickmap/error.rb +6 -0
- data/lib/clickmap/version.rb +3 -0
- data/test/lib/clickmap/base_test.rb +64 -0
- data/test/lib/clickmap/version_test.rb +7 -0
- data/test/test_helper.rb +3 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZTA5NTM2NmUyMTIyODQ0ZDg5YWM4NGRlNTExNDZkMTgzYWMzY2UxYw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
OThlNjhiOWU5MzFiOTdlZDU2YzVmMGQ2ZmEwYTNhMjJlMGU2NWFmZg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YTYwNDljNzJhOTM4YWFiN2YzNWQ4N2U3MzhlY2U1YzQ2YzUxMTYzZmZhZTlj
|
10
|
+
NDExOWE4ZDkyZmM1MWQ0NDU0ZTUwZDM4OGRlYzc3NjYxMzc3YTA2MWQzNmM0
|
11
|
+
NDI5NjMxZDMzMjViNWMxYjM0ZDM4YjdmMTNkOTY5NTBjNDY4ZmE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MzU5OWVjMjUzMTk2MDZkYWY5MzkzOTMxMjljNDNiZDU1YWJmZDRiYTY5ZTQ5
|
14
|
+
MTY5MjZiYTVhZWY3NGVkZDE4Mzg3NWZlZmE0ODgyZmNkZWFiNjA5NGJkYmUy
|
15
|
+
MzIxNWE3Mzg1NDE1YzFiNmNjODhlYjgxMzMzYjJmZDNmMThmMDE=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Damien Brzoska
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Clickmap
|
2
|
+
|
3
|
+
Simple clickmap for html content. This gem assumes that you are passing valid HTML content and an array of hashes with the links (regex) to match and the number of clicks
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'clickmap'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install clickmap
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
Clickmap.new(html_string, array_of_links[, extras_options])
|
23
|
+
```
|
24
|
+
|
25
|
+
For example
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
html = "<html><head></head><body><a href='www.test.com'>test</a></body></html>"
|
29
|
+
array_of_links = [
|
30
|
+
{ url: /www.test.com/, count: 12 }
|
31
|
+
]
|
32
|
+
extras_options = { css_class: 'my_custom_class'}
|
33
|
+
puts Clickmap.new(html_string, array_of_links, extras_options).generate
|
34
|
+
# <html><head></head><body><a href='www.test.com' data-clickmap-count=12 class="clickmap-link my_custom_class">test</a></body></html>
|
35
|
+
```
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
1. Fork it ( http://github.com/<my-github-username>/clickmap/fork )
|
40
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
41
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
42
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
43
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
task :console do
|
5
|
+
require 'irb'
|
6
|
+
require 'irb/completion'
|
7
|
+
require 'clickmap'
|
8
|
+
ARGV.clear
|
9
|
+
IRB.start
|
10
|
+
end
|
11
|
+
|
12
|
+
Rake::TestTask.new do |t|
|
13
|
+
t.libs << 'lib/clickmap'
|
14
|
+
t.test_files = FileList['test/lib/clickmap/*_test.rb']
|
15
|
+
t.verbose = true
|
16
|
+
end
|
data/clickmap.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'clickmap/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "clickmap"
|
8
|
+
spec.version = Clickmap::VERSION
|
9
|
+
spec.authors = ["Damien Brzoska"]
|
10
|
+
spec.email = ["damien.brz@gmail.com"]
|
11
|
+
spec.summary = %q{Clickmap generator}
|
12
|
+
spec.description = "Simple clickmap for html content. This gem assumes that you are passing valid HTML content and an array of hashes with the links (regex) to match and the number of clicks"
|
13
|
+
spec.homepage = "https://github.com/damienbrz/clickmap"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.1"
|
23
|
+
spec.add_development_dependency "nokogiri", "~> 1.6"
|
24
|
+
spec.add_development_dependency "minitest", "~> 4.7"
|
25
|
+
end
|
data/lib/clickmap.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module Clickmap
|
4
|
+
class Base
|
5
|
+
attr_accessor :input_html, :links, :css_class
|
6
|
+
|
7
|
+
def initialize(input_html, links, extras = {})
|
8
|
+
self.input_html = input_html
|
9
|
+
self.links = links.map { |l| symbolize_keys(l) }
|
10
|
+
update_extras(extras)
|
11
|
+
validate_links
|
12
|
+
end
|
13
|
+
|
14
|
+
def generate
|
15
|
+
doc = Nokogiri::HTML(self.input_html)
|
16
|
+
doc.encoding = 'utf-8'
|
17
|
+
doc.css("a").each do |link|
|
18
|
+
link.attributes["class"] = link.attributes["class"].to_s + " " + self.css_class
|
19
|
+
self.links.each do |l|
|
20
|
+
if link.attributes['href'].value.match l[:url]
|
21
|
+
link.set_attribute("class", "clickmap-link #{self.css_class}")
|
22
|
+
link.set_attribute("data-clickmap-count", l[:count])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
doc.to_html
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def validate_links
|
32
|
+
raise Clickmap::Error::EmptyLinks if self.links.empty?
|
33
|
+
self.links.each do |link|
|
34
|
+
if link[:url].to_s == "" || link[:count].nil?
|
35
|
+
raise Clickmap::Error::InvalidLinks
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def update_extras(extras)
|
41
|
+
self.css_class = extras[:css_class] || 'clickmap'
|
42
|
+
end
|
43
|
+
|
44
|
+
def symbolize_keys(hash)
|
45
|
+
hash.inject({}){|result, (key, value)|
|
46
|
+
new_key = key.is_a?(String) ? key.to_sym : key
|
47
|
+
result[new_key] = value
|
48
|
+
result
|
49
|
+
}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe Clickmap::Base do
|
4
|
+
|
5
|
+
subject { Clickmap::Base }
|
6
|
+
|
7
|
+
it "should accept html, an array of link statistics and extra options" do
|
8
|
+
obj = subject.new("<!DOCTYPE html><html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'></head><body></body></html>", [{'url' => 'www.test.com', count: 45}], {})
|
9
|
+
obj.input_html.must_equal("<!DOCTYPE html><html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'></head><body></body></html>")
|
10
|
+
obj.links.must_equal([{url: 'www.test.com', count: 45}])
|
11
|
+
obj.css_class.must_equal("clickmap")
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "validate the links" do
|
15
|
+
it "should raise an error if links are empty" do
|
16
|
+
proc {
|
17
|
+
subject.new("<!DOCTYPE html><html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'></head><body></body></html>", [], {})
|
18
|
+
}.must_raise(Clickmap::Error::EmptyLinks)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should raise an error if links are invalid" do
|
22
|
+
proc {
|
23
|
+
subject.new("<!DOCTYPE html><html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'></head><body></body></html>", [{url: 'www.test.com'}], {})
|
24
|
+
}.must_raise(Clickmap::Error::InvalidLinks)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "generate html" do
|
29
|
+
|
30
|
+
it "output HTML" do
|
31
|
+
obj = subject.new("<!DOCTYPE html><html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'></head><body><a href='www.test.com'>test</a></body></html>", [{'url' => 'www.test.com', count: 45}], {})
|
32
|
+
obj.generate.must_equal("<!DOCTYPE html>\n<html>\n<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head>\n<body><a href=\"www.test.com\" class=\"clickmap-link clickmap\" data-clickmap-count=\"45\">test</a></body>\n</html>\n")
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "output HTML" do
|
36
|
+
|
37
|
+
it "using basic regex" do
|
38
|
+
obj = subject.new("<!DOCTYPE html><html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'></head><body><a href='www.test.com'>test</a></body></html>", [{'url' => /www.test.com/, count: 45}], {})
|
39
|
+
obj.generate.must_equal("<!DOCTYPE html>\n<html>\n<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head>\n<body><a href=\"www.test.com\" class=\"clickmap-link clickmap\" data-clickmap-count=\"45\">test</a></body>\n</html>\n")
|
40
|
+
end
|
41
|
+
|
42
|
+
it "matching email in URL" do
|
43
|
+
obj = subject.new("<!DOCTYPE html><html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'></head><body><a href='www.test.com?email=damien.brz@gmail.com'>test</a></body></html>", [{'url' => /www.test.com\?email=(.*)/, count: 45}], {})
|
44
|
+
obj.generate.must_equal("<!DOCTYPE html>\n<html>\n<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head>\n<body><a href=\"www.test.com?email=damien.brz@gmail.com\" class=\"clickmap-link clickmap\" data-clickmap-count=\"45\">test</a></body>\n</html>\n")
|
45
|
+
end
|
46
|
+
|
47
|
+
it "matching a subdomain" do
|
48
|
+
obj = subject.new("<!DOCTYPE html><html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'></head><body><a href='app.test.com/login'>test</a></body></html>", [{'url' => /(.*).test.com\/(.*)/, count: 45}], {})
|
49
|
+
obj.generate.must_equal("<!DOCTYPE html>\n<html>\n<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head>\n<body><a href=\"app.test.com/login\" class=\"clickmap-link clickmap\" data-clickmap-count=\"45\">test</a></body>\n</html>\n")
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "output HTML with extra options" do
|
55
|
+
|
56
|
+
it "with custom css class" do
|
57
|
+
obj = subject.new("<!DOCTYPE html><html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'></head><body><a href='www.test.com'>test</a></body></html>", [{'url' => 'www.test.com', count: 45}], { css_class: 'my-link'})
|
58
|
+
obj.generate.must_equal("<!DOCTYPE html>\n<html>\n<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head>\n<body><a href=\"www.test.com\" class=\"clickmap-link my-link\" data-clickmap-count=\"45\">test</a></body>\n</html>\n")
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: clickmap
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Damien Brzoska
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.1'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: nokogiri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4.7'
|
69
|
+
description: Simple clickmap for html content. This gem assumes that you are passing
|
70
|
+
valid HTML content and an array of hashes with the links (regex) to match and the
|
71
|
+
number of clicks
|
72
|
+
email:
|
73
|
+
- damien.brz@gmail.com
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- .gitignore
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- clickmap.gemspec
|
84
|
+
- lib/clickmap.rb
|
85
|
+
- lib/clickmap/base.rb
|
86
|
+
- lib/clickmap/error.rb
|
87
|
+
- lib/clickmap/version.rb
|
88
|
+
- test/lib/clickmap/base_test.rb
|
89
|
+
- test/lib/clickmap/version_test.rb
|
90
|
+
- test/test_helper.rb
|
91
|
+
homepage: https://github.com/damienbrz/clickmap
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ! '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.2.1
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Clickmap generator
|
115
|
+
test_files:
|
116
|
+
- test/lib/clickmap/base_test.rb
|
117
|
+
- test/lib/clickmap/version_test.rb
|
118
|
+
- test/test_helper.rb
|