partializer 0.1.1 → 0.1.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.md +18 -1
- data/VERSION +1 -1
- data/lib/partializer.rb +2 -0
- data/lib/partializer/collection.rb +1 -0
- data/lib/partializer/partials.rb +1 -0
- data/lib/partializer/path_helper.rb +13 -0
- data/lib/partializer/view_helper.rb +12 -1
- data/partializer.gemspec +3 -2
- data/spec/partializer/collection_spec.rb +4 -0
- data/spec/partializer/view_helper_spec.rb +18 -0
- metadata +4 -3
data/README.md
CHANGED
@@ -61,10 +61,27 @@ And for the `properties/show/main/lower/_communication` partial, simply:
|
|
61
61
|
|
62
62
|
```haml
|
63
63
|
#communication.column
|
64
|
-
= render_partials partialize(
|
64
|
+
= render_partials partialize('communication')
|
65
65
|
```
|
66
66
|
|
67
67
|
Since the partializer (with previous context) will be passed down as a local and used by `partialize` to resolve the context (partial path). Sleek :)
|
68
|
+
Partialize will take advantage of this fact and use this local variable unless a specific Partializer is passed in as the first argument.
|
69
|
+
|
70
|
+
*Context path building*
|
71
|
+
|
72
|
+
Since the partializer has knowledge of the current context, you can use it to generate the path of a partial. The `#partial_path` method will raise an erorr if the name of the partial is not registered with that partializer.
|
73
|
+
|
74
|
+
```haml
|
75
|
+
#communication.column
|
76
|
+
= render partial: partializer.partial_path(:sidebar)
|
77
|
+
```
|
78
|
+
|
79
|
+
You can also use the partializer to build a relative path to its context (path)
|
80
|
+
|
81
|
+
```haml
|
82
|
+
#communication.column
|
83
|
+
= render partial: partializer.build_path('sidebar/upper')
|
84
|
+
```
|
68
85
|
|
69
86
|
### The REAL power!
|
70
87
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/lib/partializer.rb
CHANGED
@@ -10,7 +10,9 @@ class Partializer
|
|
10
10
|
autoload :Collection, 'partializer/collection'
|
11
11
|
autoload :Resolver, 'partializer/resolver'
|
12
12
|
autoload :Partials, 'partializer/partials'
|
13
|
+
autoload :PathHelper, 'partializer/path_helper'
|
13
14
|
|
15
|
+
class InvalidPartialError < StandardError; end
|
14
16
|
|
15
17
|
def partials_for name, *args
|
16
18
|
hash = args.flatten.inject({}) do |res, arg|
|
data/lib/partializer/partials.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
class Partializer
|
2
|
+
module PathHelper
|
3
|
+
def partial_path name
|
4
|
+
return File.join(to_partial_path, name.to_s) if partials.include? name.to_sym
|
5
|
+
raise Partializer::InvalidPartialError, "the partial #{name} is not registered for this Partializer"
|
6
|
+
end
|
7
|
+
|
8
|
+
def build_path path
|
9
|
+
raise ArgumentError, "Must take a path argument" unless path
|
10
|
+
File.join(to_partial_path, path.to_s.gsub('.', '/'))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -1,6 +1,17 @@
|
|
1
1
|
class Partializer
|
2
2
|
module ViewHelper
|
3
|
-
def partialize
|
3
|
+
def partialize *args, &block
|
4
|
+
case args.size
|
5
|
+
when 2
|
6
|
+
subject = args.first
|
7
|
+
path = args.last
|
8
|
+
when 1
|
9
|
+
path = args.first
|
10
|
+
subject = partializer
|
11
|
+
else
|
12
|
+
raise ArgumentError, "partialize takes 1 or 2 args, was: #{args}"
|
13
|
+
end
|
14
|
+
|
4
15
|
parts = case subject
|
5
16
|
when String
|
6
17
|
subject.split('#')
|
data/partializer.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "partializer"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kristian Mandrup"]
|
12
|
-
s.date = "2012-08-
|
12
|
+
s.date = "2012-08-30"
|
13
13
|
s.description = "Makes it easy to render the subpartials of any partial"
|
14
14
|
s.email = "kmandrup@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
|
|
30
30
|
"lib/partializer/engine.rb",
|
31
31
|
"lib/partializer/partial.rb",
|
32
32
|
"lib/partializer/partials.rb",
|
33
|
+
"lib/partializer/path_helper.rb",
|
33
34
|
"lib/partializer/resolver.rb",
|
34
35
|
"lib/partializer/view_helper.rb",
|
35
36
|
"partializer.gemspec",
|
@@ -6,6 +6,8 @@ describe Partializer::ViewHelper do
|
|
6
6
|
let(:main_partializer) { partialize('properties#show', 'main') }
|
7
7
|
let(:my_main_partializer) { partialize('properties#show', 'my_main') }
|
8
8
|
|
9
|
+
let(:partializer) { main_partializer }
|
10
|
+
|
9
11
|
describe '#initialize' do
|
10
12
|
subject { main_partializer }
|
11
13
|
|
@@ -13,6 +15,15 @@ describe Partializer::ViewHelper do
|
|
13
15
|
its(:path) { should == 'properties/show/main' }
|
14
16
|
its(:to_partial_path) { should == 'properties/show/main' }
|
15
17
|
|
18
|
+
specify do
|
19
|
+
expect { subject.partial_path(:sidebar) }.to raise_error(Partializer::InvalidPartialError)
|
20
|
+
end
|
21
|
+
|
22
|
+
specify do
|
23
|
+
subject.build_path(:sidebar).should == 'properties/show/main/sidebar'
|
24
|
+
end
|
25
|
+
|
26
|
+
|
16
27
|
specify do
|
17
28
|
subject.partials.should include(:upper, :lower)
|
18
29
|
end
|
@@ -30,4 +41,11 @@ describe Partializer::ViewHelper do
|
|
30
41
|
its(:name) { should == 'my_main.lower'}
|
31
42
|
its(:path) { should == 'properties/show/my_main/lower' }
|
32
43
|
end
|
44
|
+
|
45
|
+
describe 'implicit partializer in scope' do
|
46
|
+
subject { partialize 'lower'}
|
47
|
+
|
48
|
+
its(:name) { should == 'my_main.lower'}
|
49
|
+
its(:path) { should == 'properties/show/my_main/lower' }
|
50
|
+
end
|
33
51
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: partializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: hashie
|
@@ -144,6 +144,7 @@ files:
|
|
144
144
|
- lib/partializer/engine.rb
|
145
145
|
- lib/partializer/partial.rb
|
146
146
|
- lib/partializer/partials.rb
|
147
|
+
- lib/partializer/path_helper.rb
|
147
148
|
- lib/partializer/resolver.rb
|
148
149
|
- lib/partializer/view_helper.rb
|
149
150
|
- partializer.gemspec
|
@@ -169,7 +170,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
169
170
|
version: '0'
|
170
171
|
segments:
|
171
172
|
- 0
|
172
|
-
hash:
|
173
|
+
hash: -4586459926647606653
|
173
174
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
174
175
|
none: false
|
175
176
|
requirements:
|