roger 1.3.5 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -2
  3. data/README.md +5 -5
  4. data/doc/cli.md +6 -6
  5. data/doc/{mockupfile.md → rogerfile.md} +10 -10
  6. data/doc/templating.md +76 -6
  7. data/lib/roger/cli/test.rb +1 -1
  8. data/lib/roger/generators/generator.rb +1 -1
  9. data/lib/roger/generators/new.rb +6 -6
  10. data/lib/roger/project.rb +35 -15
  11. data/lib/roger/release/finalizers/git_branch.rb +3 -3
  12. data/lib/roger/release/finalizers/rsync.rb +1 -1
  13. data/lib/roger/release/processors/mockup.rb +1 -1
  14. data/lib/roger/release/processors/url_relativizer.rb +1 -0
  15. data/lib/roger/release.rb +32 -50
  16. data/lib/roger/{mockupfile.rb → rogerfile.rb} +18 -11
  17. data/lib/roger/server.rb +1 -1
  18. data/lib/roger/template/helpers/capture.rb +53 -0
  19. data/lib/roger/template/helpers/partial.rb +37 -0
  20. data/lib/roger/template/template_context.rb +32 -0
  21. data/lib/roger/template.rb +25 -91
  22. data/lib/roger/test.rb +1 -1
  23. data/lib/roger/version.rb +1 -1
  24. data/test/helpers/cli.rb +5 -5
  25. data/test/unit/cli/cli_serve_test.rb +14 -14
  26. data/test/unit/cli/cli_test_test.rb +4 -4
  27. data/test/unit/generators_test.rb +1 -1
  28. data/test/unit/mockupfile_test.rb +38 -0
  29. data/test/unit/rack/roger_test.rb +1 -1
  30. data/test/unit/release/finalizers/dir_test.rb +43 -0
  31. data/test/unit/release/finalizers/git_branch_test.rb +26 -0
  32. data/test/unit/release/injector_test.rb +66 -0
  33. data/test/unit/release/processors/url_relativizer_test.rb +1 -1
  34. data/test/unit/release/scm/base_test.rb +23 -0
  35. data/test/unit/release/scm/git_test.rb +58 -0
  36. data/test/unit/release_test.rb +95 -5
  37. data/test/unit/server_test.rb +1 -1
  38. data/test/unit/template_test.rb +33 -0
  39. data/test/unit/test_test.rb +2 -2
  40. metadata +20 -8
  41. data/lib/roger/extractor.rb +0 -94
  42. /data/examples/default_template/{Mockupfile → Rogerfile} +0 -0
  43. /data/test/project/{Mockupfile → Rogerfile} +0 -0
@@ -0,0 +1,58 @@
1
+ require "test_helper"
2
+ require "mocha/test_unit"
3
+ require "test_construct"
4
+
5
+ module Roger
6
+ # Test for Roger Zip finalizer
7
+ class GitScmTest < ::Test::Unit::TestCase
8
+ include TestConstruct::Helpers
9
+
10
+ def setup
11
+ @construct = setup_construct
12
+
13
+ @scm = Roger::Release::Scm::Git.new(path: @construct)
14
+
15
+ @construct.file "test.html"
16
+
17
+ # Setup git
18
+ `git init`
19
+ `git add *`
20
+ `git commit -m "Commit 1"`
21
+ `git tag v0.1.0`
22
+
23
+ @construct.file "test2.html"
24
+
25
+ `git add *`
26
+ `git commit -m "Commit 2"`
27
+ `git tag v1.0.0`
28
+ end
29
+
30
+ def teardown
31
+ teardown_construct(@construct)
32
+ end
33
+
34
+ def test_implements_scm_interfase
35
+ assert @scm.respond_to?(:version)
36
+ assert @scm.respond_to?(:date)
37
+ assert @scm.respond_to?(:previous)
38
+ end
39
+
40
+ def test_version
41
+ assert_equal "1.0.0", @scm.version
42
+ end
43
+
44
+ def test_previous
45
+ assert_equal "0.1.0", @scm.previous.version
46
+ end
47
+
48
+ def test_date
49
+ now = Time.now
50
+ date = @scm.date
51
+ assert_equal now.day, date.day
52
+ assert_equal now.month, date.month
53
+ assert_equal now.year, date.year
54
+ assert_equal now.hour, date.hour
55
+ assert_equal now.min, date.min
56
+ end
57
+ end
58
+ end
@@ -1,20 +1,20 @@
1
1
  # Generators register themself on the CLI module
