roger 1.6.1 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e748a2603852f67c6114ea94b36c1ef4568aaabc
4
- data.tar.gz: 3be578652cca0187767f4635169b573a21a0012d
3
+ metadata.gz: bc5df3b7198a5c8ae6dca70a00e6a35416fa4056
4
+ data.tar.gz: 850c235b8f2426af1772cb02182e749d91557a95
5
5
  SHA512:
6
- metadata.gz: 1c3e24c404cd8b0e1197b7f7b3bf9d3b90113e59262b231a58e23b2ec2f9d68dc687df143297c2f2904023bbd34926a4c1da7fb9945abdc3a812d9be8dd27362
7
- data.tar.gz: 78eacce507b31d97738f5cace86d2ddbc5e77cf128c9118d10c16ca60d0548edd22e810df25c1218794f27508e0f70394ee70386a9bdb2a2be25d0272f5b14ec
6
+ metadata.gz: d4aabffaf1c231cdda88a03a4df296324abf857a9be70ad18273f7a2709ef9e33480e0aa0096bf18b0a377b695eceb629b8d4e1f18c18c57a592981121d95b89
7
+ data.tar.gz: 3151091868343c3aaeffa12903b5b331e78b2f7bf941e021c98b6110fa1ff5dd280a0253f0beacc9c15ab468e212907209ffa0cbe48b3fa7f5283f3e5b49c550
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## Version 1.6.2
4
+ * Allow for tempalte recursion for up to 10 levels.
5
+ * Fix issue with missing partials that would screw up the current_template nesting stack.
6
+
3
7
  ## Version 1.6.1
4
8
  * No longer process partials in html directory on release.
5
9
 
@@ -157,10 +157,10 @@ A helper is nothing more than a plain old Ruby module containing a bunch of func
157
157
  Registering helpers can best be done in the Rogerfile. Register this module as following:
158
158
 
159
159
  ```ruby
160
- Roger::Template.register MyHelperModule
160
+ Roger::Renderer.helper MyHelperModule
161
161
  ```
162
162
 
163
- After registration the helpers are available for use in all templates, partials, layouts, etc. See the [template helpers tests](../test/unit/template/template_helper_test.rb) for example usage.
163
+ After registration the helpers are available for use in all templates, partials, layouts, etc. See the [template helpers tests](../test/unit/renderer/renderer_helper_test.rb) for example usage.
164
164
 
165
165
  ## Access to Project
166
166
 
@@ -6,6 +6,7 @@ module Roger
6
6
  module Generators
7
7
  # Base Generator class
8
8
  class Base < Cli::Command
9
+ include Thor::Actions
9
10
  end
10
11
 
11
12
  def self.register(name, klass = nil)
@@ -8,6 +8,8 @@ module Roger
8
8
  # The renderer will set up an environment so you can consistently render templates
9
9
  # within that environment
10
10
  class Renderer
11
+ MAX_ALLOWED_TEMPLATE_NESTING = 10
12
+
11
13
  class << self
12
14
  # Register a helper module that should be included in
13
15
  # every template context.
@@ -129,7 +131,9 @@ module Roger
129
131
  render_result
130
132
  end
131
133
  ensure
132
- template_nesting.pop
134
+ # Only pop the template from the nesting if we actually
135
+ # put it on the nesting stack.
136
+ template_nesting.pop if template
133
137
  end
134
138
 
135
139
  # Render any file on disk. No magic. Just rendering.
@@ -142,22 +146,13 @@ module Roger
142
146
  #
143
147
  # @options options [Hash] :locals
144
148
  def render_file(path, options = {})
145
- pn = Pathname.new(path)
146
-
147
- if pn.relative?
148
- # We're explicitly checking for source_path instead of real_source_path
149
- # as you could also just have an inline template.
150
- if current_template && current_template.source_path
151
- pn = (Pathname.new(current_template.source_path).dirname + pn).realpath
152
- else
153
- err = "Only within another template you can use relative paths"
154
- fail ArgumentError, err
155
- end
156
- else
157
- pn = pn.realpath
158
- end
149
+ pn = absolute_path_from_current_template(path)
159
150
 
160
151
  template = template(pn.to_s, nil)
152
+
153
+ # Track rendered file also on the rendered stack
154
+ template_nesting.push(template)
155
+
161
156
  template.render(options[:locals] || {})
162
157
  end
163
158
 
@@ -173,6 +168,23 @@ module Roger
173
168
 
174
169
  protected
175
170
 
171
+ def absolute_path_from_current_template(path)
172
+ pn = Pathname.new(path)
173
+
174
+ if pn.relative?
175
+ # We're explicitly checking for source_path instead of real_source_path
176
+ # as you could also just have an inline template.
177
+ if current_template && current_template.source_path
178
+ (Pathname.new(current_template.source_path).dirname + pn).realpath
179
+ else
180
+ err = "Only within another template you can use relative paths"
181
+ fail ArgumentError, err
182
+ end
183
+ else
184
+ pn.realpath
185
+ end
186
+ end
187
+
176
188
  def template_and_layout_for_render(path, options = {})
