Sha256: e8474f55358fca79f2ad7b0b4a66aaf59a2e519a3bb5d861a554d2a649f8d357

Contents?: true

Size: 1.38 KB

Versions: 17

Compression:

Stored size: 1.38 KB

Contents

module Locomotive
  module Steam
    module Liquid
      module Filters
        module Misc

          # was called modulo at first
          def str_modulo(word, index, modulo)
            (index.to_i + 1) % modulo == 0 ? word : ''
          end

          # Get the nth element of the passed in array
          def index(array, position)
            array.at(position) if array.respond_to?(:at)
          end

          def shuffle(array)
            array.to_a.shuffle
          end

          def default(input, value)
            input.blank? ? value : input
          end

          def random(input)
            rand(input.to_i)
          end

          # map/collect on a given property (support to_f, to_i)
          def map(input, property)
            ::Liquid::StandardFilters::InputIterator.new(input).map do |e|
              e = e.call if e.is_a?(Proc)

              if property == 'to_liquid'.freeze
                e
              elsif property == 'to_f'.freeze
                e.to_f
              elsif property == 'to_i'.freeze
                e.to_i
              elsif e.respond_to?(:[])
                e[property]
              end
            end

          end

          def hexdigest(input, key, digest = nil)
            OpenSSL::HMAC.hexdigest(digest || 'sha1', key, input)
          end

        end

        ::Liquid::Template.register_filter(Misc)

      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
locomotivecms_steam-1.5.0.rc0 lib/locomotive/steam/liquid/filters/misc.rb
locomotivecms_steam-1.5.0.beta3 lib/locomotive/steam/liquid/filters/misc.rb
locomotivecms_steam-1.5.0.beta2 lib/locomotive/steam/liquid/filters/misc.rb
locomotivecms_steam-1.5.0.beta1 lib/locomotive/steam/liquid/filters/misc.rb
locomotivecms_steam-1.4.1 lib/locomotive/steam/liquid/filters/misc.rb
locomotivecms_steam-1.4.0 lib/locomotive/steam/liquid/filters/misc.rb
locomotivecms_steam-1.4.0.rc2 lib/locomotive/steam/liquid/filters/misc.rb
locomotivecms_steam-1.4.0.rc1 lib/locomotive/steam/liquid/filters/misc.rb
locomotivecms_steam-1.4.0.pre.rc.1 lib/locomotive/steam/liquid/filters/misc.rb
locomotivecms_steam-1.3.0 lib/locomotive/steam/liquid/filters/misc.rb
locomotivecms_steam-1.3.0.rc2 lib/locomotive/steam/liquid/filters/misc.rb
locomotivecms_steam-1.2.1 lib/locomotive/steam/liquid/filters/misc.rb
locomotivecms_steam-1.3.0.rc1 lib/locomotive/steam/liquid/filters/misc.rb
locomotivecms_steam-1.2.0 lib/locomotive/steam/liquid/filters/misc.rb
locomotivecms_steam-1.2.0.rc3 lib/locomotive/steam/liquid/filters/misc.rb
locomotivecms_steam-1.2.0.rc2 lib/locomotive/steam/liquid/filters/misc.rb
locomotivecms_steam-1.2.0.rc1 lib/locomotive/steam/liquid/filters/misc.rb