roger 1.1.3 → 1.2.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.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/.hound.yml +2 -0
  3. data/.rubocop.yml +47 -0
  4. data/.travis.yml +1 -5
  5. data/CHANGELOG.md +8 -0
  6. data/Gemfile +3 -3
  7. data/Rakefile +10 -4
  8. data/bin/roger +1 -1
  9. data/doc/mockupfile.md +97 -0
  10. data/doc/templating.md +5 -1
  11. data/examples/default_template/Gemfile +1 -1
  12. data/lib/roger/cli.rb +41 -36
  13. data/lib/roger/cli/command.rb +2 -4
  14. data/lib/roger/cli/generate.rb +1 -0
  15. data/lib/roger/cli/release.rb +2 -2
  16. data/lib/roger/cli/serve.rb +11 -11
  17. data/lib/roger/cli/test.rb +6 -5
  18. data/lib/roger/extractor.rb +42 -43
  19. data/lib/roger/generators.rb +27 -19
  20. data/lib/roger/generators/generator.rb +7 -10
  21. data/lib/roger/generators/new.rb +56 -41
  22. data/lib/roger/generators/templates/generator.tt +5 -5
  23. data/lib/roger/helpers/get_callable.rb +15 -14
  24. data/lib/roger/helpers/logging.rb +35 -13
  25. data/lib/roger/mockupfile.rb +13 -23
  26. data/lib/roger/project.rb +41 -34
  27. data/lib/roger/rack/roger.rb +28 -29
  28. data/lib/roger/rack/sleep.rb +4 -5
  29. data/lib/roger/release.rb +95 -72
  30. data/lib/roger/release/cleaner.rb +14 -13
  31. data/lib/roger/release/finalizers.rb +10 -10
  32. data/lib/roger/release/finalizers/dir.rb +17 -19
  33. data/lib/roger/release/finalizers/git_branch.rb +76 -38
  34. data/lib/roger/release/finalizers/rsync.rb +60 -49
  35. data/lib/roger/release/finalizers/zip.rb +32 -29
  36. data/lib/roger/release/injector.rb +43 -37
  37. data/lib/roger/release/processors.rb +24 -22
  38. data/lib/roger/release/processors/mockup.rb +97 -69
  39. data/lib/roger/release/processors/url_relativizer.rb +57 -30
  40. data/lib/roger/release/scm.rb +30 -27
  41. data/lib/roger/release/scm/git.rb +101 -92
  42. data/lib/roger/resolver.rb +86 -61
  43. data/lib/roger/server.rb +52 -27
  44. data/lib/roger/template.rb +102 -74
  45. data/lib/roger/test.rb +16 -13
  46. data/lib/roger/version.rb +3 -2
  47. data/roger.gemspec +9 -5
  48. data/test/helpers/cli.rb +17 -15
  49. data/test/project/Gemfile +2 -2
  50. data/test/project/html/formats/csv.rcsv +0 -0
  51. data/test/project/lib/generators/test.rb +2 -3
  52. data/test/project/lib/tests/fail/fail.rb +5 -6
  53. data/test/project/lib/tests/noop/lib/cli.rb +2 -1
  54. data/test/project/lib/tests/noop/lib/test.rb +5 -5
  55. data/test/project/lib/tests/noop/noop.rb +2 -1
  56. data/test/project/lib/tests/succeed/succeed.rb +5 -6
  57. data/test/unit/cli/cli_base_test.rb +2 -3
  58. data/test/unit/cli/cli_generate_test.rb +9 -10
  59. data/test/unit/cli/cli_serve_test.rb +22 -18
  60. data/test/unit/cli/cli_test_test.rb +13 -15
  61. data/test/unit/cli/cli_version_test.rb +4 -4
  62. data/test/unit/generators_test.rb +8 -10
  63. data/test/unit/helpers/logging_test.rb +64 -0
  64. data/test/unit/rack/roger_test.rb +21 -0
  65. data/test/unit/release/cleaner_test.rb +23 -19
  66. data/test/unit/release/finalizers/git_branch_test.rb +2 -1
  67. data/test/unit/release/finalizers/zip_test.rb +48 -0
  68. data/test/unit/release/mockup_test.rb +48 -0
  69. data/test/unit/release/processors_test.rb +19 -19
  70. data/test/unit/release_test.rb +15 -14
  71. data/test/unit/resolver_test.rb +21 -14
  72. data/test/unit/server_test.rb +31 -0
  73. data/test/unit/template_test.rb +58 -36
  74. data/test/unit/test_test.rb +3 -2
  75. metadata +35 -9
  76. data/test/Mockupfile-syntax.rb +0 -93
