middleman-segment 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 131761cacf7d834b49918069ad2e4368eea2c80c
4
+ data.tar.gz: 50c8dbbb8dd577347e3ce94554922d3f63e33756
5
+ SHA512:
6
+ metadata.gz: 1df1eee0d6ffcf1a4d0116a1ee901bda525ab3829dc0c001f30c0c03254ff0e7f4841b48e5aeeffa2329e70c7b7d6c3824d1e49494bde762551d7496ddad9b5e
7
+ data.tar.gz: 4b779cf0da45a16ced88e32489daa8b6657347c30f21e1d3ab5e1f75aabe2672411fdcf4b022dbd3464e1fc1944606082f984b29bbae27577a3c0699eaf1b1d0
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ Gemfile.lock
2
+ pkg
3
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1 @@
1
+ language: ruby
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/).
6
+
7
+ ## [Unreleased]
8
+ ### Added
9
+ ### Changed
10
+ ### Fixed
11
+
12
+ ## [0.1.0] - 2018-02-03
13
+ - Initial release.
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem "rake", "~> 12.3.0"
7
+ gem "rdoc", "~> 6.0.1"
8
+ end
9
+
10
+ group :test do
11
+ gem "aruba", "~> 0.14.3"
12
+ gem "capybara", "~> 2.17.0"
13
+ gem "cucumber", "~> 3.1.0"
14
+ gem "rspec", "~> 3.7.0"
15
+ end
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # Middleman Segment
2
+ [![Dependency Status](https://gemnasium.com/badges/github.com/bnadlerjr/middleman-segment.svg)](https://gemnasium.com/github.com/bnadlerjr/middleman-segment)
3
+ [![Build Status](https://travis-ci.org/bnadlerjr/middleman-segment.svg?branch=master)](https://travis-ci.org/bnadlerjr/middleman-segment)
4
+
5
+ A [Middleman](https://middlemanapp.com/) extension to handle generating your Segment tracking code.
6
+
7
+ ## Installation
8
+ Specify the dependency in your project's `Gemfile`:
9
+
10
+ gem "middleman-segment", "~> 0.1.0"
11
+
12
+ ## Usage
13
+ Activate the extension in your `config.rb`:
14
+
15
+ activate :middleman_segment, write_key: <YOUR SEGMENT WRITE KEY>
16
+
17
+ Include the Segment snippet in any of your templates (most likely in `layout.erb`):
18
+
19
+ <%= segment_tag %>
20
+
21
+ ## Contributing
22
+
23
+ 1. Fork it
24
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
25
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
26
+ 4. Push to the branch (`git push origin my-new-feature`)
27
+ 5. Create new Pull Request
28
+
29
+ ## License
30
+ Copyright (c) 2018 Bob Nadler, Jr.
31
+
32
+ MIT License
33
+
34
+ Permission is hereby granted, free of charge, to any person obtaining
35
+ a copy of this software and associated documentation files (the
36
+ "Software"), to deal in the Software without restriction, including
37
+ without limitation the rights to use, copy, modify, merge, publish,
38
+ distribute, sublicense, and/or sell copies of the Software, and to
39
+ permit persons to whom the Software is furnished to do so, subject to
40
+ the following conditions:
41
+
42
+ The above copyright notice and this permission notice shall be
43
+ included in all copies or substantial portions of the Software.
44
+
45
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
46
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
47
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
48
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
49
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
50
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
51
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require "bundler"
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require "cucumber/rake/task"
5
+
6
+ Cucumber::Rake::Task.new(:cucumber, "Cucumber feature tests") do |t|
7
+ t.cucumber_opts = "--color --tags ~@wip --strict"
8
+ end
9
+
10
+ require "rake/clean"
11
+
12
+ task test: ["cucumber"]
13
+
14
+ task default: :test
@@ -0,0 +1,13 @@
1
+ Feature: Segment tracking code
2
+ Scenario: Tracking code helper is on the page
3
+ Given the Server is running at "segment"
4
+ When I go to "/index.html"
5
+ Then I should see:
6
+ """
7
+ <script type="text/javascript">
8
+ !function(){var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","once","off","on"];analytics.factory=function(t){return function(){var e=Array.prototype.slice.call(arguments);e.unshift(t);analytics.push(e);return analytics}};for(var t=0;t<analytics.methods.length;t++){var e=analytics.methods[t];analytics[e]=analytics.factory(e)}analytics.load=function(t){var e=document.createElement("script");e.type="text/javascript";e.async=!0;e.src=("https:"===document.location.protocol?"https://":"http://")+"cdn.segment.com/analytics.js/v1/"+t+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(e,n)};analytics.SNIPPET_VERSION="4.0.0";
9
+ analytics.load("MY_SEGMENT_WRITE_KEY");
10
+ analytics.page();
11
+ }}();
12
+ </script>
13
+ """
@@ -0,0 +1,4 @@
1
+ PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
2
+ require "middleman-core"
3
+ require "middleman-core/step_definitions"
4
+ require File.join(PROJECT_ROOT_PATH, "lib", "middleman-segment")
@@ -0,0 +1 @@
1
+ activate :middleman_segment, write_key: "MY_SEGMENT_WRITE_KEY"
@@ -0,0 +1 @@
1
+ <%= segment_tag %>
@@ -0,0 +1,6 @@
1
+ require "middleman-core"
2
+
3
+ Middleman::Extensions.register :middleman_segment do
4
+ require "middleman-segment/extension"
5
+ MiddlemanSegment
6
+ end
@@ -0,0 +1,26 @@
1
+ require "middleman-core"
2
+
3
+ class MiddlemanSegment < ::Middleman::Extension
4
+ option :write_key, nil, "Segment write key"
5
+
6
+ def initialize(app, options_hash={}, &block)
7
+ super
8
+ require "erubis"
9
+ end
10
+
11
+ def after_configuration
12
+ unless options.write_key
13
+ $stderr.puts("Segment requires a write key")
14
+ raise ArgumentError, "No segment write key given" if app.build?
15
+ end
16
+ end
17
+
18
+ helpers do
19
+ def segment_tag
20
+ options = extensions[:middleman_segment].options
21
+ template_path = File.join(File.dirname(__FILE__), "segment.html.erb")
22
+ erb = Erubis::FastEruby.new(File.read(template_path))
23
+ erb.evaluate({options: options})
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,6 @@
1
+ <script type="text/javascript">
2
+ !function(){var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","once","off","on"];analytics.factory=function(t){return function(){var e=Array.prototype.slice.call(arguments);e.unshift(t);analytics.push(e);return analytics}};for(var t=0;t<analytics.methods.length;t++){var e=analytics.methods[t];analytics[e]=analytics.factory(e)}analytics.load=function(t){var e=document.createElement("script");e.type="text/javascript";e.async=!0;e.src=("https:"===document.location.protocol?"https://":"http://")+"cdn.segment.com/analytics.js/v1/"+t+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(e,n)};analytics.SNIPPET_VERSION="4.0.0";
3
+ analytics.load("<%= @options.write_key %>");
4
+ analytics.page();
5
+ }}();
6
+ </script>
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "middleman-segment"
6
+ s.version = "0.1.0"
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Bob Nadler, Jr."]
9
+ s.homepage = "https://github.com/bnadlerjr/middleman-segment"
10
+ s.summary = %q{A Middleman extension to handle generating your Segment tracking code.}
11
+
12
+ s.files = `git ls-files`.split("\n")
13
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
15
+ s.require_paths = ["lib"]
16
+
17
+ s.add_runtime_dependency("middleman-core", [">= 4.2.1"])
18
+ s.add_runtime_dependency("erubis", ["~> 2.7.0"])
19
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: middleman-segment
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Bob Nadler, Jr.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-02-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: middleman-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: erubis
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.7.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.7.0
41
+ description:
42
+ email:
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - ".gitignore"
48
+ - ".travis.yml"
49
+ - CHANGELOG.md
50
+ - Gemfile
51
+ - README.md
52
+ - Rakefile
53
+ - features/segment.feature
54
+ - features/support/env.rb
55
+ - fixtures/segment/config.rb
56
+ - fixtures/segment/source/index.html.erb
57
+ - lib/middleman-segment.rb
58
+ - lib/middleman-segment/extension.rb
59
+ - lib/middleman-segment/segment.html.erb
60
+ - middleman-segment.gemspec
61
+ homepage: https://github.com/bnadlerjr/middleman-segment
62
+ licenses: []
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.6.14
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: A Middleman extension to handle generating your Segment tracking code.
84
+ test_files:
85
+ - features/segment.feature
86
+ - features/support/env.rb