Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/julien-meichelbeck/partial_parameters
Validate required, optional or deprecated parameters of your Rails partials.
https://github.com/julien-meichelbeck/partial_parameters
optional parameters partials rails validation
Last synced: 4 months ago
JSON representation
Validate required, optional or deprecated parameters of your Rails partials.
- Host: GitHub
- URL: https://github.com/julien-meichelbeck/partial_parameters
- Owner: julien-meichelbeck
- License: mit
- Created: 2017-07-25T19:20:56.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-08-11T14:04:18.000Z (over 7 years ago)
- Last Synced: 2024-10-22T22:41:35.793Z (4 months ago)
- Topics: optional, parameters, partials, rails, validation
- Language: Ruby
- Homepage:
- Size: 12.7 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# PartialParameters
Make your partials reusable and self-documented by validating the given parameters in development and test environments.
If a required parameter is missing or an unknown parameter is given, an exception will be raised.![](https://api.travis-ci.org/julien-meichelbeck/partial_parameters.svg?branch=master)
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'partial_parameters'
```And then execute:
$ bundle
Or install it yourself as:
$ gem install partial_parameters
And you are ready to go!
## Usage
At the top of your partials, simply call the method `partial_parameters` and list your required and optional parameters:Erb example:
```erb
<% partial_parameters { required(:name); required(:age); optional(:height) }%>
```Slim example:
```slim
- partial_parameters do
- required(:name)
- required(:age)
- optional(:height)
```### Strict mode
By default strict mode is enabled and an error will be raised if an unknown parameter has been passed to the partial. Of course, you can disable the strict mode:
```slim
- partial_parameters(strict: false) do
- required(:name)
- required(:age)
- optional(:height)
```## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/julien-meichelbeck/partial_parameters.
## License
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).