ruhl 0.17.0 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/ruhl/engine.rb +2 -2
- data/lib/ruhl/rails.rb +4 -2
- data/lib/ruhl/rails/helper.rb +10 -1
- data/lib/ruhl/rails/ruhl_presenter.rb +27 -9
- data/ruhl.gemspec +1 -1
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.18.0
|
data/lib/ruhl/engine.rb
CHANGED
@@ -210,9 +210,9 @@ module Ruhl
|
|
210
210
|
else
|
211
211
|
args = code.strip.split('|').collect{|p| p.strip}
|
212
212
|
|
213
|
-
if block_object.respond_to?(
|
213
|
+
if block_object.respond_to?(args.first)
|
214
214
|
block_object.send(*args)
|
215
|
-
elsif local_object.respond_to?(
|
215
|
+
elsif local_object.respond_to?(args.first)
|
216
216
|
local_object.send(*args)
|
217
217
|
else
|
218
218
|
scope.send(*args)
|
data/lib/ruhl/rails.rb
CHANGED
@@ -11,8 +11,10 @@ module Ruhl
|
|
11
11
|
def render(template, options = {})
|
12
12
|
layout = @action_view.controller.send(:active_layout)
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
if layout
|
15
|
+
options[:layout] = layout.filename
|
16
|
+
options[:layout_source] = layout.source
|
17
|
+
end
|
16
18
|
|
17
19
|
Ruhl::Engine.new(template.source, options).render(@action_view)
|
18
20
|
end
|
data/lib/ruhl/rails/helper.rb
CHANGED
@@ -4,6 +4,15 @@ module Ruhl
|
|
4
4
|
def form_authenticity
|
5
5
|
{:value => form_authenticity_token, :type => "hidden", :name => "authenticity_token"}
|
6
6
|
end
|
7
|
+
|
8
|
+
def i(type,column)
|
9
|
+
model = presentee.class.name.underscore
|
10
|
+
{ :type => type,
|
11
|
+
:id => "#{model}_#{column}",
|
12
|
+
:name => "#{model}[#{column}]",
|
13
|
+
:value => presentee.send(column)
|
14
|
+
}
|
15
|
+
end
|
7
16
|
end
|
8
17
|
end
|
9
|
-
end
|
18
|
+
end
|
@@ -9,10 +9,14 @@ module Ruhl
|
|
9
9
|
|
10
10
|
attr_reader :presentee, :context
|
11
11
|
|
12
|
-
def initialize(
|
13
|
-
@presentee = obj
|
12
|
+
def initialize(context, obj = nil)
|
14
13
|
@context = context
|
15
|
-
|
14
|
+
|
15
|
+
# May only want to use the form helper
|
16
|
+
if obj
|
17
|
+
@presentee = obj
|
18
|
+
define_paths(obj.class.name.underscore.downcase)
|
19
|
+
end
|
16
20
|
end
|
17
21
|
|
18
22
|
def method_missing(name, *args)
|
@@ -44,15 +48,29 @@ module ActionController
|
|
44
48
|
|
45
49
|
protected
|
46
50
|
|
47
|
-
def present(
|
48
|
-
|
49
|
-
|
51
|
+
def present(action_sym = action_name, object = nil)
|
52
|
+
object_sym = object || controller_name.singularize
|
53
|
+
|
54
|
+
render :template => "#{controller_name}/#{action_sym}",
|
55
|
+
:locals => {:object => presenter_for(object_sym) }
|
50
56
|
end
|
51
57
|
|
52
|
-
def presenter_for(
|
53
|
-
|
58
|
+
def presenter_for(object)
|
59
|
+
|
60
|
+
if object.is_a?(Symbol) || object.is_a?(String)
|
61
|
+
# Set instance variable if it exists
|
62
|
+
if instance_variables.include?("@#{object}")
|
63
|
+
obj = instance_variable_get("@#{object}")
|
64
|
+
end
|
65
|
+
name = object.to_s.camelize
|
66
|
+
else
|
67
|
+
name = object.class.name.camelize
|
68
|
+
obj = object
|
69
|
+
end
|
70
|
+
|
71
|
+
Object.const_get("#{name}Presenter").new(@template, obj)
|
54
72
|
end
|
55
|
-
|
73
|
+
|
56
74
|
helper_method :presenter_for
|
57
75
|
end
|
58
76
|
end
|
data/ruhl.gemspec
CHANGED