Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sinatra-decorator

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sinatra-decorator

  • 0.2.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Sinatra Decorator

sinatra-decorator is a gem for Sinatra.
Adds an object-oriented layer of presentation logic to your Sinatra application.

Build Status Code Climate Coverage Status Dependency Status

Installation

Add the following to your Gemfile:

gem 'sinatra/decorator'

And then execute:

$ bundle

Examples

# 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::Decoratable

  attr_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 (c) 2013 Takeshi Yabe (the author of padrino-decorator).
  • Copyright (c) 2014 Naotoshi Seo. See LICENSE for details.

Special Thanks

This gem was made on the basis of the padrino-decorator. I greatly appreciate for the orignal author Mr. @tyabe.

FAQs

Package last updated on 02 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc