roger 1.7.0 → 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -3
  3. data/CHANGELOG.md +5 -1
  4. data/doc/templating.md +6 -2
  5. data/lib/roger/cli/serve.rb +1 -1
  6. data/lib/roger/cli/test.rb +0 -2
  7. data/lib/roger/generators.rb +3 -3
  8. data/lib/roger/generators/new.rb +1 -1
  9. data/lib/roger/helpers/get_callable.rb +1 -1
  10. data/lib/roger/helpers/get_files.rb +1 -1
  11. data/lib/roger/helpers/logging.rb +2 -2
  12. data/lib/roger/helpers/registration.rb +2 -2
  13. data/lib/roger/project.rb +2 -2
  14. data/lib/roger/release.rb +2 -3
  15. data/lib/roger/release/cleaner.rb +8 -10
  16. data/lib/roger/release/finalizers/git_branch.rb +19 -19
  17. data/lib/roger/release/finalizers/rsync.rb +2 -2
  18. data/lib/roger/release/injector.rb +4 -8
  19. data/lib/roger/release/processors.rb +2 -2
  20. data/lib/roger/release/processors/mockup.rb +1 -1
  21. data/lib/roger/release/scm.rb +3 -3
  22. data/lib/roger/release/scm/git.rb +1 -1
  23. data/lib/roger/renderer.rb +25 -12
  24. data/lib/roger/resolver.rb +10 -10
  25. data/lib/roger/rogerfile.rb +2 -2
  26. data/lib/roger/server.rb +6 -6
  27. data/lib/roger/template.rb +19 -23
  28. data/lib/roger/template/helpers/capture.rb +1 -1
  29. data/lib/roger/template/helpers/partial.rb +5 -5
  30. data/lib/roger/test.rb +4 -4
  31. data/lib/roger/version.rb +1 -1
  32. data/roger.gemspec +1 -1
  33. data/test/helpers/generators.rb +2 -2
  34. data/test/project/lib/tests/noop/lib/cli.rb +1 -2
  35. data/test/unit/cli/cli_release_test.rb +39 -0
  36. data/test/unit/cli/cli_serve_test.rb +1 -1
  37. data/test/unit/generators/generator_test.rb +28 -0
  38. data/test/unit/generators/new_test.rb +74 -0
  39. data/test/unit/generators_test.rb +5 -15
  40. data/test/unit/helpers/get_files_test.rb +1 -1
  41. data/test/unit/mockupfile_test.rb +1 -1
  42. data/test/unit/rack/roger_test.rb +3 -1
  43. data/test/unit/release/finalizers/git_branch_test.rb +2 -2
  44. data/test/unit/release/injector_test.rb +11 -0
  45. data/test/unit/release/processors/mockup_test.rb +3 -1
  46. data/test/unit/release/processors_test.rb +4 -4
  47. data/test/unit/renderer/renderer_layout_test.rb +33 -4
  48. metadata +11 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 254dec98111150e5adbe9e84f7aa1f46c66f5531
4
- data.tar.gz: a5dc918ad5089d30ca4e05cc33d2cd9c5add57eb
3
+ metadata.gz: 513655e105f751dca8bbc543a7256b732aeb511b
4
+ data.tar.gz: e9d571bfed7a5daa925441689eee296e489cd64c
5
5
  SHA512:
6
- metadata.gz: 40834adf5d70b5935c8a783b962a34c59e4a74103db5f39bb13cc3805b28924535acf16abb1cc56c4c1c4998247894eeeb01825907ffac61ac432150aabb2369
7
- data.tar.gz: 39fbb668e16cfa3d6c082325a167c6e6ab357feea2276ceca8fb5cae40f799998f5a7c1b1b4a3fe4f95dfe5a0514fcd904dbf2bdc2401d860d248f1d406b3c88
6
+ metadata.gz: 91fb6db2902cf5c9aa25a95d30c5ad2cb75bcb701d04fdddaa182c2544f0d4d2af2cc7c020398c960e51fdbc8774407a2b8b1b6679184f961ad471485ca95cd3
7
+ data.tar.gz: 60cda336208d541df3bdd447343a0a46a87feab919c84c55c70a5ac9b2c8cfeeab4d3ef931f64fc1f025195538e90de1cf6ebcb75a6f70dd6ced94d656e9cb03
data/.rubocop.yml CHANGED
@@ -24,8 +24,8 @@ Style/ClassAndModuleChildren:
24
24
 
25
25
  # By default, the rails cops are not run. Override in project or home
26
26
  # directory .rubocop.yml files, or by giving the -R/--rails option.
27
- AllCops:
28
- RunRailsCops: false
27
+ Rails:
28
+ Enabled: false
29
29
 
30
30
  # Disabled cops
31
31
  Metrics/ClassLength:
@@ -44,4 +44,4 @@ Lint/AssignmentInCondition:
44
44
  Enabled: false
45
45
 
46
46
  Style/SingleLineBlockParams:
47
- Enabled: false
47
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## Version 1.7.1
4
+ * Allow setting defaults per template extension.
5
+ * Minor fixes
6
+
3
7
  ## Version 1.7.0
4
8
  * Finalizers and processors now use the same stack. This means you can run processors after certain finalizers
5
9
  * Finalizers and processors now have exactly the same API
@@ -268,4 +272,4 @@ There should be no breaking changes between 0.12.5 and 0.13.0
268
272
  * Replace CLI "generate" command with "new" subcommand and add support for remote git skeletons based on Thor templating.
269
273
  * Add most simple mockup directory as default_template
270
274
  * Requirejs processor updated so it will search for a global r.js command, a local npm r.js command and a vendored r.js command
271
- * Minor fixes and changes
275
+ * Minor fixes and changes
data/doc/templating.md CHANGED
@@ -73,10 +73,14 @@ Layout (after)
73
73
  ```
74
74
 
75
75
  ### Default layout
76
- It is possible to define a global default layout in the Rogerfile.
76
+ It is possible to define a global default layout per template extension in the Rogerfile.
77
77
 
78
78
  ```
