sinatra-partial 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES ADDED
@@ -0,0 +1 @@
1
+ v0.1.0 The locals hash doesn't get clobbered if passing a collection now, but you do get the chance to clobber the default of passing the collection local if you so wish. With great power comes great responsibility!
data/README CHANGED
@@ -1,3 +1,7 @@
1
+ Quick note: If you do decide to use this gem, please let me know if it isn't working for you - make a contribution!
2
+
3
+ Back to our previously scheduled programming...
4
+
1
5
  You may say "why is this needed?".
2
6
 
3
7
  Go on then.
@@ -52,6 +56,14 @@ Here's one inside a view:
52
56
 
53
57
  Yes, a tad confusing, but I can't be bothered to cook up a simple example - just look at the _partials_ and how they're used. Concentration brings insight (so it's said!)
54
58
 
59
+ Another quick note: Since the locals hash was getting clobbered when using a collection, I've changed the code so that you can pass in a collection _and_ locals that will be accessible too.
60
+
61
+ = partial( :record, collection: v[:records], :locals => {something_else: 243} )
62
+
63
+ Now you'll be able to access the local `something_else` within the :record partial.
64
+
65
+ You can also decide to do some clobbering of your own and HULK SMASH! the defaults for the collection, which in this case would be :record (as it's the template name) and :layout => false. Perhaps you might need this so I've left it up to you, but probably best to leave it alone and call your locals something else. It's your code.
66
+
55
67
  Thanks to Chris Schneider and Sam Elliott for sharing their code, I just made it into this gem.
56
68
 
57
69
  MIT Licence (i.e. be good!)
@@ -13,10 +13,9 @@ module Sinatra
13
13
  opts.merge!(:layout => false) # don't layout, this is a partial
14
14
 
15
15
  if collection = opts.delete(:collection)
16
+ locals = opts[:locals].nil? ? {} : opts.delete(:locals)
16
17
  collection.inject([]) do |buffer, member|
17
- buffer << haml(template, opts.merge(
18
- :layout => false,
19
- :locals => {template.to_sym => member}
18
+ buffer << haml( template, opts.merge(:layout => false, :locals => {template.to_sym => member}.merge(locals)
20
19
  )
21
20
  )
22
21
  end.join("\n")
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module Partial
3
- VERSION = "0.0.1"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-partial
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2011-06-25 00:00:00.000000000Z
14
+ date: 2011-07-04 00:00:00.000000000Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: sinatra
18
- requirement: &2153111220 !ruby/object:Gem::Requirement
18
+ requirement: &2152975500 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,7 +23,7 @@ dependencies:
23
23
  version: '0'
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *2153111220
26
+ version_requirements: *2152975500
27
27
  description: Just the partials helper in a gem. That is all.
28
28
  email:
29
29
  - iainspeed@gmail.com
@@ -32,6 +32,7 @@ extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
34
  - .gitignore
35
+ - CHANGES
35
36
  - README
36
37
  - lib/sinatra/partial.rb
37
38
  - lib/sinatra/partial/version.rb