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.
Files changed (3) hide show
  1. data/README +79 -0
  2. data/lib/basic_helpers.rb +28 -0
  3. 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>
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: djanowski-rails_basic_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damian Janowski