class Bytewise::Helpers::ForHelper

Public Instance Methods

render(each:, as: :value, key: :key) click to toggle source
# File lib/brace_markup/helpers/for.rb, line 5
def render(each:, as: :value, key: :key)
  output = ''

  if each.is_a? Array
    each.each_with_index do |value, index|
      ctx = @context.clone
      ctx.vars[as.to_sym] = value
      ctx.vars[key.to_sym] = index

      output += @tag.body.render(ctx)
    end
  end

  output
end