roger 1.6.4 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -3
  3. data/CHANGELOG.md +12 -0
  4. data/Gemfile +4 -3
  5. data/Rakefile +1 -0
  6. data/doc/cli.md +12 -1
  7. data/doc/templating.md +9 -0
  8. data/lib/roger/cli/serve.rb +12 -8
  9. data/lib/roger/cli.rb +78 -5
  10. data/lib/roger/helpers/registration.rb +33 -0
  11. data/lib/roger/project.rb +14 -8
  12. data/lib/roger/rack/roger.rb +1 -1
  13. data/lib/roger/release/finalizers/dir.rb +10 -7
  14. data/lib/roger/release/finalizers/git_branch.rb +18 -32
  15. data/lib/roger/release/finalizers/rsync.rb +24 -23
  16. data/lib/roger/release/finalizers/zip.rb +16 -16
  17. data/lib/roger/release/finalizers.rb +3 -19
  18. data/lib/roger/release/processors/mockup.rb +17 -28
  19. data/lib/roger/release/processors/url_relativizer.rb +11 -13
  20. data/lib/roger/release/processors.rb +50 -22
  21. data/lib/roger/release/scm/git.rb +15 -15
  22. data/lib/roger/release.rb +12 -37
  23. data/lib/roger/renderer.rb +16 -8
  24. data/lib/roger/server.rb +59 -3
  25. data/lib/roger/template/helpers/partial.rb +6 -1
  26. data/lib/roger/version.rb +1 -1
  27. data/roger.gemspec +1 -1
  28. data/test/helpers/generators.rb +25 -0
  29. data/test/project/layouts/bracket.html.erb +1 -0
  30. data/test/project/partials/test/locals.html.erb +1 -0
  31. data/test/project/partials/test/max_depth.html.erb +1 -1
  32. data/test/project/partials/test/parent_template.html.erb +1 -0
  33. data/test/unit/cli/cli_base_test.rb +67 -0
  34. data/test/unit/cli/cli_generate_test.rb +0 -20
  35. data/test/unit/cli/cli_serve_test.rb +19 -4
  36. data/test/unit/generators_test.rb +5 -28
  37. data/test/unit/rack/roger_test.rb +19 -3
  38. data/test/unit/release/finalizers/rsync_test.rb +11 -9
  39. data/test/unit/release/processors/mockup_test.rb +12 -0
  40. data/test/unit/release_test.rb +27 -4
  41. data/test/unit/renderer/renderer_base_test.rb +24 -0
  42. data/test/unit/renderer/renderer_layout_test.rb +26 -2
  43. data/test/unit/renderer/renderer_partial_test.rb +12 -2
  44. data/test/unit/server_test.rb +32 -0
  45. data/test/unit/test_helper.rb +2 -7
  46. metadata +13 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 92478f7482bcbb5fa9dfe14d0a96d092a46e5d78
4
- data.tar.gz: b6f75c7d2deb4c7d3d5afb2fd5c5ea3bd2e9c22d
3
+ metadata.gz: 254dec98111150e5adbe9e84f7aa1f46c66f5531
4
+ data.tar.gz: a5dc918ad5089d30ca4e05cc33d2cd9c5add57eb
5
5
  SHA512:
6
- metadata.gz: 2a7ca884f0897b455af8b81c1eff91fe0066ac71b3d3f89bd302b533fdf2b7dc7ba1ba8f69a1472727327fc9434b328f11ad92b6fb98d7ef8a0d7f836469ad43
7
- data.tar.gz: 560301778c4892fbbeb5040a7c1e00162f1012af0395202e4f0c92c52c2401bb7e920f9df40e9bdda9b9af4c212bebd4fd02c0339256fbf1c94000b57a08bb1c
6
+ metadata.gz: 40834adf5d70b5935c8a783b962a34c59e4a74103db5f39bb13cc3805b28924535acf16abb1cc56c4c1c4998247894eeeb01825907ffac61ac432150aabb2369
7
+ data.tar.gz: 39fbb668e16cfa3d6c082325a167c6e6ab357feea2276ceca8fb5cae40f799998f5a7c1b1b4a3fe4f95dfe5a0514fcd904dbf2bdc2401d860d248f1d406b3c88
data/.travis.yml CHANGED
@@ -1,12 +1,12 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
4
- - 2.1.1
5
- - 2.2.2
6
3
  - 2.3.0
