trackman 0.4.8 → 0.5.0

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/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  Gemfile.lock
4
4
  pkg/*
5
5
  *.orig
6
+ *.DS_Store
data/Gemfile.lock CHANGED
@@ -9,7 +9,7 @@ GIT
9
9
  PATH
10
10
  remote: .
11
11
  specs:
12
- trackman (0.4.6)
12
+ trackman (0.5.0)
13
13
  heroku (>= 2.26.2)
14
14
  json
15
15
  nokogiri
@@ -23,9 +23,9 @@ GEM
23
23
  addressable (2.3.2)
24
24
  blockenspiel (0.4.5)
25
25
  diff-lcs (1.1.3)
26
- excon (0.16.2)
27
- heroku (2.31.2)
28
- heroku-api (~> 0.3.4)
26
+ excon (0.16.3)
27
+ heroku (2.31.5)
28
+ heroku-api (~> 0.3.5)
29
29
  launchy (>= 0.3.2)
30
30
  netrc (~> 0.7.7)
31
31
  rest-client (~> 1.6.1)
data/README.md CHANGED
@@ -1,76 +1,112 @@
1
1
  # Trackman
2
- Trackman is a Heroku add-on that hosts your maintenance pages and their assets outside your app.
3
- You keep them within your project, trackman syncs them to s3 when you deploy.
2
+ Trackman is a Heroku add-on that hosts your maintenance pages and their assets outside your app (S3).
3
+ You keep them versioned in the comfort of your project and Trackman syncs them to s3 when you deploy.
4
4
 
5
5
  Works out of the box for Ruby(1.8.7 and 1.9.3) on
6
6
  * Rails 2.3
7
- * Rails 3.x
7
+ * Rails 3
8
8
 
9
- ##Quick peek
10
- ###The first time
11
- * Create maintenance pages as if they were served by your app.
9
+
10
+ ## Quick peek
11
+ ### The first time
12
12
  * Run a rake task to setup the heroku configs.
13
+ * Generate a controller to scaffold your static pages.
13
14
  * Deploy the changes and boot your app.
14
15
 
15
16
  ### Need to change your layout or assets?
16
- Simply modify those pages, link different assets, go crazy...
17
+ Simply edit your static pages, link different assets, go crazy!
17
18
  Trackman will sync upon application boot on your next deployment.
18
19
 
20
+ ### Conventions
21
+ We assume your maintenance page is located at:
22
+
23
+ ```console
24
+ public/503.html
25
+ ```
26
+
27
+ And the page to display if your app breaks during initialization:
28
+
29
+ ```console
30
+ public/503-error.html
31
+ ```
19
32
 
20
33
  ## Getting started
21
- ### Step 1 - Install the heroku add-on
34
+ ### Step 1 - Install the addon, add the gem and run bundle install
35
+
36
+
22
37
  ```console
23
38
  heroku addons:add trackman
24
39
  ```
25
- ### Step 2 - Add the gem to your Gemfile
26
- ```console
40
+
41
+
42
+ ```ruby
27
43
  gem 'trackman'
28
44
  ```
29
45
 
30
- ##### Step 2.1 - Rails 2 only
46
+
31
47
  ```console
32
- ./script/generate trackman
48
+ bundle install
33
49
  ```
50
+
51
+ ##### Step 1.5 (Rails 2 only) - Generate Trackman tasks
52
+
53
+ ```console
54
+ ./script/generate trackman_tasks
55
+ ```
56
+
57
+
34
58
  This will add trackman.rake to lib/tasks/
35
59
 
36
- ### Step 3 - Setup
60
+ ### Step 2 - Setup
61
+
62
+
37
63
  ```console
38
64
  rake trackman:setup
39
65
  ```
66
+
67
+
40
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.
41
- If you have maintenance or error pages setup for heroku, trackman will back them up in a configuration before we overwrite them.
69
+ If you already have maintenance or error pages configs for heroku, Trackman will copy with .bkp extensions before he overwrites them.
42
70
 
43
- On your next push Trackman will look for changes to your pages, linked assets and sync them.
71
+ ### Step 3 (optional) - Scaffold your static pages
44
72
 
45
- ### Optional - If for any reason you wish to troubleshoot the sync operation:
73
+ ##### Rails 2.3
46
74
 
47
75
  ```console
48
- heroku run rake trackman:sync
76
+ ./script/generate trackman_controller [name]
49
77
  ```
50
- Calling this command manually will throw exceptions instead of silently failing like the normal sync would.
51
78
 
52
- ### For best results, make sure you have those installed:
53
- * Heroku >= 2.26.2
54
- * Bundler >= 1.1.3
79
+ ##### Rails 3
55
80
 
56
- ### Notes
57
- By convention, we assume your maintenance page is located at
58
81
 
59
82
  ```console
60
- public/503.html
83
+ rails generate trackman:controller [name]
61
84
  ```
62
85
 
63
- If you want two different pages for maintenance and when your app is down, we expect:
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
+ ### To troubleshoot the sync operation
64
98
 
65
- For maintenance
66
- ```console
67
- public/503.html
68
- ```
69
- Broken app
70
99
  ```console
71
- public/503-error.html
100
+ heroku run rake trackman:sync
72
101
  ```
73
102
 
103
+
104
+ Executing this task will throw exceptions instead of silently failing like the normal sync would.
105
+
106
+ ### For best results, make sure you have those installed:
107
+ * Heroku >= 2.26.2
108
+ * Bundler >= 1.1.3
109
+
74
110
  ### Bug reports
75
111
 
76
112
  Any bug report can be submitted here.
@@ -82,7 +118,7 @@ https://github.com/SynApps/trackman/issues
82
118
  * Jeremy Fabre (https://github.com/jfabre)
83
119
  * Emanuel Petre (https://github.com/epetre)
84
120
 
85
- ###Copyright
121
+ ### Copyright
86
122
 
87
123
  Copyright © 2012 SynApps
88
124
 
@@ -0,0 +1,12 @@
1
+ Description:
2
+ Generates a controller which will scaffold your maintenance pages when you execute the corresponding actions.
3
+ The controller will also handle your 404 and 500 error pages.
4
+ Usage:
5
+ Pass the name of the controller as the first argument. If no name is specified
6
+ it will take "errors" as default.
7
+
8
+ Examples:
9
+ rails generate trackman:controller abc
10
+
11
+ Will create a controller called "abc". It will contain four GET methods to
12
+ access your error pages and generate your static pages.
@@ -0,0 +1,45 @@
1
+ require 'rails/generators'
2
+ module Trackman
3
+ class ControllerGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+ argument :controller_name, :type => :string, :default => 'errors'
6
+
7
+ desc "Generates a controller to generate your static pages"
8
+
9
+ @@actions = ['not_found', 'error', 'maintenance', 'maintenance_error']
10
+ @@routes = {'404' => 'not_found', '500' => 'error', 'maintenance' => 'maintenance', 'maintenance-error' => 'maintenance_error'}
11
+
12
+ def create_controller
13
+ template "controller_layout.rb.erb", "app/controllers/#{controller_name}_controller.rb"
14
+ end
15
+
16
+ def create_app_config
17
+ puts "
18
+ ------
19
+ Trackman added \"config.exceptions_app = self.routes\" in app/config/application.rb
20
+ ------\n"
21
+ application do
22
+ "config.exceptions_app = self.routes"
23
+ end
24
+ end
25
+ def create_views
26
+ create_views_for(:erb)
27
+ end
28
+
29
+ def create_routes
30
+ @@routes.each do |k, v|
31
+ route "match \"/#{k}\", :to => \"#{controller_name}##{v}\""
32
+ end
33
+ end
34
+
35
+ protected
36
+ def create_views_for(engine)
37
+ view_folder = "app/views/#{controller_name}"
38
+ layout = "view_layout.html.#{engine}"
39
+
40
+ @@actions.each do |n|
41
+ template layout, "#{view_folder}/#{n}.html.#{engine}"
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,38 @@
1
+ class ErrorsController < ApplicationController
2
+ include Trackman::Scaffold::ContentSaver
3
+ after_filter :save_content if Rails.env.development?
4
+
5
+ # ContentSaver defines two class methods for filtering the ouput of your pages
6
+ #
7
+ # Note that it uses nokogiri to parse the output.
8
+ # You can call the methods multiples times if you need, it will stack the calls.
9
+
10
+ # edit selector, &block
11
+ # pass a css or xpath selector and a block that will get executed for each result
12
+
13
+ # ie:
14
+ # edit "//link[contains(@src 'http://127.0.0.1:3000'))" do |node|
15
+ # node['src'] = "http://www.production.com"
16
+ # end
17
+
18
+ # remove selector[, &predicate]
19
+ # pass a css or xpath selector. You can also pass an optional predicate
20
+ # to refine the scan instead of trying to make the perfect selector.
21
+
22
+ # ie:
23
+ # remove 'script' do |node|
24
+ # node['src'].include?('/assets') && !node['src'].include?('application')
25
+ # end
26
+
27
+ def not_found
28
+ end
29
+
30
+ def error
31
+ end
32
+
33
+ def maintenance
34
+ end
35
+
36
+ def maintenance_error
37
+ end
38
+ end
@@ -0,0 +1 @@
1
+ <p>This error/maintenance page was generated by Trackman</p>
data/lib/railtie.rb ADDED
@@ -0,0 +1,37 @@
1
+ #Bundler.require
2
+
3
+ if defined?(Rails)
4
+ if ::Rails::VERSION::STRING =~ /^2\.[1-9]/ && Rails.env.production?
5
+ module Trackman
6
+ class RackMiddleware
7
+ def initialize(app)
8
+ @app = app
9
+ Trackman::Assets::Asset.autosync
10
+ end
11
+
12
+ def call(env)
13
+ @app.call(env)
14
+ end
15
+ end
16
+ end
17
+ require './config/environment'
18
+ Rails.configuration.middleware.use Trackman::RackMiddleware
19
+ elsif ::Rails::VERSION::STRING =~ /^[3-9]\.[1-9]/
20
+ require 'generators/controller/controller_generator'
21
+ module Trackman
22
+ class Railtie < Rails::Railtie
23
+ rake_tasks do
24
+ Dir[File.join(File.dirname(__FILE__),'../rails_generators/trackman/templates/*.rake')].each { |f| load f }
25
+ end
26
+
27
+ if Rails.env == "production"
28
+ initializer "trackman.hook" do |app|
29
+ app.config.after_initialize do
30
+ Trackman::Assets::Asset.autosync
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,20 +1,3 @@
1
- class String
2
- def trackman_underscore
3
- word = dup
4
- word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
5
- word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
6
- word.tr!("-", "_")
7
- word.downcase!
8
- word
9
- end
10
- end
11
-
12
- class Symbol
13
- def trackman_underscore
14
- to_s.trackman_underscore
15
- end
16
- end
17
-
18
1
  module Trackman
19
2
  module Assets
20
3
 
@@ -0,0 +1,35 @@
1
+
2
+ class String
3
+ def trackman_underscore
4
+ word = dup
5
+ word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
6
+ word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
7
+ word.tr!("-", "_")
8
+ word.downcase!
9
+ word
10
+ end
11
+ end
12
+
13
+ class Symbol
14
+ def trackman_underscore
15
+ to_s.trackman_underscore
16
+ end
17
+ end
18
+
19
+ #ruby 1.8.7 does not take blocks (this fixes it) -- used in Asset.all
20
+ if RUBY_VERSION !~ /^1\.9/
21
+ class Array
22
+ def uniq
23
+ ret, keys = [], []
24
+ each do |x|
25
+ key = block_given? ? yield(x) : x
26
+ unless keys.include? key
27
+ ret << x
28
+ keys << key
29
+ end
30
+ end
31
+ ret
32
+ end
33
+ end
34
+ end
35
+
@@ -0,0 +1,65 @@
1
+ require 'nokogiri'
2
+
3
+ module Trackman
4
+ module Scaffold
5
+ module ContentSaver
6
+ def self.included(base)
7
+ class << base; attr_accessor :nodes_to_remove, :nodes_to_edit, :mappings; end
8
+ base.nodes_to_remove = {}
9
+ base.nodes_to_edit = {}
10
+
11
+ if defined?(Rails)
12
+ base.mappings = { :maintenance => '503', :maintenance_error => '503-error' }
13
+ base.mappings.merge!({:not_found => '404', :error => '500'}) if ::Rails::VERSION::STRING =~ /^2\./
14
+ else
15
+ base.mappings = {}
16
+ end
17
+ base.extend ClassMethods
18
+ end
19
+
20
+
21
+ module ClassMethods
22
+ def edit selector, &block
23
+ raise 'block parameter is mandatory' unless block_given?
24
+ nodes_to_edit[selector] = block
25
+ end
26
+ def remove selector, &predicate
27
+ nodes_to_remove[selector] = predicate
28
+ end
29
+ end
30
+
31
+ protected
32
+ def remove_nodes doc
33
+ self.class.nodes_to_remove.each do |selector, predicate|
34
+ nodes = doc.search(selector)
35
+ nodes = nodes.select(&predicate) unless predicate.nil?
36
+ nodes.each{|n| n.remove }
37
+ end
38
+ doc
39
+ end
40
+
41
+ def edit_nodes doc
42
+ self.class.nodes_to_edit.each do |selector, block|
43
+ doc.search(selector).each { |n| block.call(n) }
44
+ end
45
+ doc
46
+ end
47
+
48
+ def save_content
49
+ to_write = self.class.mappings[params[:action].to_sym]
50
+
51
+ unless to_write.nil?
52
+ path = "/public/#{to_write}.html"
53
+
54
+ xsl = Nokogiri::XSLT(File.open("#{File.dirname(__FILE__)}/pretty-print.xslt"))
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) }
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,46 @@
1
+ <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
2
+ <xsl:output method="html" omit-xml-declaration="yes" encoding="UTF-8" />
3
+ <xsl:param name="indent-increment" select="' '"/>
4
+
5
+ <xsl:template name="newline">
6
+ <xsl:text disable-output-escaping="yes">
7
+ </xsl:text>
8
+ </xsl:template>
9
+
10
+ <xsl:template match="comment() | processing-instruction()">
11
+ <xsl:param name="indent" select="''"/>
12
+ <xsl:call-template name="newline"/>
13
+ <xsl:value-of select="$indent"/>
14
+ <xsl:copy />
15
+ </xsl:template>
16
+
17
+ <xsl:template match="text()">
18
+ <xsl:param name="indent" select="''"/>
19
+ <xsl:call-template name="newline"/>
20
+ <xsl:value-of select="$indent"/>
21
+ <xsl:value-of select="normalize-space(.)"/>
22
+ </xsl:template>
23
+
24
+ <xsl:template match="text()[normalize-space(.)='']"/>
25
+
26
+ <xsl:template match="*">
27
+ <xsl:param name="indent" select="''"/>
28
+ <xsl:call-template name="newline"/>
29
+ <xsl:value-of select="$indent"/>
30
+ <xsl:choose>
31
+ <xsl:when test="count(child::*) > 0">
32
+ <xsl:copy>
33
+ <xsl:copy-of select="@*"/>
34
+ <xsl:apply-templates select="*|text()">
35
+ <xsl:with-param name="indent" select="concat ($indent, $indent-increment)"/>
36
+ </xsl:apply-templates>
37
+ <xsl:call-template name="newline"/>
38
+ <xsl:value-of select="$indent"/>
39
+ </xsl:copy>
40
+ </xsl:when>
41
+ <xsl:otherwise>
42
+ <xsl:copy-of select="."/>
43
+ </xsl:otherwise>
44
+ </xsl:choose>
45
+ </xsl:template>
46
+ </xsl:stylesheet>
@@ -0,0 +1,19 @@
1
+ module Trackman
2
+ module Scaffold
3
+
4
+ #TODO do something better than this to share the scope
5
+ def self.autoloads path, items
6
+ items.each do |s|
7
+ if block_given?
8
+ yield(s, "#{path}/#{s.trackman_underscore}" )
9
+ else
10
+ autoload s, "#{path}/#{s.trackman_underscore}"
11
+ end
12
+ end
13
+ end
14
+
15
+ @@modules = [:ContentSaver]
16
+
17
+ autoloads 'trackman/scaffold', @@modules
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module Trackman
2
- VERSION = "0.4.8"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/trackman.rb CHANGED
@@ -1,37 +1,12 @@
1
1
  require "rubygems"
2
2
  require "bundler/setup"
3
- require 'tasks'
3
+ require File.expand_path('../trackman/core_extensions', __FILE__)
4
+ require 'railtie'
4
5
 
5
6
  module Trackman
6
- autoload :RackMiddleware, 'trackman/rack_middleware'
7
7
  autoload :Assets, 'trackman/assets'
8
8
  autoload :ConfigurationHandler, 'trackman/configuration_handler'
9
+ autoload :Scaffold, 'trackman/scaffold'
9
10
  end
10
11
 
11
- autoload :Debugger, 'trackman/debugger'
12
-
13
- if defined?(Rails) && Rails.env == "production"
14
- if ::Rails::VERSION::STRING =~ /^2\.[1-9]/
15
- require './config/environment'
16
- Rails.configuration.middleware.use Trackman::RackMiddleware
17
- elsif ::Rails::VERSION::STRING =~ /^[3-9]\.[1-9]/
18
- require "trackman/railtie"
19
- end
20
- end
21
-
22
- #ruby 1.8.7 does not take blocks (this fixes it) -- used in Asset.all
23
- if RUBY_VERSION !~ /^1\.9/
24
- class Array
25
- def uniq
26
- ret, keys = [], []
27
- each do |x|
28
- key = block_given? ? yield(x) : x
29
- unless keys.include? key
30
- ret << x
31
- keys << key
32
- end
33
- end
34
- ret
35
- end
36
- end
37
- end
12
+ autoload :Debugger, 'trackman/debugger'
@@ -0,0 +1,13 @@
1
+ Description:
2
+ Generates a controller which will scaffold your error and maintenance pages
3
+ when you execute the corresponding actions.
4
+
5
+ Usage:
6
+ Pass the name of the controller as the first argument. If no name is specified
7
+ it will take 'errors' as default.
8
+
9
+ Examples:
10
+ rails generate trackman_controller abc
11
+
12
+ Will create a controller called "abc". It will contain four GET methods to
13
+ generate your error and maintenance pages.
@@ -0,0 +1,40 @@
1
+ class ErrorsController < ApplicationController
2
+ include Trackman::Scaffold::ContentSaver
3
+ after_filter :save_content if Rails.env.development?
4
+
5
+ # ContentSaver defines two class methods for filtering the ouput of your pages
6
+ #
7
+ # Note that it uses nokogiri to parse the output.
8
+ # You can call the methods multiples times if you need, it will stack the calls.
9
+
10
+ # edit selector, &block
11
+ # pass a css or xpath selector and a block that will get executed for each result
12
+
13
+ # ie:
14
+ # edit "//link[contains(@src 'http://127.0.0.1:3000'))" do |node|
15
+ # node['src'] = "http://www.production.com"
16
+ # end
17
+
18
+ # remove selector, [optional]&predicate
19
+ # pass a css or xpath selector. You can also pass an optional predicate
20
+ # to refine the scan instead of trying to make the perfect selector.
21
+
22
+ # ie:
23
+ # remove 'script' do |node|
24
+ # node['src'].include?('/assets') && !node['src'].include?('application')
25
+ # end
26
+
27
+ <%= route_doc true %>
28
+
29
+ def not_found
30
+ end
31
+
32
+ def error
33
+ end
34
+
35
+ def maintenance
36
+ end
37
+
38
+ def maintenance_error
39
+ end
40
+ end
@@ -0,0 +1 @@
1
+ <p>This error/maintenance page was generated by Trackman</p>
@@ -0,0 +1,41 @@
1
+
2
+ class TrackmanControllerGenerator < ::Rails::Generator::Base
3
+ def initialize runtime_args, runtime_options = {}
4
+ self.controller_name = options[:controller_name] || 'errors'
5
+ super
6
+ end
7
+
8
+ attr_accessor :controller_name
9
+
10
+ @@actions = ['not_found', 'error', 'maintenance', 'maintenance_error']
11
+ @@routes = {'404' => 'not_found', '500' => 'error', 'maintenance' => 'maintenance', 'maintenance-error' => 'maintenance_error'}
12
+
13
+ def manifest # this method is default entrance of generator
14
+ puts route_doc false
15
+ record do |m|
16
+ m.template 'controller_layout.rb.erb', "app/controllers/#{controller_name}_controller.rb"
17
+ create_views_for(:erb, m)
18
+ end
19
+ end
20
+
21
+ protected
22
+ def create_views_for(engine, m)
23
+ view_folder = "app/views/#{controller_name}"
24
+ layout = "view_layout.html.#{engine}"
25
+
26
+ m.directory(view_folder)
27
+ @@actions.each do |n|
28
+ m.template layout, "#{view_folder}/#{n}.html.#{engine}"
29
+ end
30
+ end
31
+
32
+ def route_doc show_as_comments = false
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"
40
+ end
41
+ end
@@ -0,0 +1,10 @@
1
+ Description:
2
+ Generates Trackman related rake tasks within your project.
3
+
4
+ Usage:
5
+ No parameter is needed to run this command.
6
+
7
+ Examples:
8
+ rails generate trackman_tasks
9
+
10
+ Will create a rake file located at 'lib/tasks/trackman.rake'.
@@ -1,4 +1,4 @@
1
- class TrackmanGenerator < Rails::Generator::Base
1
+ class TrackmanTasksGenerator < Rails::Generator::Base
2
2
  def manifest
3
3
  record do |m|
4
4
  m.directory('lib/tasks')
@@ -0,0 +1,128 @@
1
+ require 'spec_helper'
2
+
3
+ class TestSaver
4
+ include Trackman::Scaffold::ContentSaver
5
+
6
+ def self.clean
7
+ self.nodes_to_remove = {}
8
+ self.nodes_to_edit = {}
9
+ end
10
+ end
11
+ describe Trackman::Scaffold::ContentSaver do
12
+ before :all do
13
+ @saver = TestSaver.new
14
+ end
15
+ after :each do
16
+ TestSaver.clean
17
+ end
18
+
19
+ it "removes the a with an abc href" do
20
+ TestSaver.remove('a'){ |n| n['href'].include? 'abc' }
21
+
22
+ html = "
23
+ <html>
24
+ <head></head>
25
+ <body>
26
+ <a href='/hello'></a>
27
+ <a href='/abc'></a>
28
+ <a href='/world'></a>
29
+ </body>
30
+ </html>"
31
+
32
+ doc = Nokogiri::HTML(html)
33
+ @saver.send(:remove_nodes, doc)
34
+ actual = doc.to_s
35
+
36
+ actual.should_not include('abc')
37
+ actual.should include('/hello')
38
+ actual.should include('world')
39
+ end
40
+
41
+ it "removes the a with an abc href" do
42
+ TestSaver.remove 'a'
43
+ TestSaver.remove '.bobby'
44
+
45
+ html = "
46
+ <html>
47
+ <head></head>
48
+ <body>
49
+ <a href='/hello'></a>
50
+ <a href='/abc'></a>
51
+ <a href='/world'></a>
52
+
53
+ <div class='bobby'></div>
54
+ <div>
55
+ <p>allo</p>
56
+ </div>
57
+ </body>
58
+ </html>"
59
+
60
+ doc = Nokogiri::HTML(html)
61
+ @saver.send(:remove_nodes, doc)
62
+ actual = doc.to_s
63
+
64
+ actual.should_not include('<a href')
65
+ actual.should_not include('bobby')
66
+ end
67
+
68
+ it "edits all the href" do
69
+ TestSaver.edit('a'){ |e| e['href'] = 'bobby' }
70
+
71
+ html = "
72
+ <html>
73
+ <head></head>
74
+ <body>
75
+ <a href='/hello'></a>
76
+ <a href='/abc'></a>
77
+ <a href='/world'></a>
78
+
79
+ <div class='bobby'></div>
80
+ <div>
81
+ <p>allo</p>
82
+ </div>
83
+ </body>
84
+ </html>"
85
+
86
+ doc = Nokogiri::HTML(html)
87
+ @saver.send(:edit_nodes, doc)
88
+ actual = doc.to_s
89
+
90
+ actual.should_not include('/hello')
91
+ actual.should_not include('/abc')
92
+ actual.should_not include('/world')
93
+ actual.should include('bobby')
94
+ end
95
+
96
+ it "edits multiple things" do
97
+ TestSaver.edit 'a' do |e|
98
+ e['href'] = 'bobby' if e['href'] == '/abc'
99
+ end
100
+
101
+ TestSaver.edit '.bobby' do |e|
102
+ e.content = '<span>Allo</span>'
103
+ end
104
+
105
+ html = "
106
+ <html>
107
+ <head></head>
108
+ <body>
109
+ <a href='/hello'></a>
110
+ <a href='/abc'></a>
111
+ <a href='/world'></a>
112
+
113
+ <div class='bobby'></div>
114
+ <div>
115
+ <p>allo</p>
116
+ </div>
117
+ </body>
118
+ </html>"
119
+
120
+ doc = Nokogiri::HTML(html)
121
+ @saver.send(:edit_nodes, doc)
122
+ actual = doc.to_s
123
+
124
+ actual.should_not include('/abc')
125
+ actual.should include('bobby')
126
+ actual.should include('span')
127
+ end
128
+ end
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.4.8
4
+ version: 0.5.0
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-09-22 00:00:00.000000000 Z
13
+ date: 2012-09-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client
@@ -157,7 +157,11 @@ files:
157
157
  - LICENSE
158
158
  - README.md
159
159
  - Rakefile
160
- - lib/tasks.rb
160
+ - lib/generators/controller/USAGE
161
+ - lib/generators/controller/controller_generator.rb
162
+ - lib/generators/controller/templates/controller_layout.rb.erb
163
+ - lib/generators/controller/templates/view_layout.html.erb
164
+ - lib/railtie.rb
161
165
  - lib/trackman.rb
162
166
  - lib/trackman/assets.rb
163
167
  - lib/trackman/assets/asset.rb
@@ -180,12 +184,19 @@ files:
180
184
  - lib/trackman/assets/html_asset.rb
181
185
  - lib/trackman/assets/remote_asset.rb
182
186
  - lib/trackman/configuration_handler.rb
187
+ - lib/trackman/core_extensions.rb
183
188
  - lib/trackman/debugger.rb
184
- - lib/trackman/rack_middleware.rb
185
- - lib/trackman/railtie.rb
189
+ - lib/trackman/scaffold.rb
190
+ - lib/trackman/scaffold/content_saver.rb
191
+ - lib/trackman/scaffold/pretty-print.xslt
186
192
  - lib/trackman/version.rb
187
- - rails_generators/trackman/templates/trackman.rake
188
- - rails_generators/trackman/trackman_generator.rb
193
+ - rails_generators/trackman_controller/USAGE
194
+ - rails_generators/trackman_controller/templates/controller_layout.rb.erb
195
+ - rails_generators/trackman_controller/templates/view_layout.html.erb
196
+ - rails_generators/trackman_controller/trackman_controller_generator.rb
197
+ - rails_generators/trackman_tasks/USAGE
198
+ - rails_generators/trackman_tasks/templates/trackman.rake
199
+ - rails_generators/trackman_tasks/trackman_tasks_generator.rb
189
200
  - spec/asset_all_spec.rb
190
201
  - spec/asset_factory_spec.rb
191
202
  - spec/asset_spec.rb
@@ -438,6 +449,7 @@ files:
438
449
  - spec/rails32/first_push_spec.rb
439
450
  - spec/rails32_path_resolver_spec.rb
440
451
  - spec/remote_asset_spec.rb
452
+ - spec/scaffolding_spec.rb
441
453
  - spec/shippable_spec.rb
442
454
  - spec/spec_helper.rb
443
455
  - spec/sync_spec.rb
@@ -749,6 +761,7 @@ test_files:
749
761
  - spec/rails32/first_push_spec.rb
750
762
  - spec/rails32_path_resolver_spec.rb
751
763
  - spec/remote_asset_spec.rb
764
+ - spec/scaffolding_spec.rb
752
765
  - spec/shippable_spec.rb
753
766
  - spec/spec_helper.rb
754
767
  - spec/sync_spec.rb
data/lib/tasks.rb DELETED
@@ -1,8 +0,0 @@
1
- if defined?(Rails) && ::Rails::VERSION::STRING =~ /^[3-9]\.[1-9]/
2
- Bundler.require
3
- class Tasks < Rails::Railtie
4
- rake_tasks do
5
- Dir[File.join(File.dirname(__FILE__),'../rails_generators/trackman/templates/*.rake')].each { |f| load f }
6
- end
7
- end
8
- end
@@ -1,12 +0,0 @@
1
- module Trackman
2
- class RackMiddleware
3
- def initialize(app)
4
- @app = app
5
- Trackman::Assets::Asset.autosync
6
- end
7
-
8
- def call(env)
9
- @app.call(env)
10
- end
11
- end
12
- end
@@ -1,10 +0,0 @@
1
- module Trackman
2
- class Railtie < Rails::Railtie
3
- initializer "trackman.hook" do |app|
4
- app.config.after_initialize do
5
- Trackman::Assets::Asset.autosync
6
- end
7
- end
8
- end
9
- end
10
-