79
- roger.project.options[:renderer][:layout] = "my_default_layout"
79
+ roger.project.options[:renderer][:layout] = {
80
+ "html.erb" => "my_default_layout",
81
+ "md.erb" => "my_markdown_layout",
82
+ "md" => "my_markdown_layout"
83
+ }
80
84
  ```
81
85
 
82
86
  The layout can of course be overwritten in the frontmatter. Setting an empty layout will disable the default layout.
@@ -19,7 +19,7 @@ module Roger
19
19
  end
20
20
 
21
21
  def start
22
- server = @project.server
22
+ server = @project.server
23
23
 
24
24
  @project.server.run! do |server_instance|
25
25
  puts "Running Roger with #{server.used_handler.inspect}"
@@ -9,8 +9,6 @@ module Roger
9
9
 
10
10
  desc "all", "Run all tests defined in Rogerfile. (this is the default action)"
11
11
  def all
12
- # If we use fail here the test breaks; no idea why
13
- # rubocop:disable Style/SignalException:
14
12
  raise(Thor::Error, "Test failed") unless Cli::Base.project.test.run!
15
13
  end
16
14
  end
@@ -12,13 +12,13 @@ module Roger
12
12
  def self.register(name, klass = nil)
13
13
  name, klass = generator_name(name, klass)
14
14
 
15
- fail(
15
+ raise(
16
16
  ArgumentError,
17
17
  "Generator name '#{name.inspect}' already in use"
18
18
  ) if Cli::Generate.tasks.key?(name)
19
19
 
20
20
  usage = "#{name} #{klass.arguments.map(&:banner).join(' ')}"
21
- long_desc = klass.desc || "Run #{name} generator"
21
+ long_desc = klass.desc || "Run #{name} generator"
22
22
 
23
23
  Cli::Generate.register klass, name, usage, long_desc
24
24
  Cli::Generate.tasks[name].options = klass.class_options if klass.class_options
@@ -31,7 +31,7 @@ module Roger
31
31
  klass = name
32
32
  name = klass.to_s.sub(/Generator$/, "").sub(/^.*Generators::/, "").downcase
33
33
  else
34
- fail ArgumentError, "Name must be a symbol" unless name.is_a?(Symbol)
34
+ raise ArgumentError, "Name must be a symbol" unless name.is_a?(Symbol)
35
35
  end
36
36
 
37
37
  [name.to_s, klass]
@@ -57,7 +57,7 @@ class Roger::Generators::NewGenerator < Thor::Group
57
57
  def git_clone_template(template)
58
58
  tmp_dir = temp_directory
59
59
 
60
- if run("git clone --depth=1 #{Shellwords.escape(template)} #{tmp_dir}")
60
+ if run("git clone -q --depth=1 #{Shellwords.escape(template)} #{tmp_dir}")
61
61
  say "Cloned template from #{template}"
62
62
  run("rm -rf #{tmp_dir + '.git'}")
63
63
  @cleanup << tmp_dir.to_s
@@ -21,7 +21,7 @@ module Roger
21
21
  error_message = "Could not resolve #{callable.inspect}. Callable must"
22
22
  error_message << "be an object that responds to #call or a symbol that resolve"
23
23
  error_message << "to such an object or a class with a #call instance method."
24
- fail ArgumentError, error_message
24
+ raise ArgumentError, error_message
25
25
  end
26
26
  end
27
27
  end
@@ -20,7 +20,7 @@ module Roger
20
20
 
21
21
  # The default path to use when calling get_files
22
22
  def get_files_default_path
23
- fail "Implement #get_files_default_path in your class"
23
+ raise "Implement #get_files_default_path in your class"
24
24
  end
25
25
  end
26
26
  end
@@ -2,8 +2,8 @@ module Roger
2
2
  module Helpers
3
3
  # Helper module for logging
4
4
  module Logging
5
- GRAY = "\e[37m"
6
- RED = "\e[31m"
5
+ GRAY = "\e[37m".freeze
6
+ RED = "\e[31m".freeze
7
7
 
8
8
  # Write out a log message
9
9
  def log(part, msg, verbose = false, &block)
@@ -19,8 +19,8 @@ module Roger
19
19
 
20
20
  type = to_s.split("::").last
21
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)
22
+ raise ArgumentError, "#{type} name '#{name.inspect}' already in use" if map.key?(name)
23
+ raise ArgumentError, "Name must be a symbol" unless name.is_a?(Symbol)
24
24
 
25
25
  map[name] = processor
26
26
  end
data/lib/roger/project.rb CHANGED
@@ -66,8 +66,8 @@ module Roger
66
66
  def partial_path=(p)
67
67
  @partial_path = single_or_multiple_paths(p)
68
68
  end
69
- alias_method :partials_path, :partial_path
70
- alias_method :partials_path=, :partial_path=
69
+ alias partials_path partial_path
70
+ alias partials_path= partial_path=
71
71
 
72
72
  def layouts_path=(p)
73
73
  @layouts_path = single_or_multiple_paths(p)
data/lib/roger/release.rb CHANGED
@@ -80,7 +80,7 @@ module Roger
80
80
  when :fixed
81
81
  @_scm = Release::Scm::Fixed.new
82
82
  else
83
- fail "Unknown SCM #{options[:scm].inspect}"
83
+ raise "Unknown SCM #{options[:scm].inspect}"
84
84
  end
85
85
  end
86
86
 
@@ -240,7 +240,7 @@ module Roger
240
240
  rm_rf(build_path)
241
241
  end
242
242
 
243
- unless target_path.exist? # rubocop:disable Style/GuardClause
243
+ unless target_path.exist?
244
244
  log self, "Creating target path \"#{target_path}\""
245
245
  mkdir target_path
246
246
  end
@@ -259,7 +259,6 @@ module Roger
259
259
  @stack.push([Roger::Release::Processors::UrlRelativizer.new, {}])
260
260
  end
261
261
 
262
- # rubocop:disable Style/GuardClause
263
262
  unless find_in_stack(Roger::Release::Finalizers::Dir)
264
263
  @stack.push([Roger::Release::Finalizers::Dir.new, {}])
265
264
  end
@@ -36,21 +36,19 @@ module Roger
36
36
  begin
37
37
  build_path = Pathname.new(build_path).realpath.to_s
38
38
  path = Pathname.new(path)
39
- if path.absolute?
40
- path = path.realpath.to_s
41
- else
42
- path = Pathname.new(File.join(build_path.to_s, path)).realpath.to_s
43
- end
39
+ path = if path.absolute?
40
+ path.realpath.to_s
41
+ else
42
+ Pathname.new(File.join(build_path.to_s, path)).realpath.to_s
43
+ end
44
44
  rescue Errno::ENOENT
45
45
  # Real path does not exist
46
46
  return false
47
47
  end
48
48
 
49
- if path[build_path]
50
- return true
51
- else
52
- fail "Cleaning pattern is not inside build directory"
53
- end
49
+ raise "Cleaning pattern is not inside build directory" unless path[build_path]
50
+
51
+ true
54
52
  end
55
53
  end
56
54
  end
@@ -58,8 +58,8 @@ module Roger::Release::Finalizers
58
58
  FileUtils.cp_r @release.build_path.to_s + "/.", clone_dir.to_s
59
59
 
60
60
  commands = [
61
- %w(git add .), # 4. Add all files
62
- %w(git commit -a -m) << "Release #{@release.scm.version}" # 5. Commit
61
+ %w(git add . ), # 4. Add all files
62
+ %w(git commit -q -a -m) << "Release #{@release.scm.version}" # 5. Commit
63
63
  ]
64
64
 
65
65
  # 6. Git push if in options
@@ -74,20 +74,20 @@ module Roger::Release::Finalizers
74
74
  # Check if remote already has branch
75
75
  def remote_has_branch?(remote, branch)
76
76
  command = Shellwords.join([
77
- "git",
78
- "ls-remote",
79
- "--heads",
80
- remote,
81
- "refs/heads/#{branch}"
82
- ])
77
+ "git",
78
+ "ls-remote",
79
+ "--heads",
80
+ remote,
81
+ "refs/heads/#{branch}"
82
+ ])
83
83
  `#{command}` != ""
