Sha256: 31fe685578d1de78071956978898fe890015eefeee173e64a018c0855ab03820

Contents?: true

Size: 1.31 KB

Versions: 3

Compression:

Stored size: 1.31 KB

Contents

# -*- encoding : utf-8 -*-
# ============================================================================
#
#	RAILS BOOTSTRAP ENGINE
#
## ============================================================================
#
# Copyright 2012-2013 Luiz Eduardo de Oliveira Fonseca, AgĂȘncia Orangeweb
#
# Licensed under The MIT License
#
# http://opensource.org/licenses/MIT
#
module RailsBootstrapEngine

  class BootstrapMarkupCollection
    attr_accessor :calls, :view

    def initialize(view)
      @view = view
      @calls = []
    end

    def method_missing(symbol, *args, &block)
      @calls << HelperMethodCall.new(@view, symbol, args, block)
    end

    def each
      @calls.each do |c|
        yield c
      end
    end

    def [](x)
      @calls[x]
    end

    def size
      @calls.size
    end

    def shift
      @calls.shift
    end
  end

  class HelperMethodCall
    attr_accessor :method, :options, :args

    def initialize(view, symbol, args, block)
      @view    = view
      @method  = symbol
      @options = args.extract_options!
      @args    = args
      @block   = block
    end

    def to_s
      args = @args
      args << @options

      if @block
        @view.send(@method, *args, &@block).html_safe
      else
        @view.send(@method, *args).html_safe
      end
    end

  end
  
end #RailsBootstrapEngine

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rails-bootstrap-engine-0.0.5 lib/rails-bootstrap-engine/markup/bootstrap_markup_collection.rb
rails-bootstrap-engine-0.0.4 lib/rails-bootstrap-engine/markup/bootstrap_markup_collection.rb
rails-bootstrap-engine-0.0.3 lib/rails-bootstrap-engine/markup/bootstrap_markup_collection.rb