Sha256: 95739c6d723c81ca72953da1d12f81f684b71573a148fa28d0e27c0349970243

Contents?: true

Size: 1.46 KB

Versions: 4

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

# reference: https://github.com/rails/rails/blob/master/activesupport/lib/active_support/inflector/methods.rb
# require 'active_support/core_ext/string'

# require 'handlebars/helpers/base_helper'

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.
      # < Handlebars::Helpers::BaseHelper
      class And
        # 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 handlebars_helper
          # Exclude last paramater which is the context V8::Object
          proc { |_context, *values| wrapper(parse(values[0..-2])) }
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
handlebarsjs-0.4.0 lib/handlebarsjs/helpers/comparison/and.rb
handlebarsjs-0.3.0 lib/handlebarsjs/helpers/comparison/and.rb
handlebarsjs-0.2.0 lib/handlebarsjs/helpers/comparison/and.rb
handlebarsjs-0.1.2 lib/handlebarsjs/helpers/comparison/and.rb