djanowski-rails_basic_helpers 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README +79 -0
- data/lib/basic_helpers.rb +28 -0
- metadata +1 -1
data/README
CHANGED
@@ -1 +1,80 @@
|
|
1
1
|
A Ruby on Rails plugin providing some super simple helpers.
|
2
|
+
|
3
|
+
=== Examples
|
4
|
+
|
5
|
+
rows =
|
6
|
+
[
|
7
|
+
%w{John john@domain.com},
|
8
|
+
%w{Doe doe@domain.com}
|
9
|
+
]
|
10
|
+
|
11
|
+
table(rows)
|
12
|
+
|
13
|
+
# <table>
|
14
|
+
# <tr>
|
15
|
+
# <td>John</td>
|
16
|
+
# <td>john@domain.com</td>
|
17
|
+
# </tr>
|
18
|
+
# <tr>
|
19
|
+
# <td>Doe</td>
|
20
|
+
# <td>doe@domain.com</td>
|
21
|
+
# </tr>
|
22
|
+
# </table>
|
23
|
+
|
24
|
+
table([%w{Name E-mail}] + rows, :headers => true)
|
25
|
+
table(rows, :headers => %w{Name E-mail})
|
26
|
+
|
27
|
+
# <table>
|
28
|
+
# <thead>
|
29
|
+
# <tr>
|
30
|
+
# <th>Name</th>
|
31
|
+
# <th>E-mail</th>
|
32
|
+
# </tr>
|
33
|
+
# </thead>
|
34
|
+
# <tr>
|
35
|
+
# <td>John</td>
|
36
|
+
# <td>john@domain.com</td>
|
37
|
+
# </tr>
|
38
|
+
# <tr>
|
39
|
+
# <td>Doe</td>
|
40
|
+
# <td>doe@domain.com</td>
|
41
|
+
# </tr>
|
42
|
+
# </table>
|
43
|
+
|
44
|
+
@people =
|
45
|
+
[
|
46
|
+
Person.new('John', 'john@domain.com'),
|
47
|
+
Person.new('Doe', 'doe@domain.com')
|
48
|
+
]
|
49
|
+
|
50
|
+
table(:people, %w{name email})
|
51
|
+
|
52
|
+
# <table>
|
53
|
+
# <tr>
|
54
|
+
# <td>John</td>
|
55
|
+
# <td>john@domain.com</td>
|
56
|
+
# </tr>
|
57
|
+
# <tr>
|
58
|
+
# <td>Doe</td>
|
59
|
+
# <td>doe@domain.com</td>
|
60
|
+
# </tr>
|
61
|
+
# </table>
|
62
|
+
|
63
|
+
table(rows, [:name, :email], :headers => true)
|
64
|
+
|
65
|
+
# <table>
|
66
|
+
# <thead>
|
67
|
+
# <tr>
|
68
|
+
# <th>Name</th>
|
69
|
+
# <th>Email</th>
|
70
|
+
# </tr>
|
71
|
+
# </thead>
|
72
|
+
# <tr>
|
73
|
+
# <td>John</td>
|
74
|
+
# <td>john@domain.com</td>
|
75
|
+
# </tr>
|
76
|
+
# <tr>
|
77
|
+
# <td>Doe</td>
|
78
|
+
# <td>doe@domain.com</td>
|
79
|
+
# </tr>
|
80
|
+
# </table>
|
data/lib/basic_helpers.rb
CHANGED
@@ -125,4 +125,32 @@ module BasicHelpers
|
|
125
125
|
|
126
126
|
table(rows, options)
|
127
127
|
end
|
128
|
+
|
129
|
+
def ul(items, options = {}, &block)
|
130
|
+
return nil if items.blank?
|
131
|
+
|
132
|
+
tag = options.delete(:tag) || :ul
|
133
|
+
|
134
|
+
contents = if block_given?
|
135
|
+
items.inject([]) do |html,item|
|
136
|
+
html << content_tag(:li, *yield(item))
|
137
|
+
end.join("\n")
|
138
|
+
else
|
139
|
+
"\n<li>#{items.join("</li>\n<li>")}</li>\n"
|
140
|
+
end
|
141
|
+
|
142
|
+
content_tag(tag, contents, options)
|
143
|
+
end
|
144
|
+
|
145
|
+
def ol(items, options = {}, &block)
|
146
|
+
ul(items, options.merge(:tag => :ol), &block)
|
147
|
+
end
|
148
|
+
|
149
|
+
def dl(items, options = {}, &block)
|
150
|
+
return nil if items.blank?
|
151
|
+
|
152
|
+
items = items.map(&block) if block_given?
|
153
|
+
|
154
|
+
content_tag(:dl, items.inject('') {|html,item| content_tag(:dt, item.first) + content_tag(:dd, item.last) }, options)
|
155
|
+
end
|
128
156
|
end
|