Sha256: febc1720119316a7d1b9124b242bdc020f2a6ed1412bf83b355e7f07b5aa9fff

Contents?: true

Size: 1.05 KB

Versions: 12

Compression:

Stored size: 1.05 KB

Contents

module ExpressTemplates
  module Components
    class UnlessBlock < Components::Container

      attr :conditional

      def initialize(*args)
        @conditional = args.shift
        @alt = args.shift[:alt] if args.first.kind_of?(Hash)
        parent = args.shift
        if @conditional.kind_of?(Symbol)
          @conditional = @conditional.to_s
        elsif @conditional.kind_of?(Proc)
          @conditional = "(#{@conditional.source}.call)"
        elsif iterator.kind_of?(String)
          @conditional = "(#{@conditional}.call)"
        else
          raise "UnlessBlock unknown conditional: #{@conditional.inspect}"
        end

        if @alt.kind_of?(Proc)
          @alt = _compile_fragment @alt
        elsif @alt.nil?
          @alt = "''"
        end
      end

      def compile
        s = unless @alt
          %Q((unless #{@conditional}#{compile_children}\nend))
        else
          %Q((unless #{@conditional}#{compile_children}\nelse #{@alt}\nend))
        end
        puts s if ENV['DEBUG'].eql?('true')
        s
      end

    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
express_admin-1.2.1 vendor/gems/express_templates/lib/express_templates/components/unless_block.rb
express_admin-1.2.0 vendor/gems/express_templates/lib/express_templates/components/unless_block.rb
express_templates-0.5.0 lib/express_templates/components/unless_block.rb
express_templates-0.4.2 lib/express_templates/components/unless_block.rb
express_templates-0.4.1 lib/express_templates/components/unless_block.rb
express_templates-0.4.0 lib/express_templates/components/unless_block.rb
express_templates-0.3.6 lib/express_templates/components/unless_block.rb
express_templates-0.3.5 lib/express_templates/components/unless_block.rb
express_templates-0.3.4 lib/express_templates/components/unless_block.rb
express_templates-0.3.2 lib/express_templates/components/unless_block.rb
express_templates-0.3.1 lib/express_templates/components/unless_block.rb
express_templates-0.3.0 lib/express_templates/components/unless_block.rb