` or a `
` are rendered. Those custom elements have an `IntersectionObserver` attached that will send a signed global id to an ActionCable channel (`FuturismChannel`) which will then replace the placeholders with the actual resource partial.
With that method, you could lazy load every class that has to_partial_path defined (ActiveModel has by default).
You can pass the placeholder as a block:
```erb
<%= futurize @posts, extends: :tr do %>
|
<% end %>
```
![aa601dec1930151f71dbf0d6b02b61c9](https://user-images.githubusercontent.com/4352208/87131629-f768a480-c294-11ea-89a9-ea0a76ee06ef.gif)
## API
Currently there are two ways to call `futurize`, designed to wrap `render`'s behavior:
### Resource
You can pass a single `ActiveRecord` or an `ActiveRecord::Relation` to `futurize`, just as you would call `render`:
```erb
<%= futurize @posts, extends: :tr do %>
|
<% end %>
```
#### Partial Path
Remember that you can override the partial path in you models, like so:
```rb
class Post < ApplicationRecord
def to_partial_path
"home/post"
end
end
```
That way you get maximal flexibility when just specifying a single resource.
### Explicit Partial
Call `futurize` with a `partial` keyword:
```erb
<%= futurize partial: "items/card", locals: {card: @card}, extends: :div do %>
<% end %>
```
You can also use the shorthand syntax:
```erb
<%= futurize "items/card", card: @card, extends: :div do %>
<% end %>
```
#### Collections
Collection rendering is also possible:
```erb
<%= futurize partial: "items/card", collection: @cards, extends: :div do %>
<% end %>
```
### HTML Options
You can pass a hash of attribute/value pairs which will be mixed into the HTML markup for the placeholder element. This is important for layouts that require elements to have dimensionality. For example, many scripts calculate size based on element height and width. This option ensures that your elements have integrity, even if they are gone before you see them.
```erb
<%= futurize @posts, extends: :tr, html_options: {style: "width: 50px; height: 50px;"} do %>
|
<% end %>
```
This will output the following:
```html
|
```
## Events
Once your futurize element has been rendered, the `futurize:appeared` custom event will be called.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'futurism'
```
And then execute:
```bash
$ bundle
```
To copy over the javascript files to your application, run
```bash
$ bin/rails futurism:install
```
**! Note that the installer will run `yarn add @minthesize/futurism` for you !**
### Manual Installation
After `bundle`, install the Javascript library:
```bash
$ bin/yarn add @minthesize/futurism
```
In your `app/javascript/channels/index.js`, add the following
```js
import * as Futurism from '@minthesize/futurism''
import consumer from './consumer'
Futurism.initializeElements()
Futurism.createSubscription(consumer)
```
## Contributing
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
## Contributors ✨
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!