kelredd-sinatra-helpers 0.2.2 → 0.2.3
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/lib/sinatra_helpers/erb/partials.rb +96 -27
- data/lib/sinatra_helpers/generator/file_templates/reset-fonts.less.erb +8 -0
- data/lib/sinatra_helpers/generator/file_templates/reset.less.erb +11 -22
- data/lib/sinatra_helpers/generator/template.rb +1 -0
- data/lib/sinatra_helpers/version.rb +1 -1
- metadata +4 -3
@@ -6,37 +6,106 @@ module SinatraHelpers::Erb; end
|
|
6
6
|
|
7
7
|
module SinatraHelpers::Erb::Partials
|
8
8
|
|
9
|
-
# helper to emulate rails' 'render :partial' helper, using erb
|
10
|
-
# => taken from the sinatra book
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
9
|
+
# helper to somewhat emulate rails' 'render :partial' helper, using erb
|
10
|
+
# => originally taken from the sinatra book:
|
11
|
+
# http://sinatra-book.gittr.com/#implemention_of_rails_style_partials
|
12
|
+
# => updated: pass a block to specify the partial subject (ie object or collection)
|
13
|
+
# => updated: pass a hash to specify locals directly
|
14
|
+
# => if a block is passed, will look for template in a path relative to
|
15
|
+
# to the calling template path. Specify template with a leading '/'
|
16
|
+
# to force the path to be relative to the views directory.
|
17
|
+
#
|
18
|
+
# Render the partial once (no subject) with no locals:
|
19
|
+
# Usage: partial :item
|
20
|
+
# => looks for template at <views>/_item.erb
|
21
|
+
# Render a nested template
|
22
|
+
# Usage: partial '/items/item'
|
23
|
+
# => looks for template at <views>/items/_item.erb
|
24
|
+
#
|
25
|
+
# Render the partial once (no subject) WITH locals:
|
26
|
+
# Usage: partial :item, :user => @me
|
27
|
+
#
|
28
|
+
# Render the partial once on an object:
|
29
|
+
# Implicit usage: partial :item { @item }
|
30
|
+
# => knows subject should be treated as an object (and not a collection)
|
31
|
+
# b/c @item is not enumerable
|
32
|
+
# Explicit usage: partial :item, :item => @item_set
|
33
|
+
# -- or --: partial :item, :object => @item_set
|
34
|
+
# => use a local if your subject is enumerable and you want
|
35
|
+
# it treated as a single object
|
36
|
+
#
|
37
|
+
# Render the partial over a collection:
|
38
|
+
# => knows subject should be treated as a collection (and not a single object)
|
39
|
+
# b/c @items is enumerable
|
40
|
+
# Implicit usage: partial :item { @items }
|
41
|
+
# Explicit usage: partial :item, :collection => @items
|
42
|
+
#
|
43
|
+
# Generally, passing a block is the preferred method b/c
|
44
|
+
# you can specify templates relative to the calling template's
|
45
|
+
# path, for example:
|
46
|
+
# => if in template <views>/items/_item_list.erb
|
47
|
+
# => partial :item { @items }
|
48
|
+
# => will look for the template at <views>/items/_item.erb
|
49
|
+
# => however
|
50
|
+
# => partial :item, :collection => @items
|
51
|
+
# => will look for the template at <views>/_item.erb
|
52
|
+
# => you can force this behavior in the block version
|
53
|
+
# => by prepending a '/' to the template
|
54
|
+
# => partial '/item' { @items }
|
55
|
+
# => will look for the template at <views>/_item.erb
|
56
|
+
|
57
|
+
def partial(path, locals={}, &subject_block)
|
58
|
+
raise "locals must be specified with a Hash" unless locals.kind_of?(::Hash)
|
59
|
+
params = _partial_params(path, locals, subject_block)
|
60
|
+
if params[:subject] && params[:subject].respond_to?(:collect)
|
26
61
|
counter = 0
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
62
|
+
params[:subject].collect do |subject|
|
63
|
+
erb(params[:path], params[:options].merge({
|
64
|
+
:locals => params[:locals].merge({
|
65
|
+
params[:name].to_sym => subject,
|
66
|
+
"#{params[:name]}_counter".to_sym => counter += 1
|
67
|
+
})
|
68
|
+
}))
|
32
69
|
end.join("\n")
|
33
70
|
else
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
71
|
+
erb(params[:path], params[:options].merge({
|
72
|
+
:locals => params[:locals].merge({
|
73
|
+
params[:name].to_sym => params[:subject]
|
74
|
+
})
|
75
|
+
}))
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def _partial_params(path, locals, subject_block)
|
82
|
+
{
|
83
|
+
:name => name = File.basename(path.to_s).split(".").first.to_sym,
|
84
|
+
:subject => begin
|
85
|
+
subject_block.call
|
86
|
+
rescue
|
87
|
+
nil
|
88
|
+
end ||
|
89
|
+
locals.delete(:collection) ||
|
90
|
+
locals.delete(:object) ||
|
91
|
+
locals.delete(name),
|
92
|
+
:locals => locals.delete(:locals) || locals,
|
93
|
+
:options => { :layout => false },
|
94
|
+
:path => _partial_path(path, subject_block).to_sym
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
def _partial_path(path, subject_block)
|
99
|
+
partial_path = if path.to_s =~ /\A\// || subject_block.nil?
|
100
|
+
path.to_s
|
101
|
+
else
|
102
|
+
File.join(*[
|
103
|
+
eval("File.expand_path(File.dirname(__FILE__))", subject_block).
|
104
|
+
gsub(File.expand_path(Sinatra::Application.views), ''),
|
105
|
+
path.to_s
|
106
|
+
])
|
39
107
|
end
|
108
|
+
File.join(File.dirname(partial_path), "_#{File.basename(partial_path)}")
|
40
109
|
end
|
41
110
|
|
42
111
|
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2009, Yahoo! Inc. All rights reserved.
|
3
|
+
Code licensed under the BSD License:
|
4
|
+
http://developer.yahoo.net/yui/license.txt
|
5
|
+
version: 2.7.0
|
6
|
+
*/
|
7
|
+
html{color:#000;background:#FFF;}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,p,blockquote,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}address,caption,cite,code,dfn,em,strong,th,var,optgroup{font-style:inherit;font-weight:inherit;}del,ins{text-decoration:none;}li{list-style:none;}caption,th{text-align:left;}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}q:before,q:after{content:'';}abbr,acronym{border:0;font-variant:normal;}sup{vertical-align:baseline;}sub{vertical-align:baseline;}legend{color:#000;}input,button,textarea,select,optgroup,option{font-family:inherit;font-size:inherit;font-style:inherit;font-weight:inherit;}input,button,textarea,select{*font-size:100%;}body{font:13px/1.231 arial,helvetica,clean,sans-serif;*font-size:small;*font:x-small;}select,input,button,textarea,button{font:99% arial,helvetica,clean,sans-serif;}table{font-size:inherit;font:100%;}pre,code,kbd,samp,tt{font-family:monospace;*font-size:108%;line-height:100%;}
|
8
|
+
|
@@ -1,24 +1,13 @@
|
|
1
|
-
/*
|
2
|
-
Copyright (c) 2009, Yahoo! Inc. All rights reserved.
|
3
|
-
Code licensed under the BSD License:
|
4
|
-
http://developer.yahoo.net/yui/license.txt
|
5
|
-
version: 2.7.0
|
6
|
-
*/
|
7
|
-
html{color:#000;background:#FFF;}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,p,blockquote,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}address,caption,cite,code,dfn,em,strong,th,var,optgroup{font-style:inherit;font-weight:inherit;}del,ins{text-decoration:none;}li{list-style:none;}caption,th{text-align:left;}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}q:before,q:after{content:'';}abbr,acronym{border:0;font-variant:normal;}sup{vertical-align:baseline;}sub{vertical-align:baseline;}legend{color:#000;}input,button,textarea,select,optgroup,option{font-family:inherit;font-size:inherit;font-style:inherit;font-weight:inherit;}input,button,textarea,select{*font-size:100%;}body{font:13px/1.231 arial,helvetica,clean,sans-serif;*font-size:small;*font:x-small;}select,input,button,textarea,button{font:99% arial,helvetica,clean,sans-serif;}table{font-size:inherit;font:100%;}pre,code,kbd,samp,tt{font-family:monospace;*font-size:108%;line-height:100%;}
|
8
|
-
|
9
1
|
/*
|
10
2
|
Copyright (c) 2009, Kelly Redding. All rights reserved.
|
11
3
|
See http://github.com/kelredd/sinatra-helpers for license details
|
12
4
|
*/
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
list-style-position: outside;
|
20
|
-
list-style-type: none;
|
21
|
-
}
|
5
|
+
@import "reset-fonts.less";
|
6
|
+
|
7
|
+
@base_font_family: 'Lucida Grande',arial,helvetica,clean,sans-serif;
|
8
|
+
@base_font_size: 10pt;
|
9
|
+
@base_font_size_adjust: 1em;
|
10
|
+
|
22
11
|
UL.bulleted LI {
|
23
12
|
list-style-position: inside !important;
|
24
13
|
list-style-type: disc !important;
|
@@ -29,12 +18,12 @@ OL LI {
|
|
29
18
|
}
|
30
19
|
|
31
20
|
HTML {
|
32
|
-
font-size:
|
21
|
+
font-size: @base_font_size;
|
33
22
|
}
|
34
23
|
BODY {
|
35
24
|
width: 100%;
|
36
|
-
font-family:
|
37
|
-
font-size:
|
25
|
+
font-family: @base_font_family;
|
26
|
+
font-size: @base_font_size_adjust;
|
38
27
|
font-size-adjust: none;
|
39
28
|
font-variant: normal;
|
40
29
|
}
|
@@ -46,8 +35,8 @@ A, IMG, FORM, FIELDSET {
|
|
46
35
|
INPUT, SELECT, TEXTAREA, BUTTON {
|
47
36
|
margin: 0;
|
48
37
|
padding: .2em .3em;
|
49
|
-
font-family :
|
50
|
-
font-size:
|
38
|
+
font-family : @base_font_family;
|
39
|
+
font-size: @base_font_size_adjust;
|
51
40
|
font-size-adjust: none;
|
52
41
|
font-variant: normal;
|
53
42
|
}
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 3
|
9
|
+
version: 0.2.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Kelly Redding
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-04-05 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -131,6 +131,7 @@ files:
|
|
131
131
|
- lib/sinatra_helpers/generator/file_templates/model_test.rb.erb
|
132
132
|
- lib/sinatra_helpers/generator/file_templates/production.ru.erb
|
133
133
|
- lib/sinatra_helpers/generator/file_templates/Rakefile.erb
|
134
|
+
- lib/sinatra_helpers/generator/file_templates/reset-fonts.less.erb
|
134
135
|
- lib/sinatra_helpers/generator/file_templates/reset.less.erb
|
135
136
|
- lib/sinatra_helpers/generator/file_templates/staging.ru.erb
|
136
137
|
- lib/sinatra_helpers/generator/file_templates/test_helper.rb.erb
|