trackman 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -21,7 +21,7 @@ Trackman works out of the box for Ruby(1.8.7 and 1.9.3) on
21
21
  ```console
22
22
  heroku addons:add trackman
23
23
  ```
24
- ### Step 2 - Add the client gem to your Gemfile
24
+ ### Step 2 - Add the gem to your Gemfile
25
25
  ```console
26
26
  gem 'trackman'
27
27
  ```
@@ -36,7 +36,7 @@ This will add trackman.rake to lib/tasks/
36
36
  ```console
37
37
  rake trackman:setup
38
38
  ```
39
- Sets up your initial configuration and add custom error page add-on if you don't have it yet.
39
+ Sets up your initial configuration.
40
40
 
41
41
  ### Optional
42
42
  ```console
@@ -69,14 +69,14 @@ public/503-error.html
69
69
 
70
70
  After the add-on installation
71
71
 
72
- * On the first publish or manual sync, your html file(s) and every internal assets referenced by your pages(s) will be pushed to our server so that we can store them properly on S3.
72
+ * On the first publish or manual sync, your html file(s) and every internal assets referenced by your pages(s) will be pushed to the server so that we can store them properly on S3.
73
73
  * On the next publications, only modified assets will be published.
74
- * Any renamed or missing asset will be handled properly on our side.
74
+ * Any renamed or missing asset will be handled properly.
75
75
 
76
76
  ### Bug reports
77
77
 
78
78
  Any bug report can be submitted here.
79
- https://github.com/jfabre/trackman/issues
79
+ https://github.com/SynApps/trackman/issues
80
80
 
81
81
 
82
82
  ### Creators / Maintainers
@@ -72,7 +72,8 @@ module Trackman
72
72
  def self.autosync
73
73
  autosync = ENV['TRACKMAN_AUTOSYNC'] || true
74
74
  autosync = autosync !~ /(0|false|FALSE)/ unless autosync.is_a? TrueClass
75
- if const_defined?(:Rails)
75
+
76
+ if Object.const_defined?(:Rails)
76
77
  autosync = autosync && Rails.env.production?
77
78
  end
78
79
 
@@ -1,38 +1,41 @@
1
+ require 'sprockets'
2
+
1
3
  module Trackman
2
4
  module Assets
3
5
  module Components
4
6
  module Rails32PathResolver
5
- extend PathResolver
7
+ include PathResolver
6
8
 
7
- class << self
8
- alias old_translate translate
9
- alias old_parent_of parent_of
10
-
11
- def parent_of(url)
12
- if url.to_s.include?('assets')
13
- old_parent_of(url).ascend do |p|
14
- return p if p.basename.to_s == 'assets'
15
- end
16
- else
17
- return old_parent_of(url)
18
- end
19
- end
9
+ def translate url, parent_url
10
+ root = working_dir.realpath
11
+
12
+ path = url
13
+ path.slice! /^\/assets/
14
+ path = Pathname.new path
15
+
16
+ if path.relative?
17
+ folder = (root + Pathname.new(parent_url)).parent.realpath
18
+ path = (folder + path).to_s
19
+ path.slice! sprockets.paths.select{|p| path.include? p }.first
20
+ end
21
+
22
+ path = sprockets.resolve path
23
+ path.relative_path_from(root).to_s
20
24
  end
21
25
 
22
- def translate url, parent_url
23
- path = Rails32PathResolver.old_translate(url, parent_url)
24
- parts = path.split('/')
25
- parts.insert(0, 'app') if parts.first == 'assets'
26
-
27
- if parts.first == 'app' && parts[1] == 'assets'
28
- parts.insert(2, subfolder(parts.last))
29
- elsif parts.first != 'public'
30
- parts.insert(0, 'public')
26
+ def sprockets
27
+ @@sprockets ||= init_env
28
+ end
29
+ def init_env
30
+ env = ::Sprockets::Environment.new
31
+ paths = ['app', 'lib', 'vendor'].inject([]) do |array, f|
32
+ array + ["images", "stylesheets", "javascripts"].map{|p| "#{working_dir}/#{f}/assets/#{p}" }
31
33
  end
32
-
33
- parts.join('/')
34
+ paths << "#{working_dir}/public"
35
+ paths.each{|p| env.append_path p }
36
+
37
+ env
34
38
  end
35
-
36
39
  def subfolder(file)
37
40
  if file.include?('.js')
38
41
  subfolder = "javascripts"
@@ -2,26 +2,23 @@ module Trackman
2
2
  module Assets
3
3
  module Components
4
4
  module RailsPathResolver
5
+ include PathResolver
5
6
 
6
- #way 2
7
- extend PathResolver
8
- class << self
9
- alias old_translate translate
10
- alias old_parent_of parent_of
7
+ alias old_translate translate
8
+ alias old_parent_of parent_of
11
9
 
12
- def parent_of(url)
13
- if url.to_s.include?('assets')
14
- old_parent_of(url).ascend do |p|
15
- return p if p.basename.to_s == 'assets'
16
- end
17
- else
18
- return old_parent_of(url)
10
+ def parent_of(url)
11
+ if url.to_s.include?('assets')
12
+ old_parent_of(url).ascend do |p|
13
+ return p if p.basename.to_s == 'assets'
19
14
  end
20
- end
21
- end
22
-
15
+ else
16
+ return old_parent_of(url)
17
+ end
18
+ end
19
+
23
20
  def translate url, parent_url
24
- path = RailsPathResolver.old_translate(url, parent_url)
21
+ path = old_translate(url, parent_url)
25
22
 
26
23
  parts = path.split('/')
27
24
  parts.insert(0, 'public') if parts.first != 'public'
@@ -39,13 +39,13 @@ module Trackman
39
39
  end
40
40
 
41
41
  def create!
42
- response = RestClient.post @@site, :asset => {:path => path.to_s, :file => File.open(path)}, :content_type => :json, :accept => :json
42
+ response = RestClient.post @@site, build_params, :content_type => :json, :accept => :json
43
43
  path = response.headers[:location]
44
44
  @id = path[/\d+$/].to_i
45
45
  end
46
46
 
47
47
  def update!
48
- RestClient.put "#{@@site}/#{id}", :asset => {:path => path, :file => File.open(path)}, :content_type => :json, :accept => :json
48
+ RestClient.put "#{@@site}/#{id}", build_params, :content_type => :json, :accept => :json
49
49
  end
50
50
  def delete
51
51
  response = RestClient.delete "#{@@site}/#{id}"
@@ -63,7 +63,10 @@ module Trackman
63
63
  false
64
64
  end
65
65
 
66
- private
66
+ private
67
+ def build_params
68
+ { :asset => { :path => path.to_s, :file => File.open(path) } }
69
+ end
67
70
  def ensure_config
68
71
  raise Errors::ConfigNotFoundError, "The config TRACKMAN_URL is missing." if @@server_url.nil?
69
72
  end
@@ -1,3 +1,3 @@
1
1
  module Trackman
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -0,0 +1,4 @@
1
+ img{
2
+ img{
3
+ width:100%;
4
+ }
@@ -0,0 +1,4 @@
1
+ img{
2
+ img{
3
+ width:100%;
4
+ }
@@ -0,0 +1,27 @@
1
+
2
+ class ActLikeRails2311
3
+ def self.switch_on
4
+ Trackman::Assets::Components::AssetFactory.module_eval do
5
+ alias :old_rails_defined? :rails_defined?
6
+ alias :old_asset_pipeline_enabled? :asset_pipeline_enabled?
7
+
8
+ define_method :rails_defined? do
9
+ true
10
+ end
11
+
12
+ define_method :asset_pipeline_enabled? do
13
+ false
14
+ end
15
+ end
16
+ end
17
+
18
+ def self.switch_off
19
+ Trackman::Assets::Components::AssetFactory.module_eval do
20
+ alias :rails_defined? :old_rails_defined?
21
+ alias :asset_pipeline_enabled? :old_asset_pipeline_enabled?
22
+
23
+ remove_method :old_rails_defined?
24
+ remove_method :old_asset_pipeline_enabled?
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,18 @@
1
+ class ActLikeRails32
2
+ def self.switch_on
3
+ Trackman::Assets::Components::AssetFactory.module_eval do
4
+ alias :old_asset_pipeline_enabled? :asset_pipeline_enabled?
5
+
6
+ define_method :asset_pipeline_enabled? do
7
+ true
8
+ end
9
+ end
10
+ end
11
+
12
+ def self.switch_off
13
+ Trackman::Assets::Components::AssetFactory.module_eval do
14
+ alias :asset_pipeline_enabled? :old_asset_pipeline_enabled?
15
+ remove_method :old_asset_pipeline_enabled?
16
+ end
17
+ end
18
+ end
@@ -3,39 +3,41 @@ class FakablePathManTester
3
3
  Conventions = Trackman::Assets::Components::Conventions
4
4
 
5
5
  def self.switch_on prepath
6
+ override_remote_assets prepath
7
+ override_conventions prepath
8
+ override_resolvers prepath
9
+ end
10
+
11
+ def self.switch_off
12
+ reset_resolvers
13
+ reset_conventions
14
+ reset_remote_assets
15
+ end
16
+
17
+ def self.override_resolvers prepath
18
+
19
+ PathResolver.module_eval do
20
+ alias real_working_dir working_dir
21
+
22
+ define_method :working_dir do
23
+ real_working_dir + prepath
24
+ end
25
+ end
26
+
6
27
  @@modules.each do |m|
7
28
  m.module_eval do
8
29
  alias real_translate translate
9
- alias real_working_dir working_dir if method_defined? :working_dir
10
-
30
+
11
31
  define_method :translate do |url, parent_url|
12
32
  parent = parent_url.to_s.dup
13
33
  parent.slice!(prepath)
14
34
  prepath + real_translate(url, parent)
15
35
  end
16
-
17
- if method_defined? :working_dir
18
- define_method :working_dir do
19
- real_working_dir + prepath
20
- end
21
- end
22
36
  end
23
37
  end
24
-
25
- RemoteAsset.class_eval do
26
- singleton_class = class << self; self; end
27
- singleton_class.instance_eval do
28
- alias_method :old_get_attributes, :get_attributes
29
- define_method :get_attributes do
30
- old_get_attributes.map do |h|
31
- my_hash = h.dup
32
- my_hash[:path] = prepath + h[:path] unless h[:path].start_with? prepath
33
- my_hash
34
- end
35
- end
36
- end
37
- end
38
-
38
+ end
39
+
40
+ def self.override_conventions prepath
39
41
  Conventions.module_eval do
40
42
  alias :real_maintenance_path :maintenance_path
41
43
  alias :real_error_path :error_path
@@ -50,19 +52,48 @@ class FakablePathManTester
50
52
  end
51
53
  end
52
54
 
53
- def self.switch_off
55
+ def self.override_remote_assets prepath
56
+ RemoteAsset.class_eval do
57
+ alias_method :old_build_params, :build_params
58
+ define_method :build_params do
59
+ params = old_build_params
60
+ path = params[:asset][:path]
61
+ path.slice! prepath
62
+
63
+ params
64
+ end
65
+
66
+ singleton_class = class << self; self; end
67
+ singleton_class.instance_eval do
68
+ alias_method :old_get_attributes, :get_attributes
69
+
70
+ define_method :get_attributes do
71
+ old_get_attributes.map do |h|
72
+ my_hash = h.dup
73
+ my_hash[:path] = prepath + h[:path] unless h[:path].start_with? prepath
74
+ my_hash
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ def self.reset_resolvers
82
+ PathResolver.module_eval do
83
+ alias :working_dir :real_working_dir
84
+ remove_method :real_working_dir
85
+ end
86
+
54
87
  @@modules.each do |m|
55
88
  m.module_eval do
56
89
  alias :translate :real_translate
57
90
  remove_method :real_translate
58
-
59
- if method_defined? :working_dir
60
- alias :working_dir :real_working_dir
61
- remove_method :real_working_dir
62
- end
63
91
  end
64
92
  end
65
-
93
+ Rails32PathResolver.send(:class_variable_set, :@@sprockets, nil)
94
+ end
95
+
96
+ def self.reset_conventions
66
97
  Conventions.module_eval do
67
98
  alias :maintenance_path :real_maintenance_path
68
99
  alias :error_path :real_error_path
@@ -70,8 +101,13 @@ class FakablePathManTester
70
101
  remove_method :real_maintenance_path
71
102
  remove_method :real_error_path
72
103
  end
104
+ end
73
105
 
106
+ def self.reset_remote_assets
74
107
  RemoteAsset.class_eval do
108
+ alias_method :build_params, :old_build_params
109
+ remove_method :old_build_params
110
+
75
111
  singleton_class = class << self; self; end
76
112
  singleton_class.instance_eval do
77
113
  alias_method :get_attributes, :old_get_attributes
@@ -80,60 +116,3 @@ class FakablePathManTester
80
116
  end
81
117
  end
82
118
  end
83
-
84
-
85
- module Trackman
86
- module Assets
87
- module Components
88
- module AssetFactory
89
- alias :old_asset_pipeline_enabled? :asset_pipeline_enabled?
90
- end
91
- end
92
- end
93
- end
94
-
95
- class ActLikeRails32
96
- def self.switch_on
97
- Trackman::Assets::Components::AssetFactory.module_eval do
98
- alias :old_asset_pipeline_enabled? :asset_pipeline_enabled?
99
-
100
- define_method :asset_pipeline_enabled? do
101
- true
102
- end
103
- end
104
- end
105
-
106
- def self.switch_off
107
- Trackman::Assets::Components::AssetFactory.module_eval do
108
- alias :asset_pipeline_enabled? :old_asset_pipeline_enabled?
109
- remove_method :old_asset_pipeline_enabled?
110
- end
111
- end
112
- end
113
-
114
- class ActLikeRails2311
115
- def self.switch_on
116
- Trackman::Assets::Components::AssetFactory.module_eval do
117
- alias :old_rails_defined? :rails_defined?
118
- alias :old_asset_pipeline_enabled? :asset_pipeline_enabled?
119
-
120
- define_method :rails_defined? do
121
- true
122
- end
123
-
124
- define_method :asset_pipeline_enabled? do
125
- false
126
- end
127
- end
128
- end
129
-
130
- def self.switch_off
131
- Trackman::Assets::Components::AssetFactory.module_eval do
132
- alias :rails_defined? :old_rails_defined?
133
- alias :asset_pipeline_enabled? :old_asset_pipeline_enabled?
134
-
135
- remove_method :old_rails_defined?
136
- remove_method :old_asset_pipeline_enabled?
137
- end
138
- end
139
- end
@@ -1,17 +1,22 @@
1
1
  require 'spec_helper'
2
+ require 'sprockets'
2
3
 
3
4
  class Rails32Tester
4
5
  extend Rails32PathResolver
6
+
7
+ def self.working_dir
8
+ Pathname.new('spec/fixtures/sprockets')
9
+ end
5
10
  end
6
11
 
7
12
 
8
13
  describe Rails32PathResolver do
9
14
  it "serves an image linked by an html" do
10
15
  parent_url = 'public/503.html'
11
- url = '/assets/bombero.jpg'
16
+ url = '/assets/bombero.jpeg'
12
17
 
13
18
  actual = Rails32Tester.translate url, parent_url
14
- expected = 'app/assets/images/bombero.jpg'
19
+ expected = 'app/assets/images/bombero.jpeg'
15
20
 
16
21
  actual.should == expected
17
22
  end
@@ -37,11 +42,11 @@ describe Rails32PathResolver do
37
42
  end
38
43
 
39
44
  it "serves a relative image" do
40
- parent_url = 'app/assets/stylesheets/trundle.css'
41
- url = 'image.jpg'
45
+ parent_url = 'app/assets/stylesheets/bombero/tralala/trundle.css'
46
+ url = 'img.jpg'
42
47
 
43
48
  actual = Rails32Tester.translate url, parent_url
44
- expected = 'app/assets/images/image.jpg'
49
+ expected = 'app/assets/images/bombero/tralala/img.jpg'
45
50
 
46
51
  actual.should == expected
47
52
  end
@@ -56,14 +61,12 @@ describe Rails32PathResolver do
56
61
  actual.should == expected
57
62
  end
58
63
 
59
-
60
-
61
64
  it "works for nested paths" do
62
65
  parent_url = 'app/assets/stylesheets/a/css.css'
63
66
  url = '3/32/allo.png'
64
67
 
65
68
  actual = Rails32Tester.translate url, parent_url
66
- expected = 'app/assets/images/3/32/allo.png'
69
+ expected = 'app/assets/images/a/3/32/allo.png'
67
70
 
68
71
  actual.should == expected
69
72
  end
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'helpers/app_creator'
3
3
  require 'helpers/fakable_pathman_tester'
4
+ require 'helpers/act_like_rails2311'
4
5
 
5
6
  describe 'full path' do
6
7
  before :all do
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'helpers/app_creator'
3
3
  require 'helpers/fakable_pathman_tester'
4
+ require 'helpers/act_like_rails32'
4
5
 
5
6
  describe 'first push' do
6
7
  before :all do
data/spec/sync_spec.rb CHANGED
@@ -1,27 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Trackman::Assets::Asset do
4
- before :all do
5
- class Asset
6
- class << self
7
- alias :old_sync :sync
8
- end
9
- end
10
-
11
- def Asset.sync
12
- @@called = true
13
- end
4
+
5
+ class MyTestAsset < Asset
14
6
  end
15
7
 
16
- after :all do
17
- def Asset.sync
18
- old_sync
19
- end
20
- end
21
-
22
8
  before :each do
23
- @@called = false
24
-
25
9
  class Env
26
10
  def production?
27
11
  true
@@ -38,18 +22,18 @@ describe Trackman::Assets::Asset do
38
22
  end
39
23
 
40
24
  it "syncs without any special config" do
41
- Asset.autosync
25
+ MyTestAsset.should_receive(:sync)
42
26
 
43
- @@called.should be_true
27
+ MyTestAsset.autosync
44
28
  end
45
29
 
46
30
  it "doesnt autosync if ENV is set to false/0/FALSE" do
31
+ MyTestAsset.should_not_receive(:sync)
32
+
47
33
  ['false', '0', 'FALSE'].each do |v|
48
34
  ENV['TRACKMAN_AUTOSYNC'] = v
49
- Asset.autosync
35
+ MyTestAsset.autosync
50
36
  end
51
-
52
- @@called.should be_false
53
37
  end
54
38
 
55
39
  it "doesn't autosync if the env is not in production" do
@@ -64,22 +48,20 @@ describe Trackman::Assets::Asset do
64
48
  false
65
49
  end
66
50
  end
51
+ MyTestAsset.should_not_receive(:sync)
67
52
 
68
- Asset.autosync
69
-
70
- @@called.should be_false
53
+ MyTestAsset.autosync
71
54
  end
72
55
 
73
56
  it "doesn't blow up when I autosync even though something is broken" do
74
- def Asset.sync
75
- @@called = true
57
+ def MyTestAsset.sync
76
58
  raise "something is wrong"
77
59
  end
78
60
  result = true
79
-
80
- lambda { result = Asset.autosync }.should_not raise_error
61
+ MyTestAsset.should_receive(:sync)
62
+
63
+ lambda { result = MyTestAsset.autosync }.should_not raise_error
81
64
 
82
65
  result.should be_false
83
- @@called.should be_true
84
66
  end
85
67
  end
data/trackman.gemspec CHANGED
@@ -25,4 +25,5 @@ Gem::Specification.new do |s|
25
25
  s.add_runtime_dependency "heroku", ">= 2.26.2"
26
26
 
27
27
  s.add_development_dependency "rspec"
28
+ s.add_development_dependency "sprockets"
28
29
  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.1.5
4
+ version: 0.1.6
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-06-22 00:00:00.000000000 Z
13
+ date: 2012-06-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client
@@ -108,6 +108,22 @@ dependencies:
108
108
  - - ! '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: sprockets
113
+ requirement: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
111
127
  description: Trackman hosts your maintenances and app-down pages (503s) and lets you
112
128
  keep them in your current development environment so that you can focus on delivering
113
129
  and not configuring.
@@ -381,11 +397,20 @@ files:
381
397
  - spec/fixtures/rails32/happy-path/public/index.html
382
398
  - spec/fixtures/rails32/happy-path/public/robots.txt
383
399
  - spec/fixtures/rails32/happy-path/script/rails
400
+ - spec/fixtures/sprockets/app/assets/images/a/3/32/allo.png
401
+ - spec/fixtures/sprockets/app/assets/images/bombero.jpeg
402
+ - spec/fixtures/sprockets/app/assets/images/bombero/tralala/img.jpg
403
+ - spec/fixtures/sprockets/app/assets/images/image.jpg
404
+ - spec/fixtures/sprockets/app/assets/stylesheets/a/css.css
405
+ - spec/fixtures/sprockets/app/assets/stylesheets/bombero.css
406
+ - spec/fixtures/sprockets/app/assets/stylesheets/bombero/tralala/trundle.css
407
+ - spec/fixtures/sprockets/public/assets/rails.png
408
+ - spec/fixtures/sprockets/public/favicon.png
409
+ - spec/helpers/act_like_rails2311.rb
410
+ - spec/helpers/act_like_rails32.rb
384
411
  - spec/helpers/app_creator.rb
385
412
  - spec/helpers/fakable_pathman_tester.rb
386
413
  - spec/html_asset_spec.rb
387
- - spec/path_spec.rb
388
- - spec/paths/fakable_pathman_tester_spec.rb
389
414
  - spec/paths/pathman_spec.rb
390
415
  - spec/paths/rails32_pathman_spec.rb
391
416
  - spec/rails2311/first_push_spec.rb
data/spec/path_spec.rb DELETED
@@ -1,6 +0,0 @@
1
-
2
-
3
-
4
-
5
-
6
-
@@ -1,36 +0,0 @@
1
- require 'spec_helper'
2
- require 'helpers/fakable_pathman_tester'
3
-
4
- class Tester
5
- extend Rails32PathResolver
6
- end
7
-
8
- describe FakablePathManTester do
9
- before :all do
10
- FakablePathManTester.switch_on 'spec/fixtures/rails32/clean_path/'
11
- end
12
-
13
- after :all do
14
- FakablePathManTester.switch_off
15
- end
16
-
17
- it "should have a root anywhere for favicons" do
18
- parent_url = 'spec/fixtures/rails32/clean_path/app/assets/stylesheets/trundle.css'
19
- url = 'image.jpg'
20
-
21
- actual = Tester.translate url, parent_url
22
- expected = 'spec/fixtures/rails32/clean_path/app/assets/images/image.jpg'
23
-
24
- actual.should == expected
25
- end
26
-
27
- it "should have a root anywhere for linked images" do
28
- parent_url = 'spec/fixtures/rails32/clean_path/public/503.html'
29
- url = '/favicon.png'
30
-
31
- actual = Tester.translate url, parent_url
32
- expected = 'spec/fixtures/rails32/clean_path/public/favicon.png'
33
-
34
- actual.should == expected
35
- end
36
- end