4
+ - 2.3.3
7
5
  before_script:
8
6
  - git config --global user.email "travis-ci@digitpaint.nl"
9
7
  - git config --global user.name "Travis-CI"
8
+ after_success:
9
+ - bundle exec codeclimate-test-reporter
10
10
  matrix:
11
11
  fast_finish: true
12
12
  env:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## Version 1.7.0
4
+ * Finalizers and processors now use the same stack. This means you can run processors after certain finalizers
5
+ * Finalizers and processors now have exactly the same API
6
+ * Roger automatically detects free ports now. This can be disabled by passing `auto_port = false` to the server options ( or passing `--server:auto_port=false` on the commandline)
7
+ * Add support for using partials with directly passing locals. Instead of doing `partial "x", locals: {a: 1}` you can now do `partial "x", a: 1`. The old method still works and allows for setting other template options.
8
+ * Allow setting of a default layout by setting `roger.project.options[:renderer][:layout] = "the_default_layout_name"` in your `Rogerfile`. Or via commandline `--renderer:layout='bla'` if you must.
9
+ * Bug fixes:
10
+ - Release will take the set `project.html_path` instead of hardcoded path
11
+ - Fix issues with newer Thor versions
12
+ - Add more code higiene
13
+ - Don't fail if there is no Gemfile. This fixes the `roger generate new` command.
14
+
3
15
  ## Version 1.6.4
4
16
  * Fix bug with block partials in layouts by correctly determine the current Tilt template we're rendering.
5
17
 
data/Gemfile CHANGED
@@ -3,6 +3,7 @@ source "https://rubygems.org"
3
3
  gemspec name: "roger"
4
4
 
5
5
  gem "rake"
6
- gem "pry"
7
- # Only coverage support in CI, CODECLIMATE TOKEN is part of travis.yml
8
- gem "codeclimate-test-reporter", group: :test, require: nil if ENV["CODECLIMATE_REPO_TOKEN"]
6
+
7
+ group :test do
8
+ gem "codeclimate-test-reporter", "~> 1.0.0"
9
+ end
data/Rakefile CHANGED
@@ -13,4 +13,5 @@ Rake::TestTask.new do |t|
13
13
  t.libs << "test/unit"
14
14
  t.test_files = FileList["test/unit/**/*_test.rb"]
15
15
  t.verbose = false
16
+ t.warning = false
16
17
  end
data/doc/cli.md CHANGED
@@ -52,4 +52,15 @@ All commands accept these options.
52
52
  Options:
53
53
  -v, [--verbose] # Set's verbose output
54
54
  -h, [--help] # Help
55
- ```
55
+ ```
56
+
57
+ ## Custom options
58
+
59
+ All processors/middleware/etc. can use custom options. Roger will parse any leftover option that starts with `--` and sets it in the `project.options` hash. It even supports setting nested keys by using `:` as a separator. This means that `--release:rsync:disable=true` will become: `{release: { rsync: { disable: true}}}` in the options hash.
60
+
61
+ ### Parsing
62
+ The commandline parser will work with flags in the following formats:
63
+
64
+ * `--key` will just set the flag to `true`
65
+ * `--key=value` and `--key value` will set the key `:key` to `"value"`
66
+ * `--key=true` and `--key=false` will convert to boolean `true` and `false`
data/doc/templating.md CHANGED
@@ -72,6 +72,15 @@ Template
72
72
  Layout (after)
