binxtils 0.6.0 → 0.8.0
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
- data/README.md +8 -0
- data/app/controllers/concerns/binxtils/sortable_table.rb +6 -0
- data/lib/binxtils/input_normalizer.rb +13 -3
- data/lib/binxtils/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ae08f86d8d31882ed56c248ad820a66823606b09a5f5b429b35ea76eb5530cb7
|
|
4
|
+
data.tar.gz: 0e96c6e1230b26127f1ce6906df7b08db3d83a2b8c0bdc12d6824074ae39ac1d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8e0d408e004acbc45439477d6ea3e79e94f2975a3a1f4cb9a37bef1a6cbfcabf4935a884061e38e90b79fedcfe6e72f07e4aefd119c7b4a298e060d015b72924
|
|
7
|
+
data.tar.gz: 7ead69ca11aa5335956f0222b8892a29fc356067952d02c09840154bae0f41ccb530a1e70e586869363d70dc9734099b99fe9ae103b4a192ebbad1ed061f9b88
|
data/README.md
CHANGED
|
@@ -59,6 +59,14 @@ class BikesController < ApplicationController
|
|
|
59
59
|
end
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
+
Order with `sortable_order`, which applies `sort_direction` and puts nils last in both directions. It takes `sort_column` by default, or an Arel node or SQL string:
|
|
63
|
+
|
|
64
|
+
```ruby
|
|
65
|
+
Bike.order(sortable_order)
|
|
66
|
+
Bike.order(sortable_order(Bike.arel_table[sort_column].lower))
|
|
67
|
+
Bike.order(sortable_order("COALESCE((data -> 'bike_count')::integer, 0)"))
|
|
68
|
+
```
|
|
69
|
+
|
|
62
70
|
## npm package
|
|
63
71
|
|
|
64
72
|
This repo also publishes `@bikeindex/time-localizer`, an npm package for localizing time elements in the browser. It ships two builds of the same source:
|
|
@@ -18,6 +18,12 @@ module Binxtils
|
|
|
18
18
|
%w[asc desc].include?(params[:direction]) ? params[:direction] : default_direction
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
+
# Desc puts nils last, matching asc
|
|
22
|
+
def sortable_order(expression = sort_column)
|
|
23
|
+
node = expression.respond_to?(:asc) ? expression : Arel.sql(expression)
|
|
24
|
+
node.public_send(sort_direction).nulls_last
|
|
25
|
+
end
|
|
26
|
+
|
|
21
27
|
def permitted_time_range_columns
|
|
22
28
|
%w[created_at updated_at].freeze
|
|
23
29
|
end
|
|
@@ -20,6 +20,11 @@ module Binxtils
|
|
|
20
20
|
val.to_s.present?
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
+
def regex_escape(val)
|
|
24
|
+
# Lazy hack, good enough for current purposes. Improve if required!
|
|
25
|
+
string(val)&.gsub(/\W/, ".")
|
|
26
|
+
end
|
|
27
|
+
|
|
23
28
|
def sanitize(str = nil)
|
|
24
29
|
Rails::Html::Sanitizer.full_sanitizer.new.sanitize(str.to_s, encode_special_chars: true)
|
|
25
30
|
.strip
|
|
@@ -27,9 +32,14 @@ module Binxtils
|
|
|
27
32
|
.gsub(/\s+/, " ") # remove extra whitespace
|
|
28
33
|
end
|
|
29
34
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
# Plain text, so unlike sanitize: every entity is decoded and angle brackets stay literal
|
|
36
|
+
def plain_text(value = nil)
|
|
37
|
+
normalize_whitespace(CGI.unescapeHTML(Rails::Html::Sanitizer.full_sanitizer.new.sanitize(value.to_s)))
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# An HTML email's "blank" lines are often a , which String#strip doesn't count as whitespace
|
|
41
|
+
def normalize_whitespace(value = nil)
|
|
42
|
+
value.to_s.tr(" ", " ").lines.map(&:strip).join("\n").gsub(/\n{3,}/, "\n\n").strip
|
|
33
43
|
end
|
|
34
44
|
end
|
|
35
45
|
end
|
data/lib/binxtils/version.rb
CHANGED