2
2
  require "test_helper"
3
- require "./lib/roger/release.rb"
3
+ require "roger/testing/mock_project"
4
4
 
5
5
  module Roger
6
6
  # Test Roger Release
7
7
  class ReleaseTest < ::Test::Unit::TestCase
8
8
  def setup
9
- @project = Project.new(File.dirname(__FILE__) + "/../project", mockupfile_path: false)
10
- @mockupfile = Roger::Mockupfile.new(@project)
9
+ @project = Testing::MockProject.new
10
+ @rogerfile = Roger::Rogerfile.new(@project)
11
11
  end
12
12
 
13
13
  def test_run_should_set_project_mode
14
14
  assert_equal @project.mode, nil
15
15
 
16
16
  # Running a blank release
17
- @mockupfile.release(blank: true) do |r|
17
+ @rogerfile.release(blank: true) do |r|
18
18
  r.use proc{|release|
19
19
  assert_equal release.project.mode, :release
20
20
  }
@@ -25,13 +25,103 @@ module Roger
25
25
  end
26
26
 
27
27
  def test_blank_release_should_have_no_processors_and_finalizers
28
- @mockupfile.release(blank: true)
28
+ @rogerfile.release(blank: true)
29
29
  @project.release.run!
30
30
 
31
31
  assert @project.release.stack.empty?
32
32
  assert @project.release.finalizers.empty?
33
33
  end
34
34
 
35
+ def test_release_should_add_mockup_processor_as_first_by_default
36
+ release = @rogerfile.release
37
+ release.run!
38
+
39
+ assert release.stack.length > 0
40
+ assert_equal Roger::Release::Processors::Mockup, release.stack.first.first.class
41
+ end
42
+
43
+ def test_release_should_add_url_relativizer_by_default
44
+ release = @rogerfile.release
45
+ release.run!
46
+
47
+ assert release.stack.length > 0
48
+ assert_equal Roger::Release::Processors::UrlRelativizer, release.stack.last.first.class
49
+ end
50
+
51
+ def test_default_banner
52
+ release = @rogerfile.release(scm: :fixed)
53
+
54
+ # Set fixed version
55
+ date = Time.now
56
+ release.scm.version = "1.0.0"
57
+ release.scm.date = date
58
+
59
+ lines = release.banner.split("\n")
60
+
61
+ assert_equal "/* ====================== */", lines[0]
62
+ assert_equal "/* = Version : 1.0.0 = */", lines[1]
63
+ assert_equal "/* = Date : #{date.strftime('%Y-%m-%d')} = */", lines[2]
64
+ assert_equal "/* ====================== */", lines[3]
65
+ end
66
+
67
+ def test_banner
68
+ release = @rogerfile.release(scm: :fixed)
69
+
70
+ banner = release.banner do
71
+ "BANNER"
72
+ end
73
+
74
+ assert_equal "/* BANNER */", banner
75
+ end
76
+
77
+ def test_comment_per_line
78
+ release = @rogerfile.release
79
+
80
+ options = {
81
+ style: :css,
82
+ per_line: true
83
+ }
84
+
85
+ assert_equal "/* a */", release.comment("a", options)
86
+ assert_equal "/* a */\n/* b */", release.comment("a\nb", options)
87
+ end
88
+
89
+ def test_comment_html
90
+ release = @rogerfile.release
91
+
92
+ options = {
93
+ style: :html,
94
+ per_line: false
95
+ }
96
+
97
+ assert_equal "<!-- a -->", release.comment("a", options)
98
+ assert_equal "<!-- a\nb -->", release.comment("a\nb", options)
99
+ end
100
+
101
+ def test_comment_css
102
+ release = @rogerfile.release
103
+
104
+ options = {
105
+ style: :css,
106
+ per_line: false
107
+ }
108
+
109
+ assert_equal "/* a */", release.comment("a", options)
110
+ assert_equal "/* a\nb */", release.comment("a\nb", options)
111
+ end
112
+
113
+ def test_comment_js
114
+ release = @rogerfile.release
115
+
116
+ options = {
117
+ style: :js,
118
+ per_line: false
119
+ }
120
+
121
+ assert_equal "/* a */", release.comment("a", options)
122
+ assert_equal "/* a\nb */", release.comment("a\nb", options)
123
+ end
124
+
35
125
  def test_get_callable