73
73
  ```
74
74
 
75
+ ### Default layout
76
+ It is possible to define a global default layout in the Rogerfile.
77
+
78
+ ```
79
+ roger.project.options[:renderer][:layout] = "my_default_layout"
80
+ ```
81
+
82
+ The layout can of course be overwritten in the frontmatter. Setting an empty layout will disable the default layout.
83
+
75
84
  ### Advanced layouts
76
85
 
77
86
  #### Using `content_for`
@@ -5,7 +5,7 @@ module Roger
5
5
 
6
6
  class_options port: :string, # Defaults to 9000
7
7
  host: :string, # Defaults to 0.0.0.0
8
- handler: :string # The handler to use (defaults to mongrel)
8
+ handler: :string # The handler to use
9
9
 
10
10
  def serve
11
11
  server_options = {}
@@ -18,15 +18,19 @@ module Roger
18
18
  @project.server.set_options(server_options[:server])
19
19
  end
20
20
 
21
- def show_banner
21
+ def start
22
22
  server = @project.server
23
- puts "Running Roger with #{server.handler.inspect} on #{server.host}:#{server.port}"
24
- puts project_banner(@project)
25
- end
26
23
 
27
- # Hack so we can override it in tests.
28
- def start
29
- @project.server.run!
24
+ @project.server.run! do |server_instance|
25
+ puts "Running Roger with #{server.used_handler.inspect}"
26
+ puts " Host: #{server.host}"
27
+ puts " Port: #{server.used_port}"
28
+ puts
29
+ puts project_banner(@project)
30
+
31
+ # Hack so we can override it in tests.
32
+ yield server_instance if block_given?
33
+ end
30
34
  end
31
35
  end
32
36
  end
data/lib/roger/cli.rb CHANGED
@@ -1,7 +1,13 @@
1
1
  require "rubygems"
2
2
 
3
- # Require bundler gems if available
4
- Bundler.require(:default) if Object.const_defined?(:Bundler)
3
+ # Require bundler gems if Bundler and Gemfile is available
4
+ if Object.const_defined?(:Bundler)
5
+ begin
6
+ Bundler.require(:default)
7
+ rescue Bundler::GemfileNotFound # rubocop:disable all
8
+ # No Gemfile found, not using local bundler
9
+ end
10
+ end
5
11
 
6
12
  require "thor"
7
13
  require "thor/group"
@@ -96,14 +102,81 @@ module Roger
96
102
 
97
103
  protected
98
104
 
99
- # TODO: handle options
100
105
  def initialize_project
101
- if (Pathname.new(options[:path]) + "../partials").exist?
106
+ # Most unfortunately we have to hack around the
107
+ # class_options not being set in the help command
108
+ # since thor v0.19.4
109
+ path = options[:path] || "."
110
+
111
+ if (Pathname.new(path) + "../partials").exist?
102
112
  puts "[ERROR]: Don't use the \"html\" path, use the project base path instead"
103
113
  exit(1)
104
114
  end
105
115
 
106
- Project.new(options[:path], { shell: shell }.update(options))
116
+ project_options = { shell: shell }
117
+ project_options.update(parse_generic_options(args)[0])
118
+ project_options.update(options)
119
+
120
+ Project.new(path, project_options)
121
+ end
122
+
123
+ # Very simplified method to parse CLI options
124
+ # only works with options starting with --
125
+ # Will also make nested options by using ":" so
126
+ # --a:b:c=yes will become {a: {b: {c: "yes"}}}
127
+ def parse_generic_options(args)
128
+ a = args.dup
129
+ arguments = []
130
+ options = {}
131
+
132
+ until a.empty?
133
+ arg = a.shift
134
+ case arg
135
+ when /\A--.+=/
136
+ _, option, value = arg.match(/\A--(.+)=(.+)\Z/).to_a
137
+ update_options(option, value, options)
138
+ when /\A--.+/
139
+ if a[0].nil? || a[0].to_s.start_with?("--")
140
+ # Current option is a boolean
141
+ update_options(arg, true, options)
142
+ else
143
+ # Take value from next
144
+ update_options(arg, a.shift, options)
145
+ end
146
+ else
147
+ arguments << arg
148
+ end
149
+ end
150
+
151
+ [options, arguments]
152
+ end
153
+
154
+ # Will update the passed options array by splitting
155
+ # the composite_key by ":" and applying the keys nested
156
+ def update_options(composite_key, value, options)
157
+ nesting = options
158
+ keys = composite_key.sub(/\A--/, "").split(":")
159
+ keys.each_with_index do |key, i|
160
+ key = key.to_sym
161
+ if i < keys.length - 1
162
+ nesting[key] ||= {}
163
+ nesting = nesting[key]
164
+ else
165
+ nesting[key] = parse_possible_boolean(value)
166
+ end
167
+ end
168
+ options
169
+ end
170
+
171
+ def parse_possible_boolean(value)
172
+ case value
173
+ when "true"
174
+ true
175
+ when "false"
176
+ false
177
+ else
178
+ value
179
+ end
107
180
  end
108
181
  end
109
182
  end
@@ -0,0 +1,33 @@
1
+ module Roger
2
+ module Helpers
3
+ # Helper module to handle registration
4
+ module Registration
5
+ # Register a class with a name. The method can have the following signatures:
6
+ #
7
+ # def register(processor)
8
+ #
9
+ # and for legacy reasons:
10
+ #
11
+ # def register(name, processor)
12
+ #
13
+ # in the first case the processor must have a name class method.
14
+ def register(name, processor = nil)
15
+ if name.is_a?(Class)
16
+ processor = name
17
+ name = processor.name
18
+ end
19
+
20
+ type = to_s.split("::").last
21
+
22
+ fail ArgumentError, "#{type} name '#{name.inspect}' already in use" if map.key?(name)
23
+ fail ArgumentError, "Name must be a symbol" unless name.is_a?(Symbol)
24
+
25
+ map[name] = processor
26
+ end
27
+
28
+ def map
29
+ @_map ||= {}
30
+ end
31
+ end
32
+ end
33
+ end
data/lib/roger/project.rb CHANGED
@@ -29,6 +29,7 @@ module Roger
29
29
  partial_path: @path + "partials",
30
30
  layouts_path: @path + "layouts",
31
31
  rogerfile_path: @path + "Rogerfile",
32
+ renderer: {},
32
33
  server: {},
33
34
  release: {},
34
35
  test: {}
@@ -38,7 +39,7 @@ module Roger
38
39
  options.each { |k, v| @options[k.is_a?(String) ? k.to_sym : k] = v }
39
40
 
40
41
  initialize_accessors
41
- intialize_rogerfile_path
42
+ initialize_rogerfile_path
42
43
  initialize_roger
43
44
  end
44
45
 
@@ -47,18 +48,15 @@ module Roger
47
48
  end
48
49
 
49
50
  def server(options = {})
50
- options = {}.update(@options[:server]).update(options)
51
- @server ||= Server.new(self, options)
51
+ @server ||= Server.new(self, merge_options(options, :server))
52
52
  end
53
53
 
54
54
  def release(options = {})
55
- options = {}.update(@options[:release]).update(options)
56
- @release ||= Release.new(self, options)
55
+ @release ||= Release.new(self, merge_options(options, :release))
57
56
  end
58
57
 
59
58
  def test(options = {})
60
- options = {}.update(@options[:test]).update(options)
61
- @test ||= Test.new(self, options)
59
+ @test ||= Test.new(self, merge_options(options, :test))
62
60
  end
63
61
 
64
62
  def html_path=(p)
@@ -77,7 +75,15 @@ module Roger
77
75
 
78
76
  protected
79
77
 
80
- def intialize_rogerfile_path
78
+ # Creates new options and merges:
79
+ # - @options[:key]
80
+ # - passed options
81
+ #
82
+ def merge_options(options, key)
83
+ {}.update(@options[key]).update(options)
84
+ end
85
+
86
+ def initialize_rogerfile_path
81
87
  # We stop immediately if rogerfile is not a Pathname
82
88
  unless @options[:rogerfile_path].is_a? Pathname
83
89
  self.rogerfile_path = @options[:rogerfile_path]
@@ -44,7 +44,7 @@ module Roger
44
44
  ::Rack::Response.new do |res|
45
45
  res.headers["Content-Type"] = mime if mime
46
46
  res.status = 200
47
- res.write renderer.render(template_path)
47
+ res.write renderer.render(template_path, @project.options[:renderer] || {})
48
48
  end
49
49
  end
50
50
  end
@@ -6,17 +6,20 @@ module Roger::Release::Finalizers
6
6
  # The directory name will have the format PREFIX-VERSION
7
7
  #
8
8
  class Dir < Base
9
+ self.name = :dir
10
+
9
11
  # @option options :prefix Prefix to put before the version (default = "html")
10
- def call(release, call_options = {})
11
- options = {
12
+ def default_options
13
+ {
12
14
  prefix: "html",
13
15
  target_path: release.target_path
14
- }.update(@options)
15
- options.update(call_options) if call_options
16
+ }
17
+ end
16
18
 
17
- name = [options[:prefix], release.scm.version].join("-")
19
+ def perform
20
+ name = [@options[:prefix], @release.scm.version].join("-")
18
21
 
19
- target_dir = Pathname.new(options[:target_path])
22
+ target_dir = Pathname.new(@options[:target_path])
20
23
  FileUtils.mkdir_p(target_dir) unless target_dir.exist?
21
24
 
22
25
  target_path = target_dir + name
@@ -33,4 +36,4 @@ module Roger::Release::Finalizers
33
36
  end
34
37
  end
35
38
 
36
- Roger::Release::Finalizers.register(:dir, Roger::Release::Finalizers::Dir)
39
+ Roger::Release::Finalizers.register(Roger::Release::Finalizers::Dir)
@@ -3,6 +3,8 @@ require "tmpdir"
3
3
  module Roger::Release::Finalizers
4
4
  # Finalizes the release into a specific branch of a repository and pushes it
5
5
  class GitBranch < Roger::Release::Finalizers::Base
6
+ self.name = :git_branch
7
+
6
8
  # @param Hash options The options
7
9
  #
8
10
  # @option options String :remote The remote repository (default is the
@@ -11,8 +13,8 @@ module Roger::Release::Finalizers
11
13
  # @option options Boolean :cleanup Cleanup temp dir afterwards (default is
12
14
  # true)
13
15
  # @option options Boolean :push Push to remote (default is true)
14
- def initialize
15
- @options = {
16
+ def default_options
17
+ {
16
18
  remote: nil,
17
19
  branch: "gh-pages",
18
20
  cleanup: true,
@@ -20,8 +22,7 @@ module Roger::Release::Finalizers
20
22
  }
21
23
  end
22
24
 
23
- def call(release, options = {})
24
- @options = @options.dup.update(options)
25
+ def perform
25
26
  remote = find_git_remote(release.project.path)
26
27
  branch = @options[:branch]
27
28
 
@@ -37,9 +38,9 @@ module Roger::Release::Finalizers
37
38
  create_empty_branch(clone_dir, remote, branch)
38
39
  end
39
40
 
40
- release.log(self, "Working git magic in #{clone_dir}")
41
+ @release.log(self, "Working git magic in #{clone_dir}")
41
42
 
42
- commit_and_push_release(clone_dir, release, branch, @options)
43
+ commit_and_push_release(clone_dir, branch)
43
44
 
44
45
  if @options[:cleanup]
45
46
  FileUtils.rm_rf(tmp_dir)
@@ -50,19 +51,19 @@ module Roger::Release::Finalizers
50
51
 
51
52
  protected
52
53
 
53
- def commit_and_push_release(clone_dir, release, branch, options)
54
+ def commit_and_push_release(clone_dir, branch)
54
55
  ::Dir.chdir(clone_dir) do
55
56
  # 3. Copy changes
56
57
  FileUtils.rm_rf("*")
57
- FileUtils.cp_r release.build_path.to_s + "/.", clone_dir.to_s
58
+ FileUtils.cp_r @release.build_path.to_s + "/.", clone_dir.to_s
58
59
 
59
60
  commands = [
60
61
  %w(git add .), # 4. Add all files
61
- %w(git commit -a -m) << "Release #{release.scm.version}" # 5. Commit
62
+ %w(git commit -a -m) << "Release #{@release.scm.version}" # 5. Commit
62
63
  ]
63
64
 
64
65
  # 6. Git push if in options
65
- commands << (%w(git push origin) << branch) if options[:push]
66
+ commands << (%w(git push origin) << branch) if @options[:push]
66
67
 
67
68
  commands.each do |command|
68
69
  `#{Shellwords.join(command)}`