84
84
  end
85
85
 
86
86
  def create_empty_branch(clone_dir, remote, branch)
87
87
  commands = [
88
- %w(git init),
88
+ %w(git init -q),
89
89
  %w(git remote add origin) << remote,
90
- %w(git checkout -b) << branch
90
+ %w(git checkout -q -b) << branch
91
91
  ]
92
92
 
93
93
  # Branch does not exist yet
@@ -101,14 +101,14 @@ module Roger::Release::Finalizers
101
101
 
102
102
  def clone_branch(clone_dir, remote, branch)
103
103
  command = Shellwords.join([
104
- "git",
105
- "clone",
106
- remote,
107
- "--branch",
108
- branch,
109
- "--single-branch",
110
- clone_dir
111
- ])
104
+ "git",
105
+ "clone",
106
+ remote,
107
+ "--branch",
108
+ branch,
109
+ "--single-branch",
110
+ clone_dir
111
+ ])
112
112
  `#{command}`
113
113
  end
114
114
 
@@ -122,7 +122,7 @@ module Roger::Release::Finalizers
122
122
 
123
123
  remote.strip!
124
124
 
125
- fail "No remote found for origin" if remote.nil? || remote.empty?
125
+ raise "No remote found for origin" if remote.nil? || remote.empty?
126
126
 
127
127
  remote
128
128
  end
@@ -68,7 +68,7 @@ module Roger::Release::Finalizers
68
68
  output = `#{command.join(" ")}`
69
69
 
70
70
  # Check if rsync succeeded
71
- fail "Rsync failed.\noutput:\n #{output}" unless $CHILD_STATUS.success?
71
+ raise "Rsync failed.\noutput:\n #{output}" unless $CHILD_STATUS.success?
72
72
  end
73
73
 
74
74
  def prompt_for_upload
@@ -81,7 +81,7 @@ module Roger::Release::Finalizers
81
81
  return if (@options.keys & must_have_keys).size == must_have_keys.size
82
82
 
83
83
  release.log(self, "Missing options: #{(must_have_keys - @options.keys).inspect}")
84
- fail "Missing keys: #{(must_have_keys - @options.keys).inspect}"
84
+ raise "Missing keys: #{(must_have_keys - @options.keys).inspect}"
85
85
  end
86
86
 
87
87
  def prompt(question = "Do you wish to continue?")
@@ -56,7 +56,7 @@ module Roger
56
56
  injected_vars << variable
57
57
  end
58
58
  end
59
- if injected_vars.size > 0
59
+ unless injected_vars.empty?
60
60
  release.log(self, "Injected variables #{injected_vars.inspect} into #{f}")
61
61
  end
62
62
  File.open(f, "w") { |fh| fh.write c }
@@ -70,24 +70,20 @@ module Roger
70
70
  when Hash
71
71
  get_complex_injection(injection, release)
72
72
  else
73
- if injection.respond_to?(:to_s)
74
- injection.to_s
75
- else
76
- fail ArgumentError, "Woah, what's this? #{injection.inspect}"
77
- end
73
+ injection.to_s
78
74
  end
79
75
  end
80
76
 
81
77
  def get_complex_injection(injection, release)
82
78
  content = injection_content(injection, release)
83
79
 
84
- fail ArgumentError, "No :content or :file specified" unless content
80
+ raise ArgumentError, "No :content or :file specified" unless content
85
81
 
86
82
  if injection[:processor]
87
83
  if tmpl = Tilt[injection[:processor]]
88
84
  (tmpl.new { content }).render
89
85
  else
90
- fail ArgumentError, "Unknown processor #{injection[:processor]}"
86
+ raise ArgumentError, "Unknown processor #{injection[:processor]}"
91
87
  end
92
88
  else
