hanami-helpers 0.0.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c7c166ba28d9d65bfa9fab4325f0cfd2529f6aa9
4
- data.tar.gz: 37899e63412cc17a329506ef85606df67f80210a
3
+ metadata.gz: 00c50648c23a0d34befe080287206beb9e46aa34
4
+ data.tar.gz: 2be73f77dead23bc48142b567b0a2595d9ba6a00
5
5
  SHA512:
6
- metadata.gz: d4536ae052bec8721bcdf14173ba55fe1967cd05a20edbaf5e43377feaa66eb3233840e93c665ea66caf9236c0a1039b811c9b5b3a87765379acdbab54769e9d
7
- data.tar.gz: 02b9b40ba70a5eb29a5a0fca353ffc90f356bbcf815582a53abfd0be53f4154d52c9584c6e1256d15883b960339553c045d0c940dfcb43522cff386a700bec1c
6
+ metadata.gz: ce6e712b2a0e0aaf38e79a682112a51929ec62fb77cc2f2af17c0645fddc28d56654e0c0b8dd4acf4c707c502ea7cc6dc19870e1ed7ca027304755d90dde9826
7
+ data.tar.gz: 75c87873818c331507ce01574fbd5652a9be6f8e782805e4f731377f37e81429578384cc9dde5b7a1f521d6c0473ab4e6f4057ff9593fcee49bf68bdd9f6d419
data/CHANGELOG.md ADDED
@@ -0,0 +1,39 @@
1
+ # Hanami::Helpers
2
+ View helpers for Ruby web applications
3
+
4
+ ## v0.3.0 - 2016-01-22
5
+ ### Changed
6
+ - [Luca Guidi] Renamed the project
7
+
8
+ ## v0.2.6 - 2016-01-12
9
+ ### Added
10
+ - [Cam Huynh] Added support for HTML helper (`#html`) block syntax (eg. `html { div('hello') }`)
11
+ - [Shin-ichi Ueda] Added support for `<dd>` HTML tag
12
+
13
+ ### Fixed
14
+ - [Rodrigo Panachi] Don't generate CSRF token hidden input for forms with `GET` method
15
+
16
+ ## v0.2.5 - 2015-09-30
17
+ ### Added
18
+ - [Leonardo Saraiva] Improved support for HTML content in `#link_to` helper. It now accepts blocks to build markup inside an anchor tag.
19
+ - [José Mota] Added `#text` to the form builder
20
+ - [Alex Wochna] Added `#number_field` to the form builder
21
+ - [Scott Le] Added `#text_area` to the form builder
22
+
23
+ ### Fixed
24
+ - [Pascal Betz] Ensure boolean attributes in HTML forms to not be printed if their value is `nil` (eg. avoid to print `disabled=""`).
25
+
26
+ ### Changed
27
+ - [Luca Guidi] Form `#label` helper outputs capitalized strings, instead of titleized (eg. `"Remember me"` instead of `"Remember Me"`).
28
+
29
+ ## v0.2.0 - 2015-06-23
30
+ ### Added
31
+ - [Luca Guidi] Introduced `Lotus::Helpers::FormHelper`. HTML5 form generator (`#form_for`).
32
+ - [Tom Kadwill & Luca Guidi] Introduced `Lotus::Helpers::NumberFormattingHelper`. Format numbers (`#format_number`).
33
+ - [Tom Kadwill] Introduced `Lotus::Helpers::LinkToHelper`. Link helper (`#link_to`).
34
+
35
+ ## v0.1.0 - 2015-03-23
36
+ ### Added
37
+ - [Luca Guidi] Introduced `Lotus::Helpers::RoutingHelper`. It exposes `#routes` in views for compatibility with Lotus (`hanamirb` gem)
38
+ - [Alfonso Uceda Pompa] Introduced `Lotus::Helpers::EscapeHelper`. It implements OWASP/ESAPI suggestions for HTML, HTML attribute and URL escape helpers.
39
+ - [Luca Guidi] Introduced `Lotus::Helpers::HtmlHelper`. It allows to generate complex HTML5 markup with Ruby.
data/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014-2016 Luca Guidi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,8 +1,28 @@
1
1
  # Hanami::Helpers
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/hanami/helpers`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ View helpers for Ruby applications
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ ## Status
6
+
7
+ [![Gem Version](http://img.shields.io/gem/v/hanami-helpers.svg)](https://badge.fury.io/rb/hanami-helpers)
8
+ [![Build Status](http://img.shields.io/travis/hanami/helpers/master.svg)](https://travis-ci.org/hanami/helpers?branch=master)
9
+ [![Coverage](http://img.shields.io/coveralls/hanami/helpers/master.svg)](https://coveralls.io/r/hanami/helpers)
10
+ [![Code Climate](http://img.shields.io/codeclimate/github/hanami/helpers.svg)](https://codeclimate.com/github/hanami/helpers)
11
+ [![Dependencies](http://img.shields.io/gemnasium/hanami/helpers.svg)](https://gemnasium.com/hanami/helpers)
12
+ [![Inline Docs](http://inch-ci.org/github/hanami/helpers.svg)](http://inch-ci.org/github/hanami/helpers)
13
+
14
+ ## Contact
15
+
16
+ * Home page: http://hanamirb.org
17
+ * Mailing List: http://hanamirb.org/mailing-list
18
+ * API Doc: http://rdoc.info/gems/hanami-helpers
19
+ * Bugs/Issues: https://github.com/hanami/helpers/issues
20
+ * Support: http://stackoverflow.com/questions/tagged/hanami
21
+ * Chat: https//chat.hanamirb.org
22
+
23
+ ## Rubies
24
+
25
+ __Hanami::Helpers__ supports Ruby (MRI) 2.2+
6
26
 
7
27
  ## Installation
8
28
 
@@ -14,23 +34,356 @@ gem 'hanami-helpers'
14
34
 
15
35
  And then execute:
16
36
 
17
- $ bundle
37
+ ```shell
38
+ $ bundle
39
+ ```
18
40
 
19
41
  Or install it yourself as:
20
42
 
21
- $ gem install hanami-helpers
43
+ ```shell
44
+ $ gem install hanami-helpers
45
+ ```
22
46
 
23
47
  ## Usage
24
48
 
25
- TODO: Write usage instructions here
49
+ `Hanami::Helpers` offers a set of utilities to enrich web views.
50
+
51
+ ### HTML helper
52
+
53
+ HTML5 markup generator (`#html`).
26
54
 