@@ -1,11 +1,9 @@
1
1
  module Roger
2
2
  # Loader for mockupfile
3
3
  class Mockupfile
4
-
5
4
  # This is the context for the mockupfile evaluation. It should be empty except for the
6
5
  # #mockup method.
7
6
  class Context
8
-
9
7
  def initialize(mockupfile)
10
8
  @_mockupfile = mockupfile
11
9
  end
@@ -17,7 +15,6 @@ module Roger
17
15
  def binding
18
16
  ::Kernel.binding
19
17
  end
20
-
21
18
  end
22
19
 
23
20
  # @attr :path [Pathname] The path of the Mockupfile for this project
@@ -30,12 +27,12 @@ module Roger
30
27
 
31
28
  # Actually load the mockupfile
32
29
  def load
33
- if File.exist?(@path) && !self.loaded?
34
- @source = File.read(@path)
35
- context = Context.new(self)
36
- eval @source, context.binding, @path.to_s, 1
37
- @loaded = true
38
- end
30
+ return unless File.exist?(@path) && !self.loaded?
31
+
32
+ @source = File.read(@path)
33
+ context = Context.new(self)
34
+ eval @source, context.binding, @path.to_s, 1 # rubocop:disable Lint/Eval
35
+ @loaded = true
39
36
  end
40
37
 
41
38
  # Wether or not the Mockupfile has been loaded
@@ -44,30 +41,23 @@ module Roger
44
41
  end
45
42
 
46
43
  def release(options = {})
47
- release = self.project.release(options)
48
- if block_given?
49
- yield(release)
50
- end
44
+ release = project.release(options)
45
+ yield(release) if block_given?
51
46
  release
52
47
  end
53
48
 
54
49
  def serve(options = {})
55
- server = self.project.server(options)
56
- if block_given?
57
- yield(server)
58
- end
50
+ server = project.server(options)
51
+ yield(server) if block_given?
59
52
  server
60
53
  end
61
54
 
62
- alias :server :serve
55
+ alias_method :server, :serve
63
56
 
64
57
  def test(options = {})
65
- test = self.project.test(options)
66
- if block_given?
67
- yield(test)
68
- end
58
+ test = project.test(options)
59
+ yield(test) if block_given?
69
60
  test
70
61
  end
71
-
72
62
  end
73
63
  end
@@ -7,48 +7,38 @@ require File.dirname(__FILE__) + "/mockupfile"
7
7
  module Roger
8
8
  # Loader for mockupfile and project dependencies
9
9
  class Project
10
-
11
10
  # @attr :path [Pathname] The project path
12
11
  # @attr :html_path [Pathname] The path of the HTML mockup
13
12
  # @attr :partial_path [Pathname] The path for the partials for this mockup
14
13
  # @attr :mockupfile [Mockupfile] The Mockupfile for this project
15
14
  # @attr :mockupfile_path [Pathname] The path to the Mockupfile
16
- # @attr :mode [nil, :test, :server, :release] The mode we're currently in. If nil, we aren't doing anything.
17
- attr_accessor :path, :html_path, :partial_path, :layouts_path, :mockupfile, :mockupfile_path, :mode
15
+ # @attr :mode [nil, :test, :server, :release] The mode we're currently in.
16
+ # If nil, we aren't doing anything.
17
+ attr_accessor :path, :html_path, :partial_path, :layouts_path,
18
+ :mockupfile, :mockupfile_path, :mode
18
19
 
19
20
  attr_accessor :shell
20
21
 
21
22
  attr_accessor :options
22
23
 
23
- def initialize(path, options={})
24
+ def initialize(path, options = {})
24
25
  @path = Pathname.new(path)
25
26
 
