roger 1.1.3 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -3,7 +3,9 @@ require File.dirname(__FILE__) + "/helpers/get_callable"
3
3
  require File.dirname(__FILE__) + "/helpers/logging"
4
4
 
5
5
  module Roger
6
+ # The test class itself
6
7
  class Test
8
+ # The Test CLI Thor command
7
9
  class Cli < Thor
8
10
  def self.exit_on_failure?
9
11
  true
@@ -17,9 +19,8 @@ module Roger
17
19
 
18
20
  desc "test", "Run the test"
19
21
  def test
20
- unless Roger::Cli::Base.project.test.run_test!(self.class.stack_index)
21
- raise Thor::Error, "The test failed"
22
- end
22
+ ok = Roger::Cli::Base.project.test.run_test!(self.class.stack_index)
23
+ fail(Thor::Error, "The test failed") unless ok
23
24
  end
24
25
  end
25
26
 
@@ -33,10 +34,13 @@ module Roger
33
34
  # Register a test method to Roger::Test so it can be used in the Mockupfile
34
35
 
35
36
  def register(name, test, cli = nil)
36
- raise ArgumentError, "Another test has already claimed the name #{name.inspect}" if self.map.has_key?(name)
37
- raise ArgumentError, "Name must be a symbol" unless name.kind_of?(Symbol)
38
- self.map[name] = test
39
- self.cli_map[name] = cli if cli
37
+ if map.key?(name)
38
+ fail ArgumentError, "Another test has already claimed the name #{name.inspect}"
39
+ end
40
+
41
+ fail ArgumentError, "Name must be a symbol" unless name.is_a?(Symbol)
42
+ map[name] = test
43
+ cli_map[name] = cli if cli
40
44
  end
41
45
 
42
46
  # Mapping names to test callers
@@ -65,7 +69,7 @@ module Roger
65
69
  def use(processor, options = {})
66
70
  test = self.class.get_callable(processor, Roger::Test.map)
67
71
  if processor.is_a?(Symbol)
68
- self.register_in_cli(processor, @stack.size, self.class.cli_map[processor])
72
+ register_in_cli(processor, @stack.size, self.class.cli_map[processor])
69
73
  end
70
74
  @stack << [test, options]
71
75
  end
@@ -104,7 +108,7 @@ module Roger
104
108
  # if you wasted more then an hour of your life because the
105
109
  # shell glob didn't 'work'.
106
110
  def get_files(globs, excludes = [])
107
- files = globs.map{|g| Dir.glob(self.project.path + g) }.flatten
111
+ files = globs.map { |g| Dir.glob(project.path + g) }.flatten
108
112
  if excludes.any?
109
113
  files.reject { |c| excludes.detect { |e| c.match(e) } }
110
114
  else
@@ -115,7 +119,7 @@ module Roger
115
119
  protected
116
120
 
117
121
  def call_test(task)
118
- if (task.kind_of?(Array))
122
+ if task.is_a?(Array)
119
123
  task[0].call(self, task[1])
120
124
  else
121
125
  task.call(self)
@@ -125,8 +129,8 @@ module Roger
125
129
  def register_in_cli(name, stack_index, klass)
126
130
  long_desc = "Run #{name} tests"
127
131
 
128
- if klass && klass.kind_of?(Class) && klass <= Roger::Test::Cli
129
- usage = "#{name} #{klass.arguments.map{ |arg| arg.banner }.join(" ")}"
132
+ if klass && klass.is_a?(Class) && klass <= Roger::Test::Cli
133
+ usage = "#{name} #{klass.arguments.map(&:banner).join(' ')}"
130
134
  thor_class = klass
131
135
  else
132
136
  usage = "#{name}"
@@ -138,7 +142,6 @@ module Roger
138
142
  end
139
143
 
140
144
  Roger::Cli::Test.register thor_class, name, usage, long_desc
141
-
142
145
  end
143
146
  end
144
147
  end
