Module: ModeratorHelper
- Defined in:
- /var/apps/qpixel/app/helpers/moderator_helper.rb
Overview
Provides helper methods for use by views under ModeratorController.
Instance Method Summary collapse
-
#split_hash_ip(ip, salting_user) ⇒ [String, [String?]]
Split an IP address into an array of hashed octets (well, hexadecets for IPv6).
-
#text_bg(cls, content = nil, **opts) {|context| ... } ⇒ ActiveSupport::SafeBuffer
Display text on a specified background color.
Instance Method Details
#split_hash_ip(ip, salting_user) ⇒ [String, [String?]]
Split an IP address into an array of hashed octets (well, hexadecets for IPv6). must use the same user for each IP address you wish to compare, even if sourced from a different user.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File '/var/apps/qpixel/app/helpers/moderator_helper.rb', line 26 def split_hash_ip(ip, salting_user) begin addr = IPAddress.parse(ip) rescue ArgumentError return ['', []] end splat = if addr.ipv6? addr.hexs else addr.octets end salt = BCrypt::Password.new(salting_user.encrypted_password).salt splat = splat.map { |p| Digest::SHA2.hexdigest(salt + p.to_s) } [ addr.ipv6? ? 'IPv6' : 'IPv4', splat ] end |
#text_bg(cls, content = nil, **opts) {|context| ... } ⇒ ActiveSupport::SafeBuffer
Display text on a specified background color. For instance, if the background color is dark, consider passing a class for a light text color.
12 13 14 15 16 17 18 |
# File '/var/apps/qpixel/app/helpers/moderator_helper.rb', line 12 def text_bg(cls, content = nil, **opts, &block) if block_given? tag.span class: ["has-background-color-#{cls}", opts[:class]].join(' '), &block else tag.span content, class: ["has-background-color-#{cls}", opts[:class]].join(' ') end end |