heap-helpers 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.travis.yml +17 -0
- data/Gemfile +17 -0
- data/Gemfile187 +25 -0
- data/LICENSE.txt +20 -0
- data/README.md +75 -0
- data/Rakefile +44 -0
- data/VERSION +1 -0
- data/heap-helpers.gemspec +81 -0
- data/lib/heap-helpers.rb +4 -0
- data/lib/heap-helpers/client.rb +3 -0
- data/lib/heap-helpers/helpers.rb +66 -0
- data/lib/heap-helpers/snippet.js +1 -0
- data/test/client_test.rb +30 -0
- data/test/heap_test.rb +7 -0
- data/test/helper.rb +47 -0
- data/test/tags_test.rb +63 -0
- metadata +188 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 031ebac3f1c6632650dae379427e0f46d5529d02
|
4
|
+
data.tar.gz: 8f3bfc58301b00e8725786d8ce71955c78148578
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 22dbdcee27ab764699c91efc954eefbc33145fa4e90e71923d154829bb4922b6c6b83196648c0335e8d7e74613c79cac0a75b22b01222c8198e113a3e62a7bbd
|
7
|
+
data.tar.gz: d36eec156050dd26c94f921ded930a3e63cd1ee7926bcc190118493b6453c51bf162bebf79da0aeeeed13bbc9ce3b6861ef34958eef5c609db10cf50f83c5fe4
|
data/.document
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
matrix:
|
4
|
+
include:
|
5
|
+
- rvm: 1.8.7
|
6
|
+
gemfile: Gemfile187
|
7
|
+
- rvm: 1.9.3
|
8
|
+
gemfile: Gemfile
|
9
|
+
- rvm: 2.0.0
|
10
|
+
gemfile: Gemfile
|
11
|
+
- rvm: 2.1.8
|
12
|
+
gemfile: Gemfile
|
13
|
+
- rvm: 2.2.4
|
14
|
+
gemfile: Gemfile
|
15
|
+
- rvm: 2.3.0
|
16
|
+
gemfile: Gemfile
|
17
|
+
env: COVERAGE=1
|
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Add dependencies required to use your gem here.
|
4
|
+
gem 'heap', '~> 1.0'
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem 'activesupport', '>= 2.3.8'
|
10
|
+
gem 'bundler', '>= 1.0'
|
11
|
+
gem 'coveralls', '>= 0.8.10'
|
12
|
+
gem 'jeweler', '>= 2.0.1'
|
13
|
+
gem 'minitest', '>= 5.8.4'
|
14
|
+
gem 'rdoc', '>= 3.12'
|
15
|
+
gem 'simplecov', '>= 0.11.2'
|
16
|
+
gem 'yard', '>= 0.8.7.6'
|
17
|
+
end
|
data/Gemfile187
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Add dependencies required to use your gem here.
|
4
|
+
gem 'heap', '~> 1.0'
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem 'bundler', '>= 1.0'
|
10
|
+
gem 'minitest', '>= 5.8.4'
|
11
|
+
gem 'rdoc', '>= 4.2.2'
|
12
|
+
gem 'yard', '>= 0.8.7.6'
|
13
|
+
|
14
|
+
# NOTE: The latest versions of these dependencies do not support Ruby 1.8.7.
|
15
|
+
gem 'activesupport', '~> 2.3.8'
|
16
|
+
gem 'jeweler', '~> 1.8.8'
|
17
|
+
|
18
|
+
# NOTE: These are dependencies of the gems that we require whose latest
|
19
|
+
# versions do not support Ruby 1.8.7.
|
20
|
+
gem 'addressable', '~> 2.3.8'
|
21
|
+
gem 'faraday', '~> 0.8.11'
|
22
|
+
gem 'faraday_middleware', '~> 0.8.0'
|
23
|
+
gem 'git', '~> 1.2.9'
|
24
|
+
gem 'highline', '~> 1.6.21'
|
25
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2016 Victor Costan
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# Heap Helpers for Ruby
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/pwnall/heap-helpers-ruby.svg?branch=master)](https://travis-ci.org/pwnall/heap-helpers-ruby)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/github/pwnall/heap-helpers-ruby/badge.svg?branch=master)](https://coveralls.io/github/pwnall/heap-helpers-ruby?branch=master)
|
5
|
+
[![Dependency Status](https://gemnasium.com/pwnall/heap-helpers-ruby.svg)](https://gemnasium.com/pwnall/heap-helpers/ruby)
|
6
|
+
[![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/github/pwnall/heap-helpers-ruby/master/frames)
|
7
|
+
[![Gem Version](https://badge.fury.io/rb/heap-helpers.svg)](https://badge.fury.io/rb/heap-helpers)
|
8
|
+
|
9
|
+
This Ruby gem contains helpers for embedding the
|
10
|
+
[heap.js snippet](https://heapanalytics.com/docs/installation#web) used to
|
11
|
+
instal [Heap](https://heapanalytics.com/) on a site.
|
12
|
+
|
13
|
+
|
14
|
+
## Prerequisites
|
15
|
+
|
16
|
+
This gem is tested on Ruby 1.8.7 and above, and is expected to work with Rails
|
17
|
+
2.3.8 and above. The gem depends on the official
|
18
|
+
[heap](https://github.com/heap/heap-ruby) gem.
|
19
|
+
|
20
|
+
|
21
|
+
## Installation
|
22
|
+
|
23
|
+
If you're using [bundler](http://bundler.io/), add the following line to your
|
24
|
+
[Gemfile](http://bundler.io/v1.11/gemfile.html).
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
gem 'heap-helpers'
|
28
|
+
```
|
29
|
+
|
30
|
+
Otherwise, install the [heap-helpers](https://rubygems.org/gems/heap) gem and
|
31
|
+
activate it in your code manually.
|
32
|
+
|
33
|
+
```bash
|
34
|
+
gem install heap
|
35
|
+
```
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
require 'heap-helpers'
|
39
|
+
```
|
40
|
+
|
41
|
+
|
42
|
+
## Setup
|
43
|
+
|
44
|
+
Follow the instructions for the `heap` gem.
|
45
|
+
|
46
|
+
|
47
|
+
## Usage
|
48
|
+
|
49
|
+
Add the following in your layouts or views, before the closing `</head>` tag.
|
50
|
+
In a typical Ruby on Rails application, this change would go into
|
51
|
+
`app/views/layouts/application.html.erb`.
|
52
|
+
|
53
|
+
```erb
|
54
|
+
<%= Heap.javascript_tag %>
|
55
|
+
```
|
56
|
+
|
57
|
+
The helper supports advanced heap.js options.
|
58
|
+
|
59
|
+
```erb
|
60
|
+
<%= Heap.javascript_tag force_ssl: true %>
|
61
|
+
```
|
62
|
+
|
63
|
+
You can also specify advanced options in the initialization code. This is
|
64
|
+
especially useful if you're using the same helper in multiple places in your
|
65
|
+
code.
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
Heap.app_id = 'YOUR_APP_ID'
|
69
|
+
Heap.js_options = { force_ssl: true }
|
70
|
+
```
|
71
|
+
|
72
|
+
|
73
|
+
## Copyright
|
74
|
+
|
75
|
+
Copyright (c) 2016 Victor Costan, released under the MIT license.
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
17
|
+
gem.name = "heap-helpers"
|
18
|
+
gem.homepage = "http://github.com/pwnall/heap-helpers-ruby"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Heap javascript snippet helpers}
|
21
|
+
gem.description = %Q{Rails-compatible helpers for setting the heap.js snippet}
|
22
|
+
gem.email = "victor@costan.us"
|
23
|
+
gem.authors = ["Victor Costan"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/*_test.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
desc 'Code coverage detail'
|
36
|
+
task :simplecov do
|
37
|
+
ENV['COVERAGE'] = 'true'
|
38
|
+
Rake::Task['test'].execute
|
39
|
+
end
|
40
|
+
|
41
|
+
task :default => :test
|
42
|
+
|
43
|
+
require 'yard'
|
44
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: heap-helpers 0.1.0 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "heap-helpers"
|
9
|
+
s.version = "0.1.0"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.authors = ["Victor Costan"]
|
14
|
+
s.date = "2016-03-01"
|
15
|
+
s.description = "Rails-compatible helpers for setting the heap.js snippet"
|
16
|
+
s.email = "victor@costan.us"
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE.txt",
|
19
|
+
"README.md"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".travis.yml",
|
24
|
+
"Gemfile",
|
25
|
+
"Gemfile187",
|
26
|
+
"LICENSE.txt",
|
27
|
+
"README.md",
|
28
|
+
"Rakefile",
|
29
|
+
"VERSION",
|
30
|
+
"heap-helpers.gemspec",
|
31
|
+
"lib/heap-helpers.rb",
|
32
|
+
"lib/heap-helpers/client.rb",
|
33
|
+
"lib/heap-helpers/helpers.rb",
|
34
|
+
"lib/heap-helpers/snippet.js",
|
35
|
+
"test/client_test.rb",
|
36
|
+
"test/heap_test.rb",
|
37
|
+
"test/helper.rb",
|
38
|
+
"test/tags_test.rb"
|
39
|
+
]
|
40
|
+
s.homepage = "http://github.com/pwnall/heap-helpers-ruby"
|
41
|
+
s.licenses = ["MIT"]
|
42
|
+
s.rubygems_version = "2.5.1"
|
43
|
+
s.summary = "Heap javascript snippet helpers"
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
s.specification_version = 4
|
47
|
+
|
48
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
|
+
s.add_runtime_dependency(%q<heap>, ["~> 1.0"])
|
50
|
+
s.add_development_dependency(%q<activesupport>, [">= 2.3.8"])
|
51
|
+
s.add_development_dependency(%q<bundler>, [">= 1.0"])
|
52
|
+
s.add_development_dependency(%q<coveralls>, [">= 0.8.10"])
|
53
|
+
s.add_development_dependency(%q<jeweler>, [">= 2.0.1"])
|
54
|
+
s.add_development_dependency(%q<minitest>, [">= 5.8.4"])
|
55
|
+
s.add_development_dependency(%q<rdoc>, [">= 3.12"])
|
56
|
+
s.add_development_dependency(%q<simplecov>, [">= 0.11.2"])
|
57
|
+
s.add_development_dependency(%q<yard>, [">= 0.8.7.6"])
|
58
|
+
else
|
59
|
+
s.add_dependency(%q<heap>, ["~> 1.0"])
|
60
|
+
s.add_dependency(%q<activesupport>, [">= 2.3.8"])
|
61
|
+
s.add_dependency(%q<bundler>, [">= 1.0"])
|
62
|
+
s.add_dependency(%q<coveralls>, [">= 0.8.10"])
|
63
|
+
s.add_dependency(%q<jeweler>, [">= 2.0.1"])
|
64
|
+
s.add_dependency(%q<minitest>, [">= 5.8.4"])
|
65
|
+
s.add_dependency(%q<rdoc>, [">= 3.12"])
|
66
|
+
s.add_dependency(%q<simplecov>, [">= 0.11.2"])
|
67
|
+
s.add_dependency(%q<yard>, [">= 0.8.7.6"])
|
68
|
+
end
|
69
|
+
else
|
70
|
+
s.add_dependency(%q<heap>, ["~> 1.0"])
|
71
|
+
s.add_dependency(%q<activesupport>, [">= 2.3.8"])
|
72
|
+
s.add_dependency(%q<bundler>, [">= 1.0"])
|
73
|
+
s.add_dependency(%q<coveralls>, [">= 0.8.10"])
|
74
|
+
s.add_dependency(%q<jeweler>, [">= 2.0.1"])
|
75
|
+
s.add_dependency(%q<minitest>, [">= 5.8.4"])
|
76
|
+
s.add_dependency(%q<rdoc>, [">= 3.12"])
|
77
|
+
s.add_dependency(%q<simplecov>, [">= 0.11.2"])
|
78
|
+
s.add_dependency(%q<yard>, [">= 0.8.7.6"])
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
data/lib/heap-helpers.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# Helper tags.
|
2
|
+
module HeapAPI::Helpers
|
3
|
+
# Generates a <script> tag that includes and configures heap.js.
|
4
|
+
#
|
5
|
+
# The tag should be inserted before the closing </head> tag on each page of
|
6
|
+
# the site.
|
7
|
+
#
|
8
|
+
# @param options [Hash] advanced configuration for heap.js
|
9
|
+
# @option options [Boolean] :force_ssl when set to true, heap.js will only
|
10
|
+
# use SSL to send data to our collection endpoints; defaults to false
|
11
|
+
# @option options [Boolean] :secure_cookie when set to true, user cookies in
|
12
|
+
# heap.js will only be transmitted via SSL; defaults to false
|
13
|
+
# @option options [Boolean] :disable_text_capture when set to true, heap.js
|
14
|
+
# will not capture the text content of elements; defaults to false
|
15
|
+
# @return {ActiveSupport::SafeBuffer} <script> tag that includes and
|
16
|
+
# configures heap.js
|
17
|
+
# @see https://heapanalytics.com/docs/installation#web
|
18
|
+
def javascript_tag(options = {})
|
19
|
+
ensure_valid_app_id!
|
20
|
+
app_string = app_id.inspect
|
21
|
+
|
22
|
+
option_strings = []
|
23
|
+
options.merge(js_options).each do |key, value|
|
24
|
+
unless js_key = JS_OPTIONS[key]
|
25
|
+
raise ArgumentError, "Invalid heap.js advanced option #{key.inspect}"
|
26
|
+
end
|
27
|
+
option_strings << "#{js_key}:#{!!value}"
|
28
|
+
end
|
29
|
+
|
30
|
+
if option_strings.empty?
|
31
|
+
js_args = app_string
|
32
|
+
else
|
33
|
+
js_args = "#{app_string},{#{option_strings.join(',')}}"
|
34
|
+
end
|
35
|
+
|
36
|
+
JS_SNIPPET.join(js_args).html_safe
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [Hash<Symbol, Object>] default heap.js advanced options
|
40
|
+
# @see HeapAPI::Client#javascript_tag
|
41
|
+
attr_accessor :js_options
|
42
|
+
|
43
|
+
def js_options
|
44
|
+
@js_options ||= {}
|
45
|
+
end
|
46
|
+
|
47
|
+
def js_options=(new_options)
|
48
|
+
new_options.each do |key, value|
|
49
|
+
unless JS_OPTIONS[key]
|
50
|
+
raise ArgumentError, "Invalid heap.js advanced option #{key.inspect}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
@js_options = new_options
|
54
|
+
end
|
55
|
+
|
56
|
+
# The fragments that make up the Heap JS snippet.
|
57
|
+
JS_SNIPPET = File.read(File.join(File.dirname(__FILE__), 'snippet.js')).
|
58
|
+
split('$$args')
|
59
|
+
|
60
|
+
# Maps Ruby-esque snake_case heap.js options to JS-esque CamelCase options.
|
61
|
+
JS_OPTIONS = {
|
62
|
+
:force_ssl => 'forceSSL',
|
63
|
+
:secure_cookie => 'secureCookie',
|
64
|
+
:disable_text_capture => 'disableTextCapture',
|
65
|
+
}
|
66
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<script type="text/javascript">window.heap=window.heap||[],heap.load=function(e,t){window.heap.appid=e,window.heap.config=t=t||{};var n=t.forceSSL||"https:"===document.location.protocol,a=document.createElement("script");a.type="text/javascript",a.async=!0,a.src=(n?"https:":"http:")+"//cdn.heapanalytics.com/js/heap-"+e+".js";var o=document.getElementsByTagName("script")[0];o.parentNode.insertBefore(a,o);for(var r=function(e){return function(){heap.push([e].concat(Array.prototype.slice.call(arguments,0)))}},p=["clearEventProperties","identify","setEventProperties","track","unsetEventProperty"],c=0;c<p.length;c++)heap[p[c]]=r(p[c])};heap.load($$args);</script>
|
data/test/client_test.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class ClientTest < MiniTest::Test
|
4
|
+
def setup
|
5
|
+
@heap = HeapAPI::Client.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_default_js_options
|
9
|
+
assert_equal({}, @heap.js_options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_js_options_setter
|
13
|
+
@heap.js_options = { :force_ssl => true }
|
14
|
+
assert_equal({ :force_ssl => true }, @heap.js_options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_invalid_js_options
|
18
|
+
exception = assert_raises ArgumentError do
|
19
|
+
@heap.js_options = { :derp => true }
|
20
|
+
end
|
21
|
+
assert_equal ArgumentError, exception.class
|
22
|
+
assert_equal 'Invalid heap.js advanced option :derp', exception.message
|
23
|
+
end
|
24
|
+
def test_constructor_options
|
25
|
+
heap = Heap.new :app_id => 'test-app-id',
|
26
|
+
:js_options => { :force_ssl => true }
|
27
|
+
assert_equal 'test-app-id', heap.app_id
|
28
|
+
assert_equal({ :force_ssl => true }, heap.js_options)
|
29
|
+
end
|
30
|
+
end
|
data/test/heap_test.rb
ADDED
data/test/helper.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
if RUBY_VERSION >= '1.9' # simplecov only works on MRI 1.9+
|
2
|
+
require 'simplecov'
|
3
|
+
require 'coveralls'
|
4
|
+
|
5
|
+
module SimpleCov::Configuration
|
6
|
+
def clean_filters
|
7
|
+
@filters = []
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
SimpleCov.configure do
|
12
|
+
clean_filters
|
13
|
+
load_adapter 'test_frameworks'
|
14
|
+
end
|
15
|
+
|
16
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
17
|
+
SimpleCov::Formatter::HTMLFormatter,
|
18
|
+
Coveralls::SimpleCov::Formatter
|
19
|
+
]
|
20
|
+
|
21
|
+
ENV["COVERAGE"] && SimpleCov.start do
|
22
|
+
add_filter "/.rvm/"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require 'rubygems'
|
27
|
+
require 'bundler'
|
28
|
+
begin
|
29
|
+
Bundler.setup(:default, :development)
|
30
|
+
rescue Bundler::BundlerError => e
|
31
|
+
$stderr.puts e.message
|
32
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
33
|
+
exit e.status_code
|
34
|
+
end
|
35
|
+
require 'minitest/autorun'
|
36
|
+
|
37
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
38
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
39
|
+
require 'heap-helpers'
|
40
|
+
|
41
|
+
# We need String#html_safe.
|
42
|
+
require 'active_support/core_ext/string/output_safety'
|
43
|
+
|
44
|
+
class MiniTest::Test
|
45
|
+
end
|
46
|
+
|
47
|
+
MiniTest.autorun
|
data/test/tags_test.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TagsTest < MiniTest::Test
|
4
|
+
def setup
|
5
|
+
@heap = HeapAPI::Client.new
|
6
|
+
@heap.app_id = 'test-app-id'
|
7
|
+
@heap.js_options = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_javascript_tag_without_app_id
|
11
|
+
new_client = HeapAPI::Client.new
|
12
|
+
exception = assert_raises RuntimeError do
|
13
|
+
new_client.javascript_tag
|
14
|
+
end
|
15
|
+
assert_equal RuntimeError, exception.class
|
16
|
+
assert_equal 'Heap app_id not set', exception.message
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_javascript_tag_with_invalid_option
|
20
|
+
exception = assert_raises ArgumentError do
|
21
|
+
@heap.javascript_tag :derp => true
|
22
|
+
end
|
23
|
+
assert_equal ArgumentError, exception.class
|
24
|
+
assert_equal 'Invalid heap.js advanced option :derp', exception.message
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_javascript_tag
|
28
|
+
assert_includes @heap.javascript_tag, 'heap.load("test-app-id");'
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_javascript_tag_is_html_safe
|
32
|
+
buffer = ''.html_safe
|
33
|
+
buffer << @heap.javascript_tag
|
34
|
+
|
35
|
+
assert_match(/\A<script /, buffer)
|
36
|
+
assert_match(/<\/script>\Z/, buffer)
|
37
|
+
assert_includes buffer, 'heap.load("test-app-id");'
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_javascript_tag_options
|
41
|
+
assert_includes @heap.javascript_tag(:disable_text_capture => true),
|
42
|
+
'heap.load("test-app-id",{disableTextCapture:true});'
|
43
|
+
|
44
|
+
tag_text = @heap.javascript_tag :force_ssl => true, :secure_cookie => true
|
45
|
+
assert_match(/heap\.load\("test-app-id",\{.*\}\);/, tag_text)
|
46
|
+
match = /heap\.load\("test-app-id",\{(.*)\}\);/.match tag_text
|
47
|
+
assert_includes(['forceSSL:true,secureCookie:true',
|
48
|
+
'secureCookie:true,forceSSL:true'], match[1])
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_javascript_tag_default_options
|
52
|
+
@heap.js_options = { :disable_text_capture => true }
|
53
|
+
assert_includes @heap.javascript_tag,
|
54
|
+
'heap.load("test-app-id",{disableTextCapture:true});'
|
55
|
+
|
56
|
+
@heap.js_options = { :force_ssl => true }
|
57
|
+
tag_text = @heap.javascript_tag :secure_cookie => true
|
58
|
+
assert_match(/heap\.load\("test-app-id",\{.*\}\);/, tag_text)
|
59
|
+
match = /heap\.load\("test-app-id",\{(.*)\}\);/.match tag_text
|
60
|
+
assert_includes(['forceSSL:true,secureCookie:true',
|
61
|
+
'secureCookie:true,forceSSL:true'], match[1])
|
62
|
+
end
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: heap-helpers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Victor Costan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: heap
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.3.8
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.3.8
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.8.10
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.8.10
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: jeweler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.0.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.0.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 5.8.4
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 5.8.4
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rdoc
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.12'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.12'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.11.2
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.11.2
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: yard
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.8.7.6
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.8.7.6
|
139
|
+
description: Rails-compatible helpers for setting the heap.js snippet
|
140
|
+
email: victor@costan.us
|
141
|
+
executables: []
|
142
|
+
extensions: []
|
143
|
+
extra_rdoc_files:
|
144
|
+
- LICENSE.txt
|
145
|
+
- README.md
|
146
|
+
files:
|
147
|
+
- ".document"
|
148
|
+
- ".travis.yml"
|
149
|
+
- Gemfile
|
150
|
+
- Gemfile187
|
151
|
+
- LICENSE.txt
|
152
|
+
- README.md
|
153
|
+
- Rakefile
|
154
|
+
- VERSION
|
155
|
+
- heap-helpers.gemspec
|
156
|
+
- lib/heap-helpers.rb
|
157
|
+
- lib/heap-helpers/client.rb
|
158
|
+
- lib/heap-helpers/helpers.rb
|
159
|
+
- lib/heap-helpers/snippet.js
|
160
|
+
- test/client_test.rb
|
161
|
+
- test/heap_test.rb
|
162
|
+
- test/helper.rb
|
163
|
+
- test/tags_test.rb
|
164
|
+
homepage: http://github.com/pwnall/heap-helpers-ruby
|
165
|
+
licenses:
|
166
|
+
- MIT
|
167
|
+
metadata: {}
|
168
|
+
post_install_message:
|
169
|
+
rdoc_options: []
|
170
|
+
require_paths:
|
171
|
+
- lib
|
172
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
173
|
+
requirements:
|
174
|
+
- - ">="
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: '0'
|
177
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - ">="
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
182
|
+
requirements: []
|
183
|
+
rubyforge_project:
|
184
|
+
rubygems_version: 2.5.1
|
185
|
+
signing_key:
|
186
|
+
specification_version: 4
|
187
|
+
summary: Heap javascript snippet helpers
|
188
|
+
test_files: []
|