@@ -111,25 +112,13 @@ module Roger::Release::Finalizers
111
112
  `#{command}`
112
113
  end
113
114
 
114
- # Find the git dir
115
- # TODO: this is just a copy from release/scm/git.rb
116
- def find_git_dir(path)
117
- path = Pathname.new(path).realpath
118
- while path.parent != path && !(path + ".git").directory?
119
- path = path.parent
120
- end
121
-
122
- path += ".git"
123
-
124
- fail "Could not find suitable .git dir in #{path}" unless path.directory?
125
-
126
- path
127
- end
128
-
129
115
  def find_git_remote(path)
130
- remote =
131
- @options[:remote] ||
132
- `git --git-dir=#{Shellwords.escape(find_git_dir(path).to_s)} config --get remote.origin.url`
116
+ if @options[:remote]
117
+ remote = @options[:remote]
118
+ else
119
+ git_dir = Roger::Release::Scm::Git.find_git_dir(path)
120
+ remote = `git --git-dir=#{Shellwords.escape(git_dir.to_s)} config --get remote.origin.url`
121
+ end
133
122
 
134
123
  remote.strip!
135
124
 
@@ -140,7 +129,4 @@ module Roger::Release::Finalizers
140
129
  end
141
130
  end
142
131
 
143
- Roger::Release::Finalizers.register(
144
- :git_branch,
145
- Roger::Release::Finalizers::GitBranch
146
- )
132
+ Roger::Release::Finalizers.register(Roger::Release::Finalizers::GitBranch)
@@ -7,6 +7,8 @@ module Roger::Release::Finalizers
7
7
  # @see RsyncFinalizer#initialize for options