36
126
  p = -> {}
37
127
  assert_equal Release.get_callable(p, {}), p
@@ -5,7 +5,7 @@ module Roger
5
5
  # Test Roger Server test
6
6
  class ServerTest < ::Test::Unit::TestCase
7
7
  def setup
8
- @project = Project.new(File.dirname(__FILE__) + "/../../project", mockupfile_path: false)
8
+ @project = Project.new(File.dirname(__FILE__) + "/../../project", rogerfile_path: false)
9
9
  @server = Server.new(@project)
10
10
  end
11
11
 
@@ -4,6 +4,17 @@ require "test_helper"
4
4
  require "./lib/roger/template.rb"
5
5
 
6
6
  module Roger
7
+ # A simple template helper to use for testing
8
+ module TemplateHelper
9
+ def a
10
+ "a"
11
+ end
12
+
13
+ def from_env(key)
14
+ env[key]
15
+ end
16
+ end
17
+
7
18
  # Roger template tests
8
19
  class TemplateTest < ::Test::Unit::TestCase
9
20
  def setup
@@ -171,5 +182,27 @@ module Roger
171
182
  template = Template.new("<%= env[:test] %>", @config)
172
183
  assert_equal template.render(test: "test"), "test"
173
184
  end
185
+
186
+ # Helpers
187
+
188
+ def test_register_helper
189
+ Roger::Template.helper TemplateHelper
190
+
191
+ assert Roger::Template.helpers.include?(TemplateHelper)
192
+ end
193
+
194
+ def test_helper_works
195
+ Roger::Template.helper TemplateHelper
196
+
197
+ template = Roger::Template.new("<%= a %>", @config)
198
+ assert_equal template.render, "a"
199
+ end
200
+
201
+ def test_helper_has_access_to_env
202
+ Roger::Template.helper TemplateHelper
203
+
204
+ template = Roger::Template.new("<%= from_env(:test) %>", @config)
205
+ assert_equal template.render(test: "test"), "test"
206
+ end
174
207
  end
175
208
  end
@@ -16,7 +16,7 @@ module Roger
16
16
  @project.construct.file file
17
17
  end
18
18
 
19
- @mockupfile = Roger::Mockupfile.new(@project)
19
+ @rogerfile = Roger::Rogerfile.new(@project)
20
20
  end
21
21
 
22
22
  def teardown
@@ -26,7 +26,7 @@ module Roger
26
26
  def test_test_run_should_set_project_mode
27
27
  assert_equal @project.mode, nil
28
28
 
29
- @mockupfile.test do |t|
29
+ @rogerfile.test do |t|
30
30
  t.use proc{|test|
31
31
  assert_equal test.project.mode, :test
32
32
  }
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.3.5
4
+ version: 1.4.0
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: 2015-08-05 00:00:00.000000000 Z
13
+ date: 2015-07-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: thor
@@ -206,12 +206,12 @@ files:
206
206
  - doc/images/logo_plain-square.png
207
207
  - doc/images/logo_plain.png
208
208
  - doc/images/logo_plain.svg
209
- - doc/mockupfile.md
209
+ - doc/rogerfile.md
210
210
  - doc/templating.md
211
211
  - examples/default_template/.gitignore
212
212
  - examples/default_template/CHANGELOG
213
213
  - examples/default_template/Gemfile