93
89
  content
@@ -11,7 +11,7 @@ module Roger::Release::Processors
11
11
 
12
12
  # Name of this processor
13
13
  def name
14
- @name || fail(ArgumentError, "Implement in subclass")
14
+ @name || raise(ArgumentError, "Implement in subclass")
15
15
  end
16
16
  end
17
17
 
@@ -49,7 +49,7 @@ module Roger::Release::Processors
49
49
  end
50
50
 
51
51
  def perform
52
- fail ArgumentError, "Implement in subclass"
52
+ raise ArgumentError, "Implement in subclass"
53
53
  end
54
54
  end
55
55
  end
@@ -13,7 +13,7 @@ module Roger::Release::Processors
13
13
  "application/xml" => "xml",
14
14
  "text/csv" => "csv",
15
15
  "application/json" => "json"
16
- }
16
+ }.freeze
17
17
 
18
18
  def default_options
19
19
  {
@@ -13,19 +13,19 @@ module Roger
13
13
  #
14
14
  # @return String The current version string
15
15
  def version
16
- fail "Implement in subclass"
16
+ raise "Implement in subclass"
17
17
  end
18
18
 
19
19
  # Returns the release version date from the SCM
20
20
  def date
21
- fail "Implement in subclass"
21
+ raise "Implement in subclass"
22
22
  end
23
23
 
24
24
  # Returns a Release::Scm object with the previous version's data
25
25
  #
26
26
  # @return Roger::Release::Scm The previous version
27
27
  def previous
28
- fail "Implement in subclass"
28
+ raise "Implement in subclass"
29
29
  end
30
30
  end
31
31
  end
@@ -15,7 +15,7 @@ module Roger
15
15
 
16
16
  path += ".git"
17
17
 
18
- fail "Could not find suitable .git dir in #{path}" unless path.directory?
18
+ raise "Could not find suitable .git dir in #{path}" unless path.directory?
19
19
 
20
20
  path
21
21
  end
@@ -183,7 +183,7 @@ module Roger
183
183
  (Pathname.new(current_template.source_path).dirname + pn).realpath
184
184
  else
185
185
  err = "Only within another template you can use relative paths"
186
- fail ArgumentError, err
186
+ raise ArgumentError, err
187
187
  end
188
188
  else
189
189
  pn.realpath
@@ -204,7 +204,11 @@ module Roger
204
204
 
205
205
  # Gets the layout for a specific template
206
206
  def layout_for_template(template, options)
207
- layout_name = template.data.key?(:layout) ? template.data[:layout] : options[:layout]
207
+ layout_name = if template.data.key?(:layout)
208
+ template.data[:layout]
209
+ else
210
+ get_default_layout(template, options)
211
+ end
208
212
 
209
213
  # Only attempt to load layout when:
210
214
  # - Template is the toplevel template
@@ -214,6 +218,15 @@ module Roger
214
218
  template(layout_name, nil, :layout)
215
219
  end
216
220
 
221
+ # Gets the default layout that can be specified by the Rogerfile:
222
+ # roger.project.options[:renderer][:layout] = {
223
+ # "html.erb" => "default"
224
+ # }
225
+ def get_default_layout(template, options)
226
+ source_ext = Renderer.source_extension_for(template.source_path)
227
+ options[:layout][source_ext] if options.key?(:layout)
228
+ end
229
+
217
230
  # Will check the template nesting if we haven't already
218
231
  # rendered this path before. If it has we'll throw an argumenteerror
219
232
  def prevent_recursion!(template)
@@ -230,7 +243,7 @@ module Roger
230
243
  err = "Recursive render detected for '#{template.source_path}'"
231
244
  err += " in '#{current_template.source_path}'"
232
245
 
233
- fail ArgumentError, err
246
+ raise ArgumentError, err
234
247
  end
235
248
 
236
249
  # Will instantiate a Template or throw an ArgumentError
@@ -239,14 +252,14 @@ module Roger
239
252
  if source
240
253
  template = Template.new(source, @context, source_path: path)
241
254
  else
242
- case type
243
- when :partial
244
- template_path = find_partial(path)
245
- when :layout
246
- template_path = find_layout(path)
247
- else
248
- template_path = path
249
- end
255
+ template_path = case type
256
+ when :partial
257
+ find_partial(path)
258
+ when :layout
259
+ find_layout(path)
260
+ else
261
+ path
262
+ end
250
263
 
251
264
  if template_path && File.exist?(template_path)
252
265
  template = Template.open(template_path, @context)
@@ -263,7 +276,7 @@ module Roger
263
276
  def template_not_found!(type, path)
264
277
  err = "No such #{type} #{path}"
265
278
  err += " in #{@current_template.source_path}" if @current_template
266
- fail ArgumentError, err
279
+ raise ArgumentError, err
267
280
  end
268
281
 
269
282
  # Find a partial
@@ -24,12 +24,12 @@ module Roger
24
24
  erubis
25
25
  str
26
26
  )
27
- }
27
+ }.freeze
28
28
 
29
29
  attr_reader :load_paths
30
30
 
31
31
  def initialize(paths)
32
- fail ArgumentError, "Resolver base path can't be nil" if paths.nil?
32
+ raise ArgumentError, "Resolver base path can't be nil" if paths.nil?
33
33
 
34
34
  # Convert to paths
35
35
  @load_paths = [paths].flatten.map { |p| Pathname.new(p) }
@@ -57,7 +57,7 @@ module Roger
57
57
 
58
58
  output
59
59
  end
60
- alias_method :url_to_path, :find_template
60
+ alias url_to_path find_template
61
61
 
62
62
  # Convert a disk path on file to an url
63
63
  def path_to_url(path, relative_to = nil)
@@ -81,7 +81,7 @@ module Roger
81
81
  path, qs, anch = strip_query_string_and_anchor(url)
82
82
 
83
83
  # Get disk path
84
- if true_path = url_to_path(path, exact_match: true)
84
+ if true_path = url_to_path(path, exact_match: true)
85
85
  path = path_to_url(true_path, relative_to_path)
