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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5d72b64353d985a2d1473b717fe1adff0e04c89af0d62ef6b5a1a1af9d274509
4
- data.tar.gz: dc3707cc25fd903d65bddca88af6eeea7ea1e05abad11ae17f9f53b2afacc880
3
+ metadata.gz: ae08f86d8d31882ed56c248ad820a66823606b09a5f5b429b35ea76eb5530cb7
4
+ data.tar.gz: 0e96c6e1230b26127f1ce6906df7b08db3d83a2b8c0bdc12d6824074ae39ac1d
5
5
  SHA512:
6
- metadata.gz: 965dbfb38c5dc90180f92ebd1ca5a1403d39cc4688183c42ee474d859efc396387453eec0647ec04a67b57df64a10b05bf29b99294a5d72c2f6f4e80b35f1a9f
7
- data.tar.gz: b3a516d70a73ae33f9d4486f23c292f6f644c4a341e591c07d83d67737813e1cda77b6f3649a268887bd6902e611cbabe83f0ae76c291ab339f825c790e365d4
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
- def regex_escape(val)
31
- # Lazy hack, good enough for current purposes. Improve if required!
32
- string(val)&.gsub(/\W/, ".")
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 &nbsp;, 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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Binxtils
4
- VERSION = "0.6.0"
4
+ VERSION = "0.8.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: binxtils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bike Index