sinatra-partial 0.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.
- data/.gitignore +11 -0
- data/README +57 -0
- data/lib/sinatra/partial.rb +32 -0
- data/lib/sinatra/partial/version.rb +5 -0
- data/sinatra-partial.gemspec +22 -0
- metadata +64 -0
data/.gitignore
ADDED
data/README
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
You may say "why is this needed?".
|
2
|
+
|
3
|
+
Go on then.
|
4
|
+
|
5
|
+
_huff_ "Why is this needed?"
|
6
|
+
|
7
|
+
Because I was forever copying the code I took from http://www.sinatrarb.com/faq.html#partials into each and every project. It may well be that this is included in some other gem full of useful helpers, but I haven't found it yet, and besides _this is what I really want_. The whole point of Sinatra is not to get a lot of stuff you didn't really need anyway.
|
8
|
+
|
9
|
+
So here it is, partials, and that's it.
|
10
|
+
|
11
|
+
Installation
|
12
|
+
============
|
13
|
+
|
14
|
+
gem install sinatra-partial
|
15
|
+
|
16
|
+
Some examples
|
17
|
+
=============
|
18
|
+
|
19
|
+
At the top of your app.rb:
|
20
|
+
|
21
|
+
require 'sinatra/partial'
|
22
|
+
|
23
|
+
class Blah < Sinatra::Base
|
24
|
+
helpers Sinatra::Partial
|
25
|
+
|
26
|
+
|
27
|
+
Inside a route:
|
28
|
+
|
29
|
+
get "/" do
|
30
|
+
output = ''
|
31
|
+
post_links = some_array_full_of_links
|
32
|
+
output << partial( :main, :locals => { :output => partial( :post_links, :locals => { title: "Posts", posts: post_links } ) } )
|
33
|
+
haml :content, :locals => { :output => output, title: "posts" }
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
Here's one inside a view:
|
38
|
+
|
39
|
+
- address = "ip#{ip.first.gsub(".", "_")}"
|
40
|
+
- v = ip.last
|
41
|
+
%div{class: "ip", id: "#{address}", ip: "#{ip.first}" }
|
42
|
+
%a{name: "#{address}"}
|
43
|
+
%h3= "#{ip.first}"
|
44
|
+
%p= "last visit: #{v[:last_visit]} No. of visits: #{v[:visits]}"
|
45
|
+
= partial( :geo, :locals => { geo: v[:geo] } )
|
46
|
+
|
47
|
+
%a{href: "##{address}", class: "records", ip: "#{ip.first}"}
|
48
|
+
Show/hide records
|
49
|
+
%div{class: "records", ip: "#{ip.first}"}
|
50
|
+
<h4>Records:</h4>
|
51
|
+
= partial( :record, collection: v[:records] )
|
52
|
+
|
53
|
+
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
|
+
|
55
|
+
Thanks to Chris Schneider and Sam Elliott for sharing their code, I just made it into this gem.
|
56
|
+
|
57
|
+
MIT Licence (i.e. be good!)
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'sinatra/base'
|
4
|
+
|
5
|
+
module Sinatra
|
6
|
+
module Partial
|
7
|
+
|
8
|
+
# support for partials
|
9
|
+
# @example
|
10
|
+
# partial( :meta, :locals => {meta: meta} )
|
11
|
+
def partial(template, *args)
|
12
|
+
opts = args.last.is_a?(Hash) ? args.pop : {} # get hash options if they're there
|
13
|
+
opts.merge!(:layout => false) # don't layout, this is a partial
|
14
|
+
|
15
|
+
if collection = opts.delete(:collection)
|
16
|
+
collection.inject([]) do |buffer, member|
|
17
|
+
buffer << haml(template, opts.merge(
|
18
|
+
:layout => false,
|
19
|
+
:locals => {template.to_sym => member}
|
20
|
+
)
|
21
|
+
)
|
22
|
+
end.join("\n")
|
23
|
+
else
|
24
|
+
haml(template, opts)
|
25
|
+
end
|
26
|
+
end # def
|
27
|
+
end
|
28
|
+
|
29
|
+
helpers Partial
|
30
|
+
end
|
31
|
+
|
32
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "sinatra/partial/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "sinatra-partial"
|
7
|
+
s.version = Sinatra::Partial::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Chris Schneider", "Sam Elliott", "Iain Barnett"]
|
10
|
+
s.email = ["iainspeed@gmail.com"]
|
11
|
+
s.homepage = "https://github.com/yb66/Sinatra-Partial"
|
12
|
+
s.summary = %q{Rack middleware for Geo IP city lookup}
|
13
|
+
s.description = %q{Just the partials helper in a gem. That is all.}
|
14
|
+
s.license = 'MIT'
|
15
|
+
|
16
|
+
s.add_dependency 'sinatra'
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sinatra-partial
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Chris Schneider
|
9
|
+
- Sam Elliott
|
10
|
+
- Iain Barnett
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
date: 2011-06-25 00:00:00.000000000Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: sinatra
|
18
|
+
requirement: &2153111220 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ! '>='
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '0'
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *2153111220
|
27
|
+
description: Just the partials helper in a gem. That is all.
|
28
|
+
email:
|
29
|
+
- iainspeed@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- .gitignore
|
35
|
+
- README
|
36
|
+
- lib/sinatra/partial.rb
|
37
|
+
- lib/sinatra/partial/version.rb
|
38
|
+
- sinatra-partial.gemspec
|
39
|
+
homepage: https://github.com/yb66/Sinatra-Partial
|
40
|
+
licenses:
|
41
|
+
- MIT
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.8.5
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: Rack middleware for Geo IP city lookup
|
64
|
+
test_files: []
|