26
27
  @options = {
27
- :html_path => @path + "html",
28
- :partial_path => @path + "partials",
29
- :layouts_path => @path + "layouts",
30
- :mockupfile_path => @path + "Mockupfile",
31
- :server => {},
32
- :release => {},
33
- :test => {}
28
+ html_path: @path + "html",
29
+ partial_path: @path + "partials",
30
+ layouts_path: @path + "layouts",
31
+ mockupfile_path: @path + "Mockupfile",
32
+ server: {},
33
+ release: {},
34
+ test: {}
34
35
  }
35
36
 
36
37
  # Clumsy string to symbol key conversion
37
- options.each{|k,v| @options[k.is_a?(String) ? k.to_sym : k] = v }
38
-
39
- self.html_path = @options[:html_path]
40
- self.partial_path = @options[:partials_path] || @options[:partial_path] || self.html_path + "../partials/"
41
- self.layouts_path = @options[:layouts_path]
42
- self.mockupfile_path = @options[:mockupfile_path]
43
- self.shell = @options[:shell]
44
-
45
- if self.mockupfile_path
46
- @mockupfile = Mockupfile.new(self, self.mockupfile_path)
47
- @mockupfile.load
48
- else
49
- @mockupfile = Mockupfile.new(self)
50
- end
38
+ options.each { |k, v| @options[k.is_a?(String) ? k.to_sym : k] = v }
51
39
 
40
+ initialize_accessors
41
+ initialize_mockup
52
42
  end
53
43
 
54
44
  def shell
@@ -71,26 +61,44 @@ module Roger
71
61
  end
72
62
 
73
63
  def html_path=(p)
74
- @html_path = self.realpath_or_path(p)
64
+ @html_path = realpath_or_path(p)
75
65
  end
76
66
 
77
67
  def partial_path=(p)
78
- @partial_path = self.single_or_multiple_paths(p)
68
+ @partial_path = single_or_multiple_paths(p)
79
69
  end
80
- alias :partials_path :partial_path
81
- alias :partials_path= :partial_path=
70
+ alias_method :partials_path, :partial_path
71
+ alias_method :partials_path=, :partial_path=
82
72
 
83
73
  def layouts_path=(p)
84
- @layouts_path = self.single_or_multiple_paths(p)
74
+ @layouts_path = single_or_multiple_paths(p)
85
75
  end
86
76
 
87
77
  protected
88
78
 
79
+ def initialize_accessors
80
+ self.html_path = @options[:html_path]
81
+ self.partial_path =
82
+ @options[:partials_path] || @options[:partial_path] || html_path + "../partials/"
83
+ self.layouts_path = @options[:layouts_path]
84
+ self.mockupfile_path = @options[:mockupfile_path]
85
+ self.shell = @options[:shell]
86
+ end
87
+
88
+ def initialize_mockup
89
+ if mockupfile_path
90
+ @mockupfile = Mockupfile.new(self, mockupfile_path)
91
+ @mockupfile.load
92
+ else
93
+ @mockupfile = Mockupfile.new(self)
94
+ end
95
+ end
96
+
89
97
  def single_or_multiple_paths(p)
90
- if p.kind_of?(Array)
91
- p.map{|tp| self.realpath_or_path(tp) }
98
+ if p.is_a?(Array)
99
+ p.map { |tp| realpath_or_path(tp) }
92
100
  else
93
- self.realpath_or_path(p)
101
+ realpath_or_path(p)
94
102
  end
95
103
  end
96
104
 
@@ -102,6 +110,5 @@ module Roger
102
110
  path
103
111
  end
104
112
  end
105
-
106
113
  end
107
114
  end
@@ -1,52 +1,51 @@
1
- require 'rack/request'
2
- require 'rack/response'
3
- require 'rack/file'
1
+ require "rack/request"
2
+ require "rack/response"
3
+ require "rack/file"
4
4
 
5
- require File.dirname(__FILE__) + '/../resolver'
5
+ require File.dirname(__FILE__) + "/../resolver"
6
6
 
7
7
  module Roger
8
8
  module Rack
9
-
9
+ # Roger middleware that processe roger templates
10
10
  class Roger
11
-
12
11
  attr_reader :project
13
-
12
+
14
13
  def initialize(project)
15
14
  @project = project
16
15
  @docroot = project.html_path
17
-
16
+
18
17
  @resolver = Resolver.new(@docroot)
