Sha256: a73a2ecd98877fbc25c6fe515202568d25f9fc66017be9ff992c71ed190609f1

Contents?: true

Size: 1.29 KB

Versions: 33

Compression:

Stored size: 1.29 KB

Contents

# frozen-string-literal: true

#
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
      # 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('/')
            template[-1] = "_#{template[-1]}"
            opts[:template] = template.join('/')
          end
          render_template(opts)
        end
      end
    end

    register_plugin(:partials, Partials)
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
roda-3.31.0 lib/roda/plugins/partials.rb
roda-3.30.0 lib/roda/plugins/partials.rb
roda-3.29.0 lib/roda/plugins/partials.rb
roda-3.28.0 lib/roda/plugins/partials.rb
roda-3.27.0 lib/roda/plugins/partials.rb
roda-3.26.0 lib/roda/plugins/partials.rb
roda-3.25.0 lib/roda/plugins/partials.rb
roda-3.24.0 lib/roda/plugins/partials.rb
roda-3.23.0 lib/roda/plugins/partials.rb
roda-3.22.0 lib/roda/plugins/partials.rb
roda-3.21.0 lib/roda/plugins/partials.rb
roda-3.20.0 lib/roda/plugins/partials.rb
roda-3.19.0 lib/roda/plugins/partials.rb
roda-3.18.0 lib/roda/plugins/partials.rb
roda-3.17.0 lib/roda/plugins/partials.rb
roda-3.16.0 lib/roda/plugins/partials.rb
roda-3.15.0 lib/roda/plugins/partials.rb
roda-3.14.1 lib/roda/plugins/partials.rb
roda-3.14.0 lib/roda/plugins/partials.rb
roda-3.13.0 lib/roda/plugins/partials.rb