trackman 0.6.6 → 0.6.7

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -9,7 +9,7 @@ GIT
9
9
  PATH
10
10
  remote: .
11
11
  specs:
12
- trackman (0.6.5)
12
+ trackman (0.6.8)
13
13
  heroku (>= 2.26.2)
14
14
  json
15
15
  nokogiri
@@ -5,7 +5,7 @@ module Trackman
5
5
  argument :controller_name, :type => :string, :default => 'errors'
6
6
 
7
7
  @@actions = ['not_found', 'error', 'maintenance', 'maintenance_error']
8
- @@routes = {'not-found' => 'not_found', 'error' => 'error', 'maintenance' => 'maintenance', 'maintenance-error' => 'maintenance_error'}
8
+ @@routes = {'404' => 'not_found', '500' => 'error', '503' => 'maintenance', '503-error' => 'maintenance_error'}
9
9
 
10
10
  def create_controller
11
11
  template "controller_layout.rb.erb", "app/controllers/#{controller_name}_controller.rb"
@@ -17,7 +17,7 @@ module Trackman
17
17
 
18
18
  def create_routes
19
19
  @@routes.each do |k, v|
20
- route "match \"/#{k}\", :to => \"#{controller_name}##{v}\""
20
+ route "match \"#{controller_name.camelize}/#{k}\", :to => \"#{controller_name}##{v}\""
21
21
  end
22
22
  end
23
23
 
@@ -1,9 +1,6 @@
1
1
  module Trackman
2
2
  module Assets
3
- module CompositeAsset
4
- @@url ||= /url\(['"]?([^'"\)]+)['"]?\)/
5
- @@import ||= /url\(['"]?[^'"\)]+['"]?\)/
6
-
3
+ module CompositeAsset
7
4
  def self.included(mod)
8
5
  mod.send(:include, Path::Resolver)
9
6
  end
@@ -22,22 +19,6 @@ module Trackman
22
19
  def asset_from(virtual, physical)
23
20
  Asset.create(:virtual_path => virtual, :path => physical)
24
21
  end
