Sha256: 41ba33ca34174a0d7912a3ee63dc893b57dacd9ef01ee61b3428b3bbc22a135d

Contents?: true

Size: 964 Bytes

Versions: 38

Compression:

Stored size: 964 Bytes

Contents

# frozen-string-literal: true

#
class Roda
  module RodaPlugins
    # The inject_erb plugin allows you to inject content directly
    # into the template output:
    #
    #   <% inject_erb("Some HTML Here") %>
    #
    # This will inject <tt>Some HTML Here</tt> into the template output,
    # even though the tag being used is <tt><%</tt> and not <tt><%=</tt>.
    #
    # This method can be used inside methods, such as to wrap calls to
    # methods that accept template blocks, to inject code before and after
    # the template blocks.
    module InjectERB
      def self.load_dependencies(app)
        app.plugin :render
      end

      module InstanceMethods
        # Inject into the template output for the template currently being
        # rendered.
        def inject_erb(value)
          instance_variable_get(render_opts[:template_opts][:outvar]) << value.to_s
        end
      end
    end

    register_plugin(:inject_erb, InjectERB)
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
roda-3.88.0 lib/roda/plugins/inject_erb.rb
roda-3.87.0 lib/roda/plugins/inject_erb.rb
roda-3.86.0 lib/roda/plugins/inject_erb.rb
roda-3.85.0 lib/roda/plugins/inject_erb.rb
roda-3.84.0 lib/roda/plugins/inject_erb.rb
roda-3.83.0 lib/roda/plugins/inject_erb.rb
roda-3.82.0 lib/roda/plugins/inject_erb.rb
roda-3.81.0 lib/roda/plugins/inject_erb.rb
roda-3.79.0 lib/roda/plugins/inject_erb.rb
roda-3.78.0 lib/roda/plugins/inject_erb.rb
roda-3.77.0 lib/roda/plugins/inject_erb.rb
roda-3.76.0 lib/roda/plugins/inject_erb.rb
roda-3.75.0 lib/roda/plugins/inject_erb.rb
roda-3.74.0 lib/roda/plugins/inject_erb.rb
roda-3.73.0 lib/roda/plugins/inject_erb.rb
roda-3.72.0 lib/roda/plugins/inject_erb.rb
roda-3.71.0 lib/roda/plugins/inject_erb.rb
roda-3.70.0 lib/roda/plugins/inject_erb.rb
roda-3.69.0 lib/roda/plugins/inject_erb.rb
roda-3.68.0 lib/roda/plugins/inject_erb.rb