better_partials 1.0.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.
Files changed (6) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +61 -0
  3. data/Rakefile +20 -0
  4. data/VERSION +1 -0
  5. data/lib/better_partials.rb +94 -0
  6. metadata +66 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 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.rdoc ADDED
@@ -0,0 +1,61 @@
1
+ = better_partials
2
+ Provides syntactic sugar for render :partial.
3
+
4
+ == Examples
5
+
6
+ === Render a partial
7
+ <%= partial "people/search_box" %>
8
+
9
+ === Pass some parameters in
10
+ <% form_for @person do |f| %>
11
+ <%= partial "people/form", :f => f %>
12
+ <% end %>
13
+
14
+ === Pass in a collection
15
+
16
+ <%= partial "people/person", :collection => @people %>
17
+
18
+ Or the terse way...
19
+
20
+ <%= partials @people %>
21
+
22
+ Also works, but not as nice reading...
23
+
24
+ <%= partial @people %>
25
+
26
+ === Rendering a block
27
+
28
+ <% partial "people/box" do %>
29
+ Inner content goes here.. (gets called in your partial's yield statement)
30
+ <% end %>
31
+
32
+ === Special Options
33
+ These special options pass through to render :partial. All others are passed through as :locals.
34
+
35
+ :collection
36
+ :spacer_template
37
+ :object
38
+ :use_full_path
39
+
40
+ == Installation
41
+ === Install Plugin
42
+
43
+ script/plugin install git://github.com/jcnetdev/better_partials.git
44
+
45
+ === Install Gem
46
+
47
+ If you're using Rails 2.1, you -can- should use the plugin as a gem.
48
+
49
+ Add this to your environment.rb:
50
+
51
+ config.gem 'jcnetdev-better_partials', :version => '>= 1.1.3', :lib => 'better_partials', :source => 'http://gems.github.com'
52
+
53
+ To install:
54
+
55
+ rake gems:install
56
+
57
+ To unpack:
58
+
59
+ rake gems:unpack
60
+
61
+ Copyright (c) 2008 Jacques Crocker (www.railsjedi.com), released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |s|
8
+ s.name = "better_partials"
9
+ s.summary = "rails3 helper for better partials"
10
+ s.email = "railsjedi@gmail.com"
11
+ s.homepage = "http://github.com/railsjedi/better_partials"
12
+ s.description = "Allows a simpler interface when calling partials"
13
+ s.authors = ["Jacques Crocker"]
14
+ s.files = FileList["[A-Z]*", "{bin,generators,lib,test}/**/*"]
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+
18
+ rescue LoadError
19
+ # puts "Jeweler, or one of its dependencies, is not available. Install it with: gem install jeweler"
20
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.1
@@ -0,0 +1,94 @@
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.respond_to?(:to_model)
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
+ :as
51
+ ]
52
+
53
+ # cycle through and add these options directly to partial_options
54
+ passoff_options.each do |passoff_option|
55
+ # only assign if passoff option exists
56
+ if options.has_key?(passoff_option)
57
+ # move the option from options to partial_options
58
+ partial_options[passoff_option] = options.delete(passoff_option)
59
+ end
60
+ end
61
+
62
+ # move whats left of the remaining options into partial_locals
63
+ partial_locals = options.merge(partial_locals)
64
+ end
65
+
66
+ # set partial locals
67
+ partial_options[:locals] = partial_locals
68
+ if block_given?
69
+ # swap layout and partial options
70
+ partial_options[:layout] = partial_options.delete(:partial)
71
+
72
+ # render the partial
73
+ render(partial_options, &block)
74
+
75
+ # return nothing since render :layout will write directly to EROUT
76
+ return nil
77
+ else
78
+ # normal render call
79
+ return render(partial_options)
80
+ end
81
+ end
82
+
83
+ # make it more sermantic
84
+ # e.g. partials @people
85
+ def partials(collection)
86
+ partial(collection) if collection
87
+ end
88
+ end
89
+ end
90
+
91
+
92
+ if defined?(Rails) and defined?(ActionView)
93
+ ActionView::Base.send :include, BetterPartials::Helpers
94
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: better_partials
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 1
9
+ version: 1.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Jacques Crocker
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-15 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Allows a simpler interface when calling partials
22
+ email: railsjedi@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - README.rdoc
29
+ files:
30
+ - MIT-LICENSE
31
+ - README.rdoc
32
+ - Rakefile
33
+ - VERSION
34
+ - lib/better_partials.rb
35
+ has_rdoc: true
36
+ homepage: http://github.com/railsjedi/better_partials
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options:
41
+ - --charset=UTF-8
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ segments:
49
+ - 0
50
+ version: "0"
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ requirements: []
59
+
60
+ rubyforge_project:
61
+ rubygems_version: 1.3.6
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: rails3 helper for better partials
65
+ test_files: []
66
+