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 CHANGED
@@ -1 +1 @@
1
- 0.17.0
1
+ 0.18.0
@@ -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?(code)
213
+ if block_object.respond_to?(args.first)
214
214
  block_object.send(*args)
215
- elsif local_object.respond_to?(code)
215
+ elsif local_object.respond_to?(args.first)
216
216
  local_object.send(*args)
217
217
  else
218
218
  scope.send(*args)
@@ -11,8 +11,10 @@ module Ruhl
11
11
  def render(template, options = {})
12
12
  layout = @action_view.controller.send(:active_layout)
13
13
 
14
- options[:layout] = layout.filename
15
- options[:layout_source] = layout.source
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
@@ -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(obj, context)
13
- @presentee = obj
12
+ def initialize(context, obj = nil)
14
13
  @context = context
15
- define_paths(obj.class.name.underscore.downcase)
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(object_sym, action_sym)
48
- render :template => "#{object_sym.to_s.pluralize}/#{action_sym}",
49
- :locals => {:object => presenter_for( instance_variable_get("@#{object_sym}") )}
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(obj)
53
- Object.const_get("#{obj.class.name}Presenter").new(obj, @template)
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ruhl}
8
- s.version = "0.17.0"
8
+ s.version = "0.18.0"
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"]
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: 0.17.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Stone