repolho 0.1.2 → 0.1.4
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.md +72 -0
- data/lib/repolho/version.rb +1 -1
- data/lib/repolho.rb +17 -0
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a3e4934d30d047214771997a27514e112e4fdeb21f7eed8aacb708780faef774
|
|
4
|
+
data.tar.gz: 0c3a81c167092259ca264d0b79187223686ad1057a42bd09c619539d8822f2a4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 628f99c9f6b261d09197974030b9d9e733914fe531762bed01ec524ed1c7f803d84efb5726dd67965aa7fbf3e3e87b80677eede46e941e7ef12e25a6f5046114
|
|
7
|
+
data.tar.gz: 891ede10e5b285ac7bd809b805fc7a3cbaecf432f5ed9c737cf63a986ef59ced396fa35b6172128d50bc696e13bbabdf580ef77210733ea120311a4572147314
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/README.md
CHANGED
|
@@ -230,8 +230,80 @@ To preview the structure, rename the file to `.html` and open it in a browser
|
|
|
230
230
|
| `count(:field)` | Number of values |
|
|
231
231
|
| `number` | Current page or group number |
|
|
232
232
|
|
|
233
|
+
## Rails helpers
|
|
234
|
+
|
|
235
|
+
You can make Rails view helpers available inside the ERB templates by calling
|
|
236
|
+
`Repolho.include_rails_helpers!`. By default it includes
|
|
237
|
+
`ActionView::Helpers::NumberHelper` (so you get `number_to_currency`,
|
|
238
|
+
`number_with_precision`, etc.).
|
|
239
|
+
|
|
240
|
+
### Inside a Rails application
|
|
241
|
+
|
|
242
|
+
```ruby
|
|
243
|
+
# config/initializers/repolho.rb
|
|
244
|
+
Repolho.include_rails_helpers!
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
After that you can use the helpers normally in any template:
|
|
248
|
+
|
|
249
|
+
```erb
|
|
250
|
+
<td class="text-end"><%= number_to_currency(attr(:value)) %></td>
|
|
251
|
+
<td><%= number_with_precision(sum(:value), precision: 2) %></td>
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
You can also pass extra modules:
|
|
255
|
+
|
|
256
|
+
```ruby
|
|
257
|
+
Repolho.include_rails_helpers!(
|
|
258
|
+
ActionView::Helpers::NumberHelper,
|
|
259
|
+
ActionView::Helpers::TextHelper
|
|
260
|
+
)
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### Outside Rails
|
|
264
|
+
|
|
265
|
+
You need the corresponding gems. Directly requiring the individual helper file
|
|
266
|
+
triggers an autoload problem in recent Rails versions, so load the helpers
|
|
267
|
+
framework first:
|
|
268
|
+
|
|
269
|
+
```ruby
|
|
270
|
+
# Gemfile
|
|
271
|
+
gem "actionview"
|
|
272
|
+
|
|
273
|
+
require "action_view"
|
|
274
|
+
require "action_view/helpers" # loads NumberHelper and the rest
|
|
275
|
+
Repolho.include_rails_helpers!
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
Alternatively (and often simpler), use `ActiveSupport::NumberHelper`, which is
|
|
279
|
+
designed to be used outside of a view context. The method names are almost the
|
|
280
|
+
same (`number_to_currency`, `number_to_rounded`, etc.):
|
|
281
|
+
|
|
282
|
+
```ruby
|
|
283
|
+
# Gemfile
|
|
284
|
+
gem "activesupport"
|
|
285
|
+
|
|
286
|
+
require "active_support/number_helper"
|
|
287
|
+
Repolho.include_rails_helpers!(ActiveSupport::NumberHelper)
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
Note: some method names differ slightly between the two modules
|
|
291
|
+
(`number_with_delimiter` vs `number_to_delimited`). Prefer the ActiveSupport
|
|
292
|
+
version when you are not inside Rails.
|
|
293
|
+
|
|
294
|
+
Instance variables from the Rails view (such as `@current_template`) are not
|
|
295
|
+
automatically copied. Pass them explicitly through the `locals` hash:
|
|
296
|
+
|
|
297
|
+
```ruby
|
|
298
|
+
Repolho::Main.new(path, data, current_template: @current_template, user: current_user)
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
They become `@current_template` and `@user` inside the templates.
|
|
302
|
+
|
|
303
|
+
|
|
233
304
|
## Signing
|
|
234
305
|
|
|
306
|
+
|
|
235
307
|
This gem is cryptographically signed. To verify the signature on install:
|
|
236
308
|
|
|
237
309
|
```bash
|
data/lib/repolho/version.rb
CHANGED
data/lib/repolho.rb
CHANGED
|
@@ -8,4 +8,21 @@ require_relative "repolho/report"
|
|
|
8
8
|
require_relative "repolho/main"
|
|
9
9
|
|
|
10
10
|
module Repolho
|
|
11
|
+
# Includes Rails helper modules into Container so they become available
|
|
12
|
+
# in ERB templates (headers, footers, rows, previous and after).
|
|
13
|
+
#
|
|
14
|
+
# By default includes ActionView::Helpers::NumberHelper.
|
|
15
|
+
# Pass additional modules if needed.
|
|
16
|
+
#
|
|
17
|
+
# Example:
|
|
18
|
+
# Repolho.include_rails_helpers!
|
|
19
|
+
# Repolho.include_rails_helpers!(ActionView::Helpers::NumberHelper, ActionView::Helpers::TextHelper)
|
|
20
|
+
def self.include_rails_helpers!(*modules)
|
|
21
|
+
modules = [ActionView::Helpers::NumberHelper] if modules.empty?
|
|
22
|
+
modules.each do |mod|
|
|
23
|
+
next if Container.include?(mod)
|
|
24
|
+
|
|
25
|
+
Container.include(mod)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
11
28
|
end
|
data.tar.gz.sig
CHANGED
|
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
|
Binary file
|