Top Related Projects
Quick Overview
Padrino is a Ruby web framework built upon the Sinatra web library. It aims to make it easy to develop advanced web applications while adhering to the spirit of Sinatra. Padrino provides a full stack of tools for development, including generators, helpers, and components.
Pros
- Lightweight and modular architecture
- Built-in admin interface generator
- Extensive set of helpers for common web development tasks
- Seamless integration with various ORMs, testing frameworks, and JavaScript libraries
Cons
- Smaller community compared to Rails
- Less comprehensive documentation
- Steeper learning curve for beginners compared to Sinatra
- Fewer third-party gems and plugins available
Code Examples
- Basic Padrino application structure:
# app/app.rb
module MyApp
class App < Padrino::Application
register Padrino::Mailer
register Padrino::Helpers
enable :sessions
get :index do
"Hello, World!"
end
end
end
- Using Padrino's routing DSL:
# app/controllers/posts.rb
MyApp::App.controllers :posts do
get :index do
@posts = Post.all
render 'posts/index'
end
get :show, :with => :id do
@post = Post.find(params[:id])
render 'posts/show'
end
end
- Utilizing Padrino helpers:
# app/helpers/posts_helper.rb
MyApp::App.helpers do
def format_date(date)
date.strftime("%B %d, %Y")
end
def truncate_text(text, length = 100)
text.truncate(length)
end
end
Getting Started
To get started with Padrino, follow these steps:
-
Install the Padrino gem:
gem install padrino -
Create a new Padrino project:
padrino g project myapp cd myapp -
Start the server:
padrino s
Your Padrino application is now running at http://localhost:3000. You can begin adding controllers, models, and views to build your web application.
Competitor Comparisons
Classy web-development dressed in a DSL (official / canonical repo)
Pros of Sinatra
- Lightweight and minimalistic, offering a simple and intuitive API
- Highly flexible, allowing developers to structure their applications as they see fit
- Excellent for small to medium-sized projects and microservices
Cons of Sinatra
- Lacks built-in structure for larger applications, requiring more manual organization
- Fewer out-of-the-box features compared to Padrino, necessitating more third-party gems
Code Comparison
Sinatra:
require 'sinatra'
get '/' do
'Hello, World!'
end
Padrino:
module MyApp
class App < Padrino::Application
get '/' do
'Hello, World!'
end
end
end
Key Differences
- Sinatra focuses on simplicity and minimalism, while Padrino builds upon Sinatra to provide a full-stack framework
- Padrino offers more built-in features like generators, helpers, and mailers, making it suitable for larger applications
- Sinatra gives developers more freedom in structuring their applications, whereas Padrino provides a more opinionated structure
Use Cases
- Choose Sinatra for small to medium-sized projects, APIs, or microservices where simplicity and flexibility are priorities
- Opt for Padrino when building larger, more complex applications that benefit from additional structure and built-in features
Ruby on Rails
Pros of Rails
- Larger ecosystem with more gems, plugins, and community support
- More comprehensive out-of-the-box features, including built-in ORM (Active Record)
- Better suited for large, complex applications with extensive requirements
Cons of Rails
- Heavier framework with more overhead, potentially slower for simpler applications
- Steeper learning curve due to its size and conventions
- Less flexibility in choosing components, as many are tightly integrated
Code Comparison
Rails:
class UsersController < ApplicationController
def index
@users = User.all
end
end
Padrino:
MyApp.controllers :users do
get :index do
@users = User.all
render 'users/index'
end
end
Rails follows a more traditional MVC structure with separate controller files, while Padrino uses a more compact, Sinatra-like syntax for defining routes and actions within the app file.
Both frameworks offer powerful features for web development, but Rails is generally better suited for larger projects with complex requirements, while Padrino provides a lighter alternative for smaller applications or those requiring more flexibility in component selection.
A flexible framework for maintainable Ruby apps
Pros of Hanami
- More modular architecture, promoting better separation of concerns
- Built-in security features, including Content Security Policy (CSP) support
- Emphasis on functional programming concepts, leading to more predictable code
Cons of Hanami
- Steeper learning curve due to its unique architecture and conventions
- Smaller community and ecosystem compared to Padrino
- Less flexibility in terms of ORM choices (primarily supports ROM)
Code Comparison
Hanami route definition:
# config/routes.rb
root to: 'home#index'
resources :books, only: [:index, :show]
Padrino route definition:
# app/app.rb
get '/' do
render 'home/index'
end
get '/books', :provides => [:html, :rss, :atom] do
@books = Book.all
render 'books/index'
end
Hanami focuses on a more declarative approach to routing, while Padrino's routing syntax is closer to Sinatra's style. Hanami's modular architecture is evident in its routing configuration, whereas Padrino's approach is more straightforward and familiar to those coming from Sinatra or Rails backgrounds.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
= Padrino
Padrino is the godfather of Sinatra. Follow us on {www.padrinorb.com}[http://padrinorb.com] and on twitter {@padrinorb}[http://twitter.com/padrinorb]. Join us on {gitter}[https://gitter.im/padrino/padrino-framework]
{rdoc-image:https://github.com/padrino/padrino-framework/actions/workflows/ci.yml/badge.svg?branch=master}[https://github.com/padrino/padrino-framework/actions/workflows/ci.yml] {rdoc-image:https://api.codeclimate.com/v1/badges/900d6e424498f0e2b7ff/maintainability}[https://codeclimate.com/github/padrino/padrino-framework/maintainability] {rdoc-image:https://badges.gitter.im/Join Chat.svg}[https://gitter.im/padrino/padrino-framework] {rdoc-image:https://www.codetriage.com/padrino/padrino-framework/badges/users.svg}[https://www.codetriage.com/padrino/padrino-framework]
== Preface
Padrino is a ruby framework built upon the excellent {Sinatra Web Library}[http://www.sinatrarb.com]. Sinatra is a DSL for creating simple web applications in Ruby quickly and with minimal effort. This framework tries to make it as fun and easy as possible to code more advanced web applications by building upon the Sinatra philosophies and foundations.
== Introduction
Many people love that Sinatra is simple and lightweight but soon begin to miss the great deal of functionality provided by other web frameworks such as Django or Rails when building non-trivial applications.
Our goal with this framework is to adhere to the essence of Sinatra and at the same time create a standard library of tools, helpers and components that will make Sinatra suitable for increasingly complex applications.
Here is a brief overview of functionality provided by the Padrino framework:
Agnostic:: Full support for many popular testing, templating, mocking, and data storage choices. Generators:: Create Padrino applications, models, controllers i.e: padrino-gen project. Mountable:: Unlike other ruby frameworks, principally designed for mounting multiple apps. Routing:: Full url named routes, named params, before/after filter support. Tag Helpers:: View helpers such as: tag, content_tag, input_tag. Asset Helpers:: View helpers such as: link_to, image_tag, javascript_include_tag. Form Helpers:: Builder support such as: form_tag, form_for, field_set_tag, text_field. Text Helpers:: Useful formatting like: time_ago_in_words, js_escape_html, sanitize_html. Mailer:: Fast and simple delivery support for sending emails (akin to ActionMailer). Caching:: Simple route and fragment caching to easily speed up your web requests. Admin:: Built-in Admin interface (like Django) Logging:: Provide a unified logger that can interact with your ORM or any library. Reloading:: Automatically reloads server code during development. Localization:: Full support of I18n language localization and can auto-set user's locale.
Keep in mind, developers are able to individually pull in these modular components {into existing Sinatra applications}[http://padrinorb.com/guides/advanced-usage/standalone-usage-in-sinatra/] or use them altogether for a full-stack Padrino application.
== Installation
To install the padrino framework, simply grab the latest version from {RubyGems}[https://rubygems.org]:
$ gem install padrino
This will install the necessary padrino gems to get you started. Now you are ready to use this gem to enhance your Sinatra projects or to create new Padrino applications.
For a more detailed look at installing Padrino, check out the {Installation Guide}[http://padrinorb.com/guides/getting-started/installation/].
== Usage
Padrino is a framework which builds on the existing functionality of Sinatra and provides a variety of additional tools and helpers to build upon that foundation. This README and Padrino documentation in general will focus on the enhancements to the core Sinatra functionality. To use Padrino, one should be familiar with the basic usage of Sinatra itself.
You can also check out the {Why Learn Padrino?}[http://padrinorb.com/guides/introduction/why-learn-padrino/] introduction to learn more about how Sinatra and Padrino work together.
For information on how to use a specific gem in isolation within an existing Sinatra project, checkout the guide for {Using Padrino within Sinatra}[http://padrinorb.com/guides/advanced-usage/standalone-usage-in-sinatra/].
== Getting Started
Once a developer understands Sinatra, Padrino is quite easy to get comfortable with since Padrino is simply a superset of existing Sinatra functionality!
First, be sure to read over the {Getting Started}[http://padrinorb.com/guides/getting-started/overview/] guide to learn more about how Sinatra and Padrino work together.
Best way to learn more about building Padrino applications is to read following resources:
- {Padrino Guides}[http://padrinorb.com/guides] - Guides outlining the major functionality within Padrino.
- {Blog Tutorial}[http://padrinorb.com/guides/getting-started/blog-tutorial/] - Step-by-step guide to building a blog application with Padrino.
- {Padrino API}[http://www.rubydoc.info/github/padrino/padrino-framework] - YARD documentation for the Padrino framework.
- {Quick Overview}[http://padrinorb.com/guides/getting-started/basic-projects/] - Outlines basic generation commands.
The individual Padrino sub-gems also contain README's which outlines their functionality.
== Further Questions
Can't find an answer in the resources above?
- Ask any questions on the {gitter channel}[https://gitter.im/padrino/padrino-framework].
== Bug reporting
Log it onto Github by {creating a new issue}[http://github.com/padrino/padrino-framework/issues].
Be sure to include all relevant information, like the versions of Padrino, Rack, Sinatra, Ruby and operating system you are using.
A minimal project showing the issue published on Github with Gemfile.lock is also extremely helpful.
== Copyright
Copyright (c) 2010-2016 Padrino. See LICENSE for details.
Top Related Projects
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot