https://github.com/lcampanari/action_view_preview
Development tool for rendering views that wouldn't otherwise be rendered in your application
https://github.com/lcampanari/action_view_preview
hacktoberfest rails ruby
Last synced: 11 months ago
JSON representation
Development tool for rendering views that wouldn't otherwise be rendered in your application
- Host: GitHub
- URL: https://github.com/lcampanari/action_view_preview
- Owner: lcampanari
- License: mit
- Created: 2021-04-11T23:02:57.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2022-09-16T20:35:36.000Z (almost 4 years ago)
- Last Synced: 2025-05-25T18:54:44.121Z (about 1 year ago)
- Topics: hacktoberfest, rails, ruby
- Language: Ruby
- Homepage:
- Size: 84 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: MIT-LICENSE
Awesome Lists containing this project
README
# ActionViewPreview
Sometimes being able to preview a view might come in handy, like when a view is going to be used only inside a PDF, for example.
This gem allows a setup similar `ActionMailer::Preview`, and provides a development tool for rendering and debugging views that wouldn't otherwise be rendered in your application.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'action_view_preview'
```
And then execute:
```bash
$ bundle
```
Or install it yourself as:
```bash
$ gem install action_view_preview
```
## Usage
### Command Line Install
Run `rails generate action_view_preview:install` and the generator should create a `hello_preview.rb` and mount the route in your `routes.rb` file, similar to the steps shown below in the manual install.
### Manual Install
1. Mount the engine in your `routes.rb`:
```ruby
Rails.application.routes.draw do
# Add the line below
mount ActionViewPreview::Engine => "/action_view_preview"
end
```
2. Create files `*_preview.rb` on `test/views/previews/`, e.g. `hello_preview.rb`:
```ruby
class HelloViewPreview < ActionViewPreview::Base
def hello
'Hello world'
end
end
```
3. Access the route `/action_view_preview` to see the available previews
## Configuration
Use `config.action_view_preview` on `config/application.rb` to add custom configuration. For example, if you want to place the preview files in `lib/view_previews`:
```ruby
config.action_view_preview.preview_path = "#{Rails.root}/lib/view_previews"
```
Possible config values:
| Config | Default | Description |
| - | - | - |
| `preview_path` | `test/views/previews` | Path to the preview files |
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).