177
189
  # A previous template has been set so it's a partial
178
190
  # If no previous template is set, we're
@@ -196,12 +208,12 @@ module Roger
196
208
  # If this template is not a real file it cannot ever conflict.
197
209
  return unless template.real_source_path
198
210
 
199
- caller_template = template_nesting.detect do |t|
211
+ caller_templates = template_nesting.select do |t|
200
212
  t.real_source_path == template.real_source_path
201
213
  end
202
214
 
203
- # We're good, no recursion!
204
- return unless caller_template
215
+ # We're good, no deeper recursion then MAX_ALLOWED_TEMPLATE_NESTING
216
+ return if caller_templates.length <= MAX_ALLOWED_TEMPLATE_NESTING
205
217
 
206
218
  err = "Recursive render detected for '#{template.source_path}'"
207
219
  err += " in '#{current_template.source_path}'"
@@ -1,4 +1,4 @@
1
1
  # Roger main namespace
2
2
  module Roger
3
- VERSION = "1.6.1"
3
+ VERSION = "1.6.2"
4
4
  end
@@ -0,0 +1,5 @@
1
+ <% if depth < max_depth %>
2
+ <%= partial 'test/max_depth', locals: { depth: locals[:depth] + 1, max_depth: locals[:max_depth] } %>
3
+ <% else %>
4
+ Stop! Hammertime!
5
+ <% end %>
@@ -81,6 +81,27 @@ module Roger
81
81
  end
82
82
  end
83
83
 
84
+ def test_partial_ten_max_depth_recursion
85
+ r = render_erb_template "<%= partial 'test/max_depth', locals: {depth: 0, max_depth: 10} %>"
86
+
87
+ assert_match(/Hammertime/, r)
88
+
89
+ assert_raise(ArgumentError) do
90
+ render_erb_template "<%= partial 'test/max_depth', locals: {depth: 0, max_depth: 11} %>"
91
+ end
92
+ end
93
+
94
+ def test_no_partial_state
95
+ r = render_erb_template '
96
+ <%= begin
97
+ partial "../html/bla/partials/dunno"
98
+ rescue ArgumentError
99
+ end %>
100
+ <%= partial "test/simple" %>'
101
+
102
+ assert_match(/ERB/, r)
103
+ end
104
+
84
105
  def render_erb_template(template)
85
106
  @renderer.render(@base + "html/partials/test.html.erb", source: template)
86
107
  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.6.1
4
+ version: 1.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Flurin Egger
@@ -10,62 +10,62 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-05-17 00:00:00.000000000 Z
13
+ date: 2016-09-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: thor
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - ~>
19
+ - - "~>"
20
20
  - !ruby/object:Gem::Version
21
21
  version: 0.19.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - ~>
26
+ - - "~>"
27
27
  - !ruby/object:Gem::Version
28
28
  version: 0.19.0
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: rack
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - '>='
33
+ - - ">="
34
34
  - !ruby/object:Gem::Version
35
35
  version: 1.0.0
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - '>='
40
+ - - ">="
41
41
  - !ruby/object:Gem::Version
42
42
  version: 1.0.0
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: tilt
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - ~>
47
+ - - "~>"
48
48
  - !ruby/object:Gem::Version
49
49
  version: 2.0.1
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - ~>
54
+ - - "~>"
55
55
  - !ruby/object:Gem::Version
56
56
  version: 2.0.1
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: mime-types
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - ~>
61
+ - - "~>"
62
62
  - !ruby/object:Gem::Version
63
63
  version: '2.2'
64
64
  type: :runtime
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - ~>
68
+ - - "~>"
69
69
  - !ruby/object:Gem::Version
70
70
  version: '2.2'
71
71
  - !ruby/object:Gem::Dependency
@@ -86,98 +86,98 @@ dependencies:
86
86
  name: redcarpet
87
87
  requirement: !ruby/object:Gem::Requirement
88
88
  requirements:
89
- - - '>='
89
+ - - ">="
90
90
  - !ruby/object:Gem::Version
91
91
  version: 3.1.1
92
92
  type: :runtime
93
93
  prerelease: false
94
94
  version_requirements: !ruby/object:Gem::Requirement
95
95
  requirements:
96
- - - '>='
96
+ - - ">="
97
97
  - !ruby/object:Gem::Version
98
98
  version: 3.1.1
99
99
  - !ruby/object:Gem::Dependency
100
100
  name: test_construct
101
101
  requirement: !ruby/object:Gem::Requirement
102
102
  requirements:
103
- - - ~>
103
+ - - "~>"
104
104
  - !ruby/object:Gem::Version
105
105
  version: '2.0'
106
106
  type: :runtime
107
107
  prerelease: false
108
108
  version_requirements: !ruby/object:Gem::Requirement
109
109
  requirements:
110
- - - ~>
110
+ - - "~>"
111
111
  - !ruby/object:Gem::Version
112
112
  version: '2.0'
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: test-unit
115
115
  requirement: !ruby/object:Gem::Requirement
