Sha256: 7051a435098acc782a3c2d691ee5dae756cef2e6e33e67feecccdb3df68f406b

Contents?: true

Size: 979 Bytes

Versions: 10

Compression:

Stored size: 979 Bytes

Contents

# frozen_string_literal: true
module Temple
  module Generators
    # Implements a rails output buffer.
    #
    #   @output_buffer = ActiveSupport::SafeBuffer
    #   @output_buffer.safe_concat "static"
    #   @output_buffer.safe_concat dynamic.to_s
    #   @output_buffer
    #
    # @api public
    class RailsOutputBuffer < StringBuffer
      define_options :streaming, # ignored
                     buffer_class: 'ActionView::OutputBuffer',
                     buffer: '@output_buffer',
                     capture_generator: RailsOutputBuffer

      def call(exp)
        [preamble, compile(exp), postamble].flatten.compact.join('; '.freeze)
      end

      def create_buffer
        if buffer == '@output_buffer'
          "#{buffer} = output_buffer || #{options[:buffer_class]}.new"
        else
          "#{buffer} = #{options[:buffer_class]}.new"
        end
      end

      def concat(str)
        "#{buffer}.safe_concat((#{str}))"
      end
    end
  end
end

Version data entries

10 entries across 9 versions & 3 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/temple-0.10.3/lib/temple/generators/rails_output_buffer.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/temple-0.10.3/lib/temple/generators/rails_output_buffer.rb
brakeman-7.0.0 bundle/ruby/3.1.0/gems/temple-0.10.3/lib/temple/generators/rails_output_buffer.rb
brakeman-6.2.2 bundle/ruby/3.1.0/gems/temple-0.10.3/lib/temple/generators/rails_output_buffer.rb
brakeman-6.2.2.rc1 bundle/ruby/3.3.0/gems/temple-0.10.3/lib/temple/generators/rails_output_buffer.rb
brakeman-6.2.1 bundle/ruby/3.1.0/gems/temple-0.10.3/lib/temple/generators/rails_output_buffer.rb
brakeman-6.2.0 bundle/ruby/3.1.0/gems/temple-0.10.3/lib/temple/generators/rails_output_buffer.rb
temple-0.10.3 lib/temple/generators/rails_output_buffer.rb
temple-0.10.2 lib/temple/generators/rails_output_buffer.rb
temple-0.10.1 lib/temple/generators/rails_output_buffer.rb