214
- - examples/default_template/Mockupfile
214
+ - examples/default_template/Rogerfile
215
215
  - examples/default_template/html/.empty_directory
216
216
  - examples/default_template/partials/.empty_directory
217
217
  - lib/roger/cli.rb
@@ -220,7 +220,6 @@ files:
220
220
  - lib/roger/cli/release.rb
221
221
  - lib/roger/cli/serve.rb
222
222
  - lib/roger/cli/test.rb
223
- - lib/roger/extractor.rb
224
223
  - lib/roger/generators.rb
225
224
  - lib/roger/generators/generator.rb
226
225
  - lib/roger/generators/new.rb
@@ -228,7 +227,6 @@ files:
228
227
  - lib/roger/helpers/get_callable.rb
229
228
  - lib/roger/helpers/get_files.rb
230
229
  - lib/roger/helpers/logging.rb
231
- - lib/roger/mockupfile.rb
232
230
  - lib/roger/project.rb
233
231
  - lib/roger/rack/roger.rb
234
232
  - lib/roger/rack/sleep.rb
@@ -247,8 +245,12 @@ files:
247
245
  - lib/roger/release/scm/fixed.rb
248
246
  - lib/roger/release/scm/git.rb
249
247
  - lib/roger/resolver.rb
248
+ - lib/roger/rogerfile.rb
250
249
  - lib/roger/server.rb
251
250
  - lib/roger/template.rb
251
+ - lib/roger/template/helpers/capture.rb
252
+ - lib/roger/template/helpers/partial.rb
253
+ - lib/roger/template/template_context.rb
252
254
  - lib/roger/test.rb
253
255
  - lib/roger/testing/mock_project.rb
254
256
  - lib/roger/testing/mock_release.rb
@@ -258,7 +260,7 @@ files:
258
260
  - test/project/.rvmrc
259
261
  - test/project/Gemfile
260
262
  - test/project/Gemfile.lock
261
- - test/project/Mockupfile
263
+ - test/project/Rogerfile
262
264
  - test/project/html/formats/csv.rcsv
263
265
  - test/project/html/formats/erb.html.erb
264
266
  - test/project/html/formats/index.html
@@ -298,15 +300,20 @@ files:
298
300
  - test/unit/generators_test.rb
299
301
  - test/unit/helpers/get_files_test.rb
300
302
  - test/unit/helpers/logging_test.rb
303
+ - test/unit/mockupfile_test.rb
301
304
  - test/unit/rack/roger_test.rb
302
305
  - test/unit/release/cleaner_test.rb
306
+ - test/unit/release/finalizers/dir_test.rb
303
307
  - test/unit/release/finalizers/git_branch_test.rb
304
308
  - test/unit/release/finalizers/rsync_test.rb
305
309
  - test/unit/release/finalizers/zip_test.rb
310
+ - test/unit/release/injector_test.rb
306
311
  - test/unit/release/processors/mockup_test.rb
307
312
  - test/unit/release/processors/url_relativizer_test.rb
308
313
  - test/unit/release/processors_test.rb
314
+ - test/unit/release/scm/base_test.rb
309
315
  - test/unit/release/scm/fixed_test.rb
316
+ - test/unit/release/scm/git_test.rb
310
317
  - test/unit/release_test.rb
311
318
  - test/unit/resolver_test.rb
312
319
  - test/unit/server_test.rb
@@ -343,7 +350,7 @@ test_files:
343
350
  - test/project/.rvmrc
344
351
  - test/project/Gemfile
345
352
  - test/project/Gemfile.lock
346
- - test/project/Mockupfile
353
+ - test/project/Rogerfile
347
354
  - test/project/html/formats/csv.rcsv
348
355
  - test/project/html/formats/erb.html.erb
349
356
  - test/project/html/formats/index.html
@@ -383,15 +390,20 @@ test_files:
383
390
  - test/unit/generators_test.rb
384
391
  - test/unit/helpers/get_files_test.rb
385
392
  - test/unit/helpers/logging_test.rb
393
+ - test/unit/mockupfile_test.rb
386
394
  - test/unit/rack/roger_test.rb
