easypartials 0.0.1 → 0.0.2
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/README.rdoc +15 -3
- data/TODO +0 -5
- data/lib/easypartials.rb +47 -10
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -5,13 +5,13 @@
|
|
5
5
|
== DESCRIPTION:
|
6
6
|
|
7
7
|
EasyPartials are a way to make partials in Rails even easier! This is
|
8
|
-
|
8
|
+
an expansion of a blog post by Mike Stone at
|
9
9
|
"http://smellsblue.blogspot.com/2009/11/easy-partials-in-rails.html".
|
10
10
|
|
11
|
-
== FEATURES
|
11
|
+
== FEATURES:
|
12
12
|
|
13
13
|
* Allows easy partial invocation syntax, with simpler local variable passing
|
14
|
-
* Allows
|
14
|
+
* Allows configurable shared directories for partials
|
15
15
|
|
16
16
|
== SYNOPSIS:
|
17
17
|
|
@@ -28,6 +28,18 @@ tags included.
|
|
28
28
|
|
29
29
|
Note that you need to use <% rather than <%=.
|
30
30
|
|
31
|
+
For a shared partial, use a line like the following in environment.rb
|
32
|
+
or in a file under initializers:
|
33
|
+
|
34
|
+
Easypartials.shared_directories = ["mydir1", "mydir2"]
|
35
|
+
|
36
|
+
This will set up app/views/mydir1 and app/views/mydir2 as the
|
37
|
+
locations to look for partials when a directory isn't explicitly
|
38
|
+
given.
|
39
|
+
|
40
|
+
This plugin will first check the directory of the view being rendered,
|
41
|
+
then check the shared directories in the order given.
|
42
|
+
|
31
43
|
== REQUIREMENTS:
|
32
44
|
|
33
45
|
You'll need a recent-ish version of Rails. You'll also need hoe and
|
data/TODO
CHANGED
data/lib/easypartials.rb
CHANGED
@@ -2,38 +2,75 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
3
|
|
4
4
|
module Easypartials
|
5
|
-
VERSION = '0.0.
|
5
|
+
VERSION = '0.0.2'
|
6
|
+
|
7
|
+
def self.shared_directories
|
8
|
+
@ep_shared_directories || []
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.shared_directories=(arglist)
|
12
|
+
@ep_shared_directories = arglist
|
13
|
+
end
|
6
14
|
end
|
7
15
|
|
8
16
|
module ApplicationHelper
|
9
17
|
alias_method :method_missing_without_easy_partials, :method_missing
|
18
|
+
alias_method :respond_to_without_easy_partials, :respond_to?
|
19
|
+
|
20
|
+
METHOD_REGEXP = /^_(.+)$/
|
21
|
+
|
22
|
+
def respond_to_with_easy_partials(method_name, inc_priv = false)
|
23
|
+
return true if method_name =~ METHOD_REGEXP
|
24
|
+
|
25
|
+
respond_to_without_easy_partials(method_name, inc_priv)
|
26
|
+
end
|
10
27
|
|
11
28
|
def method_missing_with_easy_partials(method_name, *args, &block)
|
12
29
|
method_str = method_name.to_s
|
13
30
|
|
14
|
-
if method_str =~
|
15
|
-
partial_name = method_str[
|
31
|
+
if method_str =~ METHOD_REGEXP
|
32
|
+
partial_name = method_str[METHOD_REGEXP, 1]
|
16
33
|
|
34
|
+
self.class.class_eval <<ENDEVAL
|
35
|
+
def #{method_str}(*args, &block)
|
36
|
+
begin
|
37
|
+
concat_partial "#{partial_name}", *args, &block
|
38
|
+
rescue ActionView::MissingTemplate
|
39
|
+
last_exc = nil
|
40
|
+
done = false
|
41
|
+
dirs = Easypartials.shared_directories
|
42
|
+
dirs.each do |shared|
|
17
43
|
begin
|
18
|
-
concat_partial partial_name, *args, &block
|
19
|
-
|
20
|
-
|
21
|
-
|
44
|
+
concat_partial shared + "/#{partial_name}", *args, &block
|
45
|
+
done = true
|
46
|
+
rescue ActionView::MissingTemplate => exc
|
47
|
+
last_exc = exc
|
22
48
|
end
|
49
|
+
break if done
|
50
|
+
end
|
51
|
+
unless done
|
52
|
+
exc = ActionView::MissingTemplate.new dirs, "#{partial_name}"
|
53
|
+
raise exc
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
ENDEVAL
|
58
|
+
self.send(method_str, *args, &block)
|
23
59
|
else
|
24
60
|
method_missing_without_easy_partials method_name, *args, &block
|
25
61
|
end
|
26
62
|
end
|
27
63
|
|
28
64
|
alias_method :method_missing, :method_missing_with_easy_partials
|
65
|
+
alias_method :respond_to?, :respond_to_with_easy_partials
|
29
66
|
|
30
67
|
# Concat the given partial.
|
31
|
-
def concat_partial(partial_name,
|
68
|
+
def concat_partial(partial_name, locals = {}, &block)
|
32
69
|
unless block.nil?
|
33
|
-
|
70
|
+
locals.merge! :body => capture(&block)
|
34
71
|
end
|
35
72
|
|
36
|
-
content = render :partial => partial_name, :locals =>
|
73
|
+
content = render :partial => partial_name, :locals => locals
|
37
74
|
concat content
|
38
75
|
nil
|
39
76
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easypartials
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Noah Gibbs
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-23 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
version:
|
25
25
|
description: |-
|
26
26
|
EasyPartials are a way to make partials in Rails even easier! This is
|
27
|
-
|
27
|
+
an expansion of a blog post by Mike Stone at
|
28
28
|
"http://smellsblue.blogspot.com/2009/11/easy-partials-in-rails.html".
|
29
29
|
email:
|
30
30
|
- noah_gibbs (AT) yahoo dawt com
|
@@ -82,7 +82,7 @@ rubyforge_project: easypartials
|
|
82
82
|
rubygems_version: 1.3.5
|
83
83
|
signing_key:
|
84
84
|
specification_version: 3
|
85
|
-
summary: EasyPartials are a way to make partials in Rails even easier! This is
|
85
|
+
summary: EasyPartials are a way to make partials in Rails even easier! This is an expansion of a blog post by Mike Stone at "http://smellsblue.blogspot.com/2009/11/easy-partials-in-rails.html".
|
86
86
|
test_files:
|
87
87
|
- test/test_easypartials.rb
|
88
88
|
- test/test_helper.rb
|