27
- ## Development
55
+ View:
56
+
57
+ ```ruby
58
+ module Users
59
+ class Show
60
+ include Hanami::Helpers
61
+
62
+ def sidebar
63
+ html.aside(id: 'sidebar') do
64
+ p "Languages", class: 'title'
65
+
66
+ ul do
67
+ li "Italian"
68
+ li "English"
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ ```
75
+
76
+ Template:
77
+
78
+ ```erb
79
+ <%= sidebar %>
80
+ ```
28
81
 
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
82
+ Output:
30
83
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
84
+ ```html
85
+ <aside id="sidebar">
86
+ <p class="title">Languages</p>
87
+
88
+ <ul>
89
+ <li>Italian</li>
90
+ <li>English</li>
91
+ </ul>
92
+ </aside>
93
+ ```
94
+
95
+ ### Form Helper
96
+
97
+ Form generator for HTML5 (`#form_for`)
98
+
99
+ #### Template Usage
100
+
101
+ Template:
102
+
103
+ ```erb
104
+ <%=
105
+ form_for :book, routes.books_path do
106
+ text_field :title
107
+
108
+ submit 'Create'
109
+ end
110
+ %>
111
+ ```
112
+
113
+ Output:
114
+
115
+ ```html
116
+ <form action="/books" method="POST" accept-charset="utf-8" id="book-form">
117
+ <input type="text" name="book[title]" id="book-id" value="">
118
+ <button type="submit">Create</button>
119
+ </form>
120
+ ```
121
+
122
+ #### View Usage
123
+
124
+ View:
125
+
126
+ ```ruby
127
+ module Books
128
+ class New
129
+ include Hanami::Helpers
130
+
131
+ def form
132
+ form_for :book, routes.books_path do
133
+ text_field :title
134
+
135
+ submit 'Create'
136
+ end
137
+ end
138
+ end
139
+ end
140
+ ```
141
+
142
+ Template:
143
+
144
+ ```erb
145
+ <%= form %>
146
+ ```
147
+
148
+ Output:
149
+
150
+ ```html
151
+ <form action="/books" method="POST" accept-charset="utf-8" id="book-form">
152
+ <input type="text" name="book[title]" id="book-id" value="">
153
+ <button type="submit">Create</button>
154
+ </form>
155
+ ```
156
+
157
+ #### Reuse Code
158
+
159
+ Views:
160
+
161
+ ```ruby
162
+ module Books
163
+ class New
164
+ include Hanami::Helpers
165
+
166
+ def form
167
+ Form.new(:book, routes.books_path)
168
+ end
169
+
170
+ def submit_label
171
+ 'Create'
172
+ end
173
+ end
174
+
175
+ class Edit
176
+ include Hanami::Helpers
177
+
178
+ def form
179
+ Form.new(:book, routes.book_path(id: book.id), {book: book}, {method: :patch})
180
+ end
181
+
182
+ def submit_label
183
+ 'Update'
184
+ end
185
+ end
186
+ end
187
+ ```
188
+
189
+ Templates:
190
+
191
+ ```erb
192
+ # books/new.html.erb
193
+ <%= render partial: 'books/form' %>
194
+ ```
195
+
196
+ ```erb
197
+ # books/edit.html.erb
198
+ <%= render partial: 'books/form' %>
199
+ ```
200
+
201
+ ```erb
202
+ # books/_form.html.erb
203
+ <%=
204
+ form_for form, class: 'form-horizontal' do
205
+ text_field :title
206
+
207
+ submit submit_label
208
+ end
209
+ %>
210
+ ```
211
+
212
+ Output for new:
213
+
214
+ ```html
215
+ <form action="/books" method="POST" accept-charset="utf-8" id="book-form">
216
+ <input type="text" name="book[title]" id="book-id" value="">
217
+ <button type="submit">Create</button>
218
+ </form>
219
+ ```
220
+
221
+ Output for edit:
222
+
223
+ ```html
224
+ <form action="/books/23" method="POST" accept-charset="utf-8" id="book-form">
225
+ <input type="hidden" name="_method" value="PATCH">
226
+ <input type="text" name="book[title]" id="book-id" value="TDD">
227
+ <button type="submit">Update</button>
228
+ </form>
229
+ ```
230
+
231
+ ### Escape helper
232
+
233
+ HTML (`#h`), HTML attribute (`#ha`) and URL (`#hu`) escape helpers.
234
+
235
+ View:
236
+
237
+ ```ruby
238
+ module Users
239
+ class Show
240
+ include Hanami::Helpers
241
+
242
+ def home_page_link
243
+ %(<a href="#{ hu(user.home_page_url) }" title="#{ ha(user.name} }'s website">#{ h(user.website_name) }</a>)
244
+ end
245
+
246
+ def code_snippet
247
+ raw user.code_snippet
248
+ end
249
+ end
250
+ end
251
+ ```
252
+
253
+ Template:
254
+
255
+ ```erb
256
+ <%= home_page_link %>
257
+ <%= code_snippet %>
258
+ ```
259
+
260
+ Output:
261
+
262
+ ```html
263
+ <a href="https://example.org" title="Maria's website">My Blog</a>
264
+ <code>puts "Hello, World!"</code>
265
+ ```
266
+
267
+ ### Routing Helper
268
+
269
+ Hanami and Hanami::Router integration (`#routes`).
270
+
271
+ View:
272
+
273
+ ```ruby
274
+ module Home
275
+ class Index
276
+ include Hanami::Helpers
277
+
278
+ def link_to_home
279
+ %(<a href="#{ routes.home_path }">Home</a>)
280
+ end
281
+ end
282
+ end
283
+ ```
284
+
285
+ Template:
286
+
287
+ ```erb
288
+ <%= link_to_home %>
289
+ ```
290
+
291
+ Output:
292
+
293
+ ```html
294
+ <a href="/">Home</a>
295
+ ```
296
+
297
+ ### Number Formatting Helper
298
+
299
+ Format numbers (`#format_number`).
300
+
301
+ View:
302
+
303
+ ```ruby
304
+ module Home
305
+ class Index
306
+ include Hanami::Helpers
307
+
308
+ def visitors_count
309
+ format_number '1000'
310
+ end
311
+ end
312
+ end
313
+ ```
314
+
315
+ Template:
316
+
317
+ ```erb
318
+ <p><%= visitors_count %></p>
319
+ ```
320
+
321
+ Output:
322
+
323
+ ```html
324
+ <p>1,000</p>
325
+ ```
326
+
327
+ ## Philosophy
328
+
329
+ All the Hanami helpers are modules to include.
330
+
331
+ Most of the time they inject **private** methods.
332
+ This restriction prevents helper methods to be used on the outside (eg. in a template).
333
+
334
+ We want to encourage developers to use **meaningful** and **simple APIs** in their templates.
335
+
336
+ ### Bad style example
337
+
338
+ ```ruby
339
+ module Users
340
+ class Show
341
+ include Hanami::Helpers
342
+ end
343
+ end
344
+ ```
345
+
346
+ ```erb
347
+ <%= format_number user.followers_count %>
348
+ ```
349
+
350
+ This style increases the complexity of the template and it makes testing hard.
351
+
352
+ ### Good style example
353
+
354
+ ```ruby
355
+ module Users
356
+ class Show
357
+ include Hanami::Helpers
358
+
359
+ def followers_count
360
+ format_number user.followers_count
361
+ end
362
+ end
363
+ end
364
+ ```
365
+
366
+ ```erb
367
+ <%= followers_count %>
368
+ ```
369
+
370
+ This simplifies the markup.
371
+ In order to test the value that will be printed becomes easier: `Users::Show#followers_count`.
372
+
373
+ ## Versioning
374
+
375
+ __Hanami::Helpers__ uses [Semantic Versioning 2.0.0](http://semver.org)
32
376
 
33
377
  ## Contributing
34
378
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/hanami-helpers.
379
+ 1. Fork it ( https://github.com/hanami/helpers/fork )
380
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
381
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
382
+ 4. Push to the branch (`git push origin my-new-feature`)
383
+ 5. Create a new Pull Request
384
+
385
+ ## Copyright
386
+
387
+ Copyright © 2014-2016 Luca Guidi – Released under MIT License
36
388
 
389
+ This project was formerly known as Lotus (`lotus-helpers`).