https://github.com/tyabe/padrino-decorator
Decorators for Padrino Applications
https://github.com/tyabe/padrino-decorator
Last synced: about 2 months ago
JSON representation
Decorators for Padrino Applications
- Host: GitHub
- URL: https://github.com/tyabe/padrino-decorator
- Owner: tyabe
- License: mit
- Created: 2013-08-25T08:57:52.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2017-12-10T13:00:38.000Z (over 7 years ago)
- Last Synced: 2024-06-15T13:54:50.692Z (12 months ago)
- Language: Ruby
- Size: 25.4 KB
- Stars: 9
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Padrino Decorator
padrino-decorator is a gem for [Padrino](http://www.padrinorb.com/).
Adds an object-oriented layer of presentation logic to your Padrino application.[](https://travis-ci.org/tyabe/padrino-decorator)
[](https://codeclimate.com/github/tyabe/padrino-decorator)
[](https://coveralls.io/r/tyabe/padrino-decorator)
[](https://gemnasium.com/tyabe/padrino-decorator)## Installation
Note: Version 0.0.3 or later work with Padrino 0.12.3 later.
Add the following to your `Gemfile`:
```ruby
gem 'padrino-decorator'
```And then execute:
```plain
$ bundle
```## Decorator Generator
Padrino provides generator support for quickly creating new decorators within your Padrino application.
Note that the decorator tests are generated specifically tailored towards the testing framework chosen during application generation.Very important to note that decorator generators are intended primarily to work within applications
created through the Padrino application generator and that follow Padrino conventions.Using the decorator generator is as simple as:
```plain
$ padrino-gen decorator User
```
Options
Default
Aliases
Description
root
.
-r
specify the root destination path
app
/app
-a
specify the application
destroy
false
-d
removes all generated files
namespace
-n
specify the name space of your padrino project
## Examples
```ruby
# app/controllers/posts.rb
SampleProject::App.controllers :posts doget :index do
source = Post.all
@posts = decorate(source)
render 'posts/index'
endget :show, with: :id do
source = Post.find(params[:id])
@post = decorate(source)
# or
@post = PostDecorator.new(source, context: self)
render 'posts/show'
endend
# app/decorators/post_decorator.rb
class PostDecorator < Padrino::Decorator::Base
context SampleProject::Appdef formated_body
h.simple_format(object.body)
endend
# app/views/posts/show.slim
h1 = @post.title
div
= @post.formated_body
```## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request## Copyright
Copyright (c) 2013 Takeshi Yabe. See LICENSE for details.