Sha256: 2e00206b0d61bcb59786ac43e3b66eb39041f6a9a5e8cad09f231a30e32806c3

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

module Hyde
  module Helpers
    def partial(partial_path, locals = {})
      begin
        p = project[partial_path.to_s, :Partial]
        p.referrer = (referrer || self)
        p.render locals

      rescue ::Hyde::NotFound
        "<!-- Can't find #{partial_path.to_s} -->"
      end
    end

    def content_for(key, &block)
      content_block[key.to_sym] = block
    end

    def has_content?(key)
      content_block.keys.include? key.to_sym
    end

    def yield_content(key, *args, &default_block)
      block = content_block[key.to_sym]

      if respond_to?(:block_is_haml?) && block_is_haml?(block)
        capture_haml *args, &block

      elsif block.respond_to?(:call)
        block.call *args

      elsif block_given? and respond_to(:block_is_haml?) and block_is_haml?(default_block)
        capture_haml *args, &default_block

      elsif block_given?
        yield

      else
        ''
      end
    end

  protected
    def content_block
      file_key = (referrer || self).to_sym
      @@content_blocks ||= Hash.new
      @@content_blocks[file_key] ||= Hash.new
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hydeweb-0.0.8.pre2 lib/hyde/helpers.rb
hydeweb-0.0.8.pre1 lib/hyde/helpers.rb
hydeweb-0.0.7 lib/hyde/helpers.rb