Sha256: b397fa8067dfb134cf2519098b429ae3f8f98f25578e0d600bdbdaa58855bfd3

Contents?: true

Size: 1.36 KB

Versions: 24

Compression:

Stored size: 1.36 KB

Contents

module Locomotive
  module Steam
    module Liquid
      module Filters
        module Number

          def money(input, *options)
            NumberProxyHelper.new(:currency, @context).invoke(input, options)
          end

          def percentage(input, *options)
            NumberProxyHelper.new(:percentage, @context).invoke(input, options)
          end

          def human_size(input, *options)
            NumberProxyHelper.new(:human_size, @context).invoke(input, options)
          end

          def mod(input, modulus)
            input.to_i % modulus.to_i
          end

          class NumberProxyHelper

            include ActiveSupport::NumberHelper

            def initialize(name, context)
              @name     = name
              @context  = context
            end

            def invoke(input, options)
              _options = parse_and_interpolate_options(options)
              send :"number_to_#{@name}", input, _options
            end

            def parse_and_interpolate_options(string_or_array)
              return {} if string_or_array.empty?

              string = [*string_or_array].flatten.join(', ')
              arguments = Solid::Arguments.parse(string)

              (arguments.interpolate(@context).first || {})
            end

          end

          ::Liquid::Template.register_filter(Number)

        end

      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

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