ruhl 1.3.2 → 1.3.3
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.
- data/VERSION +1 -1
- data/lib/ruhl/engine.rb +26 -56
- data/ruhl.gemspec +2 -2
- data/spec/spec_helper.rb +9 -8
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.3.
|
1
|
+
1.3.3
|
data/lib/ruhl/engine.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Ruhl
|
2
2
|
class Engine
|
3
3
|
attr_reader :layout, :layout_source, :local_object, :block_object
|
4
|
-
attr_reader :document, :scope, :current_tag, :call_result, :ruhl_actions
|
4
|
+
attr_reader :document, :scope, :current_tag, :original_tag, :call_result, :ruhl_actions
|
5
5
|
|
6
6
|
def initialize(html, options = {})
|
7
7
|
@local_object = options[:local_object] || options[:object]
|
@@ -65,9 +65,9 @@ module Ruhl
|
|
65
65
|
|
66
66
|
if actions.empty? && current_tag.xpath('.//*[@data-ruhl]').empty?
|
67
67
|
if item.kind_of?(Hash)
|
68
|
-
|
69
|
-
apply_hash(
|
70
|
-
|
68
|
+
duped_tag = current_tag.dup
|
69
|
+
apply_hash(duped_tag, item)
|
70
|
+
duped_tag.to_html
|
71
71
|
else
|
72
72
|
current_tag.inner_html = item.to_s
|
73
73
|
current_tag.to_html
|
@@ -100,6 +100,7 @@ module Ruhl
|
|
100
100
|
return if nodes.empty?
|
101
101
|
|
102
102
|
@current_tag = nodes.first
|
103
|
+
@original_tag = @current_tag.dup
|
103
104
|
|
104
105
|
@ruhl_actions = current_tag.remove_attribute('data-ruhl').value.split(',')
|
105
106
|
|
@@ -134,13 +135,6 @@ module Ruhl
|
|
134
135
|
write_tag_attribute(current_tag, attribute, call_result)
|
135
136
|
end
|
136
137
|
end
|
137
|
-
rescue NoMethodError => nme
|
138
|
-
Ruhl.logger.error "Processing Ruhl: #{action}"
|
139
|
-
Ruhl.logger.error "Current tag.to_s: #{current_tag.to_s}"
|
140
|
-
Ruhl.logger.error "Current tag: #{current_tag.inspect}"
|
141
|
-
Ruhl.logger.error "Exception message: #{nme.message}"
|
142
|
-
Ruhl.logger.error "Exception backtrace: #{nme.backtrace.join("\n")}"
|
143
|
-
raise nme
|
144
138
|
end
|
145
139
|
|
146
140
|
def ruhl_use_if
|
@@ -159,11 +153,11 @@ module Ruhl
|
|
159
153
|
alias_method :ruhl_collection, :ruhl_use
|
160
154
|
|
161
155
|
def ruhl_if
|
162
|
-
if
|
156
|
+
if call_result.nil? || call_result == false || call_result_empty_array?
|
163
157
|
current_tag.remove
|
164
158
|
throw :done
|
165
159
|
else
|
166
|
-
if
|
160
|
+
if call_result == true || call_result_populated_array?
|
167
161
|
# yield if block given. otherwise do nothing and have ruhl
|
168
162
|
# continue processing
|
169
163
|
yield if block_given?
|
@@ -224,16 +218,16 @@ module Ruhl
|
|
224
218
|
if code == '_render_'
|
225
219
|
_render_
|
226
220
|
else
|
227
|
-
args = code.strip.split('|').collect{|
|
221
|
+
args = code.strip.split('|').collect{|part| part.strip}
|
228
222
|
|
229
|
-
[block_object, local_object, scope].compact
|
230
|
-
|
223
|
+
for obj in [block_object, local_object, scope].compact do
|
224
|
+
call_status, result = call_to(obj, args)
|
225
|
+
return result if call_status == :success
|
231
226
|
end
|
232
227
|
|
233
228
|
if Ruhl.use_instance_variables
|
234
229
|
calling = args.first
|
235
|
-
# No luck so far, lets see if calling is actually an instance
|
236
|
-
# variable.
|
230
|
+
# No luck so far, lets see if calling is actually an instance variable.
|
237
231
|
ivar = :"@#{calling}"
|
238
232
|
if scope.instance_variable_defined?(ivar)
|
239
233
|
if Ruhl.log_instance_variable_warning
|
@@ -243,16 +237,17 @@ module Ruhl
|
|
243
237
|
end
|
244
238
|
end
|
245
239
|
|
246
|
-
|
247
|
-
raise NoMethodError.new("Neither method nor instance variable found: #{calling}")
|
240
|
+
raise NoMethodError.new( current_context(code) )
|
248
241
|
end
|
249
242
|
end
|
250
243
|
|
251
244
|
def call_to(object, args)
|
252
245
|
if object.kind_of?(Hash) && ( object.has_key?(args.first) || object.has_key?(args.first.to_sym))
|
253
|
-
object[args.first] || object[args.first.to_sym]
|
246
|
+
return :success, object[args.first] || object[args.first.to_sym]
|
254
247
|
else
|
255
|
-
object.
|
248
|
+
if object.respond_to?(args.first)
|
249
|
+
return :success, object.send(*args)
|
250
|
+
end
|
256
251
|
end
|
257
252
|
end
|
258
253
|
|
@@ -261,16 +256,6 @@ module Ruhl
|
|
261
256
|
@scope = current_scope
|
262
257
|
end
|
263
258
|
|
264
|
-
def stop_processing?
|
265
|
-
call_result.nil? ||
|
266
|
-
call_result == false ||
|
267
|
-
call_result_empty_array?
|
268
|
-
end
|
269
|
-
|
270
|
-
def continue_processing?
|
271
|
-
call_result == true || call_result_populated_array?
|
272
|
-
end
|
273
|
-
|
274
259
|
def call_result_populated_array?
|
275
260
|
call_result.kind_of?(Array) && !call_result.empty?
|
276
261
|
end
|
@@ -279,40 +264,25 @@ module Ruhl
|
|
279
264
|
call_result.kind_of?(Array) && call_result.empty?
|
280
265
|
end
|
281
266
|
|
282
|
-
def
|
283
|
-
|
267
|
+
def current_context(code)
|
268
|
+
<<CONTEXT
|
269
|
+
|
284
270
|
Context:
|
285
|
-
|
286
|
-
|
271
|
+
trying to execute : #{code.inspect}
|
272
|
+
on tag : #{original_tag.to_s}
|
287
273
|
CONTEXT
|
288
|
-
|
289
|
-
error_message << " #{show_class_or_inspect('local_object')}\n"
|
290
|
-
error_message << " #{show_class_or_inspect('block_object')}\n"
|
291
|
-
error_message << " #{show_class_or_inspect('scope')}\n"
|
292
|
-
|
293
|
-
Ruhl.logger.error error_message
|
294
|
-
end
|
295
|
-
|
296
|
-
def show_class_or_inspect(object_str)
|
297
|
-
str = "#{object_str} : "
|
298
|
-
|
299
|
-
str + if Ruhl.send("inspect_#{object_str}")
|
300
|
-
send(object_str).inspect
|
301
|
-
else
|
302
|
-
send(object_str).class.to_s
|
303
|
-
end
|
304
274
|
end
|
305
275
|
|
306
276
|
if RUBY_VERSION == '1.8.6'
|
307
277
|
def file_contents(path_to_file)
|
308
|
-
File.open(path_to_file,'r') do |
|
309
|
-
|
278
|
+
File.open(path_to_file,'r') do |file|
|
279
|
+
file.read
|
310
280
|
end
|
311
281
|
end
|
312
282
|
else
|
313
283
|
def file_contents(path_to_file)
|
314
|
-
File.open(path_to_file, "r:#{Ruhl.encoding}") do |
|
315
|
-
|
284
|
+
File.open(path_to_file, "r:#{Ruhl.encoding}") do |file|
|
285
|
+
file.read
|
316
286
|
end
|
317
287
|
end
|
318
288
|
end
|
data/ruhl.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ruhl}
|
8
|
-
s.version = "1.3.
|
8
|
+
s.version = "1.3.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Andrew Stone"]
|
12
|
-
s.date = %q{2010-02-
|
12
|
+
s.date = %q{2010-02-17}
|
13
13
|
s.description = %q{Make your HTML dynamic with the addition of a data-ruhl attribute.}
|
14
14
|
s.email = %q{andy@stonean.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/spec/spec_helper.rb
CHANGED
@@ -41,10 +41,6 @@ class TestUser
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
def user
|
45
|
-
TestUser.new('Jane', 'Doe', 'jane@stonean.com')
|
46
|
-
end
|
47
|
-
|
48
44
|
|
49
45
|
class ContextObject
|
50
46
|
def initialize
|
@@ -228,8 +224,13 @@ class ContextObject
|
|
228
224
|
{'name' => 'RubyTrends', 'href' => 'http://rubytrends.com'}
|
229
225
|
]
|
230
226
|
end
|
231
|
-
end
|
232
227
|
|
233
|
-
def
|
234
|
-
|
235
|
-
end
|
228
|
+
def user
|
229
|
+
TestUser.new('Jane', 'Doe', 'jane@stonean.com')
|
230
|
+
end
|
231
|
+
|
232
|
+
def points_of_interest
|
233
|
+
[ "Object oriented", "dynamic", "mixins", "blocks", "open source"]
|
234
|
+
end
|
235
|
+
end # context object
|
236
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruhl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Stone
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-17 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|