ruhl 0.15.0 → 0.16.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/rails/active_record.rb +44 -0
- data/lib/ruhl/rails/helper.rb +9 -0
- data/lib/ruhl/rails/ruhl_presenter.rb +34 -29
- metadata +3 -4
- data/lib/ruhl/rails/active_record_presenter.rb +0 -40
- data/lib/ruhl/rails/form_helper.rb +0 -5
- data/ruhl.gemspec +0 -83
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.16.0
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Ruhl
|
2
|
+
module Rails
|
3
|
+
module ActiveRecord
|
4
|
+
def error_messages?
|
5
|
+
!presentee.errors.empty?
|
6
|
+
end
|
7
|
+
|
8
|
+
def error_messages
|
9
|
+
return if presentee.errors.empty?
|
10
|
+
presentee.errors.full_messages
|
11
|
+
end
|
12
|
+
|
13
|
+
def define_paths(model)
|
14
|
+
define_action(model, 'show') # show_path(@user)
|
15
|
+
define_action(model, 'update') # update_path(@user)
|
16
|
+
define_action(model, 'delete') # delete_path(@user)
|
17
|
+
define_action("edit_#{model}", 'edit') # edit_path(@user)
|
18
|
+
define_action(model.pluralize, 'index', false) # index_path
|
19
|
+
define_action(model.pluralize, 'create', false) # create_path
|
20
|
+
define_action("new_#{model}", 'new', false) # new_path
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def define_action(model, action, use_presentee = true)
|
26
|
+
if use_presentee
|
27
|
+
self.class.send(:define_method, "#{action}_path") do
|
28
|
+
context.send("#{model}_path", presentee)
|
29
|
+
end
|
30
|
+
self.class.send(:define_method, "#{action}_url") do
|
31
|
+
context.send("#{model}_url", presentee)
|
32
|
+
end
|
33
|
+
else
|
34
|
+
self.class.send(:define_method, "#{action}_path") do
|
35
|
+
context.send("#{model}_path")
|
36
|
+
end
|
37
|
+
self.class.send(:define_method, "#{action}_url") do
|
38
|
+
context.send("#{model}_url")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -1,37 +1,42 @@
|
|
1
|
-
require 'ruhl/rails/
|
1
|
+
require 'ruhl/rails/active_record'
|
2
|
+
require 'ruhl/rails/helper'
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
module Ruhl
|
5
|
+
module Rails
|
6
|
+
class Presenter
|
7
|
+
include Ruhl::Rails::ActiveRecord
|
8
|
+
include Ruhl::Rails::Helper
|
6
9
|
|
7
|
-
|
10
|
+
attr_reader :presentee, :context
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
def initialize(obj, context)
|
13
|
+
@presentee = obj
|
14
|
+
@context = context
|
15
|
+
define_paths(obj.class.name.underscore.downcase)
|
16
|
+
end
|
14
17
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
18
|
+
def method_missing(name, *args)
|
19
|
+
if presentee.respond_to?(name)
|
20
|
+
# Pass presenter method call to model so you don't have to
|
21
|
+
# redefine every model method in the presenter class.
|
22
|
+
presentee.send(name, *args)
|
23
|
+
elsif context.respond_to?(name)
|
24
|
+
# Instead of saying context.link_to('Some site', some_path)
|
25
|
+
# can just use link_to
|
26
|
+
context.send(name, *args)
|
27
|
+
end
|
28
|
+
end
|
26
29
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
# Extend scope of respond_to? to model.
|
31
|
+
def respond_to?(name)
|
32
|
+
if super
|
33
|
+
true
|
34
|
+
else
|
35
|
+
presentee.respond_to?(name)
|
36
|
+
end
|
37
|
+
end
|
33
38
|
end
|
34
|
-
end
|
39
|
+
end
|
35
40
|
end
|
36
41
|
|
37
42
|
module ActionController
|
@@ -45,7 +50,7 @@ module ActionController
|
|
45
50
|
end
|
46
51
|
|
47
52
|
def presenter_for(obj)
|
48
|
-
|
53
|
+
Object.const_get("#{obj.class.name}Presenter").new(obj, @template)
|
49
54
|
end
|
50
55
|
|
51
56
|
helper_method :presenter_for
|
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.
|
4
|
+
version: 0.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Stone
|
@@ -49,11 +49,10 @@ files:
|
|
49
49
|
- lib/ruhl/engine.rb
|
50
50
|
- lib/ruhl/errors.rb
|
51
51
|
- lib/ruhl/rails.rb
|
52
|
-
- lib/ruhl/rails/
|
53
|
-
- lib/ruhl/rails/
|
52
|
+
- lib/ruhl/rails/active_record.rb
|
53
|
+
- lib/ruhl/rails/helper.rb
|
54
54
|
- lib/ruhl/rails/ruhl_presenter.rb
|
55
55
|
- lib/ruhl/sinatra.rb
|
56
|
-
- ruhl.gemspec
|
57
56
|
- spec/html/basic.html
|
58
57
|
- spec/html/collection_of_hashes.html
|
59
58
|
- spec/html/collection_of_strings.html
|
@@ -1,40 +0,0 @@
|
|
1
|
-
module ActiveRecordPresenter
|
2
|
-
def error_messages?
|
3
|
-
!presentee.errors.empty?
|
4
|
-
end
|
5
|
-
|
6
|
-
def error_messages
|
7
|
-
return if presentee.errors.empty?
|
8
|
-
presentee.errors.full_messages
|
9
|
-
end
|
10
|
-
|
11
|
-
def define_paths(model)
|
12
|
-
define_action(model, 'show') # show_path(@user)
|
13
|
-
define_action(model, 'update') # update_path(@user)
|
14
|
-
define_action(model, 'delete') # delete_path(@user)
|
15
|
-
define_action("edit_#{model}", 'edit') # edit_path(@user)
|
16
|
-
define_action(model.pluralize, 'index', false) # index_path
|
17
|
-
define_action(model.pluralize, 'create', false) # create_path
|
18
|
-
define_action("new_#{model}", 'new', false) # new_path
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def define_action(model, action, use_presentee = true)
|
24
|
-
if use_presentee
|
25
|
-
self.class.send(:define_method, "#{action}_path") do
|
26
|
-
context.send("#{model}_path", presentee)
|
27
|
-
end
|
28
|
-
self.class.send(:define_method, "#{action}_url") do
|
29
|
-
context.send("#{model}_url", presentee)
|
30
|
-
end
|
31
|
-
else
|
32
|
-
self.class.send(:define_method, "#{action}_path") do
|
33
|
-
context.send("#{model}_path")
|
34
|
-
end
|
35
|
-
self.class.send(:define_method, "#{action}_url") do
|
36
|
-
context.send("#{model}_url")
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
data/ruhl.gemspec
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{ruhl}
|
8
|
-
s.version = "0.15.0"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Andrew Stone"]
|
12
|
-
s.date = %q{2009-11-21}
|
13
|
-
s.description = %q{Make your HTML dynamic with the addition of a data-ruhl attribute.}
|
14
|
-
s.email = %q{andy@stonean.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"README"
|
17
|
-
]
|
18
|
-
s.files = [
|
19
|
-
".gitignore",
|
20
|
-
"README",
|
21
|
-
"Rakefile",
|
22
|
-
"VERSION",
|
23
|
-
"lib/ruhl.rb",
|
24
|
-
"lib/ruhl/engine.rb",
|
25
|
-
"lib/ruhl/errors.rb",
|
26
|
-
"lib/ruhl/rails.rb",
|
27
|
-
"lib/ruhl/rails/active_record_presenter.rb",
|
28
|
-
"lib/ruhl/rails/form_helper.rb",
|
29
|
-
"lib/ruhl/rails/ruhl_presenter.rb",
|
30
|
-
"lib/ruhl/sinatra.rb",
|
31
|
-
"ruhl.gemspec",
|
32
|
-
"spec/html/basic.html",
|
33
|
-
"spec/html/collection_of_hashes.html",
|
34
|
-
"spec/html/collection_of_strings.html",
|
35
|
-
"spec/html/form.html",
|
36
|
-
"spec/html/fragment.html",
|
37
|
-
"spec/html/hash.html",
|
38
|
-
"spec/html/if.html",
|
39
|
-
"spec/html/if_on_collection.html",
|
40
|
-
"spec/html/layout.html",
|
41
|
-
"spec/html/loop.html",
|
42
|
-
"spec/html/main_with_form.html",
|
43
|
-
"spec/html/main_with_sidebar.html",
|
44
|
-
"spec/html/medium.html",
|
45
|
-
"spec/html/parameters.html",
|
46
|
-
"spec/html/seo.html",
|
47
|
-
"spec/html/sidebar.html",
|
48
|
-
"spec/html/special.html",
|
49
|
-
"spec/html/swap.html",
|
50
|
-
"spec/html/use.html",
|
51
|
-
"spec/html/use_if.html",
|
52
|
-
"spec/rcov.opts",
|
53
|
-
"spec/ruhl_spec.rb",
|
54
|
-
"spec/spec.opts",
|
55
|
-
"spec/spec_helper.rb"
|
56
|
-
]
|
57
|
-
s.homepage = %q{http://github.com/stonean/ruhl}
|
58
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
59
|
-
s.require_paths = ["lib"]
|
60
|
-
s.rubygems_version = %q{1.3.5}
|
61
|
-
s.summary = %q{Ruby Hypertext Language}
|
62
|
-
s.test_files = [
|
63
|
-
"spec/ruhl_spec.rb",
|
64
|
-
"spec/spec_helper.rb"
|
65
|
-
]
|
66
|
-
|
67
|
-
if s.respond_to? :specification_version then
|
68
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
69
|
-
s.specification_version = 3
|
70
|
-
|
71
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
72
|
-
s.add_runtime_dependency(%q<nokogiri>, ["= 1.4.0"])
|
73
|
-
s.add_development_dependency(%q<rspec>, [">= 0"])
|
74
|
-
else
|
75
|
-
s.add_dependency(%q<nokogiri>, ["= 1.4.0"])
|
76
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
77
|
-
end
|
78
|
-
else
|
79
|
-
s.add_dependency(%q<nokogiri>, ["= 1.4.0"])
|
80
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|