Sha256: 0d6fecfc769c0890d80e37cc759f6139a16eca5733d2c6f8ab3970fcdbe75fc8

Contents?: true

Size: 702 Bytes

Versions: 20

Compression:

Stored size: 702 Bytes

Contents

class Stasis
  class Helpers < Plugin

    controller_method :helpers
    before_render :before_render

    def initialize(stasis)
      @stasis = stasis
      @blocks = []
    end

    #  This event triggers before each file renders through Stasis. For each helper
    # `block`, evaluate the `block` in the scope of the `action` class.
    def before_render
      @blocks.each do |(path, block)|
        if _within?(path)
          @stasis.action.class.class_eval(&block)
        end
      end
    end

    # This method is bound to all controllers. Stores a block in the `@blocks` `Array`.
    def helpers(&block)
      if block
        @blocks << [ @stasis.path, block ]
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
stasis-0.1.19 lib/stasis/plugins/helpers.rb
stasis-0.1.18 lib/stasis/plugins/helpers.rb
stasis-0.1.17 lib/stasis/plugins/helpers.rb
stasis-0.1.16 lib/stasis/plugins/helpers.rb
stasis-0.1.15 lib/stasis/plugins/helpers.rb
stasis-0.1.14 lib/stasis/plugins/helpers.rb
stasis-0.1.13 lib/stasis/plugins/helpers.rb
stasis-0.1.12 lib/stasis/plugins/helpers.rb
stasis-0.1.11 lib/stasis/plugins/helpers.rb
stasis-0.1.10 lib/stasis/plugins/helpers.rb
stasis-0.1.9 lib/stasis/plugins/helpers.rb
stasis-0.1.8 lib/stasis/plugins/helpers.rb
stasis-0.1.7 lib/stasis/plugins/helpers.rb
stasis-0.1.6 lib/stasis/plugins/helpers.rb
stasis-0.1.5 lib/stasis/plugins/helpers.rb
stasis-0.1.4 lib/stasis/plugins/helpers.rb
stasis-0.1.3 lib/stasis/plugins/helpers.rb
stasis-0.1.2 lib/stasis/plugins/helpers.rb
stasis-0.1.1 lib/stasis/plugins/helpers.rb
stasis-0.1.0 lib/stasis/plugins/helpers.rb