trackman 0.6.0 → 0.6.1
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.
- data/Gemfile.lock +1 -3
- data/README.md +8 -65
- data/lib/generators/controller/controller_generator.rb +2 -2
- data/lib/generators/controller/templates/controller_layout.rb.erb +3 -2
- data/lib/trackman/scaffold/content_saver.rb +29 -13
- data/lib/trackman/version.rb +1 -1
- data/rails_generators/trackman_controller/templates/controller_layout.rb.erb +3 -3
- data/rails_generators/trackman_controller/trackman_controller_generator.rb +3 -3
- metadata +2 -2
data/Gemfile.lock
CHANGED
@@ -9,12 +9,11 @@ GIT
|
|
9
9
|
PATH
|
10
10
|
remote: .
|
11
11
|
specs:
|
12
|
-
trackman (0.
|
12
|
+
trackman (0.6.1)
|
13
13
|
heroku (>= 2.26.2)
|
14
14
|
json
|
15
15
|
nokogiri
|
16
16
|
rack
|
17
|
-
rake
|
18
17
|
rest-client
|
19
18
|
versionomy
|
20
19
|
|
@@ -42,7 +41,6 @@ GEM
|
|
42
41
|
netrc (0.7.7)
|
43
42
|
nokogiri (1.5.5)
|
44
43
|
rack (1.4.1)
|
45
|
-
rake (0.9.2.2)
|
46
44
|
rspec (2.10.0)
|
47
45
|
rspec-core (~> 2.10.0)
|
48
46
|
rspec-expectations (~> 2.10.0)
|
data/README.md
CHANGED
@@ -5,7 +5,9 @@ You keep them within your project and Trackman syncs them to S3 when you deploy.
|
|
5
5
|
Works out of the box for Ruby(1.8.7 and 1.9.3) on
|
6
6
|
* Rails 2.3
|
7
7
|
* Rails 3
|
8
|
+
* Sinatra
|
8
9
|
|
10
|
+
For a detailed tutorial of each framework integration visit the [Wiki](https://github.com/SynApps/trackman/wiki).
|
9
11
|
|
10
12
|
## Quick peek
|
11
13
|
### The first time
|
@@ -17,6 +19,8 @@ Works out of the box for Ruby(1.8.7 and 1.9.3) on
|
|
17
19
|
Simply edit your static pages, link different assets, go crazy!
|
18
20
|
Trackman will sync upon application boot on your next deployment.
|
19
21
|
|
22
|
+
## How to use
|
23
|
+
|
20
24
|
### Conventions
|
21
25
|
We assume your maintenance page is located at:
|
22
26
|
|
@@ -30,78 +34,17 @@ And the page to display if your app breaks during initialization:
|
|
30
34
|
public/503-error.html
|
31
35
|
```
|
32
36
|
|
33
|
-
## Getting started
|
34
|
-
### Step 1 - Install the addon, add the gem and run bundle install
|
35
|
-
|
36
|
-
|
37
|
-
```console
|
38
|
-
heroku addons:add trackman
|
39
|
-
```
|
40
|
-
|
41
|
-
|
42
|
-
```ruby
|
43
|
-
gem 'trackman'
|
44
|
-
```
|
45
|
-
|
46
|
-
|
47
|
-
```console
|
48
|
-
bundle install
|
49
|
-
```
|
50
|
-
|
51
|
-
##### Step 1.5 (Rails 2 only) - Generate Trackman tasks
|
52
|
-
|
53
|
-
```console
|
54
|
-
./script/generate trackman_tasks
|
55
|
-
```
|
56
|
-
|
57
|
-
|
58
|
-
This will add trackman.rake to lib/tasks/
|
59
|
-
|
60
|
-
### Step 2 - Setup
|
61
|
-
|
62
|
-
|
63
|
-
```console
|
64
|
-
rake trackman:setup
|
65
|
-
```
|
66
|
-
|
67
|
-
|
68
|
-
This sets your initial heroku configurations and ensures that when your app is down or in maintenance your pages will be requested by heroku.
|
69
|
-
If you already have maintenance or error pages configs for heroku, Trackman will copy with .bkp extensions before he overwrites them.
|
70
|
-
|
71
|
-
### Step 3 (optional) - Scaffold your static pages
|
72
|
-
|
73
|
-
##### Rails 2.3
|
74
|
-
|
75
|
-
```console
|
76
|
-
./script/generate trackman_controller [name]
|
77
|
-
```
|
78
|
-
|
79
|
-
##### Rails 3
|
80
|
-
|
81
|
-
|
82
|
-
```console
|
83
|
-
rails generate trackman:controller [name]
|
84
|
-
```
|
85
|
-
|
86
|
-
This will generate a special controller that, when on development, will create your maintenance pages for you when you execute its actions.
|
87
|
-
Because Rails 3 can handle 500 and 404 pages dynamically, the controller also adds the required route to handle them.
|
88
|
-
On Rails 2, it generates the 4 different static pages instead.
|
89
|
-
|
90
|
-
The controller has class methods to filter the response output.
|
91
|
-
You can find examples on how to use them within the controller itself.
|
92
|
-
|
93
|
-
### Step 4 - Deploy
|
94
|
-
Now that you have your maintenance pages, you can commit and push to Heroku.
|
95
|
-
Trackman will look for changes to your pages and linked assets and sync them on application boot.
|
96
|
-
|
97
37
|
### To troubleshoot the sync operation
|
98
38
|
|
39
|
+
|
99
40
|
```console
|
100
41
|
heroku run rake trackman:sync
|
101
42
|
```
|
102
43
|
|
103
|
-
|
104
44
|
Executing this task will throw exceptions instead of silently failing like the normal sync would.
|
45
|
+
You can also turn debugging on by adding TRACKMAN_DEBUG_ON=true in your env.
|
46
|
+
It will output every request done by restclient and also a diff about what is getting pushed.
|
47
|
+
|
105
48
|
|
106
49
|
### For best results, make sure you have those installed:
|
107
50
|
* Heroku >= 2.26.2
|
@@ -7,7 +7,7 @@ module Trackman
|
|
7
7
|
desc "Generates a controller to generate your static pages"
|
8
8
|
|
9
9
|
@@actions = ['not_found', 'error', 'maintenance', 'maintenance_error']
|
10
|
-
@@routes = {'
|
10
|
+
@@routes = {'not-found' => 'not_found', 'error' => 'error', 'maintenance' => 'maintenance', 'maintenance-error' => 'maintenance_error'}
|
11
11
|
|
12
12
|
def create_controller
|
13
13
|
template "controller_layout.rb.erb", "app/controllers/#{controller_name}_controller.rb"
|
@@ -16,7 +16,7 @@ module Trackman
|
|
16
16
|
def create_app_config
|
17
17
|
puts "
|
18
18
|
------
|
19
|
-
Trackman added \"config.exceptions_app = self.routes\" in
|
19
|
+
Trackman added \"config.exceptions_app = self.routes\" in config/application.rb
|
20
20
|
------\n"
|
21
21
|
application do
|
22
22
|
"config.exceptions_app = self.routes"
|
@@ -1,6 +1,7 @@
|
|
1
|
-
class
|
1
|
+
class <%= controller_name.camelize %>Controller < ApplicationController
|
2
2
|
include Trackman::Scaffold::ContentSaver
|
3
|
-
after_filter :
|
3
|
+
after_filter :save_filters if Rails.env.development?
|
4
|
+
after_filter :render_filters
|
4
5
|
|
5
6
|
# ContentSaver defines two class methods for filtering the ouput of your pages
|
6
7
|
#
|
@@ -17,7 +17,6 @@ module Trackman
|
|
17
17
|
base.extend ClassMethods
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
20
|
module ClassMethods
|
22
21
|
def edit selector, &block
|
23
22
|
raise 'block parameter is mandatory' unless block_given?
|
@@ -32,7 +31,10 @@ module Trackman
|
|
32
31
|
def remove_nodes doc
|
33
32
|
self.class.nodes_to_remove.each do |selector, predicate|
|
34
33
|
nodes = doc.search(selector)
|
35
|
-
|
34
|
+
i = 0;
|
35
|
+
unless predicate.nil?
|
36
|
+
nodes = nodes.select { |n| r = predicate.call(n, i); i +=1;r }
|
37
|
+
end
|
36
38
|
nodes.each{|n| n.remove }
|
37
39
|
end
|
38
40
|
doc
|
@@ -40,24 +42,38 @@ module Trackman
|
|
40
42
|
|
41
43
|
def edit_nodes doc
|
42
44
|
self.class.nodes_to_edit.each do |selector, block|
|
43
|
-
doc.search(selector).
|
45
|
+
doc.search(selector).each_with_index { |n, i| block.call(n, i) }
|
44
46
|
end
|
45
47
|
doc
|
46
48
|
end
|
49
|
+
def xslt
|
50
|
+
@xslt ||= Nokogiri::XSLT(File.open("#{File.dirname(__FILE__)}/pretty-print.xslt"))
|
51
|
+
end
|
52
|
+
|
53
|
+
def new_content
|
54
|
+
html = Nokogiri::HTML(response.body)
|
55
|
+
|
56
|
+
edit_nodes html
|
57
|
+
remove_nodes html
|
58
|
+
|
59
|
+
xslt.apply_to(html).to_s
|
60
|
+
end
|
61
|
+
|
62
|
+
def cache key
|
63
|
+
@cache ||= {}
|
64
|
+
@cache[key] || yield
|
65
|
+
end
|
47
66
|
|
48
|
-
def
|
67
|
+
def render_filters
|
68
|
+
response.body = cache(params[:action]) { new_content }
|
69
|
+
end
|
70
|
+
|
71
|
+
def save_filters
|
49
72
|
to_write = self.class.mappings[params[:action].to_sym]
|
50
|
-
|
51
73
|
unless to_write.nil?
|
52
74
|
path = "/public/#{to_write}.html"
|
53
|
-
|
54
|
-
|
55
|
-
html = Nokogiri::HTML(response.body)
|
56
|
-
|
57
|
-
edit_nodes html
|
58
|
-
remove_nodes html
|
59
|
-
|
60
|
-
File.open(Rails.root.to_s + path, 'w') { |f| f.write(xsl.apply_to(html).to_s) }
|
75
|
+
result = cache(params[:action]) { new_content }
|
76
|
+
File.open(Rails.root.to_s + path, 'w') { |f| f.write(result) }
|
61
77
|
end
|
62
78
|
end
|
63
79
|
end
|
data/lib/trackman/version.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
class
|
1
|
+
class <%= controller_name.camelize %>Controller < ApplicationController
|
2
2
|
include Trackman::Scaffold::ContentSaver
|
3
|
-
after_filter :
|
4
|
-
|
3
|
+
after_filter :save_filters if Rails.env.development?
|
4
|
+
after_filter :render_filters
|
5
5
|
# ContentSaver defines two class methods for filtering the ouput of your pages
|
6
6
|
#
|
7
7
|
# Note that it uses nokogiri to parse the output.
|
@@ -8,7 +8,7 @@ class TrackmanControllerGenerator < ::Rails::Generator::Base
|
|
8
8
|
attr_accessor :controller_name
|
9
9
|
|
10
10
|
@@actions = ['not_found', 'error', 'maintenance', 'maintenance_error']
|
11
|
-
@@routes = {'
|
11
|
+
@@routes = {'not-found' => 'not_found', 'error' => 'error', 'maintenance' => 'maintenance', 'maintenance-error' => 'maintenance_error'}
|
12
12
|
|
13
13
|
def manifest # this method is default entrance of generator
|
14
14
|
puts route_doc false
|
@@ -27,12 +27,12 @@ class TrackmanControllerGenerator < ::Rails::Generator::Base
|
|
27
27
|
@@actions.each do |n|
|
28
28
|
m.template layout, "#{view_folder}/#{n}.html.#{engine}"
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
|
32
32
|
def route_doc show_as_comments = false
|
33
33
|
char = show_as_comments ? '#' : ''
|
34
34
|
"\n#{char} Don't forget to add the routes in config/routes.rb\n#{char} ------
|
35
|
-
#{char} map.not_found '/
|
35
|
+
#{char} map.not_found '/not-found', :controller => '#{controller_name}', :action => :not_found
|
36
36
|
#{char} map.error '/error', :controller => '#{controller_name}', :action => :error
|
37
37
|
#{char} map.maintenance '/maintenance', :controller => '#{controller_name}', :action => :maintenance
|
38
38
|
#{char} map.maintenance_error '/maintenance-error', :controller => '#{controller_name}', :action => :maintenance_error
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trackman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-10-
|
13
|
+
date: 2012-10-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rest-client
|