Sha256: a0d98367151045dd87cb7130083a2e17bfc6e0d8ef2aeec7b86b9a312ba9a92e

Contents?: true

Size: 1.31 KB

Versions: 9

Compression:

Stored size: 1.31 KB

Contents

class Roda
  module RodaPlugins
    # The partials plugin adds a +partial+ method, which renders 
    # templates without the layout.
    # 
    #   plugin :partials, :views => 'path/2/views'
    # 
    # Template files are prefixed with an underscore:
    #
    #   partial('test')     # uses _test.erb
    #   partial('dir/test') # uses dir/_test.erb
    #
    # This is basically equivalent to:
    #
    #   render('_test')
    #   render('dir/_test')
    #
    # Note that this plugin automatically loads the :render plugin.
    module Partials
      OPTS = {}.freeze
      SLASH = '/'.freeze

      # Depend on the render plugin, since this overrides
      # some of its methods.
      def self.load_dependencies(app, opts=OPTS)
        app.plugin :render, opts
      end

      module InstanceMethods
        # Renders the given template without a layout, but
        # prefixes the template filename to use with an 
        # underscore.
        def partial(template, opts=OPTS)
          opts = parse_template_opts(template, opts)
          if opts[:template]
            template = opts[:template].split(SLASH)
            template[-1] = "_#{template[-1]}"
            opts[:template] = template.join(SLASH)
          end
          render_template(opts)
        end
      end
    end

    register_plugin(:partials, Partials)
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
roda-2.9.0 lib/roda/plugins/partials.rb
roda-2.8.0 lib/roda/plugins/partials.rb
roda-2.7.0 lib/roda/plugins/partials.rb
roda-2.6.0 lib/roda/plugins/partials.rb
roda-2.5.1 lib/roda/plugins/partials.rb
roda-2.5.0 lib/roda/plugins/partials.rb
roda-2.4.0 lib/roda/plugins/partials.rb
roda-2.3.0 lib/roda/plugins/partials.rb
roda-2.2.0 lib/roda/plugins/partials.rb