pixel_fire 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/MIT-LICENSE +20 -0
- data/README.md +30 -0
- data/Rakefile +37 -0
- data/app/assets/config/pixel_fire_manifest.js +2 -0
- data/app/assets/javascripts/pixel_fire/application.js +15 -0
- data/app/assets/javascripts/pixel_fire/tags.js +2 -0
- data/app/assets/javascripts/pixel_fire/triggers.js +2 -0
- data/app/assets/stylesheets/pixel_fire/application.css +19 -0
- data/app/assets/stylesheets/pixel_fire/tags.css +4 -0
- data/app/assets/stylesheets/pixel_fire/triggers.css +4 -0
- data/app/controllers/pixel_fire/application_controller.rb +5 -0
- data/app/controllers/pixel_fire/tags_controller.rb +64 -0
- data/app/controllers/pixel_fire/triggers_controller.rb +64 -0
- data/app/helpers/pixel_fire/application_helper.rb +4 -0
- data/app/helpers/pixel_fire/tags_helper.rb +4 -0
- data/app/helpers/pixel_fire/triggers_helper.rb +4 -0
- data/app/jobs/pixel_fire/application_job.rb +4 -0
- data/app/mailers/pixel_fire/application_mailer.rb +6 -0
- data/app/models/pixel_fire/application_record.rb +5 -0
- data/app/models/pixel_fire/tag.rb +21 -0
- data/app/models/pixel_fire/tags_trigger.rb +6 -0
- data/app/models/pixel_fire/trigger.rb +37 -0
- data/app/views/layouts/pixel_fire/application.html.erb +47 -0
- data/app/views/pixel_fire/tags/_form.html.erb +45 -0
- data/app/views/pixel_fire/tags/edit.html.erb +6 -0
- data/app/views/pixel_fire/tags/index.html.erb +36 -0
- data/app/views/pixel_fire/tags/new.html.erb +8 -0
- data/app/views/pixel_fire/tags/show.html.erb +26 -0
- data/app/views/pixel_fire/triggers/_form.html.erb +43 -0
- data/app/views/pixel_fire/triggers/edit.html.erb +6 -0
- data/app/views/pixel_fire/triggers/index.html.erb +38 -0
- data/app/views/pixel_fire/triggers/new.html.erb +5 -0
- data/app/views/pixel_fire/triggers/show.html.erb +31 -0
- data/config/routes.rb +6 -0
- data/db/migrate/20170301002719_create_pixel_fire_triggers.rb +11 -0
- data/db/migrate/20170301002831_create_pixel_fire_tags.rb +11 -0
- data/db/migrate/20170301002920_create_pixel_fire_tags_triggers.rb +10 -0
- data/lib/pixel_fire.rb +7 -0
- data/lib/pixel_fire/engine.rb +5 -0
- data/lib/pixel_fire/version.rb +3 -0
- data/lib/rack/pixel_fire.rb +39 -0
- data/lib/rack/pixel_fire/railtie.rb +7 -0
- data/lib/tasks/pixel_fire_tasks.rake +4 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ab5f5eb25e0fb1ce9f3a4b9cae186e0d53e0849b
|
4
|
+
data.tar.gz: 2e3f445aa0ac655b3fec19c5e52a1987ed301b60
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9c74f87d057ce5d9e784345136d8cf5f77bbf939e21afe933009262cd896f3c3aa9fcd5a4aa84d0c6a68b15b26e5dacab807bf0a93a18768177f79de2bd314f6
|
7
|
+
data.tar.gz: 0cb0c93cbc50462d655b34c677c22eb622ebedf7d013ecef386c15067ca36d73005ccd07d55d4d9b9e3f6f2081264b846a74935e81ef740cc7816a97e0306c29
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017 Eric Berry
|
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,30 @@
|
|
1
|
+
# PixelFire
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'pixel_fire'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
$ bin/rails pixel_fire:install:migrations
|
18
|
+
$ bin/rails db:migrate
|
19
|
+
```
|
20
|
+
|
21
|
+
Add the engine to your routes file:
|
22
|
+
```ruby
|
23
|
+
mount ::PixelFire::Engine, at: "/pixel_fire"
|
24
|
+
```
|
25
|
+
|
26
|
+
## Contributing
|
27
|
+
Contribution directions go here.
|
28
|
+
|
29
|
+
## License
|
30
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'PixelFire'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
require 'bundler/gem_tasks'
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
|
29
|
+
Rake::TestTask.new(:test) do |t|
|
30
|
+
t.libs << 'lib'
|
31
|
+
t.libs << 'test'
|
32
|
+
t.pattern = 'test/**/*_test.rb'
|
33
|
+
t.verbose = false
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
task default: :test
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require_tree .
|
@@ -0,0 +1,19 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
16
|
+
|
17
|
+
body {
|
18
|
+
padding-top: 50px;
|
19
|
+
}
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require_dependency "pixel_fire/application_controller"
|
2
|
+
|
3
|
+
module PixelFire
|
4
|
+
class TagsController < ApplicationController
|
5
|
+
before_action :set_tag, only: [:show, :edit, :update, :destroy]
|
6
|
+
|
7
|
+
# GET /tags
|
8
|
+
def index
|
9
|
+
@tags = Tag.all
|
10
|
+
end
|
11
|
+
|
12
|
+
# GET /tags/1
|
13
|
+
def show
|
14
|
+
end
|
15
|
+
|
16
|
+
# GET /tags/new
|
17
|
+
def new
|
18
|
+
@tag = Tag.new
|
19
|
+
end
|
20
|
+
|
21
|
+
# GET /tags/1/edit
|
22
|
+
def edit
|
23
|
+
end
|
24
|
+
|
25
|
+
# POST /tags
|
26
|
+
def create
|
27
|
+
@tag = Tag.new(tag_params)
|
28
|
+
|
29
|
+
if @tag.save
|
30
|
+
@tag.update_triggers(params[:trigger_ids])
|
31
|
+
redirect_to @tag, notice: 'Tag was successfully created.'
|
32
|
+
else
|
33
|
+
render :new
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# PATCH/PUT /tags/1
|
38
|
+
def update
|
39
|
+
if @tag.update(tag_params)
|
40
|
+
@tag.update_triggers(params[:trigger_ids])
|
41
|
+
redirect_to @tag, notice: 'Tag was successfully updated.'
|
42
|
+
else
|
43
|
+
render :edit
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# DELETE /tags/1
|
48
|
+
def destroy
|
49
|
+
@tag.destroy
|
50
|
+
redirect_to tags_url, notice: 'Tag was successfully destroyed.'
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
# Use callbacks to share common setup or constraints between actions.
|
55
|
+
def set_tag
|
56
|
+
@tag = Tag.find(params[:id])
|
57
|
+
end
|
58
|
+
|
59
|
+
# Only allow a trusted parameter "white list" through.
|
60
|
+
def tag_params
|
61
|
+
params.require(:tag).permit(:name, :custom_html, :target)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require_dependency "pixel_fire/application_controller"
|
2
|
+
|
3
|
+
module PixelFire
|
4
|
+
class TriggersController < ApplicationController
|
5
|
+
before_action :set_trigger, only: [:show, :edit, :update, :destroy]
|
6
|
+
|
7
|
+
# GET /triggers
|
8
|
+
def index
|
9
|
+
@triggers = Trigger.all
|
10
|
+
end
|
11
|
+
|
12
|
+
# GET /triggers/1
|
13
|
+
def show
|
14
|
+
end
|
15
|
+
|
16
|
+
# GET /triggers/new
|
17
|
+
def new
|
18
|
+
@trigger = Trigger.new
|
19
|
+
end
|
20
|
+
|
21
|
+
# GET /triggers/1/edit
|
22
|
+
def edit
|
23
|
+
end
|
24
|
+
|
25
|
+
# POST /triggers
|
26
|
+
def create
|
27
|
+
@trigger = Trigger.new(trigger_params)
|
28
|
+
|
29
|
+
if @trigger.save
|
30
|
+
@trigger.update_tags(params[:tag_ids])
|
31
|
+
redirect_to @trigger, notice: 'Trigger was successfully created.'
|
32
|
+
else
|
33
|
+
render :new
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# PATCH/PUT /triggers/1
|
38
|
+
def update
|
39
|
+
if @trigger.update(trigger_params)
|
40
|
+
@trigger.update_tags(params[:tag_ids])
|
41
|
+
redirect_to @trigger, notice: 'Trigger was successfully updated.'
|
42
|
+
else
|
43
|
+
render :edit
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# DELETE /triggers/1
|
48
|
+
def destroy
|
49
|
+
@trigger.destroy
|
50
|
+
redirect_to triggers_url, notice: 'Trigger was successfully destroyed.'
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
# Use callbacks to share common setup or constraints between actions.
|
55
|
+
def set_trigger
|
56
|
+
@trigger = Trigger.find(params[:id])
|
57
|
+
end
|
58
|
+
|
59
|
+
# Only allow a trusted parameter "white list" through.
|
60
|
+
def trigger_params
|
61
|
+
params.require(:trigger).permit(:name, :fire_on_all_pages, :page_url)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module PixelFire
|
2
|
+
class Tag < ApplicationRecord
|
3
|
+
has_many :tags_triggers
|
4
|
+
has_many :triggers, through: :tags_triggers
|
5
|
+
validates :name, presence: true, uniqueness: true
|
6
|
+
validates :custom_html, presence: true
|
7
|
+
|
8
|
+
def update_triggers(trigger_ids)
|
9
|
+
trigger_ids ||= []
|
10
|
+
current_ids = tags_triggers.pluck(:trigger_id)
|
11
|
+
unchanged_ids = trigger_ids & current_ids || []
|
12
|
+
new_ids = trigger_ids - unchanged_ids
|
13
|
+
remove_ids = current_ids - unchanged_ids
|
14
|
+
|
15
|
+
tags_triggers.where(trigger_id: remove_ids).map(&:destroy) if remove_ids.present?
|
16
|
+
new_ids.each do |trigger_id|
|
17
|
+
tags_triggers.create(trigger_id: trigger_id)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module PixelFire
|
2
|
+
class Trigger < ApplicationRecord
|
3
|
+
has_many :tags_triggers
|
4
|
+
has_many :tags, through: :tags_triggers
|
5
|
+
validates :name, presence: true, uniqueness: true
|
6
|
+
validates :page_url, presence: true, unless: -> (trigger) { trigger.fire_on_all_pages? }
|
7
|
+
|
8
|
+
scope :matches, -> (path) do
|
9
|
+
ids = []
|
10
|
+
::PixelFire::Trigger.pluck(:id, :page_url, :fire_on_all_pages).each do |vals|
|
11
|
+
if vals[2] == true
|
12
|
+
ids << vals[0]
|
13
|
+
elsif path =~ Regexp.new(vals[1])
|
14
|
+
ids << vals[0]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
if ids != []
|
18
|
+
where(id: ids)
|
19
|
+
else
|
20
|
+
where("1 = 0")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def update_tags(tag_ids)
|
25
|
+
tag_ids ||= []
|
26
|
+
current_ids = tags_triggers.pluck(:tag_id)
|
27
|
+
unchanged_ids = tag_ids & current_ids
|
28
|
+
new_ids = tag_ids - unchanged_ids
|
29
|
+
remove_ids = current_ids - unchanged_ids
|
30
|
+
|
31
|
+
tags_triggers.where(tag_id: remove_ids).map(&:destroy) if remove_ids.present?
|
32
|
+
new_ids.each do |tag_id|
|
33
|
+
tags_triggers.create(tag_id: tag_id)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>PixelFire</title>
|
5
|
+
|
6
|
+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
|
7
|
+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
|
8
|
+
|
9
|
+
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
|
10
|
+
<!--[if lt IE 9]>
|
11
|
+
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
|
12
|
+
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
13
|
+
<![endif]-->
|
14
|
+
|
15
|
+
<%= stylesheet_link_tag "pixel_fire/application", media: "all" %>
|
16
|
+
<%= javascript_include_tag "pixel_fire/application" %>
|
17
|
+
|
18
|
+
<%= csrf_meta_tags %>
|
19
|
+
</head>
|
20
|
+
<body>
|
21
|
+
|
22
|
+
<nav class="navbar navbar-inverse navbar-fixed-top">
|
23
|
+
<div class="container">
|
24
|
+
<div class="navbar-header">
|
25
|
+
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
|
26
|
+
<span class="sr-only">Toggle navigation</span>
|
27
|
+
<span class="icon-bar"></span>
|
28
|
+
<span class="icon-bar"></span>
|
29
|
+
<span class="icon-bar"></span>
|
30
|
+
</button>
|
31
|
+
<a class="navbar-brand" href="#">PixelFire</a>
|
32
|
+
</div>
|
33
|
+
<div id="navbar" class="collapse navbar-collapse">
|
34
|
+
<ul class="nav navbar-nav">
|
35
|
+
<li<% if controller_name == "tags" %> class="active"<% end %>><%= link_to "Tags", tags_path %></li>
|
36
|
+
<li<% if controller_name == "triggers" %> class="active"<% end %>><%= link_to "Triggers", triggers_path %>
|
37
|
+
</ul>
|
38
|
+
</div><!--/.nav-collapse -->
|
39
|
+
</div>
|
40
|
+
</nav>
|
41
|
+
|
42
|
+
<div class="container">
|
43
|
+
<%= yield %>
|
44
|
+
</div>
|
45
|
+
|
46
|
+
</body>
|
47
|
+
</html>
|
@@ -0,0 +1,45 @@
|
|
1
|
+
<%= form_for(tag) do |f| %>
|
2
|
+
<% if tag.errors.any? %>
|
3
|
+
<div id="error_explanation">
|
4
|
+
<h2><%= pluralize(tag.errors.count, "error") %> prohibited this tag from being saved:</h2>
|
5
|
+
|
6
|
+
<ul>
|
7
|
+
<% tag.errors.full_messages.each do |message| %>
|
8
|
+
<li><%= message %></li>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<div class="form-group">
|
15
|
+
<%= f.label :name %>
|
16
|
+
<%= f.text_field :name, class: "form-control", required: true %>
|
17
|
+
</div>
|
18
|
+
|
19
|
+
<div class="form-group">
|
20
|
+
<%= f.label :target, "Embed Target" %>
|
21
|
+
<%= f.select :target, ["head", "body"], {}, class: "form-control", required: true %>
|
22
|
+
</div>
|
23
|
+
|
24
|
+
<div class="form-group">
|
25
|
+
<%= f.label :custom_html, "Custom HTML" %>
|
26
|
+
<%= f.text_area :custom_html, class: "form-control", rows: 12, required: true %>
|
27
|
+
</div>
|
28
|
+
|
29
|
+
<div class="form-group">
|
30
|
+
<label>Triggers</label>
|
31
|
+
<ul class="list-unstyled">
|
32
|
+
<% ::PixelFire::Trigger.all.order(name: :asc).each do |trigger| %>
|
33
|
+
<li>
|
34
|
+
<label style="font-weight: normal;">
|
35
|
+
<input type="checkbox" name="trigger_ids[]"
|
36
|
+
value="<%= trigger.id %>" <%= "checked=\"checked\"" if tag.triggers.include?(trigger) %> />
|
37
|
+
<%= trigger.name %>
|
38
|
+
</label>
|
39
|
+
</li>
|
40
|
+
<% end %>
|
41
|
+
</ul>
|
42
|
+
</div>
|
43
|
+
|
44
|
+
<%= f.submit class: "btn btn-primary" %>
|
45
|
+
<% end %>
|
@@ -0,0 +1,36 @@
|
|
1
|
+
<p id="notice"><%= notice %></p>
|
2
|
+
|
3
|
+
<h1 class="page-header">
|
4
|
+
<%= link_to 'New Tag', new_tag_path, class: "pull-right btn btn-default" %>
|
5
|
+
Tags
|
6
|
+
</h1>
|
7
|
+
|
8
|
+
<table class="table">
|
9
|
+
<thead>
|
10
|
+
<tr>
|
11
|
+
<th>Name</th>
|
12
|
+
<th>Target</th>
|
13
|
+
<th>Triggers</th>
|
14
|
+
<th colspan="3"></th>
|
15
|
+
</tr>
|
16
|
+
</thead>
|
17
|
+
|
18
|
+
<tbody>
|
19
|
+
<% @tags.each do |tag| %>
|
20
|
+
<tr>
|
21
|
+
<td><%= tag.name %></td>
|
22
|
+
<td><%= tag.target %></td>
|
23
|
+
<td>
|
24
|
+
<% tag.triggers.each do |trigger| %>
|
25
|
+
<span class="label label-default"><%= trigger.name %></span>
|
26
|
+
<% end %>
|
27
|
+
</td>
|
28
|
+
<td class="text-right">
|
29
|
+
<%= link_to 'Show', tag, class: "btn btn-xs btn-info" %>
|
30
|
+
<%= link_to 'Edit', edit_tag_path(tag), class: "btn btn-xs btn-primary" %>
|
31
|
+
<%= link_to 'Destroy', tag, method: :delete, data: { confirm: 'Are you sure?' }, class: "btn btn-xs btn-danger" %>
|
32
|
+
</td>
|
33
|
+
</tr>
|
34
|
+
<% end %>
|
35
|
+
</tbody>
|
36
|
+
</table>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<p id="notice"><%= notice %></p>
|
2
|
+
|
3
|
+
<h1 class="page-header">
|
4
|
+
<%= link_to 'Back', tags_path, class: "pull-right btn btn-link" %>
|
5
|
+
<%= link_to 'Edit', edit_tag_path(@tag), class: "pull-right btn btn-primary" %>
|
6
|
+
Tag: <%= @tag.name %>
|
7
|
+
</h1>
|
8
|
+
|
9
|
+
<p>
|
10
|
+
<strong>Name:</strong>
|
11
|
+
<%= @tag.name %>
|
12
|
+
</p>
|
13
|
+
|
14
|
+
<p>
|
15
|
+
<strong>Custom HTML:</strong>
|
16
|
+
<pre><%= @tag.custom_html %></pre>
|
17
|
+
</p>
|
18
|
+
|
19
|
+
<p>
|
20
|
+
<strong>Triggers:</strong>
|
21
|
+
<ul>
|
22
|
+
<% @tag.triggers.each do |trigger| %>
|
23
|
+
<li><%= trigger.name %></li>
|
24
|
+
<% end %>
|
25
|
+
</ul>
|
26
|
+
</p>
|
@@ -0,0 +1,43 @@
|
|
1
|
+
<%= form_for(trigger) do |f| %>
|
2
|
+
<% if trigger.errors.any? %>
|
3
|
+
<div id="error_explanation">
|
4
|
+
<h2><%= pluralize(trigger.errors.count, "error") %> prohibited this trigger from being saved:</h2>
|
5
|
+
|
6
|
+
<ul>
|
7
|
+
<% trigger.errors.full_messages.each do |message| %>
|
8
|
+
<li><%= message %></li>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<div class="form-group">
|
15
|
+
<%= f.label :name %>
|
16
|
+
<%= f.text_field :name, class: "form-control", required: true %>
|
17
|
+
</div>
|
18
|
+
|
19
|
+
<div class="form-group">
|
20
|
+
<%= f.check_box :fire_on_all_pages %>
|
21
|
+
<%= f.label :fire_on_all_pages %>
|
22
|
+
</div>
|
23
|
+
|
24
|
+
<div class="form-group">
|
25
|
+
<%= f.label :page_url, "URL Regex" %>
|
26
|
+
<%= f.text_field :page_url, class: "form-control" %>
|
27
|
+
</div>
|
28
|
+
|
29
|
+
<div class="form-group">
|
30
|
+
<label>Tags</label>
|
31
|
+
<ul class="list-unstyled">
|
32
|
+
<% ::PixelFire::Tag.all.order(name: :asc).each do |tag| %>
|
33
|
+
<li>
|
34
|
+
<input type="checkbox" name="tag_ids[]"
|
35
|
+
value="<%= tag.id %>" <%= "checked=\"checked\"" if trigger.tags.include?(tag) %> />
|
36
|
+
<%= tag.name %>
|
37
|
+
</li>
|
38
|
+
<% end %>
|
39
|
+
</ul>
|
40
|
+
</div>
|
41
|
+
|
42
|
+
<%= f.submit class: "btn btn-primary" %>
|
43
|
+
<% end %>
|
@@ -0,0 +1,38 @@
|
|
1
|
+
<p id="notice"><%= notice %></p>
|
2
|
+
|
3
|
+
<h1 class="page-header">
|
4
|
+
<%= link_to 'New Trigger', new_trigger_path, class: "pull-right btn btn-default" %>
|
5
|
+
Triggers
|
6
|
+
</h1>
|
7
|
+
|
8
|
+
<table class="table">
|
9
|
+
<thead>
|
10
|
+
<tr>
|
11
|
+
<th>Name</th>
|
12
|
+
<th>All Pages?</th>
|
13
|
+
<th>URL Contains</th>
|
14
|
+
<th>Tags</th>
|
15
|
+
<th></th>
|
16
|
+
</tr>
|
17
|
+
</thead>
|
18
|
+
|
19
|
+
<tbody>
|
20
|
+
<% @triggers.each do |trigger| %>
|
21
|
+
<tr>
|
22
|
+
<td><%= trigger.name %></td>
|
23
|
+
<td><%= trigger.fire_on_all_pages %></td>
|
24
|
+
<td><code><%= trigger.page_url %></code></td>
|
25
|
+
<td>
|
26
|
+
<% trigger.tags.each do |tag| %>
|
27
|
+
<span class="label label-default"><%= tag.name %></span>
|
28
|
+
<% end %>
|
29
|
+
</td>
|
30
|
+
<td class="text-right">
|
31
|
+
<%= link_to 'Show', trigger, class: "btn btn-xs btn-info" %>
|
32
|
+
<%= link_to 'Edit', edit_trigger_path(trigger), class: "btn btn-xs btn-primary" %>
|
33
|
+
<%= link_to 'Destroy', trigger, method: :delete, data: { confirm: 'Are you sure?' }, class: "btn btn-xs btn-danger" %>
|
34
|
+
</td>
|
35
|
+
</tr>
|
36
|
+
<% end %>
|
37
|
+
</tbody>
|
38
|
+
</table>
|
@@ -0,0 +1,31 @@
|
|
1
|
+
<p id="notice"><%= notice %></p>
|
2
|
+
|
3
|
+
<h1 class="page-header">
|
4
|
+
<%= link_to 'Back', triggers_path, class: "pull-right btn btn-link" %>
|
5
|
+
<%= link_to 'Edit', edit_trigger_path(@trigger), class: "pull-right btn btn-primary" %>
|
6
|
+
Trigger: <%= @trigger.name %>
|
7
|
+
</h1>
|
8
|
+
|
9
|
+
<p>
|
10
|
+
<strong>Name:</strong>
|
11
|
+
<%= @trigger.name %>
|
12
|
+
</p>
|
13
|
+
|
14
|
+
<p>
|
15
|
+
<strong>Fire on all pages:</strong>
|
16
|
+
<%= @trigger.fire_on_all_pages %>
|
17
|
+
</p>
|
18
|
+
|
19
|
+
<p>
|
20
|
+
<strong>URL Contains:</strong>
|
21
|
+
<code><%= @trigger.page_url %></code>
|
22
|
+
</p>
|
23
|
+
|
24
|
+
<p>
|
25
|
+
<strong>Tags:</strong>
|
26
|
+
<ul>
|
27
|
+
<% @trigger.tags.each do |tag| %>
|
28
|
+
<li><%= tag.name %></li>
|
29
|
+
<% end %>
|
30
|
+
</ul>
|
31
|
+
</p>
|
data/config/routes.rb
ADDED
data/lib/pixel_fire.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "rack"
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
class PixelFire
|
5
|
+
def initialize(app)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
@status, @headers, @body = @app.call(env)
|
11
|
+
return [@status, @headers, @body] unless html?
|
12
|
+
response = ::Rack::Response.new([], @status, @headers)
|
13
|
+
|
14
|
+
@body.each { |fragment| response.write inject(env, fragment) }
|
15
|
+
@body.close if @body.respond_to?(:close)
|
16
|
+
|
17
|
+
response.finish
|
18
|
+
end
|
19
|
+
|
20
|
+
def html?
|
21
|
+
@headers['Content-Type'] =~ /html/
|
22
|
+
end
|
23
|
+
|
24
|
+
def inject(env, response)
|
25
|
+
puts "TAGS: #{tags(env).inspect}"
|
26
|
+
tags(env).each do |tag|
|
27
|
+
response.sub! %r{</#{tag.target}>} do |m|
|
28
|
+
tag.custom_html << m.to_s
|
29
|
+
end
|
30
|
+
end
|
31
|
+
response
|
32
|
+
end
|
33
|
+
|
34
|
+
def tags(env)
|
35
|
+
return [] if env["PATH_INFO"] =~ /\A.*\/pixel_fire.*\Z/
|
36
|
+
::PixelFire::Trigger.matches(env["PATH_INFO"]).map(&:tags).flatten.uniq
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pixel_fire
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eric Berry
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jquery-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sqlite3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Rails engine for embedding pixels (similar to Google Tag Manager)
|
56
|
+
email:
|
57
|
+
- cavneb@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- MIT-LICENSE
|
63
|
+
- README.md
|
64
|
+
- Rakefile
|
65
|
+
- app/assets/config/pixel_fire_manifest.js
|
66
|
+
- app/assets/javascripts/pixel_fire/application.js
|
67
|
+
- app/assets/javascripts/pixel_fire/tags.js
|
68
|
+
- app/assets/javascripts/pixel_fire/triggers.js
|
69
|
+
- app/assets/stylesheets/pixel_fire/application.css
|
70
|
+
- app/assets/stylesheets/pixel_fire/tags.css
|
71
|
+
- app/assets/stylesheets/pixel_fire/triggers.css
|
72
|
+
- app/controllers/pixel_fire/application_controller.rb
|
73
|
+
- app/controllers/pixel_fire/tags_controller.rb
|
74
|
+
- app/controllers/pixel_fire/triggers_controller.rb
|
75
|
+
- app/helpers/pixel_fire/application_helper.rb
|
76
|
+
- app/helpers/pixel_fire/tags_helper.rb
|
77
|
+
- app/helpers/pixel_fire/triggers_helper.rb
|
78
|
+
- app/jobs/pixel_fire/application_job.rb
|
79
|
+
- app/mailers/pixel_fire/application_mailer.rb
|
80
|
+
- app/models/pixel_fire/application_record.rb
|
81
|
+
- app/models/pixel_fire/tag.rb
|
82
|
+
- app/models/pixel_fire/tags_trigger.rb
|
83
|
+
- app/models/pixel_fire/trigger.rb
|
84
|
+
- app/views/layouts/pixel_fire/application.html.erb
|
85
|
+
- app/views/pixel_fire/tags/_form.html.erb
|
86
|
+
- app/views/pixel_fire/tags/edit.html.erb
|
87
|
+
- app/views/pixel_fire/tags/index.html.erb
|
88
|
+
- app/views/pixel_fire/tags/new.html.erb
|
89
|
+
- app/views/pixel_fire/tags/show.html.erb
|
90
|
+
- app/views/pixel_fire/triggers/_form.html.erb
|
91
|
+
- app/views/pixel_fire/triggers/edit.html.erb
|
92
|
+
- app/views/pixel_fire/triggers/index.html.erb
|
93
|
+
- app/views/pixel_fire/triggers/new.html.erb
|
94
|
+
- app/views/pixel_fire/triggers/show.html.erb
|
95
|
+
- config/routes.rb
|
96
|
+
- db/migrate/20170301002719_create_pixel_fire_triggers.rb
|
97
|
+
- db/migrate/20170301002831_create_pixel_fire_tags.rb
|
98
|
+
- db/migrate/20170301002920_create_pixel_fire_tags_triggers.rb
|
99
|
+
- lib/pixel_fire.rb
|
100
|
+
- lib/pixel_fire/engine.rb
|
101
|
+
- lib/pixel_fire/version.rb
|
102
|
+
- lib/rack/pixel_fire.rb
|
103
|
+
- lib/rack/pixel_fire/railtie.rb
|
104
|
+
- lib/tasks/pixel_fire_tasks.rake
|
105
|
+
homepage: https://github.com/cavneb/pixel_fire
|
106
|
+
licenses:
|
107
|
+
- MIT
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.5.1
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: Rails engine for embedding pixels (similar to Google Tag Manager)
|
129
|
+
test_files: []
|