rails-parts 0.2.0

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 ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rails", :path => "/Users/drogus/projekty/rails"
4
+
5
+ if RUBY_VERSION < '1.9'
6
+ gem "ruby-debug", "0.10.1"
7
+ end
8
+
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2010 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,36 @@
1
+ = Rails Parts
2
+
3
+ Merb parts ported to rails.
4
+
5
+ As it's initial and a bit experimental implementation please note that API can change (currently it's copied from Merb)
6
+
7
+ == Usage
8
+
9
+ Add part in app/parts, for example:
10
+
11
+ # app/parts/articles_part.rb
12
+ class ArticlesPart < Parts::Base
13
+ def index
14
+ @articles = Article.limit(10)
15
+ end
16
+ end
17
+
18
+ # app/parts/views/articles_part/index.html.erb
19
+ Articles: <%= @article.map(&:title).join(", ") %>
20
+
21
+ Now you can render it with:
22
+
23
+ part ArticlesPart => :index
24
+
25
+ You can also attach params that will be available in Part as <code>params</code> hash:
26
+
27
+ part ArticlesPart => :index, :limit => 5
28
+
29
+ # app/parts/articles_part.rb
30
+ class ArticlesPart < Parts::Base
31
+ def index
32
+ @articles = Article.limit(params[:limit] || 10)
33
+ end
34
+ end
35
+
36
+
data/Rakefile ADDED
@@ -0,0 +1,39 @@
1
+ # encoding: UTF-8
2
+ require 'rake'
3
+ require 'rake/rdoctask'
4
+ require 'rake/gempackagetask'
5
+
6
+ require 'rake/testtask'
7
+
8
+ Rake::TestTask.new(:test) do |t|
9
+ t.libs << 'lib'
10
+ t.libs << 'test'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = false
13
+ end
14
+
15
+ task :default => :test
16
+
17
+ Rake::RDocTask.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'Parts'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README.rdoc')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
24
+
25
+ spec = Gem::Specification.new do |s|
26
+ s.name = "parts"
27
+ s.summary = "Insert Parts summary."
28
+ s.description = "Insert Parts description."
29
+ s.files = FileList["[A-Z]*", "lib/**/*"]
30
+ s.version = "0.0.1"
31
+ end
32
+
33
+ Rake::GemPackageTask.new(spec) do |pkg|
34
+ end
35
+
36
+ desc "Install the gem #{spec.name}-#{spec.version}.gem"
37
+ task :install do
38
+ system("gem install pkg/#{spec.name}-#{spec.version}.gem --no-ri --no-rdoc")
39
+ end
data/lib/parts.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'parts/base'
2
+ require 'parts/helpers'
data/lib/parts/base.rb ADDED
@@ -0,0 +1,25 @@
1
+ require 'parts/default_layout'
2
+
3
+ module Parts
4
+ class Base < AbstractController::Base
5
+ attr_reader :params
6
+
7
+ include AbstractController::Layouts
8
+ include AbstractController::Translation
9
+ include ActionController::Helpers
10
+ include AbstractController::Rendering
11
+ include ActionController::ImplicitRender
12
+ include DefaultLayout
13
+ include AbstractController::Callbacks
14
+
15
+ def initialize(controller, params)
16
+ @params = params
17
+ self.formats = controller.formats
18
+ end
19
+
20
+ def self.inherited(klass)
21
+ super
22
+ klass.helper :all
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+ module Parts
2
+ module DefaultLayout
3
+ def _default_layout(require_layout = false)
4
+ layout_name = super
5
+
6
+ layout_name || _layout || controller_name
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ module Parts
2
+ module Helpers
3
+ def part(opts = {})
4
+ klasses, opts = opts.partition do |k,v|
5
+ k.respond_to?(:ancestors) && k.ancestors.include?(Parts::Base)
6
+ end
7
+
8
+ opts = opts.inject({}) {|h,v| h[v.first] = v.last; h}
9
+
10
+ res = klasses.inject([]) do |memo,(klass,action)|
11
+ part = klass.new(self, opts)
12
+ part.process(action)
13
+ memo << part.response_body
14
+ end
15
+
16
+ res.size == 1 ? res[0] : res
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ require "parts"
2
+ require 'rails'
3
+
4
+ module Parts
5
+ class Railtie < Rails::Railtie
6
+ initializer "parts.include_helpers" do |app|
7
+ ActiveSupport.on_load(:action_controller) do
8
+ ActionController::Base.send(:include, Parts::Helpers)
9
+ ActionController::Base.helper_method(:part)
10
+ end
11
+ end
12
+
13
+ initializer "parts.set_paths" do |app|
14
+ paths = app.config.paths
15
+ paths.app.parts 'app/parts', :eager_load => true
16
+ paths.app.parts.views 'app/parts/views'
17
+
18
+ paths.app.parts.views.to_a.each do |path|
19
+ Parts::Base.append_view_path path
20
+ end
21
+
22
+ Parts::Base.helpers_path = paths.app.helpers.to_a.first
23
+ end
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-parts
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
+ platform: ruby
12
+ authors:
13
+ - Piotr Sarnacki
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-07-30 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rails
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: -1848230024
30
+ segments:
31
+ - 3
32
+ - 0
33
+ - 0
34
+ - beta4
35
+ version: 3.0.0.beta4
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ description: This gem allows you to use parts in your rails app
39
+ email:
40
+ - drogus@gmail.com
41
+ executables: []
42
+
43
+ extensions: []
44
+
45
+ extra_rdoc_files: []
46
+
47
+ files:
48
+ - lib/parts/base.rb
49
+ - lib/parts/default_layout.rb
50
+ - lib/parts/helpers.rb
51
+ - lib/parts/railtie.rb
52
+ - lib/parts.rb
53
+ - MIT-LICENSE
54
+ - README.rdoc
55
+ - Rakefile
56
+ - Gemfile
57
+ has_rdoc: true
58
+ homepage: http://github.com/drogus/rails-parts
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options: []
63
+
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ hash: 23
81
+ segments:
82
+ - 1
83
+ - 3
84
+ - 6
85
+ version: 1.3.6
86
+ requirements: []
87
+
88
+ rubyforge_project:
89
+ rubygems_version: 1.3.7
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: Merb parts ported to rails
93
+ test_files: []
94
+