86
86
  path += qs if qs
87
87
  path += anch if anch
@@ -151,17 +151,17 @@ module Roger
151
151
  results = []
152
152
 
153
153
  files.each do |file|
154
- if file.start_with?(path)
155
- match = path
156
- else
157
- match = path_without_extension
158
- end
154
+ match = if file.start_with?(path)
155
+ path
156
+ else
157
+ path_without_extension
158
+ end
159
159
 
160
160
  processable_extensions = file[(match.length + 1)..-1].split(".")
161
161
 
162
162
  # All processable_extensions must be processable
163
163
  # by a template_extension
164
- next unless (processable_extensions - template_extensions).length == 0
164
+ next unless (processable_extensions - template_extensions).empty?
165
165
 
166
166
  if file.start_with?(path)
167
167
  # The whole path is found in the filename, not just
@@ -34,7 +34,7 @@ module Roger
34
34
 
35
35
  # Actually load the rogerfile
36
36
  def load
37
- return unless File.exist?(@path) && !self.loaded?
37
+ return unless File.exist?(@path) && !loaded?
38
38
 
39
39
  @source = File.read(@path)
40
40
  context = Context.new(self)
@@ -59,7 +59,7 @@ module Roger
59
59
  server
60
60
  end
61
61
 
62
- alias_method :server, :serve
62
+ alias server serve
63
63
 
64
64
  def test(options = {})
65
65
  test = project.test(options)
data/lib/roger/server.rb CHANGED
@@ -91,7 +91,7 @@ module Roger
91
91
  @used_port = nil
92
92
  @used_handler = nil
93
93
  end
94
- alias_method :run, :run!
94
+ alias run run!
95
95
 
96
96
  def server_options_for_handler
97
97
  # Search for available port
@@ -113,11 +113,11 @@ module Roger
113
113
  end
114
114
 
115
115
  def handler=(h)
116
- if h.respond_to?(:run)
117
- @handler = h
118
- else
119
- @handler = get_handler(h)
120
- end
116
+ @handler = if h.respond_to?(:run)
117
+ h
118
+ else
119
+ get_handler(h)
120
+ end
121
121
  end
122
122
 
123
123
  protected
@@ -59,11 +59,9 @@ module Roger
59
59
  return @_real_source_path if @_real_source_path_cached
60
60
 
61
61
  @_real_source_path_cached = true
62
- if File.exist?(source_path)
63
- @_real_source_path = Pathname.new(source_path).realpath
64
- else
65
- @_real_source_path = nil
66
- end
62
+ @_real_source_path = if File.exist?(source_path)
63
+ Pathname.new(source_path).realpath
64
+ end
67
65
  end
68
66
 
69
67
  protected
@@ -73,11 +71,11 @@ module Roger
73
71
  @current_tilt_template = template_class
74
72
  template = template_class.new(source_path) { src }
75
73
 
76
- if block_given?
77
- block_content = yield
78
- else
79
- block_content = ""
80
- end
74
+ block_content = if block_given?
75
+ yield
76
+ else
77
+ ""
78
+ end
81
79
 
82
80
  template.render(@context, locals) do |name|
83
81
  if name
@@ -92,20 +90,18 @@ module Roger
92
90
  def extract_front_matter(source)
93
91
  fm_regex = /\A(---\s*\n.*?\n?)^(---\s*$\n?)/m
94
92
 
95
- if match = source.match(fm_regex)
96
- source = source.sub(fm_regex, "")
97
-
98
- begin
99
- data = (YAML.load(match[1]) || {}).inject({}) do |memo, (k, v)|
100
- memo[k.to_sym] = v
101
- memo
102
- end
103
- rescue *YAML_ERRORS => e
104
- puts "YAML Exception: #{e.message}"
105
- return false
93
+ return [{}, source] unless match = source.match(fm_regex)
94
+
95
+ source = source.sub(fm_regex, "")
96
+
97
+ begin
98
+ data = (YAML.load(match[1]) || {}).inject({}) do |memo, (k, v)|
99
+ memo[k.to_sym] = v
100
+ memo
106
101
  end
107
- else
108
- return [{}, source]
102
+ rescue *YAML_ERRORS => e
103
+ puts "YAML Exception: #{e.message}"
104
+ return false
109
105
  end
110
106
 
111
107
  [data, source]
@@ -39,7 +39,7 @@ module Roger
39
39
  unless Thread.current[:tilt_current_template].is_a?(Tilt::ERBTemplate)
40
40
  err = "content_for works only with ERB Templates"
41
41
  err += "(was: #{template.current_tilt_template.inspect})"
42
- fail ArgumentError, err
42
+ raise ArgumentError, err
43
43
  end
44
44
 
45
45
  @block_counter ||= 0
@@ -4,11 +4,11 @@ module Roger
4
4
  # The partial helper
5
5
  module Partial
6
6
  def partial(name, locals = {}, &block)
7
- if locals[:locals]
8
- options = locals
9
- else
10
- options = { locals: locals }
11
- end
7
+ options = if locals[:locals]
8
+ locals
9
+ else
10
+ { locals: locals }
11
+ end
12
12
  if block_given?
13
13
  partial_with_block(name, options, &block)
14
14
  else
data/lib/roger/test.rb CHANGED
@@ -21,7 +21,7 @@ module Roger
21
21
  desc "test", "Run the test"
22
22
  def test
23
23
  ok = Roger::Cli::Base.project.test.run_test!(self.class.stack_index)
24
- fail(Thor::Error, "The test failed") unless ok
24
+ raise(Thor::Error, "The test failed") unless ok
25
25
  end
26
26
  end
27
27
 
@@ -37,10 +37,10 @@ module Roger
37
37
 
38
38
  def register(name, test, cli = nil)
39
39
  if map.key?(name)
40
- fail ArgumentError, "Another test has already claimed the name #{name.inspect}"
40
+ raise ArgumentError, "Another test has already claimed the name #{name.inspect}"
41
41
  end
