00:00:09.440
Good afternoon, everyone. Welcome to my talk! I'm going to be speaking about Padrino, the elegant web framework.
00:00:11.690
First off, really quick, who am I? My name is Joshua Hull, and you can find me on Twitter at @joshbuddy.
00:00:16.260
If you want to get the slides for this presentation, just go ahead to that GitHub link or check my recent tweets where I've shared the repo. You can clone it and view the slides. It's a bunch of images, but it will help you follow along.
00:00:30.449
So, why should you care about yet another web framework in Ruby? The simplest reason I can give you is that Padrino is built on top of Sinatra. Now, just to check, has everyone here used Sinatra? Okay, cool! Everyone knows what Sinatra is.
00:00:55.440
The reason why everyone knows about Sinatra is simple: it’s incredibly easy to demonstrate. For example, if you show someone the homepage of Sinatra, they can grasp its functionality with just five lines of code. It's straightforward and intuitive, which is why it's a favorable choice for teaching web frameworks.
00:01:18.990
When you're trying to teach web development to someone new, introducing Rails can be complex. There are many directories and files everywhere, making it a steep learning curve. In contrast, Sinatra is simple and easy to understand right from the start.
00:01:34.000
Padrino builds on this solid foundation of Sinatra. When I first saw Sinatra, my immediate thought was, 'Why didn’t I think of that? It’s so simple!' I was a bit jealous, feeling it was an obvious solution.
00:01:43.020
If you perform a Google search for 'Sinatra-inspired web frameworks', you’ll find Sinatra look-alikes in virtually every programming language. Sinatra's simplicity and ease of learning have made it a significant player in web development.
00:02:00.719
Now, while Sinatra is minimal and pleasing to Ruby hackers who enjoy crafting their own solutions, there’s a notable limitation: when you write many Sinatra applications, you begin to reinvent the wheel for common patterns repeatedly. If you're a good programmer, you take these common patterns, abstract them, and encapsulate them in a gem, utilizing Sinatra plugins.
00:02:23.920
For instance, according to the Sinatra book, using partials in your views is a great way to keep them clean. However, Sinatra follows a hands-off approach to framework design, meaning you have to implement a partial handler yourself, which is definitely within their rights. I appreciate that Sinatra doesn’t assume I need partials if it's just a REST API; why give me additional complexity when I don’t need it?
00:02:41.480
Padrino, on the other hand, attempts to address this issue with a common set of extensions built on Sinatra, which makes it incredibly useful. Like Sinatra, you can choose which components to use or ignore. Here's a high-level overview of the components available in Padrino: you have application and model generation, advanced routing, view helpers, a mailing component, a Django-like admin interface, a unified logger, excellent code reloading, and localization capabilities.
00:03:02.180
As I mentioned, Padrino is built on top of Sinatra, so feel free to use all of your existing Sinatra extensions. It follows the same principle as Sinatra and Rack, where you can utilize any piece of Rack that you desire. The idea is simple: you take what you want and leave behind what you don’t. What you get out of the box with Padrino includes an MVC structure, with several types of structure to choose from.
00:03:29.050
Additionally, you have a really nice set of generators that understand the components you've chosen for your application. And, if you've written a prototype in Sinatra that you want to expand, Padrino offers an easy pathway for migration to a more advanced structure.
00:03:51.470
For instance, I’ll start with the generation feature. Here's a look at some of the options you get right out of the box with the Padrino generator. You can specify your ORM, and just today, we added two new ORMs. This means that you can accommodate virtually any kind of data ORM you can think of.
00:04:09.700
Padrino provides a wide variety of test suites, including options for JavaScript rendering, stylesheet mocking, and so forth. What's particularly nice about the generation process in Padrino is that when it comes time to generate a model, it remembers the components you've selected, applying them accordingly. For example, if you choose to use Active Record and RSpec, the generated model will extend from ActiveRecord::Base and provide a blank test for you to fill in.
00:04:47.920
In instances where you've specified to use Sequel in your project, the generated model will extend from Sequel::Model with an appropriately designed RSpec test. As you develop your project, generating controllers becomes just as intuitive. For instance, if you create a controller with three actions (index, new, and create), Padrino streamlines that process for you.
00:05:13.210
When you generate a model by specifying the desired fields, Padrino handles everything automatically, generating the right migration and the corresponding base class, respecting your selected ORM. Furthermore, creating a mailer is equally straightforward: simply specify some default actions, and the generator creates a nice default mailer structure for you.
00:05:39.600
Another great feature in Padrino is the ability to create sub-applications. This allows you to build smaller applications within your larger project, which can save a lot of time. For example, let’s say you have a project named 'Catalog'. Within that, you could generate a blog app or a customer support app, all with their own separate namespaces.
00:06:12.430
Generating these sub-applications is simple, and they can be mounted at different points in your application. This functionality not only aids in modularity but also enhances reusability—allowing you to copy components from one project and utilize them elsewhere.
00:06:39.450
Now, let’s dive into routing and controller features in Padrino. If you're familiar with Sinatra, you’ll find this aspect very familiar. Padrino allows you to craft routes elegantly, reducing the need to hardcode URLs across your views. For instance, you could generate a URL for an account with a given ID, and Padrino will understand where to place parameters.
00:07:07.670
You can also adjust the structure of your URLs using various mapping techniques, even allowing for regex matching if needed. Notably, the method for defining controllers allows for significant flexibility with how your routing is structured.
00:07:36.060
For example, if you want to put certain routes behind an admin namespace, you simply prepend '/admin' to your routes, simplifying the design of your URL paths. Another great feature Padrino provides is a content type matching system, making it easy to return different types, such as JSON or JSP.
00:08:00.340
This capability allows you to manage various content responses effectively. For developers accustomed to Rails, Padrino introduces a feature allowing you to declare which types of responses a controller can provide, enabling more dynamic interactions.
00:08:30.330
Furthermore, Padrino supports before and after filters, similar to Sinatra, but with some enhancements. You can set conditions to restrict access to certain routes based on user authentication or authorization. This improves security and enhances middleware functionality.
00:09:05.710
Nesting routes is also a key feature, allowing for more organized and intuitive routes within your applications. You can achieve deeper nesting up to two levels, making the structure clearer and more accessible within your controllers.
00:09:38.780
Padrino also allows the use of layouts to organize your views better. You can disable layouts for specific views or provide custom layouts on a per-action basis, enhancing the flexibility and cleanliness of your code.
00:10:06.380
Now, let’s look at output helpers. For instance, the 'content for' and 'yield content' methods enable you to capture and display content in layouts easily. With this, you can include stylesheets or any other resources dynamically based on the context of your application.
00:10:36.600
Padrino provides extensive tag helpers to streamline the creation of HTML elements, enhancing development efficiency. You can easily create input tags, images, and a range of other HTML elements with the use of these helpers, making your work simpler.
00:11:00.879
Forms in Padrino are particularly user-friendly. You can customize HTTP methods, organize your structure with field sets, and smoothly integrate error messages and other feedback directly into the form rendering process.
00:11:31.540
Additionally, Padrino provides support for nested forms and allows you to implement a custom form builder if needed, making it adaptable to different project requirements.
00:11:56.920
The localization feature in Padrino is comprehensive, covering multiple languages out of the box. You can easily implement localization by defining language files and encapsulating various translations.
00:12:24.310
To aid with localization, Padrino has introduced new features for template management and plug-in support, making it versatile in plugin usage. This allows developers to leverage existing Sinatra plugins while also utilizing specific Padrino plugins for additional functionality.
00:12:51.500
In conclusion, Padrino is an incredibly effective framework that allows rapid development while maintaining a clean structure. Its lightweight nature enables it to deliver impressive performance metrics, and numerous benchmarks demonstrate its efficiency.
00:13:16.660
The Padrino team, originally founded by Nathan and Arthur, has grown to include members from across the globe who all contribute to ongoing development. I encourage you to find out more about Padrino through our GitHub page or follow our Twitter account for the latest updates.
00:13:41.850
If you're interested, there are many resources available, making it easy to dive deeper into Padrino’s capabilities. Thank you very much for your attention, and I look forward to your questions!