Skip to content

Commit

Permalink
Merge pull request #20 from aki77/0.9.0
Browse files Browse the repository at this point in the history
Fixing Issue with config.streaming Enabled in Rails 7.1
  • Loading branch information
aki77 authored Apr 19, 2024
2 parents 2c09f6d + 1dd56bf commit a012d08
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.9.0

- Fixing Issue with config.streaming Enabled in Rails 7.1 (#17)

## 0.8.0

- Add `csv_options` as an option to pass to `CSV.generate_line` (https://github.com/aki77/csb/pull/18)
Expand Down
28 changes: 28 additions & 0 deletions lib/csb/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,34 @@ class Railtie < Rails::Railtie
ActiveSupport.on_load :action_view do
require 'csb/handler'
ActionView::Template.register_template_handler :csb, Csb::Handler

# SEE: https://github.com/rails/rails/pull/51023
rails_version = Gem::Version.new(Rails.version)
if rails_version >= Gem::Version.new('7.1.0') && rails_version < Gem::Version.new('7.1.4')
ActionView::Template.prepend(Module.new do
# SEE: https://github.com/Shopify/rails/blob/0601929486398954a17b1985fcf7f9f0611d2d55/actionview/lib/action_view/template.rb#L262C5-L281C8
def render(view, locals, buffer = nil, implicit_locals: [], add_to_stack: true, &block)
instrument_render_template do
compile!(view)

if strict_locals? && @strict_local_keys && !implicit_locals.empty?
locals_to_ignore = implicit_locals - @strict_local_keys
locals.except!(*locals_to_ignore)
end

if buffer
view._run(method_name, self, locals, buffer, add_to_stack: add_to_stack, has_strict_locals: strict_locals?, &block)
nil
else
result = view._run(method_name, self, locals, ActionView::OutputBuffer.new, add_to_stack: add_to_stack, has_strict_locals: strict_locals?, &block)
result.is_a?(ActionView::OutputBuffer) ? result.to_s : result
end
end
rescue => e
handle_render_error(view, e)
end
end)
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/csb/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Csb
VERSION = '0.8.0'
VERSION = '0.9.0'
end

0 comments on commit a012d08

Please sign in to comment.