Sha256: c4f468aff35336955bd5e830ff14ae070a751a5aaedabf1d450662b9d6d85703

Contents?: true

Size: 591 Bytes

Versions: 3

Compression:

Stored size: 591 Bytes

Contents

module Hotcell
  module Commands
    class Unless < Hotcell::Block
      subcommand else: Hotcell::Commands::If::Else
      validate_arguments_count 1

      def validate!
        raise Hotcell::BlockError.new(
          "Unexpected `#{subcommands[1].name}` for `#{name}` command",
          *subcommands[1].position_info
        ) if subcommands[1]

        super
      end

      def process context, condition
        condition ? subnodes[2].try(:render, context) : subnodes[0].try(:render, context)
      end
    end
  end
end

Hotcell.register_command unless: Hotcell::Commands::Unless

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hotcell-0.3.0 lib/hotcell/commands/unless.rb
hotcell-0.2.0 lib/hotcell/commands/unless.rb
hotcell-0.1.0 lib/hotcell/commands/unless.rb