Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sonots/sinatra-decorator
Decorators for Sinatra Applications
https://github.com/sonots/sinatra-decorator
Last synced: 3 months ago
JSON representation
Decorators for Sinatra Applications
- Host: GitHub
- URL: https://github.com/sonots/sinatra-decorator
- Owner: sonots
- License: mit
- Created: 2014-03-27T06:00:10.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-09-02T11:21:12.000Z (over 9 years ago)
- Last Synced: 2024-09-20T08:35:18.537Z (3 months ago)
- Language: Ruby
- Size: 215 KB
- Stars: 7
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Sinatra Decorator
sinatra-decorator is a gem for [Sinatra](http://www.sinatrarb.com/).
Adds an object-oriented layer of presentation logic to your Sinatra application.[![Build Status](https://travis-ci.org/sonots/sinatra-decorator.svg)](https://travis-ci.org/sonots/sinatra-decorator)
[![Code Climate](https://codeclimate.com/github/sonots/sinatra-decorator.png)](https://codeclimate.com/github/sonots/sinatra-decorator)
[![Coverage Status](https://coveralls.io/repos/sonots/sinatra-decorator/badge.png)](https://coveralls.io/r/sonots/sinatra-decorator)
[![Dependency Status](https://gemnasium.com/sonots/sinatra-decorator.png)](https://gemnasium.com/sonots/sinatra-decorator)## Installation
Add the following to your `Gemfile`:
```ruby
gem 'sinatra/decorator'
```And then execute:
```plain
$ bundle
```## Examples
```ruby
# app.rb
require 'sinatra'
require 'slim'
require 'sinatra/decorator'
require_relative 'models/post'
require_relative 'decorators/post_decorator'get '/' do
@post = Post.new.decorate # will try to find "#{self.class}Decorator" class
slim :show
end# models/post.rb
#class Post < ActiveRecord::Base
# include Sinatra::Decorator::Decoratable
#end
class Post
include Sinatra::Decorator::Decoratableattr_accessor :id, :body
def initialize(params = {})
@id = params[:id] || 1
@body = params[:body] || "body"
end
end# decorators/post_decorator.rb
class PostDecorator < Sinatra::Decorator::Base
def formated_body
object.body.gsub('b', 'a')
end
end# views/show.slim
h1 = @post.id
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 (the author of [padrino-decorator](https://github.com/tyabe/padrino-decorator)).
* Copyright (c) 2014 Naotoshi Seo. See [LICENSE](LICENSE) for details.## Special Thanks
This gem was made on the basis of the [padrino-decorator](https://github.com/tyabe/padrino-decorator).
I greatly appreciate for the orignal author Mr. [@tyabe](https://github.com/tyabe).