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

Commit

Permalink
Add config for prerender by default
Browse files Browse the repository at this point in the history
  • Loading branch information
nning committed Jul 10, 2020
1 parent 10502fa commit 218a749
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ https://github.com/nning/svelte-rails-demo/commits/master

```erb
<%= svelte_component :Hello, name: 'Svelte' %>
<%= svelte_component :Hello, {name: 'Svelte'}, {prerender: true} %>
```

## Controller Renderer
Expand All @@ -55,6 +56,13 @@ end
* Render pools
* Better documentation for setup

## Configuration Options

Configuration can be changed in `config/application.rb`, for example.

# Prerender (SSR) by default (i.e. without passing `prerender:true` to the view helper)
config.svelte.prerender_default = false

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/nning/svelte-rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/nning/svelte-rails/blob/master/CODE_OF_CONDUCT.md).
Expand Down
5 changes: 5 additions & 0 deletions lib/svelte/rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

module Svelte::Rails
class Railtie < ::Rails::Railtie
config.svelte = ActiveSupport::OrderedOptions.new

# Prerender (SSR) by default (i.e. without passing `prerender:true` to the view helper)
config.svelte.predender_default = false

initializer 'svelte_rails.setup_view_helpers', after: :load_config_initializers, group: :all do |app|
ActiveSupport.on_load(:action_view) do
include ::Svelte::Rails::ViewHelper
Expand Down
5 changes: 5 additions & 0 deletions lib/svelte/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ class Renderer

def render(name, props = {}, options = {}, &block)
prerender_options = options[:prerender]

if prerender_options.nil?
prerender_options = ::Rails.application.config.svelte.prerender_default
end

if prerender_options
block = Proc.new { concat(prerender_component(name, props, prerender_options)) }
end
Expand Down

0 comments on commit 218a749

Please sign in to comment.