387
395
  - test/unit/release/cleaner_test.rb
396
+ - test/unit/release/finalizers/dir_test.rb
388
397
  - test/unit/release/finalizers/git_branch_test.rb
389
398
  - test/unit/release/finalizers/rsync_test.rb
390
399
  - test/unit/release/finalizers/zip_test.rb
400
+ - test/unit/release/injector_test.rb
391
401
  - test/unit/release/processors/mockup_test.rb
392
402
  - test/unit/release/processors/url_relativizer_test.rb
393
403
  - test/unit/release/processors_test.rb
404
+ - test/unit/release/scm/base_test.rb
394
405
  - test/unit/release/scm/fixed_test.rb
406
+ - test/unit/release/scm/git_test.rb
395
407
  - test/unit/release_test.rb
396
408
  - test/unit/resolver_test.rb
397
409
  - test/unit/server_test.rb
@@ -1,94 +0,0 @@
1
- require "hpricot"
2
- require File.dirname(__FILE__) + "/resolver"
3
-
4
- module Roger
5
- # @deprecated Don't use the extractor anymore, use release.use(:mockup, options) processor and
6
- # release.use(:url_relativizer, options) processor
7
- class Extractor
8
- attr_reader :project, :target_path
9
-
10
- # @param [Project] project Project object
11
- # @param [String,Pathname] target_path Path to extract to
12
- # @param [Hash] options Options hash
13
-
14
- # @option options [Array] :url_attributes The element attributes to parse and relativize
15
- # @option options [Array] :url_relativize Wether or not we should relativize
16
- # @option options [Array] :env ENV variable to pass to template renderer.
17
- def initialize(project, target_path, options = {})
18
- @project = project
19
- @target_path = Pathname.new(target_path)
20
- @resolver = Resolver.new(self.target_path)
21
-
22
- @options = {
23
- url_attributes: %w(src href action),
24
- url_relativize: true,
25
- env: {}
26
- }
27
-
28
- @options.update(options) if options
29
-
30
- @options[:env].update("MOCKUP_PROJECT" => project)
31
- end
32
-
33
- def run!
34
- target_path = self.target_path
35
- source_path = project.html_path
36
-
37
- filter = "**/*.html"
38
- fail(
39
- ArgumentError,
40
- "Target #{target_path} already exists, please choose a new directory to extract into"
41
- ) if target_path.exist?
42
-
43
- mkdir_p(target_path)
44
- target_path = target_path.realpath
45
-
46
- # Copy source to target first, we'll overwrite the templates later on.
47
- cp_r(source_path.children, target_path)
48
-
49
- Dir.chdir(source_path) do
50
- Dir.glob(filter).each do |file_path|
51
- self.run_on_file!(file_path, @options[:env])
52
- end
53
- end
54
- end
55
-
56
- def run_on_file!(file_path, env = {})
57
- source = extract_source_from_file(file_path, env)
58
- File.open(target_path + file_path, "w") { |f| f.write(source) }
59
- end
60
-
61
- # Runs the extractor on a single file and return processed source.
62
- def extract_source_from_file(file_path, env = {})
63
- source = Roger::Template.open(
64
- file_path,
65
- partials_path: project.partial_path,
66
- layouts_path: project.layouts_path
67
- ).render(env.dup)
68
-
69
- source = relativize_urls(source, file_path) if @options[:url_relativize]
70
-
71
- source
72
- end
73
-
74
- protected
75
-
76
- def relativize_urls(source, file_path)
77
- doc = Hpricot(source)
78
- @options[:url_attributes].each do |attribute|
79
- (doc / "*[@#{attribute}]").each do |tag|
80
- converted_url = @resolver.url_to_relative_url(tag[attribute], file_path)
81
-
82
- case converted_url
83
- when String
84
- tag[attribute] = converted_url
85
- when nil
86
- puts "Could not resolve link #{tag[attribute]} in #{file_path}"
87
- end
88
- end
89
- end
90
-
91
- doc.to_original_html
92
- end
93
- end
94
- end
File without changes