42
42
 
43
- fail ArgumentError, "Name must be a symbol" unless name.is_a?(Symbol)
43
+ raise ArgumentError, "Name must be a symbol" unless name.is_a?(Symbol)
44
44
  map[name] = test
45
45
  cli_map[name] = cli if cli
46
46
  end
@@ -122,7 +122,7 @@ module Roger
122
122
  usage = "#{name} #{klass.arguments.map(&:banner).join(' ')}"
123
123
  thor_class = klass
124
124
  else
125
- usage = "#{name}"
125
+ usage = name.to_s
126
126
  thor_class = Class.new(Roger::Test::Cli)
127
127
  end
128
128
 
data/lib/roger/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # Roger main namespace
2
2
  module Roger
3
- VERSION = "1.7.0"
3
+ VERSION = "1.7.1".freeze
4
4
  end
data/roger.gemspec CHANGED
@@ -42,5 +42,5 @@ Gem::Specification.new do |s|
42
42
  s.add_development_dependency("mocha", "~> 1.1.0")
43
43
  s.add_development_dependency("simplecov", "~> 0.10.0")
44
44
  s.add_development_dependency("puma", "~> 3.6.0")
45
- s.add_development_dependency("rubocop", "~> 0.31.0")
45
+ s.add_development_dependency("rubocop", "~> 0.38.0")
46
46
  end
@@ -8,7 +8,7 @@ module Generators
8
8
 
9
9
  def test
10
10
  # Somewhat ugly way of checking
11
- fail NotImplementedError
11
+ raise NotImplementedError
12
12
  end
13
13
  end
14
14
 
@@ -19,7 +19,7 @@ module Generators
19
19
  desc "Returns a project"
20
20
  def test
21
21
  # Somewhat ugly way of checking
22
- fail StandardError if @project
22
+ raise StandardError if @project
23
23
  end
24
24
  end
25
25
  end
@@ -1,9 +1,8 @@
1
1
  module RogerNoopTest
2
- # A CLI command for the Noop test. Doesn't do anything, just output "initialized"
2
+ # A CLI command for the Noop test. Doesn't do anything
3
3
  class Cli < Roger::Test::Cli
4
4
  desc "init", "init noop tests"
5
5
  def init
6
- puts "initialized"
7
6
  end
8
7
  end
9
8
  end
@@ -0,0 +1,39 @@
1
+ require "test_helper"
2
+ require "./lib/roger/cli"
3
+ require "test_construct"
4
+
5
+ require File.dirname(__FILE__) + "/../../helpers/cli"
6
+
7
+ module Roger
8
+ # These tests ar for the roger generate command
9
+ class CliReleaseTest < ::Test::Unit::TestCase
10
+ include TestConstruct::Helpers
11
+ include TestCli
12
+
13
+ def setup
14
+ # Reset project as not to leak from other tests
15
+ Cli::Base.project = nil
16
+
17
+ @base_path = setup_construct
18
+ @base_path.directory "html" do |h|
19
+ h.file "index.html"
20
+ end
21
+ @base_path.file "Rogerfile", "roger.release(scm: :fixed) { |r| r.scm.version = '1' }"
22
+ end
23
+
24
+ def teardown
25
+ teardown_construct(@base_path)
26
+ Cli::Base.project = nil
27
+ end
28
+
29
+ # roger generate
30
+ def test_has_release_command
31
+ assert_includes Cli::Base.tasks.keys, "release"
32
+ end
33
+
34
+ def test_runs_release
35
+ run_command(%w(release))
36
+ assert File.exist?(@base_path + "releases/html-1")
37
+ end
38
+ end
39
+ end
@@ -18,7 +18,7 @@ module Roger
18
18
  when Puma::Launcher
19
19
  # Most unfortunately we have to do it using an exception because
20
20
  # Puma will yield before actually starting the server resulting in failures
21
- fail "Stop"
21
+ raise "Stop"
22
22
  else
23
23
  server.stop
24
24
  end
@@ -0,0 +1,28 @@
1
+ # encoding: UTF-8
2
+ # Generators register themself on the CLI module
3
+ require "test_helper"
4
+ require "test_construct"
5
+
6
+ require File.dirname(__FILE__) + "/../../helpers/cli"
7
+
8
+ module Roger
9
+ # Test Roger Generators
10
+ class GeneratoGeneratorTest < ::Test::Unit::TestCase
11
+ include TestConstruct::Helpers
12
+ include TestCli
13
+
14
+ def test_new_generator_exists
15
+ assert_includes Cli::Generate.tasks, "generator"
16
+ end
17
+
18
+ def test_generator_generator
19
+ name = "tralal"
20
+ path = "./tmp"
21
+
22
+ within_construct do
23
+ run_command(%w(generate generator) + [name, path])
24
+ assert File.exist? "#{path}/#{name}_generator.rb"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,74 @@
1
+ # encoding: UTF-8
2
+ # Generators register themself on the CLI module
3
+ require "test_helper"
4
+ require "test_construct"
5
+
6
+ require File.dirname(__FILE__) + "/../../helpers/cli"
7
+
8
+ module Roger
9
+ # Test Roger Generators
10
+ class GeneratorNewTest < ::Test::Unit::TestCase
11
+ include TestConstruct::Helpers
12
+ include TestCli
13
+
14
+ def test_new_generator_exists
15
+ assert_includes Cli::Generate.tasks, "new"
16
+ end
17
+
18
+ def test_exits_on_existing_dir
19
+ within_construct do |c|
20
+ c.directory "existingdir"
21
+
22
+ assert_raises(SystemExit) { run_command %w(generate new existingdir) }
23
+ end
24
+ end
25
+
26
+ def test_with_non_existing_template
27
+ within_construct do
28
+ assert_raises(SystemExit) { run_command %w(generate new mydir -t template) }
29
+ end
30
+ end
31
+
32
+ def test_with_default_template
33
+ within_construct do
34
+ run_command %w(generate new mydir)
35
+
36
+ assert File.exist?("mydir/Rogerfile")
37
+ assert File.exist?("mydir/Gemfile")
38
+ assert File.exist?("mydir/CHANGELOG")
39
+ assert File.exist?("mydir/.gitignore")
40
+ assert File.directory?("mydir/html")
41
+ assert File.directory?("mydir/partials")
42
+ end
43
+ end
44
+
45
+ def test_with_git_template
46
+ within_construct do |c|
47
+ c.directory "template" do |t|
48
+ system("git init -q")
49
+ t.file "gitone"
50
+ system("git add gitone; git commit -q -am 'test'")
51
+ end
52
+
53
+ git_path = "file://#{c + 'template/.git'}"
54
+ run_command %w(generate new mydir -t) << git_path
55
+
56
+ assert File.exist?("mydir/gitone")
57
+ end
58
+ end
59
+
60
+ def test_with_custom_template
61
+ within_construct do |c|
62
+ c.directory "template" do |t|
63
+ t.file "one"
64
+ t.file "two"
65
+ end
66
+
67
+ run_command %w(generate new mydir -t template)
68
+
69
+ assert File.exist?("mydir/one")
70
+ assert File.exist?("mydir/two")
71
+ end
72
+ end
73
+ end
74
+ end
@@ -1,12 +1,17 @@
1
1
  # Generators register themself on the CLI module