116
116
  requirements:
117
- - - ~>
117
+ - - "~>"
118
118
  - !ruby/object:Gem::Version
119
119
  version: 3.0.0
120
120
  type: :development
121
121
  prerelease: false
122
122
  version_requirements: !ruby/object:Gem::Requirement
123
123
  requirements:
124
- - - ~>
124
+ - - "~>"
125
125
  - !ruby/object:Gem::Version
126
126
  version: 3.0.0
127
127
  - !ruby/object:Gem::Dependency
128
128
  name: mocha
129
129
  requirement: !ruby/object:Gem::Requirement
130
130
  requirements:
131
- - - ~>
131
+ - - "~>"
132
132
  - !ruby/object:Gem::Version
133
133
  version: 1.1.0
134
134
  type: :development
135
135
  prerelease: false
136
136
  version_requirements: !ruby/object:Gem::Requirement
137
137
  requirements:
138
- - - ~>
138
+ - - "~>"
139
139
  - !ruby/object:Gem::Version
140
140
  version: 1.1.0
141
141
  - !ruby/object:Gem::Dependency
142
142
  name: simplecov
143
143
  requirement: !ruby/object:Gem::Requirement
144
144
  requirements:
145
- - - ~>
145
+ - - "~>"
146
146
  - !ruby/object:Gem::Version
147
147
  version: 0.10.0
148
148
  type: :development
149
149
  prerelease: false
150
150
  version_requirements: !ruby/object:Gem::Requirement
151
151
  requirements:
152
- - - ~>
152
+ - - "~>"
153
153
  - !ruby/object:Gem::Version
154
154
  version: 0.10.0
155
155
  - !ruby/object:Gem::Dependency
156
156
  name: puma
157
157
  requirement: !ruby/object:Gem::Requirement
158
158
  requirements:
159
- - - ~>
159
+ - - "~>"
160
160
  - !ruby/object:Gem::Version
161
161
  version: 2.10.0
162
162
  type: :development
163
163
  prerelease: false
164
164
  version_requirements: !ruby/object:Gem::Requirement
165
165
  requirements:
166
- - - ~>
166
+ - - "~>"
167
167
  - !ruby/object:Gem::Version
168
168
  version: 2.10.0
169
169
  - !ruby/object:Gem::Dependency
170
170
  name: rubocop
171
171
  requirement: !ruby/object:Gem::Requirement
172
172
  requirements:
173
- - - ~>
173
+ - - "~>"
174
174
  - !ruby/object:Gem::Version
175
175
  version: 0.31.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
182
  version: 0.31.0
183
183
  description: See homepage for more information.
@@ -190,10 +190,10 @@ extensions: []
190
190
  extra_rdoc_files:
191
191
  - README.md
192
192
  files:
193
- - .gitignore
194
- - .hound.yml
195
- - .rubocop.yml
196
- - .travis.yml
193
+ - ".gitignore"
194
+ - ".hound.yml"
195
+ - ".rubocop.yml"
196
+ - ".travis.yml"
197
197
  - CHANGELOG.md
198
198
  - Gemfile
199
199
  - MIT_LICENSE
@@ -302,6 +302,7 @@ files:
302
302
  - test/project/partials/test/front_matter.html.erb
303
303
  - test/project/partials/test/json.json.erb
304
304
  - test/project/partials/test/markdown.md
305
+ - test/project/partials/test/max_depth.html.erb
305
306
  - test/project/partials/test/recursive.html.erb
306
307
  - test/project/partials/test/simple.html.erb
307
308
  - test/project/partials/test/yield.html.erb
@@ -344,22 +345,22 @@ licenses:
344
345
  metadata: {}
345
346
  post_install_message:
346
347
  rdoc_options:
347
- - --charset=UTF-8
348
+ - "--charset=UTF-8"
348
349
  require_paths:
349
350
  - lib
350
351
  required_ruby_version: !ruby/object:Gem::Requirement
351
352
  requirements:
352
- - - '>='
353
+ - - ">="
353
354
  - !ruby/object:Gem::Version
354
355
  version: '0'
355
356
  required_rubygems_version: !ruby/object:Gem::Requirement
356
357
  requirements:
357
- - - '>='
358
+ - - ">="
358
359
  - !ruby/object:Gem::Version
359
360
  version: '0'
360
361
  requirements: []
361
362
  rubyforge_project:
362
- rubygems_version: 2.2.2
363
+ rubygems_version: 2.5.1
363
364
  signing_key:
364
365
  specification_version: 4
365
366
  summary: Roger is a set of tools to create self-containing HTML mockups.
@@ -407,6 +408,7 @@ test_files:
407
408
  - test/project/partials/test/front_matter.html.erb
408
409
  - test/project/partials/test/json.json.erb
409
410
  - test/project/partials/test/markdown.md
411
+ - test/project/partials/test/max_depth.html.erb
410
412
  - test/project/partials/test/recursive.html.erb
411
413
  - test/project/partials/test/simple.html.erb
412
414
  - test/project/partials/test/yield.html.erb