19
18
  @file_server = ::Rack::File.new(@docroot)
20
19
  end
21
20
 
22
21
  def call(env)
23
22
  url = env["PATH_INFO"]
24
- env["MOCKUP_PROJECT"] = project
25
-
23
+ env["MOCKUP_PROJECT"] = env["roger.project"] || @project
24
+
26
25
  if template_path = @resolver.url_to_path(url)
27
26
  env["rack.errors"].puts "Rendering template #{template_path.inspect} (#{url.inspect})"
28
- # begin
29
- templ = ::Roger::Template.open(template_path, :partials_path => @project.partials_path, :layouts_path => @project.layouts_path)
30
- mime = ::Rack::Mime.mime_type(File.extname(template_path), 'text/html')
31
- resp = ::Rack::Response.new do |res|
32
- res.headers["Content-Type"] = mime if mime
33
- res.status = 200
34
- res.write templ.render(env)
35
- end
36
- resp.finish
37
- # rescue StandardError => e
38
- # env["rack.errors"].puts "#{e.message}\n #{e.backtrace.join("\n")}\n\n"
39
- # resp = ::Rack::Response.new do |res|
40
- # res.status = 500
41
- # res.write "An error occurred"
42
- # end
43
- # resp.finish
44
- # end
27
+ build_response(template_path, env).finish
45
28
  else
46
29
  env["rack.errors"].puts "Invoking file handler for #{url.inspect}"
47
30
  @file_server.call(env)
48
31
  end
49
- end
32
+ end
33
+
34
+ protected
35
+
36
+ def build_response(template_path, env)
37
+ templ = ::Roger::Template.open(
38
+ template_path,
39
+ partials_path: @project.partials_path,
40
+ layouts_path: @project.layouts_path
41
+ )
42
+ mime = ::Rack::Mime.mime_type(File.extname(template_path), "text/html")
43
+ ::Rack::Response.new do |res|
44
+ res.headers["Content-Type"] = mime if mime
45
+ res.status = 200
46
+ res.write templ.render(env)
47
+ end
48
+ end
50
49
  end
51
50
  end
52
- end
51
+ end
@@ -1,12 +1,12 @@
1
1
  module Roger
2
2
  module Rack
3
- # Listens to the "sleep" parameter and sleeps the amount of seconds specified by the parameter. There is however a maximum of 5 seconds.
3
+ # Listens to the "sleep" parameter and sleeps the amount of seconds specified by the parameter.
4
+ # There is however a maximum of 5 seconds.
4
5
  class Sleep
5
-
6
6
  def initialize(app)
7
7
  @app = app
8
8
  end
9
-
9
+
10
10
  def call(env)
11
11
  r = ::Rack::Request.new(env)
12
12
  if r.params["sleep"]
@@ -15,7 +15,6 @@ module Roger
15
15
  end
16
16
  @app.call(env)
17
17
  end
18
-
19
18
  end
20
19
  end
21
- end
20
+ end
@@ -5,6 +5,7 @@ require File.dirname(__FILE__) + "/helpers/logging"
5
5
  require "shellwords"
6
6
 
7
7
  module Roger
8
+ # The release runner
8
9
  class Release
9
10
  include Roger::Helpers::Logging
10
11
 
@@ -15,32 +16,34 @@ module Roger
15
16
  class << self
16
17
  include Roger::Helpers::GetCallable
17
18
 
18
- def default_stack
19
- []
20
- end
21
-
22
- def default_finalizers
23
- [[self.get_callable(:dir, Roger::Release::Finalizers.map), {}]]
24
- end
19
+ def default_stack
20
+ []
21
+ end
25
22
 
23
+ def default_finalizers
24
+ [[get_callable(:dir, Roger::Release::Finalizers.map), {}]]
25
+ end
26
26
  end
27
27
 
28
28
  # @option config [Symbol] :scm The SCM to use (default = :git)
29
29
  # @option config [String, Pathname] :target_path The path/directory to put the release into
30
30
  # @option config [String, Pathname]:build_path Temporary path used to build the release
