Sha256: d071755a26d81aa505bcd3a528f6683ea8dc28db3678d8b8eaaa590835c88daf

Contents?: true

Size: 747 Bytes

Versions: 4

Compression:

Stored size: 747 Bytes

Contents

# Simple hex conversion Liquid filter plugin
#
# Convert a string of hex values into an array of decimal values.
#
# Examples:
#   {{ "aabbcc" | hex_to_rgb }}
#   # => [170, 187, 204]
#
#   {{ "abc" | hex_to_rgb }}
#   # => [170, 187, 204]
#
#   {{ "0a0b0c" | hex_to_rgb }}
#   # => [10, 11, 12]
#
# hexval - string of valid hexidecimal characters
#
# Returns an array of decimal values for the parse hex characters
#

module Jekyll
  module HexToRGB
    def hex_to_rgb(hexval)
      if hexval.length.even?
        hexval.scan(/../).map {|color| color.to_i(16)}
      else
        hexval.scan(/./).map {|color| (color+color).to_i(16)}
      end
    end
  end
end

Liquid::Template.register_filter(Jekyll::HexToRGB)

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vliz-be-theme-0.4.4 _plugins/hex_to_rgb.rb
vliz-be-theme-0.4.3 _plugins/hex_to_rgb.rb
vliz-be-theme-0.4.1 _plugins/hex_to_rgb.rb
vliz-be-theme-0.4.0 _plugins/hex_to_rgb.rb