Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Commit

Permalink
Add controller renderer with additional names
Browse files Browse the repository at this point in the history
  • Loading branch information
nning committed Jul 10, 2020
1 parent d05377e commit 10502fa
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/svelte/rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ class Railtie < ::Rails::Railtie
end
end

initializer 'svelte_rails.add_component_renderer', group: :all do |app|
ActionController::Renderers.add :component do |component_name, options|
initializer 'svelte_rails.add_component_renderers', group: :all do |app|
render_component = lambda do |component_name, options|
renderer = ::Svelte::Rails::ControllerRenderer.new
html = renderer.call(component_name, options)
render_options = options.merge(inline: html)
render(render_options)
end

%i[component svelte svelte_component].each do |renderer_name|
ActionController::Renderers.add renderer_name, &render_component
end
end

rake_tasks do
Expand Down

0 comments on commit 10502fa

Please sign in to comment.