31
- # @option config [Boolean] :cleanup_build Wether or not to remove the build_path after we're done (default = true)
32
- # @option config [Array,String, nil] :cp CP command to use; Array will be escaped with Shellwords. Pass nil to get native Ruby CP. (default = ["cp", "-RL"])
33
- # @option config [Boolean] :blank Keeps the release clean, don't automatically add any processors or finalizers (default = false)
31
+ # @option config [Boolean] :cleanup_build Wether or not to remove the build_path after we're
32
+ # done (default = true)
33
+ # @option config [Array,String, nil] :cp CP command to use; Array will be escaped with
34
+ # Shellwords. Pass nil to get native Ruby CP. (default = ["cp", "-RL"])
35
+ # @option config [Boolean] :blank Keeps the release clean, don't automatically add any
36
+ # processors or finalizers (default = false)
34
37
  def initialize(project, config = {})
35
38
  real_project_path = project.path.realpath
36
39
  defaults = {
37
- :scm => :git,
38
- :source_path => real_project_path + "html",
39
- :target_path => real_project_path + "releases",
40
- :build_path => real_project_path + "build",
41
- :cp => ["cp", "-RL"],
42
- :blank => false,
43
- :cleanup_build => true
40
+ scm: :git,
41
+ source_path: real_project_path + "html",
42
+ target_path: real_project_path + "releases",
43
+ build_path: real_project_path + "build",
44
+ cp: ["cp", "-RL"],
45
+ blank: false,
46
+ cleanup_build: true
44
47
  }
45
48
 
46
49
  @config = {}.update(defaults).update(config)
@@ -55,7 +58,7 @@ module Roger
55
58
  #
56
59
  # @return Pathname the target_path
57
60
  def target_path
58
- Pathname.new(self.config[:target_path])
61
+ Pathname.new(config[:target_path])
59
62
  end
60
63
 
61
64
  # Accessor for build_path
@@ -63,7 +66,7 @@ module Roger
63
66
  #
64
67
  # @return Pathname the build_path
65
68
  def build_path
66
- Pathname.new(self.config[:build_path])
69
+ Pathname.new(config[:build_path])
67
70
  end
68
71
 
69
72
  # Accessor for source_path
@@ -71,26 +74,28 @@ module Roger
71
74
  #
72
75
  # @return Pathanem the source_path
73
76
  def source_path
74
- Pathname.new(self.config[:source_path])
77
+ Pathname.new(config[:source_path])
75
78
  end
76
79
 
77
80
  # Get the current SCM object
78
81
  def scm(force = false)
79
82
  return @_scm if @_scm && !force
80
83
 
81
- case self.config[:scm]
84
+ case config[:scm]
82
85
  when :git
83
- @_scm = Release::Scm::Git.new(:path => self.source_path)
86
+ @_scm = Release::Scm::Git.new(path: source_path)
84
87
  else
85
- raise "Unknown SCM #{options[:scm].inspect}"
88
+ fail "Unknown SCM #{options[:scm].inspect}"
86
89
  end
87
90
  end
88
91
 
89
92
  # Inject variables into files with an optional filter
90
93
  #
91
94
  # @examples
92
- # release.inject({"VERSION" => release.version, "DATE" => release.date}, :into => %w{_doc/toc.html})
93
- # release.inject({"CHANGELOG" => {:file => "", :filter => BlueCloth}}, :into => %w{_doc/changelog.html})
95
+ # release.inject({"VERSION" => release.version, "DATE" => release.date},
96
+ # :into => %w{_doc/toc.html})
97
+ # release.inject({"CHANGELOG" => {:file => "", :filter => BlueCloth}},
98
+ # :into => %w{_doc/changelog.html})
94
99
  def inject(variables, options)
95
100
  @stack << Injector.new(variables, options)
96
101
  end
@@ -137,29 +142,21 @@ module Roger
137
142
  # =======================
138
143
  #
139
144
  #
140
- # @option options [:css,:js,:html,false] :comment Wether or not to comment the output and in what style. (default=js)
141
- def banner(options = {}, &block)
145
+ # @option options [:css,:js,:html,false] :comment Wether or not to comment the output and in
146
+ # what style. (default=js)
147
+ def banner(options = {}, &_block)
142
148
  options = {
143
- :comment => :js
149
+ comment: :js
144
150
  }.update(options)
145
151
 
146
152
  if block_given?
147
153
  @_banner = yield.to_s