25
-
26
- def inner_css_paths
27
- #clean css comments
28
- my_data = data.gsub(/\/\*.*\*\//m, '')
29
- my_data = my_data.gsub(/\<\!\-\-.*\-\-\>/m, '')
30
- my_data.scan(@@import).collect{|x| @@url.match(x)[1]}.select{|x| !x.embedded? }
31
- end
32
22
  end
33
23
  end
34
- end
35
-
36
- class String
37
- def internal_path?
38
- self !~ /^http/
39
- end
40
- def embedded?
41
- self.include? 'data:'
42
- end
43
24
  end
@@ -1,11 +1,12 @@
1
1
  module Trackman
2
2
  module Assets
3
3
  class CssAsset < Asset
4
- include CompositeAsset
4
+ include CompositeAsset, Trackman::Urls::CssParser
5
5
 
6
6
  protected
7
- alias children_paths inner_css_paths
8
-
7
+ def children_paths
8
+ @children ||= parse_css(data)
9
+ end
9
10
  end
10
11
  end
11
12
  end
@@ -2,29 +2,10 @@ require 'nokogiri'
2
2
  module Trackman
3
3
  module Assets
4
4
  class HtmlAsset < Asset
5
- include CompositeAsset
6
-
7
- def document
8
- @doc ||= Nokogiri::HTML(data)
9
- end
10
-
11
- def img_paths
12
- @images_paths ||= refine_path(document.css('img'), 'src')
13
- end
14
- def js_paths
15
- @js_paths ||= refine_path(document.xpath('//script'), 'src')
16
- end
17
- def css_paths
18
- @css_paths ||= refine_path(document.xpath('//link[@type="text/css"]'), 'href')
19
- end
5
+ include CompositeAsset, Trackman::Urls::HtmlParser
20
6
 
21
7
  def children_paths
22
- @children_paths ||= img_paths + js_paths + css_paths + inner_css_paths
23
- end
24
-
25
- def refine_path(paths, node)
26
- temp = paths.map{|n| n[node].to_s.gsub(/\?[^\?]*$/, '') }
27
- temp.select{|n| n && n =~ /\w/ && n.internal_path? && !n.embedded? }
8
+ @children ||= parse(data)
28
9
  end
29
10
  end
30
11
  end
@@ -4,9 +4,12 @@ module Trackman
4
4
  module Scaffold
5
5
  module ContentSaver
6
6
  def self.included(base)
7
- class << base; attr_accessor :nodes_to_remove, :nodes_to_edit, :mappings; end
7
+ class << base
8
+ attr_accessor :nodes_to_remove, :nodes_to_edit, :text_to_edit, :mappings
9
+ end
8
10
  base.nodes_to_remove = {}
9
11
  base.nodes_to_edit = {}
12
+ base.text_to_edit = {}
10
13
 
11
14
  if defined?(Rails)
12
15
  base.mappings = { :maintenance => '503', :maintenance_error => '503-error', :not_found => '404', :error => '500' }
@@ -21,6 +24,9 @@ module Trackman
21
24
  raise 'block parameter is mandatory' unless block_given?
22
25
  nodes_to_edit[selector] = block
23
26
  end
27
+ def gsub pattern, replacement
28
+ text_to_edit[pattern] = replacement
29
+ end
24
30
  def remove selector, &predicate
25
31
  nodes_to_remove[selector] = predicate
26
32
  end
@@ -45,6 +51,13 @@ module Trackman
45
51
  end
46
52
  doc
47
53
  end
54
+ def gsub_html text
55
+ self.class.text_to_edit.each do |pattern, replacement|
56
+ text.gsub! pattern, replacement
57
+ end
58
+ text
59
+ end
60
+
48
61
  def xslt
49
62
  @xslt ||= Nokogiri::XSLT(File.open("#{File.dirname(__FILE__)}/pretty-print.xslt"))
50
63
  end
@@ -55,7 +68,8 @@ module Trackman
55
68
  edit_nodes html
56
69
  remove_nodes html
57
70
 
58
- xslt.apply_to(html).to_s
71
+ html = xslt.apply_to(html).to_s
72
+ gsub_html(html)
59
73
  end
60
74
 
61
75
  def render_content
@@ -0,0 +1,19 @@
1
+ module Trackman
2
+ module Urls
3
+ module CssParser
4
+ @@url ||= /url\(['"]?([^'"\)]+)['"]?\)/
5
+ @@import ||= /url\(['"]?[^'"\)]+['"]?\)/
6
+
7
+ def parse_css value
8
+ value = value.dup
9
+ clean_comments value
10
+ value.scan(@@import).collect{|x| @@url.match(x)[1]}.select{|x| !x.embedded? }
11
+ end
12
+
13
+ def clean_comments value
14
+ value.gsub!(/\/\*.*\*\//m, '')
15
+ value.gsub!(/\<\!\-\-.*\-\-\>/m, '')
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,32 @@
1
+ require 'nokogiri'
2
+ module Trackman
3
+ module Urls
4
+ module HtmlParser
5
+ include CssParser
6
+
7
+ def parse html
8
+ doc = Nokogiri::HTML(html)
9
+ img(doc) + js(doc) + css(doc) + parse_css(html)
10
+ end
11
+
12
+ def img doc
13
+ imgs = refine(doc.css('img'), 'src')
14
+ icons = refine(doc.xpath('//link[@rel="icon"]'), 'href')
15
+
16
+ imgs + icons
17
+ end
18
+
19
+ def js doc
20
+ refine(doc.xpath('//script'), 'src')
21
+ end
22
+ def css doc
23
+ refine(doc.xpath('//link[@type="text/css"]'), 'href')
24
+ end
25
+
26
+ def refine(paths, node)
27
+ temp = paths.map{|n| n[node].to_s.gsub(/\?[^\?]*$/, '') }
28
+ temp.select{|n| n && n =~ /\w/ && n.internal_path? && !n.embedded? }
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,6 @@
1
+ module Trackman
2
+ module Urls
3
+ autoload :HtmlParser, 'trackman/urls/html_parser'
4
+ autoload :CssParser, 'trackman/urls/css_parser'
5
+ end
6
+ end
@@ -8,6 +8,12 @@ class String
8
8
  word.downcase!
9
9
  word
10
10
  end
11
+ def internal_path?
12
+ self !~ /^http/
13
+ end
14
+ def embedded?
15
+ self.include? 'data:'
16
+ end
11
17
  end
12
18
 
13
19
  class Symbol
@@ -1,3 +1,3 @@
1
1
  module Trackman
2
- VERSION = "0.6.6"
2
+ VERSION = "0.6.7"
3
3
  end
data/lib/trackman.rb CHANGED
@@ -10,6 +10,7 @@ module Trackman
10
10
  autoload :Errors, 'trackman/errors'
11
11
  autoload :Path, 'trackman/path'
12
12
  autoload :Utility, 'trackman/utility'
13
+ autoload :Urls, 'trackman/urls'
13
14
 
14
15
  end
15
16
  require File.expand_path("../trackman/version", __FILE__)
@@ -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 = {'not-found' => 'not_found', 'error' => 'error', 'maintenance' => 'maintenance', 'maintenance-error' => 'maintenance_error'}
11
+ @@routes = {'404' => 'not_found', '500' => 'error', '503' => 'maintenance', '503-error' => 'maintenance_error'}
12
12
 
13
13
  def manifest # this method is default entrance of generator
14
14
  puts route_doc false
@@ -27,15 +27,18 @@ 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
+ end
31
31
 
32
32
  def route_doc show_as_comments = false
33
33
  char = show_as_comments ? '#' : ''
34
- "\n#{char} Don't forget to add the routes in config/routes.rb\n#{char} ------
35
- #{char} map.not_found '/not-found', :controller => '#{controller_name}', :action => :not_found
36
- #{char} map.error '/error', :controller => '#{controller_name}', :action => :error
37
- #{char} map.maintenance '/maintenance', :controller => '#{controller_name}', :action => :maintenance
38
- #{char} map.maintenance_error '/maintenance-error', :controller => '#{controller_name}', :action => :maintenance_error
39
- #{char} ------\n\n"
34
+ camelized = controller_name.camelize
35
+
36
+ doc = "\n#{char} Don't forget to add the routes in config/routes.rb\n#{char} ------\n"
37
+ @@routes.each do |k, v|
38
+ doc << "#{char} map.#{v} '#{camelized}/#{k}', :controller => '#{controller_name}', :action => :#{v}\n"
39
+ end
40
+ doc << "#{char} ------\n\n"
41
+
42
+ doc
40
43
  end
41
44
  end
@@ -53,7 +53,7 @@ describe Trackman::Assets::HtmlAsset do
53
53
  asset = Asset.create(:path => 'spec/fixtures/composite_assets/query_string_in_path.html')
54
54
  expected = [
55
55
  '/assets/burndownchartslogo.png', '/assets/google.png', '/assets/facebook.png',
56
- '/assets/twitter.png', '/assets/application.js', '/assets/application.css'
56
+ '/assets/twitter.png', '/assets/favicon.png', '/assets/application.js', '/assets/application.css'
57
57
  ]
58
58
 
59
59
  actual = asset.children_paths
@@ -69,4 +69,13 @@ describe Trackman::Assets::HtmlAsset do
69
69
 
70
70
  actual.should == expected
71
71
  end
72
+
73
+ it "returns all link tags" do
74
+ asset = Asset.create(:path => 'spec/test_data/html/favicon.html')
75
+ expected = ['assets/trackman70x70.png', '/assets/application.css']
76
+
77
+ actual = asset.children_paths
78
+
79
+ actual.should == expected
80
+ end
72
81
  end
@@ -125,4 +125,31 @@ describe Trackman::Scaffold::ContentSaver do
125
125
  actual.should include('bobby')
126
126
  actual.should include('span')
127
127
  end
128
+
129
+ it "edits multiple things" do
130
+ TestSaver.gsub 'wallo', 'bobby'
131
+
132
+ TestSaver.gsub /ginette/, 'johnny'
133
+
134
+ html = "
135
+ <html>
136
+ <head></head>
137
+ <body>
138
+ <a href='wallo'></a>
139
+ <a href='ginette'></a>
140
+ <a href='/world'></a>
141
+
142
+ <div class='bobby'></div>
143
+ <div>
144
+ <p>allo</p>
145
+ </div>
146
+ </body>
147
+ </html>"
148
+
149
+ @saver.send(:gsub_html, html)
150
+
151
+ html.should_not include('/abc')
152
+ html.should include('bobby')
153
+ html.should include('johnny')
154
+ end
128
155
  end
@@ -0,0 +1,13 @@
1
+
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5
+ <link href="assets/trackman70x70.png" rel="icon" type="image/png">
6
+ <title>Trackman - Don't spend your time on maintenance pages</title>
7
+ <link href="http://fonts.googleapis.com/css?family=Arapey:400italic,400" rel="stylesheet" type="text/css">
8
+ <meta content="Rails and Sinatra maintenance pages made easy. Trackman is an Heroku add-on for building, deploying and hosting your maintenance pages." name="description">
9
+ <link href="/assets/application.css" media="screen" rel="stylesheet" type="text/css">
10
+ </head>
11
+ <body id="home">
12
+ </body>
13
+ </html>
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.6
4
+ version: 0.6.7
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-17 00:00:00.000000000 Z
13
+ date: 2012-10-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client
@@ -189,6 +189,9 @@ files:
189
189
  - lib/trackman/scaffold/content_saver.rb
190
190
  - lib/trackman/scaffold/pretty-print.xslt
191
191
  - lib/trackman/tasks/trackman.rake
192
+ - lib/trackman/urls.rb
193
+ - lib/trackman/urls/css_parser.rb
194
+ - lib/trackman/urls/html_parser.rb
192
195
  - lib/trackman/utility.rb
193
196
  - lib/trackman/utility/configuration.rb
194
197
  - lib/trackman/utility/core_extensions.rb
@@ -487,6 +490,7 @@ files:
487
490
  - spec/test_data/external_paths/1.css
488
491
  - spec/test_data/external_paths/1.html
489
492
  - spec/test_data/html/comments.html
493
+ - spec/test_data/html/favicon.html
490
494
  - spec/test_data/sample.html
491
495
  - spec/test_data/test1.jpeg
492
496
  - spec/test_data/test2.png
@@ -803,6 +807,7 @@ test_files:
803
807
  - spec/test_data/external_paths/1.css
804
808
  - spec/test_data/external_paths/1.html
805
809
  - spec/test_data/html/comments.html
810
+ - spec/test_data/html/favicon.html
806
811
  - spec/test_data/sample.html
807
812
  - spec/test_data/test1.jpeg
808
813
  - spec/test_data/test2.png