8
8
  #
9
9
  class Rsync < Base
10
+ self.name = :rsync
11
+
10
12
  # @param Hash options The options
11
13
  #
12
14
  # @option options String :rsync The Rsync command to run (default is "rsync")
@@ -14,34 +16,32 @@ module Roger::Release::Finalizers
14
16
  # @option options String :host The remote host to upload to
15
17
  # @option options String :username The remote username to upload to
16
18
  # @option options Boolean :ask Prompt the user before uploading (default is true)
17
- def initialize(options = {})
18
- @options = {
19
+ def default_options
20
+ {
19
21
  rsync: "rsync",
20
22
  remote_path: "",
21
23
  host: nil,
22
24
  username: nil,
23
25
  ask: true
24
- }.update(options)
26
+ }
25
27
  end
26
28
 
27
- def call(release, options = {})
28
- options = @options.dup.update(options)
29
-
29
+ def perform
30
30
  # Validate options
31
- validate_options!(release, options)
31
+ validate_options!
32
32
 
33
- return unless prompt_for_upload(options)
33
+ return unless prompt_for_upload
34
34
 
35
- check_rsync_command(options[:rsync])
35
+ check_rsync_command(@options[:rsync])
36
36
 
37
- local_path = release.build_path.to_s
38
- remote_path = options[:remote_path]
37
+ local_path = @release.build_path.to_s
38
+ remote_path = @options[:remote_path]
39
39
 
