jcnetdev-better_partials 1.0.200807042

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/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Jacques Crocker (www.railsjedi.com)
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 ADDED
@@ -0,0 +1,58 @@
1
+ better_partials
2
+ ==============
3
+ Provides syntactic suger for render :partial
4
+
5
+
6
+ Example
7
+ =======
8
+ Render a partial
9
+ <%= partial "people/search_box" %>
10
+
11
+ Pass some parameters in
12
+ <% form_for @person do |f| %>
13
+ <%= partial "people/form", :f => f %>
14
+ <% end %>
15
+
16
+ Pass in a collection
17
+ <%= partial "people/person", :collection => @people %>
18
+
19
+ Or the terse way
20
+ <%= partials @people %>
21
+
22
+ Also works, but not as nice reading
23
+ <%= partial @people %>
24
+
25
+ Rendering a block
26
+ <% partial "people/box" do %>
27
+ Inner connect goes here.. (gets called in your partial's yield statement)
28
+ <% end %>
29
+
30
+
31
+ Special Partial Options pass through to render :partial
32
+ (all others are passed through to the :locals parameter)
33
+ =======
34
+ :collection,
35
+ :spacer_template,
36
+ :object,
37
+ :use_full_path
38
+
39
+
40
+ Install into vendor/plugins
41
+ =======
42
+ script/plugin install git://github.com/jcnetdev/better_partials.git
43
+
44
+
45
+ Install via Gem
46
+ =======
47
+ If you're using Rails 2.1, you can use the plugin as a gem.
48
+
49
+ Add this to your environment.rb:
50
+
51
+ config.gem 'jcnetdev-better_partials', :version => '>= 1.0',
52
+ :lib => 'better_partials',
53
+ :source => 'http://gems.github.com'
54
+
55
+ Then install via: rake gems:install
56
+
57
+
58
+ Copyright (c) 2008 Jacques Crocker (www.railsjedi.com), released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the betterpartials plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
14
+
15
+ desc 'Generate documentation for the betterpartials plugin.'
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'Betterpartials'
19
+ rdoc.options << '--line-numbers' << '--inline-source'
20
+ rdoc.rdoc_files.include('README')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
@@ -0,0 +1,29 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'better_partials'
3
+ s.version = '1.0.200807042'
4
+ s.date = '2008-07-04'
5
+
6
+ s.summary = "Makes calling partials in views look better and more fun."
7
+ s.description = "Wrapper around render :partial that removes the need to use :locals, and allows blocks to be taken easily"
8
+
9
+ s.authors = ['RailsJedi']
10
+ s.email = 'railsjedi@gmail.com'
11
+ s.homepage = 'http://www.railsjedi.com/posts/22'
12
+
13
+ s.has_rdoc = true
14
+ s.rdoc_options = ["--main", "README"]
15
+ s.extra_rdoc_files = ["README"]
16
+
17
+ s.add_dependency 'rails', ['>= 2.1']
18
+
19
+ s.files = ["MIT-LICENSE",
20
+ "README",
21
+ "Rakefile",
22
+ "better_partials.gemspec",
23
+ "init.rb",
24
+ "lib/better_partials.rb",
25
+ "rails/init.rb",
26
+ "uninstall.rb"]
27
+
28
+ end
29
+
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + "/rails/init"
@@ -0,0 +1,88 @@
1
+ module BetterPartials
2
+ module Helpers
3
+
4
+ # Renders a Partial intelligently
5
+ #
6
+ # Normal partial call:
7
+ # <%= partial "my_partial" %>
8
+ # same as...
9
+ # <%= render :partial => "my_partial" %>
10
+ #
11
+ # Partial call with arguments:
12
+ # <%= partial "my_partial", :arg1 => "test" %>
13
+ # same as...
14
+ # <%= render :partial => "my_partial", :locals => {:arg1 => "test"} %>
15
+ #
16
+ # Partial call with collection (and arguments)
17
+ # <%= partial "my_partial", :collection => @items, :arg1 => "test" %>
18
+ # same as...
19
+ # <%= render :partial => "my_partial", :collection => @items, :locals => {:arg1 => "test", :collection => @items} %>
20
+ #
21
+ # Partial also supports blocks naturally
22
+ # <% partial "my_partial", :collection => @items, :arg1 => "test" do %>
23
+ # inner partial content
24
+ # <% end %>
25
+ # same as...
26
+ # <% render :layout => "my_partial", :collection => @items, :arg1 => "test" do %>
27
+ # inner partial content
28
+ # <% end %>
29
+ def partial(partial_path, options = {}, &block)
30
+
31
+ # partial_options will build up the hash parameter to pass into render()
32
+ partial_options = {}
33
+
34
+ # partial_locals will build up the hash parameter to pass into the :locals option
35
+ partial_locals = {}
36
+
37
+ # setup partial path
38
+ partial_options[:partial] = partial_path
39
+
40
+ # handle case where options is a straight up active record model
41
+ if options.is_a? ActiveRecord::Base
42
+ partial_options[:object] = options
43
+ else
44
+ # find all the special options to passoff to render (the rest we'll put in :locals)
45
+ passoff_options = [
46
+ :collection,
47
+ :spacer_template,
48
+ :object,
49
+ :use_full_path
50
+ ]
51
+
52
+ # cycle through and add these options directly to partial_options
53
+ passoff_options.each do |passoff_option|
54
+ # only assign if passoff option exists
55
+ if options.has_key?(passoff_option)
56
+ # move the option from options to partial_options
57
+ partial_options[passoff_option] = options.delete(passoff_option)
58
+ end
59
+ end
60
+
61
+ # move whats left of the remaining options into partial_locals
62
+ partial_locals = options.merge(partial_locals)
63
+ end
64
+
65
+ # set partial locals
66
+ partial_options[:locals] = partial_locals
67
+ if block_given?
68
+ # swap layout and partial options
69
+ partial_options[:layout] = partial_options.delete(:partial)
70
+
71
+ # render the partial
72
+ render(partial_options, &block)
73
+
74
+ # return nothing since render :layout will write directly to EROUT
75
+ return nil
76
+ else
77
+ # normal render call
78
+ return render(partial_options)
79
+ end
80
+ end
81
+
82
+ # make it more suh-man-tech
83
+ # e.g. partials @people
84
+ def partials(collection)
85
+ partial(collection) if collection
86
+ end
87
+ end
88
+ end
data/rails/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'better_partials'
2
+ ActionView::Base.send :include, BetterPartials::Helpers
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jcnetdev-better_partials
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.200807042
5
+ platform: ruby
6
+ authors:
7
+ - RailsJedi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-07-04 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rails
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "2.1"
23
+ version:
24
+ description: Wrapper around render :partial that removes the need to use :locals, and allows blocks to be taken easily
25
+ email: railsjedi@gmail.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - README
32
+ files:
33
+ - MIT-LICENSE
34
+ - README
35
+ - Rakefile
36
+ - better_partials.gemspec
37
+ - init.rb
38
+ - lib/better_partials.rb
39
+ - rails/init.rb
40
+ - uninstall.rb
41
+ has_rdoc: true
42
+ homepage: http://www.railsjedi.com/posts/22
43
+ post_install_message:
44
+ rdoc_options:
45
+ - --main
46
+ - README
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ requirements: []
62
+
63
+ rubyforge_project:
64
+ rubygems_version: 1.2.0
65
+ signing_key:
66
+ specification_version: 2
67
+ summary: Makes calling partials in views look better and more fun.
68
+ test_files: []
69
+