Sha256: e078808a5f6abe4024d5737e946286068f62dd2a2c13ab699dc5f62be686505f

Contents?: true

Size: 926 Bytes

Versions: 15

Compression:

Stored size: 926 Bytes

Contents

# -*- encoding: utf-8 -*-

module WatchTower
  module Server
    module Helpers
      module Presenters

        def self.included(base)
          base.send :include, InstanceMethods
        end

        module InstanceMethods

          # Define partial as a helper
          helpers do
            # Present an object
            # Usually called with a block, the method yields the presenter into
            # the block
            #
            # @param [ActiveRecord::Base] Object: The model to present
            # @param [Nil | Object] klass: The klass to present
            def present(object, klass = nil)
              klass ||= "::WatchTower::Server::Presenters::#{object.class.to_s.split('::').last}Presenter".constantize
              presenter = klass.new(object, self)
              yield presenter if block_given?
              presenter
            end
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
watch_tower-0.0.3 lib/watch_tower/server/helpers/presenters.rb
watch_tower-0.0.2 lib/watch_tower/server/helpers/presenters.rb
watch_tower-0.0.1 lib/watch_tower/server/helpers/presenters.rb
watch_tower-0.0.1.beta12 lib/watch_tower/server/helpers/presenters.rb
watch_tower-0.0.1.beta11 lib/watch_tower/server/helpers/presenters.rb
watch_tower-0.0.1.beta10 lib/watch_tower/server/helpers/presenters.rb
watch_tower-0.0.1.beta9 lib/watch_tower/server/helpers/presenters.rb
watch_tower-0.0.1.beta8 lib/watch_tower/server/helpers/presenters.rb
watch_tower-0.0.1.beta7 lib/watch_tower/server/helpers/presenters.rb
watch_tower-0.0.1.beta6 lib/watch_tower/server/helpers/presenters.rb
watch_tower-0.0.1.beta5 lib/watch_tower/server/helpers/presenters.rb
watch_tower-0.0.1.beta4 lib/watch_tower/server/helpers/presenters.rb
watch_tower-0.0.1.beta3 lib/watch_tower/server/helpers/presenters.rb
watch_tower-0.0.1.beta2 lib/watch_tower/server/helpers/presenters.rb
watch_tower-0.0.1.beta1 lib/watch_tower/server/helpers/presenters.rb