148
154
  elsif !@_banner
149
- banner = []
150
- banner << "Version : #{self.scm.version}"
151
- banner << "Date : #{self.scm.date.strftime("%Y-%m-%d")}"
152
-
153
- size = banner.inject(0){|mem,b| b.size > mem ? b.size : mem }
154
- banner.map!{|b| "= #{b.ljust(size)} =" }
155
- div = "=" * banner.first.size
156
- banner.unshift(div)
157
- banner << div
158
- @_banner = banner.join("\n")
155
+ @_banner = default_banner.join("\n")
159
156
  end
160
157
 
161
158
  if options[:comment]
162
- self.comment(@_banner, :style => options[:comment])
159
+ comment(@_banner, style: options[:comment])
163
160
  else
164
161
  @_banner
165
162
  end
@@ -172,7 +169,8 @@ module Roger
172
169
  #
173
170
  # @deprecated Don't use the extractor anymore, use release.use(:mockup, options) processor
174
171
  def extract(options = {})
175
- self.warn(self, "Don't use the extractor anymore, use release.use(:mockup, options) and release.use(:url_relativizer, options) processors")
172
+ warn(self, "Don't use the extractor anymore, use release.use(:mockup, options)
173
+ and release.use(:url_relativizer, options) processors")
176
174
  @extractor_options = options
177
175
  end
178
176
 
@@ -195,18 +193,17 @@ module Roger
195
193
  run_finalizers!
196
194
 
197
195
  # Cleanup
198
- cleanup! if self.config[:cleanup_build]
196
+ cleanup! if config[:cleanup_build]
199
197
  ensure
200
198
  project.mode = nil
201
199
  end
202
200
 
203
-
204
201
  # @param [Array] globs an array of file path globs that will be globbed against the build_path
205
202
  # @param [Array] excludes an array of regexps that will be excluded from the result
206
203
  def get_files(globs, excludes = [])
207
- files = globs.map{|g| Dir.glob(self.build_path + g) }.flatten
204
+ files = globs.map { |g| Dir.glob(build_path + g) }.flatten
208
205
  if excludes.any?
209
- files.reject{|c| excludes.detect{|e| e.match(c) } }
206
+ files.reject { |c| excludes.detect { |e| e.match(c) } }
210
207
  else
211
208
  files
212
209
  end
@@ -214,6 +211,23 @@ module Roger
214
211
 
215
212
  protected
216
213
 
214
+ def default_banner
215
+ banner = [
216
+ "Version : #{scm.version}",
217
+ "Date : #{scm.date.strftime('%Y-%m-%d')}"
218
+ ]
219
+
220
+ # Find longest line
221
+ size = banner.map(&:size).max
222
+
223
+ # Pad all lines
224
+ banner.map! { |b| "= #{b.ljust(size)} =" }
225
+
226
+ div = "=" * banner.first.size
227
+ banner.unshift(div)
228
+ banner << div
229
+ end
230
+
217
231
  # ==============
218
232
  # = The runway =
219
233
  # ==============
@@ -221,14 +235,14 @@ module Roger
221
235
  # Checks if build path exists (and cleans it up)
222
236
  # Checks if target path exists (if not, creates it)
223
237
  def validate_paths!
224
- if self.build_path.exist?
225
- log self, "Cleaning up previous build \"#{self.build_path}\""
226
- rm_rf(self.build_path)
238
+ if build_path.exist?
239
+ log self, "Cleaning up previous build \"#{build_path}\""
240
+ rm_rf(build_path)
227
241
  end
228
242
 
229
- if !self.target_path.exist?
230
- log self, "Creating target path \"#{self.target_path}\""
231
- mkdir self.target_path
243
+ unless target_path.exist? # rubocop:disable Style/GuardClause
244
+ log self, "Creating target path \"#{target_path}\""
245
+ mkdir target_path
232
246
  end
233
247
  end
234
248
 
@@ -240,39 +254,48 @@ module Roger
240
254
 
241
255
  mockup_options = {}
242
256
  relativizer_options = {}
243
- run_relativizer = true
257
+
244
258
  if @extractor_options
245
- mockup_options = {:env => @extractor_options[:env]}
246
- relativizer_options = {:url_attributes => @extractor_options[:url_attributes]}
247
- run_relativizer = @extractor_options[:url_relativize]
259
+ mockup_options = { env: @extractor_options[:env] }
260
+ relativizer_options = { url_attributes: @extractor_options[:url_attributes] }
248
261
  end
249
262
 
250
- unless @stack.find{|(processor, options)| processor.class == Roger::Release::Processors::Mockup }
263
+ unless find_in_stack(Roger::Release::Processors::Mockup)
251
264
  @stack.unshift([Roger::Release::Processors::Mockup.new, mockup_options])
252
265
  end
253
266
 
254
- unless @stack.find{|(processor, options)| processor.class == Roger::Release::Processors::UrlRelativizer }
267
+ # rubocop:disable Style/GuardClause
268
+ unless find_in_stack(Roger::Release::Processors::UrlRelativizer)
255
269
  @stack.push([Roger::Release::Processors::UrlRelativizer.new, relativizer_options])
256
270
  end
257
271
  end
258
272
 
273
+ # Find a processor in the stack
274
+ def find_in_stack(klass)
275
+ @stack.find { |(processor, _options)| processor.class == klass }
276
+ end
277
+
259
278
  def copy_source_path_to_build_path!
260
- mkdir(self.build_path)
279
+ mkdir(build_path)
261
280
 
262
- if self.config[:cp]
263
- command = [self.config[:cp]].flatten
264
- system(Shellwords.join(command + ["#{self.source_path}/", self.build_path.to_s]))
281
+ if config[:cp]
282
+ copy_source_path_to_build_path_using_system
265
283
  else
266
- cp_r(self.source_path.children, self.build_path)
284
+ cp_r(source_path.children, build_path)
267
285
  end
268
286
  end
269
287
 
288
+ def copy_source_path_to_build_path_using_system
289
+ command = [config[:cp]].flatten
290
+ system(Shellwords.join(command + ["#{source_path}/", build_path.to_s]))
291
+ end
292
+
270
293
  def run_stack!
271
294
  @stack = self.class.default_stack.dup if @stack.empty?
272
295
 
273
296
  # call all objects in @stack
274
297
  @stack.each do |task|
275
- if (task.kind_of?(Array))
298
+ if task.is_a?(Array)
276
299
  task[0].call(self, task[1])
277
300
  else
278
301
  task.call(self)
@@ -291,35 +314,35 @@ module Roger
291
314
  @finalizers.each do |finalizer|
292
315
  finalizer[0].call(self, finalizer[1])
293
316
  end
294
-
295
317
  end
296
318
 
297
319
  def cleanup!
298
- log(self, "Cleaning up build path #{self.build_path}")
299
- rm_rf(self.build_path)
320
+ log(self, "Cleaning up build path #{build_path}")
321
+ rm_rf(build_path)
300
322
  end
301
323
 
302
324
  # @param [String] string The string to comment
303
325
  #
304
- # @option options [:html, :css, :js] :style The comment style to use (default=:js, which is the same as :css)
326
+ # @option options [:html, :css, :js] :style The comment style to use
327
+ # (default=:js, which is the same as :css)
305
328
  # @option options [Boolean] :per_line Comment per line or make one block? (default=true)
306
329
  def comment(string, options = {})
307
330
  options = {
308
- :style => :css,
309
- :per_line => true
331
+ style: :css,
332
+ per_line: true
310
333
  }.update(options)
311
334
 
312
335
  commenters = {
313
- :html => Proc.new{|s| "<!-- #{s} -->" },
314
- :css => Proc.new{|s| "/*! #{s} */" },
315
- :js => Proc.new{|s| "/*! #{s} */" }
336
+ html: proc { |s| "<!-- #{s} -->" },
337
+ css: proc { |s| "/*! #{s} */" },
338
+ js: proc { |s| "/*! #{s} */" }
316
339
  }
317
340
 
318
341
  commenter = commenters[options[:style]] || commenters[:js]
319
342
 
320
343
  if options[:per_line]
321
344
  string = string.split(/\r?\n/)
322
- string.map{|s| commenter.call(s) }.join("\n")
345
+ string.map { |s| commenter.call(s) }.join("\n")
323
346
  else
324
347
  commenter.call(s)
325
348
  end