40
40
  local_path += "/" unless local_path =~ %r{/\Z}
41
41
  remote_path += "/" unless remote_path =~ %r{/\Z}
42
42
 
43
- release.log(self, "Starting upload of #{(release.build_path + '*')} to #{options[:host]}")
44
- rsync(options[:rsync], local_path, remote_path, options)
43
+ release.log(self, "Starting upload of #{(@release.build_path + '*')} to #{@options[:host]}")
44
+ rsync(@options[:rsync], local_path, remote_path)
45
45
  end
46
46
 
47
47
  protected
@@ -52,10 +52,10 @@ module Roger::Release::Finalizers
52
52
  raise "Could not find rsync in #{command.inspect}"
53
53
  end
54
54
 
55
- def rsync(command, local_path, remote_path, options = {})
55
+ def rsync(command, local_path, remote_path)
56
56
  target_path = remote_path
57
- target_path = "#{options[:host]}:#{target_path}" if options[:host]
58
- target_path = "#{options[:username]}@#{target_path}" if options[:username]
57
+ target_path = "#{@options[:host]}:#{target_path}" if @options[:host]
58
+ target_path = "#{@options[:username]}@#{target_path}" if @options[:username]
59
59
 
60
60
  command = [
61
61
  options[:rsync],
@@ -71,17 +71,17 @@ module Roger::Release::Finalizers
71
71
  fail "Rsync failed.\noutput:\n #{output}" unless $CHILD_STATUS.success?
72
72
  end
73
73
 
74
- def prompt_for_upload(options)
74
+ def prompt_for_upload
75
75
  !options[:ask] ||
76
- (prompt("Do you wish to upload to #{options[:host]}? [y/N]: ")) =~ /\Ay(es)?\Z/
76
+ prompt("Do you wish to upload to #{@options[:host]}? [y/N]: ") =~ /\Ay(es)?\Z/
77
77
  end
78
78
 
79
- def validate_options!(release, options)
79
+ def validate_options!
80
80
  must_have_keys = [:remote_path]
81
- return if (options.keys & must_have_keys).size == must_have_keys.size
81
+ return if (@options.keys & must_have_keys).size == must_have_keys.size
82
82
 
83
- release.log(self, "Missing options: #{(must_have_keys - options.keys).inspect}")
84
- fail "Missing keys: #{(must_have_keys - options.keys).inspect}"
83
+ release.log(self, "Missing options: #{(must_have_keys - @options.keys).inspect}")
84
+ fail "Missing keys: #{(must_have_keys - @options.keys).inspect}"
85
85
  end
86
86
 
87
87
  def prompt(question = "Do you wish to continue?")
@@ -90,4 +90,5 @@ module Roger::Release::Finalizers
90
90
  end
91
91
  end
92
92
  end
93
- Roger::Release::Finalizers.register(:rsync, Roger::Release::Finalizers::Rsync)
93
+
94
+ Roger::Release::Finalizers.register(Roger::Release::Finalizers::Rsync)
@@ -1,34 +1,34 @@
1
1
  module Roger::Release::Finalizers
2
2
  # The zip finalizer
3
- # The zip finalizer will
4
3
  class Zip < Base
5
- attr_reader :release
4
+ self.name = :zip
6
5
 
7
6
  # @option options [String] :prefix Prefix to put before the version (default = "html")
8
7
  # @option options [String] :zip The zip command
9
8
  # @option options [String, Pathname] :target_path (release.target_path) The path to zip to
10
- def call(release, call_options = {})
11
- options = {
9
+
10
+ def default_options
11
+ {
12
12
  zip: "zip",
13
13
  prefix: "html",
14
14
  target_path: release.target_path
15
- }.update(@options)
16
-
17
- options.update(call_options) if call_options
15
+ }
16
+ end
18
17
 
19
- target_path = ensure_target_path(options[:target_path])
18
+ def perform
19
+ target_path = ensure_target_path(@options[:target_path])
20
20
 
21
- name = [options[:prefix], release.scm.version].join("-") + ".zip"
21
+ name = [options[:prefix], @release.scm.version].join("-") + ".zip"
22
22
  zip_path = target_path + name
23
23
 
24
- release.log(self, "Finalizing release to #{zip_path}")
24
+ @release.log(self, "Finalizing release to #{zip_path}")
25
25
 
26
- cleanup_existing_zip(release, zip_path)
26
+ cleanup_existing_zip(zip_path)
27
27
 
28
- check_zip_command(options[:zip])
28
+ check_zip_command(@options[:zip])
29
29
 
30
- ::Dir.chdir(release.build_path) do
31
- `#{options[:zip]} -r -9 "#{zip_path}" ./*`
30
+ ::Dir.chdir(@release.build_path) do
31
+ `#{@options[:zip]} -r -9 "#{zip_path}" ./*`
32
32
  end
33
33
  end
34
34
 
@@ -40,7 +40,7 @@ module Roger::Release::Finalizers
40
40
  target_path
41
41
  end
42
42
 
43
- def cleanup_existing_zip(release, path)
43
+ def cleanup_existing_zip(path)
44
44
  return unless File.exist?(path)
45
45
 
46
46
  release.log(self, "Removing existing target #{path}")
@@ -54,4 +54,4 @@ module Roger::Release::Finalizers
54
54
  end
55
55
  end
56
56
  end
57
- Roger::Release::Finalizers.register(:zip, Roger::Release::Finalizers::Zip)
57
+ Roger::Release::Finalizers.register(Roger::Release::Finalizers::Zip)
@@ -1,26 +1,10 @@
1
1
  # The Finalizers will finalize the release. Finalizers can be used to
2
2
  # copy the release, zip the release or upload the release
3
3
  module Roger::Release::Finalizers
4
- # Abstract base finalizer
5
- class Base
6
- def initialize(options = {})
7
- @options = {}
8
- @options.update(options) if options
9
- end
4
+ extend Roger::Helpers::Registration
10
5
 
11
- def call(_release, _options = {})
12
- fail ArgumentError, "Implement in subclass"
13
- end
14
- end
15
-
16
- def self.register(name, finalizer)
17
- fail ArgumentError, "Finalizer name '#{name.inspect}' already in use" if map.key?(name)
18
- fail ArgumentError, "Name must be a symbol" unless name.is_a?(Symbol)
19
- map[name] = finalizer
20
- end
21
-
22
- def self.map
23
- @_map ||= {}
6
+ # Abstract base finalizer; This is practically the same as a processor
7
+ class Base < Roger::Release::Processors::Base
24
8
  end
25
9
  end
26
10