2
2
  require "test_helper"
3
3
  require "./lib/roger/generators.rb"
4
+ require "test_construct"
4
5
 
5
6
  require File.dirname(__FILE__) + "/../helpers/generators"
7
+ require File.dirname(__FILE__) + "/../helpers/cli"
6
8
 
7
9
  module Roger
8
10
  # Test Roger Generators
9
11
  class GeneratorTest < ::Test::Unit::TestCase
12
+ include TestConstruct::Helpers
13
+ include TestCli
14
+
10
15
  def setup
11
16
  @cli = Cli::Base.new
12
17
 
@@ -39,21 +44,6 @@ module Roger
39
44
  def test_cli_help_shows_all_available_generators
40
45
  end
41
46
 
42
- def test_default_generator
43
- assert_includes Cli::Generate.tasks, "new"
44
- end
45
-
46
- def test_generator_generator
47
- generators = Cli::Generate.new
48
- name = "tralal"
49
- path = "./tmp"
50
- generators.invoke :generator, [name, path]
51
- assert File.exist? "#{path}/#{name}_generator.rb"
52
-
53
- # Remove generated generator
54
- File.unlink "#{path}/#{name}_generator.rb"
55
- end
56
-
57
47
  def test_invoke_mocked_generator
58
48
  Roger::Generators.register ::Generators::MockedGenerator
59
49
 
@@ -63,7 +63,7 @@ module Roger
63
63
 
64
64
  def test_excludes
65
65
  files = @object.get_files(["**/*.js"], ["\Adir"])
66
- expect = @files.grep(/\.js\Z/).reject { |f| f =~ /\Adir/ }
66
+ expect = @files.grep(/\.js\Z/).reject { |f| f.start_with?("dir") }
67
67
  assert_array_contains(expect, files)
68
68
  end
69
69
 
@@ -7,7 +7,7 @@ end
7
7
 
8
8
  module Roger
9
9
  # Test Roger Release
10
- class ReleaseTest < ::Test::Unit::TestCase
10
+ class MockupFileTest < ::Test::Unit::TestCase
11
11
  def setup
12
12
  @project = Testing::MockProject.new
13
13
  end
@@ -22,7 +22,9 @@ module Roger
22
22
  end
23
23
 
24
24
  def test_renderer_options_are_passed
25
- @project.options[:renderer][:layout] = "bracket"
25
+ @project.options[:renderer][:layout] = {
26
+ "html.erb" => "bracket"
27
+ }
26
28
 
27
29
  @project.construct.file "layouts/bracket.html.erb", "[<%= yield %>]"
28
30
  @project.construct.file "html/test.html.erb", "<%= 'test' %>"
@@ -44,10 +44,10 @@ module Roger
44
44
  finalizer = Roger::Release::Finalizers::GitBranch.new
45
45
  remote_repo = setup_construct(chdir: false)
46
46
 
47
- `git init`
47
+ `git init -q`
48
48
 
49
49
  Dir.chdir(remote_repo.to_s) do
50
- `git init --bare`
50
+ `git init -q --bare`
51
51
  end
52
52
 
53
53
  `git remote add origin #{Shellwords.escape(remote_repo.to_s)}`
@@ -30,6 +30,17 @@ module Roger
30
30
  assert_equal "a1b", File.read(@target_file.to_s)
31
31
  end
32
32
 
33
+ def test_to_s_injection
34
+ injector = Roger::Release::Injector.new(
35
+ { "VAR" => 1 },
36
+ into: ["out"]
37
+ )
38
+
39
+ injector.call(@release)
40
+
41
+ assert_equal "a1b", File.read(@target_file.to_s)
42
+ end
43
+
33
44
  def test_regex_injection
