rails-parts 0.3.0 → 0.3.1
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/Gemfile +2 -2
- data/README.rdoc +9 -3
- data/lib/generators/part_generator.rb +21 -0
- data/lib/generators/templates/part.rb +7 -0
- data/lib/parts.rb +1 -0
- data/lib/parts/default_layout.rb +1 -2
- metadata +9 -8
data/Gemfile
CHANGED
data/README.rdoc
CHANGED
@@ -6,7 +6,11 @@ As it's initial and a bit experimental implementation please note that API can c
|
|
6
6
|
|
7
7
|
== Usage
|
8
8
|
|
9
|
-
|
9
|
+
Generate part class using rails generator:
|
10
|
+
|
11
|
+
rails generate part Articles index
|
12
|
+
|
13
|
+
Add some logic to index method of your part:
|
10
14
|
|
11
15
|
# app/parts/articles_part.rb
|
12
16
|
class ArticlesPart < Parts::Base
|
@@ -15,12 +19,14 @@ Add part in app/parts, for example:
|
|
15
19
|
end
|
16
20
|
end
|
17
21
|
|
22
|
+
and to the view file linked to the part
|
23
|
+
|
18
24
|
# app/parts/views/articles_part/index.html.erb
|
19
25
|
Articles: <%= @article.map(&:title).join(", ") %>
|
20
26
|
|
21
|
-
Now you can render it with:
|
27
|
+
Now you can render it in the view of any controller with:
|
22
28
|
|
23
|
-
part ArticlesPart => :index
|
29
|
+
<%= part ArticlesPart => :index %>
|
24
30
|
|
25
31
|
You can also attach params that will be available in Part as <code>params</code> hash:
|
26
32
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
require 'rails/generators/named_base'
|
3
|
+
|
4
|
+
class PartGenerator < Rails::Generators::NamedBase
|
5
|
+
source_root File.expand_path("../templates", __FILE__)
|
6
|
+
|
7
|
+
argument :actions, :type => :array, :default => [], :banner => "action action"
|
8
|
+
check_class_collision :suffix => "Part"
|
9
|
+
|
10
|
+
def generate_part_class
|
11
|
+
template "part.rb", "app/parts/#{file_name}_part.rb"
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_part_views
|
15
|
+
inside("app/parts/views/#{file_name}_part") do
|
16
|
+
actions.each do |action|
|
17
|
+
create_file "#{action}.html.erb"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/parts.rb
CHANGED
data/lib/parts/default_layout.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-parts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Piotr Sarnacki
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-30 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -24,15 +24,14 @@ dependencies:
|
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 7
|
30
30
|
segments:
|
31
31
|
- 3
|
32
32
|
- 0
|
33
33
|
- 0
|
34
|
-
|
35
|
-
version: 3.0.0.beta4
|
34
|
+
version: 3.0.0
|
36
35
|
type: :runtime
|
37
36
|
version_requirements: *id001
|
38
37
|
description: This gem allows you to use parts in your rails app
|
@@ -45,6 +44,8 @@ extensions: []
|
|
45
44
|
extra_rdoc_files: []
|
46
45
|
|
47
46
|
files:
|
47
|
+
- lib/generators/part_generator.rb
|
48
|
+
- lib/generators/templates/part.rb
|
48
49
|
- lib/parts/base.rb
|
49
50
|
- lib/parts/default_layout.rb
|
50
51
|
- lib/parts/helpers.rb
|