Sha256: 50c6701df38450d2ed28cd04c3a9cfa60e344e6302a01ad3448e0dbac9d51e6c

Contents?: true

Size: 1.19 KB

Versions: 24

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true
# xxxxxxx spec
module Handlebarsjs
  module Helpers
    # Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.
    module Comparison
      # And: Block helper that renders a block if **all of** the given values are truthy. If an inverse block is specified it will be rendered when falsy.
      class And < Handlebarsjs::BaseHelper
        # Parse will And: Block helper that renders a block if **all of** the given values are truthy. If an inverse block is specified it will be rendered when falsy.
        #
        # @example
        #
        # {{#if (and p1 p2 p3 p4 p5)}}
        #   found
        # {{/if}}
        #
        # @example
        #
        # @example
        # {{#if (and name age)}}
        #   {{name}}-{{age}}
        # {{else}}
        #   no name or age
        # {{/if}}
        #
        # @param values list of values (via *splat) to be checked via AND condition
        # @return [String] return block when every value is truthy
        def parse(values)
          values.all? { |value| value }
        end

        def to_proc
          ->(*values, _opts) { wrapper(parse(values[0..-2])) }
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
handlebarsjs-0.14.2 .builders/.templates/helper_spec.rb
handlebarsjs-0.14.1 .builders/.templates/helper_spec.rb
handlebarsjs-0.14.0 .builders/.templates/helper_spec.rb
handlebarsjs-0.13.1 .builders/.templates/helper_spec.rb
handlebarsjs-0.13.0 .builders/.templates/helper_spec.rb
handlebarsjs-0.12.0 .builders/.templates/helper_spec.rb
handlebarsjs-0.11.3 .builders/.templates/helper_spec.rb
handlebarsjs-0.11.2 .builders/.templates/helper_spec.rb
handlebarsjs-0.11.1 .builders/.templates/helper_spec.rb
handlebarsjs-0.11.0 .builders/.templates/helper_spec.rb
handlebarsjs-0.10.0 .builders/.templates/helper_spec.rb
handlebarsjs-0.9.0 .builders/.templates/helper_spec.rb
handlebarsjs-0.8.0 .builders/.templates/helper_spec.rb
handlebarsjs-0.7.0 .builders/.templates/helper_spec.rb
handlebarsjs-0.6.3 .builders/.templates/helper_spec.rb
handlebarsjs-0.6.2 .builders/.templates/helper_spec.rb
handlebarsjs-0.6.1 .builders/.templates/helper_spec.rb
handlebarsjs-0.6.0 .builders/.templates/helper_spec.rb
handlebarsjs-0.5.7 .builders/.templates/helper_spec.rb
handlebarsjs-0.5.6 .builders/.templates/helper_spec.rb