@@ -1,3 +1,4 @@
1
+ # Roger main namespace
1
2
  module Roger
2
- VERSION = "1.1.3"
3
- end
3
+ VERSION = "1.2.1"
4
+ end
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- require_relative "lib/roger/version"
3
+ require File.dirname(__FILE__) + "/lib/roger/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "roger"
@@ -10,13 +10,14 @@ Gem::Specification.new do |s|
10
10
  s.email = ["info@digitpaint.nl", "flurin@digitpaint.nl"]
11
11
  s.homepage = "http://github.com/digitpaint/roger"
12
12
  s.summary = "Roger is a set of tools to create self-containing HTML mockups."
13
+ s.description = "See homepage for more information."
13
14
  s.licenses = ["MIT"]
14
15
 
15
16
  s.date = Time.now.strftime("%Y-%m-%d")
16
17
 
17
18
  s.files = `git ls-files`.split("\n")
18
19
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
20
21
  s.require_paths = ["lib"]
21
22
 
22
23
  s.extra_rdoc_files = [
@@ -25,16 +26,19 @@ Gem::Specification.new do |s|
25
26
 
26
27
  s.rdoc_options = ["--charset=UTF-8"]
27
28
 
28
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
29
+ if s.respond_to? :required_rubygems_version=
30
+ s.required_rubygems_version = Gem::Requirement.new(">= 0")
31
+ end
29
32
 
30
33
  s.add_dependency("thor", ["~> 0.19.0"])
31
34
  s.add_dependency("rack", [">= 1.0.0"])
32
35
  s.add_dependency("tilt", ["~> 2.0.1"])
33
36
  s.add_dependency("mime-types", ["~> 2.2"])
34
- s.add_dependency("hpricot", [">= 0.6.4"])
37
+ s.add_dependency("hpricot", ["= 0.8.4"])
35
38
  s.add_dependency("redcarpet", [">= 3.1.1"])
36
39
 
37
40
  s.add_development_dependency("test-unit", "~> 3.0.0")
38
41
  s.add_development_dependency("mocha", "~> 1.1.0")
39
42
  s.add_development_dependency("puma", "~> 2.10.0")
40
- end
43
+ s.add_development_dependency "rubocop", "~> 0.31.0"
44
+ end
@@ -1,10 +1,12 @@
1
1
  require "stringio"
2
2
 
3
3
  module Roger
4
+ # Module with some helper functions for testing Roger CLI commands
4
5
  module TestCli
5
6
  # Capture stdout/stderr output
6
7
  def capture
7
- @_orig_stdout, @_orig_stderr = $stdout, $stderr
8
+ @_orig_stdout = $stdout
9
+ @_orig_stderr = $stderr
8
10
 
9
11
  $stdout = StringIO.new
10
12
  $stderr = StringIO.new
@@ -13,35 +15,35 @@ module Roger
13
15
 
14
16
  return [$stdout.string, $stderr.string]
15
17
  ensure
16
- $stdout, $stderr = @_orig_stdout, @_orig_stderr
18
+ $stdout = @_orig_stdout
19
+ $stderr = @_orig_stderr
17
20
  end
18
21
 
19
- def run_command(args, &block)
22
+ def run_command(args, &_block)
20
23
  out, err = capture do
21
- Cli::Base.start(args, :debug => true)
24
+ Cli::Base.start(args, debug: true)
22
25
  end
23
- [out,err]
26
+ [out, err]
24
27
  end
25
28
 
26
-
27
- def run_command_with_mockupfile(args, &block)
28
- project = Project.new(@base_path || File.dirname(__FILE__) + "/../../project", :mockupfile_path => false)
29
+ def run_command_with_mockupfile(args, &_block)
30
+ project = Project.new(
31
+ @base_path || File.dirname(__FILE__) + "/../../project",
32
+ mockupfile_path: false
33
+ )
29
34
 
30
35
  mockupfile = Roger::Mockupfile.new(project)
31
36
 
32
- if block_given?
33
- yield(mockupfile)
34
- end
37
+ yield(mockupfile) if block_given?
35
38
 
36
39
  project.mockupfile = mockupfile
37
40
 
38
41
  Cli::Base.project = project
39
42
 
40
43
  out, err = capture do
41
- Cli::Base.start(args, :debug => true)
44
+ Cli::Base.start(args, debug: true)
42
45
  end
43
- [out,err]
46
+ [out, err]
44
47
  end
45
-
46
48
  end
47
- end
49
+ end
@@ -1,7 +1,7 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "roger", :path => File.dirname(__FILE__) + "/../../"
3
+ gem "roger", path: File.dirname(__FILE__) + "/../../"
4
4
  gem "sass"
5
5
  gem "yui-compressor"
6
6
  gem "redcarpet"
7
- gem "pry"
7
+ gem "pry"
File without changes
@@ -1,9 +1,8 @@
1
+ # A Generator for testing purposes; doesn't do much
1
2
  class TestGenerator < Roger::Generators::Base
2
-
3
3
  def do
4
4
  puts "Done!"
5
5
  end
6
-
7
6
  end
8
7
 
9
- Roger::Generators.register TestGenerator
8
+ Roger::Generators.register TestGenerator
@@ -1,17 +1,16 @@
1
1
  module RogerFailTest
2
+ # A test that always fails
2
3
  class Test
3
-
4
- def initialize(options={})
4
+ def initialize(options = {})
5
5
  @options = {}
6
- @options.update(options) if options
6
+ @options.update(options) if options
7
7
  end
8
8
 
9
- def call(test, options={})
9
+ def call(test, _options = {})
10
10
  test.log(self, "Going to fail")
11
11
  false
12
12
  end
13
-
14
13
  end
15
14
  end
16
15
 
17
- Roger::Test.register :fail, RogerFailTest::Test
16
+ Roger::Test.register :fail, RogerFailTest::Test
@@ -1,8 +1,9 @@
1
1
  module RogerNoopTest
2
+ # A CLI command for the Noop test. Doesn't do anything, just output "initialized"
2
3
  class Cli < Roger::Test::Cli
3
4
  desc "init", "init noop tests"
4
5
  def init
5
6
  puts "initialized"
6
7
  end
7
8
  end
8
- end
9
+ end
@@ -1,16 +1,16 @@
1
1
  module RogerNoopTest
2
+ # Noop test. Doesn't do anything except log a normal line and log a debug line
3
+ # Will always pass
2
4
  class Test
3
-
4
- def initialize(options={})
5
+ def initialize(options = {})
5
6
  @options = {}
6
7
  @options.update(options) if options
7
8
  end
8
9
 
9
- def call(test, options={})
10
+ def call(test, _options = {})
10
11
  test.log(self, "NOOP")
11
12
  test.debug(self, "NOOP DEBUG")
12
13
  true
13
14
  end
14
-
15
15
  end
16
- end
16
+ end
@@ -1,7 +1,8 @@
1
1
  require File.dirname(__FILE__) + "/lib/test"
2
2
  require File.dirname(__FILE__) + "/lib/cli"
3
3
 
4
+ # RogerNoopTest namespace
4
5
  module RogerNoopTest
5
6
  end
6
7
 
7
- Roger::Test.register :noop, RogerNoopTest::Test, RogerNoopTest::Cli
8
+ Roger::Test.register :noop, RogerNoopTest::Test, RogerNoopTest::Cli
@@ -1,17 +1,16 @@
1
1
  module RogerSucceedTest
2
+ # A simple Roger test that will succeed
2
3
  class Test
3
-
4
- def initialize(options={})
4
+ def initialize(options = {})
5
5
  @options = {}
6
- @options.update(options) if options
6
+ @options.update(options) if options
7
7
  end
8
8
 
9
- def call(test, options={})
9
+ def call(test, _options = {})
10
10
  test.log(self, "Going to succeed")
11
11
  true
12
12
  end
13
-
14
13
  end
15
14
  end
16
15
 
17
- Roger::Test.register :succeed, RogerSucceedTest::Test
16
+ Roger::Test.register :succeed, RogerSucceedTest::Test
@@ -2,8 +2,8 @@ require "./lib/roger/cli.rb"
2
2
  require "test/unit"
3
3
 
4
4
  module Roger
5
+ # Test for roger base commands
5
6
  class CliBaseTest < ::Test::Unit::TestCase
6
-
7
7
  def test_has_test_command
8
8
  assert_includes Cli::Base.tasks.keys, "test"
9
9
  end
@@ -23,6 +23,5 @@ module Roger
23
23
  def test_has_version_command
24
24
  assert_includes Cli::Base.tasks.keys, "version"
25
25
  end
26
-
27
26
  end
28
- end
27
+ end
@@ -3,20 +3,19 @@ require "test/unit"
3
3
 
4
4
  require File.dirname(__FILE__) + "/../../helpers/cli"
5
5
 
6
- # These tests ar for the roger generate command
7
-
6
+ # CustomGenerators namespace
8
7
  module CustomGens
8
+ # The Generators namespace
9
9
  module Generators
10
-
10
+ # Mock generator
11
11
  class MockedGenerator < Roger::Generators::Base
12
-
13
12
  desc "@mocked description"
14
- argument :path, :type => :string, :required => false, :desc => "Path to generate mockup into"
15
- argument :another_arg, :type => :string, :required => false, :desc => "Mocked or what?!"
13
+ argument :path, type: :string, required: false, desc: "Path to generate mockup into"
14
+ argument :another_arg, type: :string, required: false, desc: "Mocked or what?!"
16
15
 
17
16
  def test
18
17
  # Somewhat ugly way of checking
19
- raise NotImplementedError
18
+ fail NotImplementedError
20
19
  end
21
20
  end
22
21
 
@@ -25,6 +24,7 @@ module CustomGens
25
24
  end
26
25
 
27
26
  module Roger
27
+ # These tests ar for the roger generate command
28
28
  class CliGenerateTest < ::Test::Unit::TestCase
29
29
  include TestCli
30
30
 
@@ -38,11 +38,10 @@ module Roger
38
38
  end
39
39
 
40
40
  def test_help_shows_available_generators
41
- out, err = run_command %w{help generate}
41
+ out, _err = run_command %w(help generate)
42
42
 
43
43
  assert_includes out, "generate new"
44
44
  assert_includes out, "generate mock"
45
45
  end
46
-
47
46
  end
48
- end
47
+ end
@@ -3,16 +3,20 @@ require "test/unit"
3
3
 
4
4
  require File.dirname(__FILE__) + "/../../helpers/cli"
5
5
 
6
- # These tests ar for the roger serve command
7
-
8
- class Roger::Cli::Serve
9
- def start
10
- # Let's not start it.
6
+ module Roger
7
+ module Cli
8
+ # Overwrite Roger::Cli::Serve#start method as we don't want
9
+ # to actually start the server
10
+ class Serve
11
+ def start
12
+ # Let's not start it.
13
+ end
14
+ end
11
15
  end
12
16
  end
13
17
 
14
-
15
18
  module Roger
19
+ # These tests ar for the roger serve command
16
20
  class CliServeTest < ::Test::Unit::TestCase
17
21
  include TestCli
18
22
 
@@ -31,7 +35,7 @@ module Roger
31
35
 
32
36
  # roger server
33
37
  def test_serve_default_options
34
- out, err = run_command(%w{serve})
38
+ out, _err = run_command(%w(serve))
35
39
 
36
40
  assert_includes out, "9000"
37
41
  assert_includes out, "0.0.0.0"
@@ -39,7 +43,7 @@ module Roger
39
43
  end
40
44
 
41
45
  def test_serve_with_custom_host
42
- out, err = run_command(%w{serve --host=localhost})
46
+ out, _err = run_command(%w(serve --host=localhost))
43
47
 
44
48
  assert_includes out, "9000"
45
49
  assert_includes out, "localhost"
@@ -47,7 +51,7 @@ module Roger
47
51
  end
48
52
 
49
53
  def test_serve_with_custom_port
50
- out, err = run_command(%w{serve --port=8888})
54
+ out, _err = run_command(%w(serve --port=8888))
51
55
 
52
56
  assert_includes out, "8888"
53
57
  assert_includes out, "0.0.0.0"
@@ -55,20 +59,20 @@ module Roger
55
59
  end
56
60
 
57
61
  def test_serve_with_custom_handler
58
- out, err = run_command(%w{serve --handler=webrick})
62
+ out, _err = run_command(%w(serve --handler=webrick))
59
63
 
60
64
  assert_includes out, "9000"
61
65
  assert_includes out, "0.0.0.0"
62
66
  assert_includes out, "WEBrick"
63
67
  end
64
-
65
68
  end
66
69
 
70
+ # These tests ar for the roger serve command with a mockupfile config
67
71
  class CliServeWithMockupfileTest < ::Test::Unit::TestCase
68
72
  include TestCli
69
73
 
70
74
  def test_serve_with_port_in_mockupfile
71
- out, err = run_command_with_mockupfile(%w{serve}) do |m|
75
+ out, _err = run_command_with_mockupfile(%w(serve)) do |m|
72
76
  m.serve do |s|
73
77
  s.port = 9001
74
78
  end
@@ -80,7 +84,7 @@ module Roger
80
84
  end
81
85
 
82
86
  def test_serve_with_host_in_mockupfile
83
- out, err = run_command_with_mockupfile(%w{serve}) do |m|
87
+ out, _err = run_command_with_mockupfile(%w(serve)) do |m|
84
88
  m.serve do |s|
85
89
  s.host = "127.0.0.1"
86
90
  end
@@ -92,7 +96,7 @@ module Roger
92
96
  end
93
97
 
94
98
  def test_serve_with_handler_in_mockupfile
95
- out, err = run_command_with_mockupfile(%w{serve}) do |m|
99
+ out, _err = run_command_with_mockupfile(%w(serve)) do |m|
96
100
  m.serve do |s|
97
101
  s.handler = "webrick"
98
102
  end
@@ -104,7 +108,7 @@ module Roger
104
108
  end
105
109
 
106
110
  def test_serve_with_custom_port_should_override_mockupfile
107
- out, err = run_command_with_mockupfile(%w{serve --port=9002}) do |m|
111
+ out, _err = run_command_with_mockupfile(%w(serve --port=9002)) do |m|
108
112
  m.serve do |s|
109
113
  s.port = 9001
110
114
  end
@@ -116,7 +120,7 @@ module Roger
116
120
  end
117
121
 
118
122
  def test_serve_with_custom_host_should_override_mockupfile
119
- out, err = run_command_with_mockupfile(%w{serve --host=localhost}) do |m|
123
+ out, _err = run_command_with_mockupfile(%w(serve --host=localhost)) do |m|
120
124
  m.serve do |s|
121
125
  s.host = "127.0.0.1"
122
126
  end
@@ -128,7 +132,7 @@ module Roger
128
132
  end
129
133
 
130
134
  def test_serve_with_custom_handler_should_override_mockupfile
131
- out, err = run_command_with_mockupfile(%w{serve --handler=webrick}) do |m|
135
+ out, _err = run_command_with_mockupfile(%w(serve --handler=webrick)) do |m|
132
136
  m.serve do |s|
133
137
  s.handler = "puma"
134
138
  end
@@ -139,4 +143,4 @@ module Roger
139
143
  assert_includes out, "WEBrick"
140
144
  end
141
145
  end
142
- end
146
+ end