34
45
  injector = Roger::Release::Injector.new(
35
46
  { /V.R/ => "1" },
@@ -45,7 +45,9 @@ module Roger
45
45
  end
46
46
 
47
47
  def test_renderer_options_are_passed
48
- @release.project.options[:renderer][:layout] = "bracket"
48
+ @release.project.options[:renderer][:layout] = {
49
+ "html.erb" => "bracket"
50
+ }
49
51
  @release.project.construct.file "layouts/bracket.html.erb", "[<%= yield %>]"
50
52
  @release.project.construct.directory "build" do |dir|
51
53
  dir.file "test.html.erb", "<%= 'test' %>"
@@ -15,13 +15,13 @@ module Roger
15
15
  end
16
16
 
17
17
  def test_register_processor
18
- processor = ->(_e) { fail "ProcessorName" }
18
+ processor = ->(_e) { raise "ProcessorName" }
19
19
  assert Roger::Release::Processors.register(:name, processor)
20
20
  assert_equal Roger::Release::Processors.map, name: processor
21
21
  end
22
22
 
23
23
  def test_register_processor_with_symbol_only_name
24
- processor = ->(_e) { fail "ProcessorName" }
24
+ processor = ->(_e) { raise "ProcessorName" }
25
25
 
26
26
  assert_raise(ArgumentError) do
27
27
  Roger::Release::Processors.register("name", processor)
@@ -33,7 +33,7 @@ module Roger
33
33
  end
34
34
 
35
35
  def test_register_processor_with_same_name
36
- processor = ->(_e) { fail "ProcessorName" }
36
+ processor = ->(_e) { raise "ProcessorName" }
37
37
  Roger::Release::Processors.register(:name, processor)
38
38
 
39
39
  assert_raise(ArgumentError) do
@@ -42,7 +42,7 @@ module Roger
42
42
  end
43
43
 
44
44
  def test_register_processor_with_same_contents
45
- processor = ->(_e) { fail "ProcessorName" }
45
+ processor = ->(_e) { raise "ProcessorName" }
46
46
  Roger::Release::Processors.register(:name, processor)
47
47
 
48
48
  assert_nothing_raised do
@@ -43,22 +43,51 @@ module Roger
43
43
 
44
44
  def test_default_layout
45
45
  template = "TEMPLATE"
46
- assert_equal "[TEMPLATE]", render_erb_template(template, layout: "bracket")
46
+ default_layout = {
47
+ "html.erb" => "bracket"
48
+ }
49
+
50
+ assert_equal "[TEMPLATE]", render_erb_template(template, layout: default_layout)
47
51
  end
48
52
 
49
53
  def test_default_layout_is_overriden_by_frontmatter
50
54
  template = "---\nlayout: \"yield\"\n---\nTEMPLATE"
51
- assert_equal "TEMPLATE", render_erb_template(template, layout: "bracket")
55
+ default_layout = {
56
+ "html.erb" => "bracket"
57
+ }
58
+
59
+ assert_equal "TEMPLATE", render_erb_template(template, layout: default_layout)
52
60
  end
53
61
 
54
62
  def test_default_layout_can_by_disabled_in_frontmatter
55
63
  template = "---\nlayout: \n---\nTEMPLATE"
56
- assert_equal "TEMPLATE", render_erb_template(template, layout: "bracket")
64
+ default_layout = {
65
+ "html.erb" => "bracket"
66
+ }
67
+
68
+ assert_equal "TEMPLATE", render_erb_template(template, layout: default_layout)
69
+ end
70
+
71
+ def test_default__layouts_is_skipped_for_other_extensions_types
72
+ template = "TEMPLATE"
73
+ default_layout = {
74
+ "html.erb" => "bracket"
75
+ }
76
+
77
+ assert_equal "TEMPLATE", render_css_template(template, layout: default_layout)
57
78
  end
58
79
 
59
80
  def render_erb_template(template, options = {})
81
+ render_abstract_template(@base + "html/layouts/test.html.erb", template, options)
82
+ end
83
+
84
+ def render_css_template(template, options = {})
85
+ render_abstract_template(@base + "html/layouts/test.css.erb", template, options)
86
+ end
87
+
88
+ def render_abstract_template(filename, template, options)
60
89
  options = {}.update(options).update(source: template)
61
- @renderer.render(@base + "html/layouts/test.html.erb", options)
90
+ @renderer.render(filename, options)
62
91
  end
63
92
  end
64
93
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Flurin Egger
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-11-28 00:00:00.000000000 Z
13
+ date: 2017-06-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: thor
@@ -172,14 +172,14 @@ dependencies:
172
172
  requirements:
173
173
  - - "~>"
174
174
  - !ruby/object:Gem::Version
175
- version: 0.31.0
175
+ version: 0.38.0
176
176
  type: :development
177
177
  prerelease: false
178
178
  version_requirements: !ruby/object:Gem::Requirement
179
179
  requirements:
180
180
  - - "~>"
181
181
  - !ruby/object:Gem::Version
182
- version: 0.31.0
182
+ version: 0.38.0
183
183
  description: See homepage for more information.
184
184
  email:
185
185
  - info@digitpaint.nl
@@ -316,9 +316,12 @@ files:
316
316
  - test/project/partials2/partials2-test.html.erb
317
317
  - test/unit/cli/cli_base_test.rb
318
318
  - test/unit/cli/cli_generate_test.rb
319
+ - test/unit/cli/cli_release_test.rb
319
320
  - test/unit/cli/cli_serve_test.rb
320
321
  - test/unit/cli/cli_test_test.rb
321
322
  - test/unit/cli/cli_version_test.rb
323
+ - test/unit/generators/generator_test.rb
324
+ - test/unit/generators/new_test.rb
322
325
  - test/unit/generators_test.rb
323
326
  - test/unit/helpers/get_files_test.rb
324
327
  - test/unit/helpers/logging_test.rb
@@ -368,7 +371,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
368
371
  version: '0'
369
372
  requirements: []
370
373
  rubyforge_project:
371
- rubygems_version: 2.5.1
374
+ rubygems_version: 2.6.10
372
375
  signing_key:
373
376
  specification_version: 4
374
377
  summary: Roger is a set of tools to create self-containing HTML mockups.
@@ -429,9 +432,12 @@ test_files:
429
432
  - test/project/partials2/partials2-test.html.erb
430
433
  - test/unit/cli/cli_base_test.rb
431
434
  - test/unit/cli/cli_generate_test.rb
435
+ - test/unit/cli/cli_release_test.rb
432
436
  - test/unit/cli/cli_serve_test.rb
433
437
  - test/unit/cli/cli_test_test.rb
434
438
  - test/unit/cli/cli_version_test.rb
439
+ - test/unit/generators/generator_test.rb
440
+ - test/unit/generators/new_test.rb
435
441
  - test/unit/generators_test.rb
436
442
  - test/unit/helpers/get_files_test.rb
437
443
  - test/unit/helpers/logging_test.rb