rails-parts 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,8 +1,8 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem "rails", :path => "/Users/drogus/projekty/rails"
3
+ gem "rails", "~> 3.0"
4
4
 
5
5
  if RUBY_VERSION < '1.9'
6
- gem "ruby-debug", "0.10.1"
6
+ gem "ruby-debug", ">= 0.10.3"
7
7
  end
8
8
 
@@ -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
- Add part in app/parts, for example:
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
@@ -0,0 +1,7 @@
1
+ class <%= class_name %>Part < Parts::Base
2
+ <% actions.each do |action| -%>
3
+ def <%= action %>
4
+ end
5
+
6
+ <% end -%>
7
+ end
@@ -1,2 +1,3 @@
1
+ require 'parts/railtie'
1
2
  require 'parts/base'
2
3
  require 'parts/helpers'
@@ -2,8 +2,7 @@ module Parts
2
2
  module DefaultLayout
3
3
  def _default_layout(require_layout = false)
4
4
  layout_name = super
5
-
6
- layout_name || _layout || controller_name
5
+ layout_name || _layout
7
6
  end
8
7
  end
9
8
  end
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: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
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-01 00:00:00 +02:00
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: -1848230024
29
+ hash: 7
30
30
  segments:
31
31
  - 3
32
32
  - 0
33
33
  - 0
34
- - beta4
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