Sha256: e61c2e5d17cef1bdf8989460eba558ea4580dcee0c5f67cf2382b135f858b888

Contents?: true

Size: 824 Bytes

Versions: 6

Compression:

Stored size: 824 Bytes

Contents

module Roger
  class Template
    module Helpers
      # The partial helper
      module Partial
        def partial(name, locals = {}, &block)
          options = if locals[:locals]
                      locals
                    else
                      { locals: locals }
                    end
          if block_given?
            partial_with_block(name, options, &block)
          else
            renderer.render(name, options)
          end
        end

        protected

        # rubocop:disable Lint/Eval
        def partial_with_block(name, options, &block)
          block_content = capture(&block)
          result = renderer.render(name, options) { block_content }
          eval "_erbout.concat(#{result.dump})", block.binding
        end
        # rubocop:enable Lint/Eval
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
roger-1.10.0 lib/roger/template/helpers/partial.rb
roger-1.9.1 lib/roger/template/helpers/partial.rb
roger-1.9.0 lib/roger/template/helpers/partial.rb
roger-1.8.0 lib/roger/template/helpers/partial.rb
roger-1.7.2 lib/roger/template/helpers/partial.rb
roger-1.7.1 lib/roger/template/helpers/partial.rb