### Start Padrino Application Server (CLI) Source: https://github.com/padrino/padrino-framework/blob/master/padrino-core/README.rdoc These commands demonstrate how to start the Padrino application server from the terminal. The first command starts the server in non-daemonized mode. The second command shows how to start it as a daemon, specifying the port, environment, and adapter. ```bash # starts the app server (non-daemonized) $ padrino start # starts the app server (daemonized) with given port, environment and adapter $ padrino start -d -p 3000 -e development -a thin ``` -------------------------------- ### Install Padrino Framework Gem Source: https://github.com/padrino/padrino-framework/blob/master/padrino/README.rdoc Installs the latest version of the Padrino framework from Gemcutter. This command fetches and installs all necessary Padrino gems, enabling the development of Padrino applications or enhancement of existing Sinatra projects. ```bash sudo gem install padrino --source http://gemcutter.org ``` -------------------------------- ### Install padrino-performance Gem Source: https://github.com/padrino/padrino-framework/blob/master/padrino-performance/README.md Instructions for installing the padrino-performance gem using Bundler. This involves adding the gem to your application's Gemfile and then running the bundle install command. ```ruby gem "padrino-performance", require: false ``` ```bash $ bundle install ``` -------------------------------- ### Install Padrino Framework using RubyGems Source: https://github.com/padrino/padrino-framework/blob/master/README.rdoc Installs the latest version of the Padrino framework using the RubyGems package manager. This command fetches and installs all necessary Padrino gems. ```bash $ gem install padrino ``` -------------------------------- ### Install Padrino Framework Source: https://github.com/padrino/padrino-framework/blob/master/padrino-core/README.rdoc This command installs the latest version of the Padrino framework from gemcutter. It is the initial step to begin using Padrino for enhancing Sinatra projects or creating new Padrino applications. ```bash sudo gem install padrino ``` -------------------------------- ### Padrino Asset Directory Creation Source: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc Automates the creation of necessary empty directories for assets like `images`, `javascripts`, `stylesheets`, and `tmp` during project setup. ```ruby # Creation of empty directories for images/javascripts/stylesheets/tmp ``` -------------------------------- ### Padrino Bundler Setup Removal Source: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc Removes legacy Bundler setup code from `config/boot.rb`, suggesting a move towards more modern Bundler practices. ```ruby # Remove legacy bundler setup from config/boot.rb ``` -------------------------------- ### Configure global Padrino caching stores Source: https://github.com/padrino/padrino-framework/blob/master/padrino-cache/README.rdoc Provides examples of setting up different global caching stores for a Padrino application using `Padrino.cache`. Supported stores include LRUHash, File, Memcached, and Redis. ```ruby Padrino.cache = Padrino::Cache.new(:LRUHash) # default choice Padrino.cache = Padrino::Cache.new(:File, :dir => Padrino.root('tmp', app_name.to_s, 'cache')) # Keeps cached values in file Padrino.cache = Padrino::Cache.new(:Memcached) # Uses default server at localhost Padrino.cache = Padrino::Cache.new(:Memcached, :server => '127.0.0.1:11211', :exception_retry_limit => 1) Padrino.cache = Padrino::Cache.new(:Memcached, :backend => memcached_or_dalli_instance) Padrino.cache = Padrino::Cache.new(:Redis) # Uses default server at localhost Padrino.cache = Padrino::Cache.new(:Redis, :host => '127.0.0.1', :port => 6379, :db => 0) Padrino.cache = Padrino::Cache.new(:Redis, :backend => redis_instance) Padrino.cache = Padrino::Cache.new(:Mongo) # Uses default server at localhost Padrino.cache = Padrino::Cache.new(:Mongo, :backend => mongo_client_instance) ``` -------------------------------- ### Generate Padrino Plugin Source: https://github.com/padrino/padrino-framework/blob/master/padrino-gen/README.rdoc Installs a Padrino plugin into the application. This command automatically handles the middleware installation for the specified plugin, simplifying integration. ```bash $ padrino-gen plugin hoptoad ``` -------------------------------- ### Using Asset Helpers in Padrino Views (Haml) Source: https://github.com/padrino/padrino-framework/blob/master/padrino-helpers/README.rdoc Provides an example of using various asset helpers within a Padrino Haml view template. It demonstrates how to include stylesheets, JavaScript files, display flash messages, create links, generate mail_to links, and embed images. ```haml # app/views/example.haml ... %head = stylesheet_link_tag 'layout' = javascript_include_tag 'application' %body ... = flash_tag :notice %p= link_to 'Blog', '/blog', :class => 'example' %p Mail me at #{mail_to 'fake@faker.com', "Fake Email Link", :cc => "test@demo.com"} %p= image_tag 'padrino.png', :width => '35', :class => 'logo' ``` -------------------------------- ### Basic Padrino Application Routing Source: https://github.com/padrino/padrino-framework/blob/master/padrino-core/README.rdoc Defines a simple Padrino application with a root route and a separate controller for admin-related routes. It demonstrates basic GET request handling within the application and a nested controller block. ```ruby Padrino.load! class SimpleApp < Padrino::Application get '/' do 'Hello world' end # and for read better we can divide with controllers controller '/admin' do get '/foo' do 'Url is /admin/foo' end end end ``` -------------------------------- ### Log Information in Padrino Controller Source: https://github.com/padrino/padrino-framework/blob/master/padrino-core/README.rdoc This example shows how to log informational messages within a Padrino controller. It accesses the application's logger instance via the `logger` method and uses `logger.info` to record a message when a GET request is made to the '/test' route. ```ruby SimpleApp.controllers do get("/test") { logger.info "This is a test" } end ``` -------------------------------- ### Enable Controller-Wide Caching in Padrino Application Source: https://github.com/padrino/padrino-framework/blob/master/padrino-cache/README.rdoc This example shows how to apply caching to an entire controller in Padrino. All GET and HEAD requests within the '/admin' controller will have their responses cached for 60 seconds. POST requests are explicitly not cached. ```ruby class SimpleApp < Padrino::Application register Padrino::Cache enable :caching get '/' do 'Hello world' end # Requests to routes within '/admin' controller '/admin', :cache => true do expires 60 get '/foo' do 'Url is /admin/foo' end get '/bar' do 'Url is /admin/bar' end post '/baz' do # We cache only GET and HEAD request 'This will not be cached' end end end ``` -------------------------------- ### Use Configuration Helper in Padrino Views (Haml) Source: https://github.com/padrino/padrino-framework/wiki/YML-app-own-config Example of using the `config_get` helper method within a Padrino Haml view to dynamically render configuration values. This allows embedding application settings directly into the HTML structure, such as titles, contact information, and meta tags. ```haml %h1= config_get '/main/enterprise/name' %h2 Call us at: #{config_get '/main/enterprise/phone'} %h2 Or send mail to: #{config_get '/main/contact/email'} ``` ```haml !!! 5 %html %head %meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"} %meta{:author => "#{config_get '/main/enterprise/name'}"} %meta{:keywords => "#{config_get '/web/keywords'}"} %meta{:description => "#{config_get '/web/description'}"} %title= config_get '/web/title' ``` -------------------------------- ### Check for Conflicting JSON Libraries with Padrino Source: https://github.com/padrino/padrino-framework/blob/master/padrino-performance/README.md This example demonstrates how to use the padrino-performance tool to check for conflicting JSON libraries within a Padrino application. It is executed via the command line and outputs errors if conflicts are found. The tool helps identify duplicate or similar JSON implementations. ```bash $ bundle exec padrino-performance -j -- bundle exec padrino console >> require 'json' >> require 'json_pure' ``` -------------------------------- ### Padrino Cache Gem Inclusion Source: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc Includes the `padrino-cache` gem as part of the standard Padrino installation, making caching functionality readily available. ```ruby # Include padrino-cache gem as part of standard install ``` -------------------------------- ### Define YAML Configuration Data Source: https://github.com/padrino/padrino-framework/wiki/YML-app-own-config Example YAML files demonstrating a structure for storing application-wide configuration values. These files can contain nested data for enterprise settings, contact information, and web-related properties. ```yaml main: enterprise: name: War Games Limited tax_id: X01020304 phone: 34-555-112233 address: Camino del Cedro Alto, SN city: Ghost's Island state: Oregon contact: sender: joshua@falken.fqdn email: info@falken.fqdn ``` ```yaml web: author: joshua@falken.tld keywords: 'Falken, Maze, IA, computers, war, tic-tac-toe' description: 'The better Falken's Mazes all over the World!' ``` -------------------------------- ### Define Multipart Email in Padrino Mailer Source: https://github.com/padrino/padrino-framework/blob/master/padrino-mailer/README.rdoc This example shows how to define a multi-part email within a Padrino mailer. It specifies both a plain text part and an HTML part, rendering content from separate template files for each. ```ruby # app/mailers/sample_mailer.rb MyAppName.mailers :sample do email :registration do |name| to 'padrino@test.lindsaar.net' subject "nested multipart" from "test@example.com" text_part { render('multipart/basic.plain') } html_part { render('multipart/basic.html') } end end ``` -------------------------------- ### Render Email Template in Padrino Source: https://github.com/padrino/padrino-framework/blob/master/padrino-mailer/README.rdoc This example shows the content of an ERB template file used for rendering an email body in Padrino. It demonstrates how to access local variables passed from the mailer definition within the template. ```erb # ./views/mailers/sample/registration.erb This is the body of the email and can access the <%= name %> that was passed in from the mailer definition That's all there is to defining the body of the email which can be plain text or html ``` -------------------------------- ### Generate Padrino Mailer Source: https://github.com/padrino/padrino-framework/blob/master/padrino-gen/README.rdoc Generates a new mailer file for Padrino applications. This is intended for use within applications created by Padrino and adhering to its conventions. It simplifies the setup of email functionality. ```bash $ padrino-gen mailer UserNotifier ``` -------------------------------- ### Generate Padrino Migration Source: https://github.com/padrino/padrino-framework/blob/master/padrino-gen/README.rdoc Generates a new migration file to modify the database schema. The generated migration is specifically designed to work with the ORM selected during application setup and assumes adherence to Padrino conventions. ```bash # Example migration generation command (specific syntax not provided in text) # $ padrino-gen migration create_users ``` -------------------------------- ### Configure Rack CORS for XMLHttpRequest in Padrino Source: https://github.com/padrino/padrino-framework/wiki/Cross-domain-requests,-Access-Control-Allow-Origin This code snippet demonstrates how to configure Rack::Cors within a Padrino application to allow cross-origin requests, essential for XMLHttpRequest. It specifies allowed origins and resource methods. Ensure the rack-cors gem is installed. ```ruby use Rack::Cors do allow do # put real origins here origins '*' # and configure real resources here resource '*', :headers => :any, :methods => [:get, :post, :options] end end ``` -------------------------------- ### Measure Memory Usage of a Padrino Application Source: https://github.com/padrino/padrino-framework/blob/master/padrino-performance/README.md This example shows how to use the padrino-performance tool to measure the memory usage of a running Padrino application. The tool is invoked with the '-m' or '--mem' option, and the output displays the total memory consumed by the application. This is useful for identifying memory leaks or optimizing resource utilization. ```bash $ bundle exec padrino-performance -m -- bundle exec padrino start ``` -------------------------------- ### Configure Admin Access Control in Padrino Source: https://github.com/padrino/padrino-framework/blob/master/padrino-admin/README.rdoc Example of how to implement access control for specific URL paths within a Padrino application using Padrino::Admin::AccessControl. It redirects unauthenticated users to a login page. ```ruby class EcommerceSite < Padrino::Application register Padrino::Admin::AccessControl enable :store_location set :login_page, "/login" access_control.roles_for :any do |role| role.protect "/customer/orders" role.protect "/cart/checkout" end end ``` -------------------------------- ### Setting Content Expiry Time for Cached Controller in Padrino Source: https://github.com/padrino/padrino-framework/blob/master/padrino-cache/README.rdoc This example demonstrates setting a specific expiry time for cached content within a controller in Padrino. The '/blog/entries' route will have its content cached and refreshed every 15 seconds. If not explicitly called, cached content might persist indefinitely. ```ruby class CachedApp < Padrino::Application register Padrino::Cache # includes helpers enable :caching # turns on caching controller '/blog', :cache => true do expires 15 get '/entries' do 'just broke up eating twinkies lol' end end end ``` -------------------------------- ### Fragment-Level Cache Expiration in Padrino Source: https://github.com/padrino/padrino-framework/blob/master/padrino-cache/README.rdoc Shows how to implement fragment-level cache expiration within a Padrino controller. The `expire` helper is used to invalidate specific cached fragments when underlying data changes, ensuring fresh content is re-rendered. This example checks for deleted tweets and re-renders the feed if necessary. ```ruby class MyTweets < Padrino::Application register Padrino::Cache enable :caching enable :session COMPANY_FOUNDING = Time.utc( 2010, "April" ) controller :tweets do get :feed, :map => '/:username' do last_visit = session[:last_visit] || params[:since] || COMPANY_FOUNDING username = params[:username] @tweets = Tweet.since( last_visit, :username => username ).limit( 100 ) expire( "feed since #{last_visit}" ) if @tweets.any? { |t| t.deleted_since?( last_visit ) } session[:last_visit] = Time.now @feed = cache( "feed since #{last_visit}", :expires => 60 ) do @tweets = @tweets.find_all { |t| !t.deleted? } render 'partials/feedcontent' end render 'feeds/show' end end end ``` -------------------------------- ### Padrino Render Helpers: Basic Rendering Source: https://github.com/padrino/padrino-framework/blob/master/padrino-helpers/README.rdoc Illustrates the basic usage of Padrino's render helpers for displaying templates. It shows how to explicitly specify the template engine (like ERB or HAML) or let Padrino infer the engine based on the file extension. ```ruby render :erb, 'path/to/erb/template' render :haml, 'path/to/haml/template' render 'path/to/any/template' ``` -------------------------------- ### Padrino Render Helpers: Partial Rendering Source: https://github.com/padrino/padrino-framework/blob/master/padrino-helpers/README.rdoc Demonstrates how to use Padrino's `partial` helper for rendering reusable template fragments. It covers rendering a single partial with an object and locals, as well as rendering a collection of partials. ```ruby partial 'photo/_item', :object => @photo, :locals => { :foo => 'bar' } partial 'photo/_item', :collection => @photos ``` -------------------------------- ### Padrino Helper Input Flexibility Source: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc Allows `stylesheet_link_tag` and `javascript_include_tag` helpers to accept an array of sources, simplifying the inclusion of multiple assets. ```ruby # Stylesheet_link_tag and javascript_include_tag should allow array inputs for sources (instead of argument array) # Added stylesheet_link_tag and javascript_include_tag to allow array input for sources [Thanks to railsjedi] ``` -------------------------------- ### Padrino Route Provisioning for Content Types Source: https://github.com/padrino/padrino-framework/blob/master/padrino-core/README.rdoc Illustrates how to configure content types (e.g., JS, HTML, JSON) for specific routes in Padrino. It demonstrates handling different content types within a route's block and how Padrino can auto-lookup based on locale and content type. ```ruby # app/controllers/example.rb SimpleApp.controllers :admin do get :show, :with => :id, :provides => :js do "Url is /admin/show/#{params[:id]}.#{params[:format]}" end get :other, :with => [:id, :name], :provides => [:html, :json] do case content_type when :js then ... end when :json then ... end end end end ``` ```ruby # app/controllers/example.rb SimpleApp.controllers :admin do get :show, :with => :id, :provides => [:html, :js] do render "admin/show" end end # When you visit :+show+ and your I18n.locale == :ru Padrino try to look for "admin/show.ru.js.*" if nothing match that path # they try "admin/show.ru.*" then "admin/show.js.*" if none match return "admin/show.erb" (or other engine i.e. haml) ``` -------------------------------- ### Padrino Static Assets Handling Source: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc Details the integration of `padrino-static` for handling JavaScript and UJS adapters. It mentions using a local copy if an internet connection is unavailable and the `stylesheet_link_tag` and `javascript_include_tag` helper updates to accept array inputs for sources. ```ruby # Use https://github.com/padrino/padrino-static for download js and ujs adapters (if no internet connection use a local copy) # Stylesheet_link_tag and javascript_include_tag should allow array inputs for sources (instead of argument array) # Added stylesheet_link_tag and javascript_include_tag to allow array input for sources ``` -------------------------------- ### Padrino Template Engine Support (Slim, Erubis) Source: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc Highlights updates regarding template engine support. It notes the completion of Slim support, including Slim admin templates, and the change of Erubis to be the standard for ERB templates, aligning with Tilt and Sinatra. It also mentions combining different template rendering (e.g., Haml partial in Slim view). ```ruby # Completed support for Slim # Adds Slim admin support # Now erubis is the standard for the erb templates like in tilt/sinatra # Allow combining different templates (ex: render a partial built with haml from a slim/erubis view) ``` -------------------------------- ### Padrino Route Aliasing and Parameter Handling Source: https://github.com/padrino/padrino-framework/blob/master/padrino-core/README.rdoc Shows how to define route aliases and associate them with specific actions in Padrino. It illustrates capturing URL parameters using `:with` and accessing them via `params`. ```ruby # app/controllers/example.rb SimpleApp.controllers :posts do get :index do ... end get :show, :with => :id do # url generated is '/posts/show/:id' # access params[:id] end end ``` -------------------------------- ### Generate Padrino Project Application Source: https://github.com/padrino/padrino-framework/blob/master/padrino-gen/README.rdoc Generates a new Padrino application with specified components. It sets up the application structure, Gemfile, and configuration based on selected testing, rendering, stylesheet, mocking, scripting, and ORM libraries. Defaults to 'none' for most components if not specified. ```bash $ padrino-gen project demo_project $ padrino-gen project demo_project -t rspec -r haml -m rr -s jquery -d datamapper $ padrino-gen project demo_project --test none --renderer none $ padrino-gen project demo_project --template sampleblog ``` -------------------------------- ### Padrino Simple Format Helper Source: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc Enhances the `simple_format` helper to allow the use of a custom tag instead of only the default `

` tag, offering more flexibility in output formatting. ```ruby # Allow simple_format to use a custom tag instead the only p tag ``` -------------------------------- ### Padrino Logging Compatibility and Features Source: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc Describes enhancements to Padrino's logging capabilities, including compatibility with `Rack::CommonLogger`, the addition of session path logging, and the ability to namespace logs with application names for URLs and layouts. It also mentions log formatting changes and cache GET/SET logging. ```ruby # Padrino::Logger compatible with Rack::CommonLogger # Added in our logs app name space for urls and layouts # Logs for cache GET and SET # Changed layout of our logger # Added setting log_static setting to Padrino.logger ``` -------------------------------- ### Capturing and Yielding Content with content_for in Padrino Source: https://github.com/padrino/padrino-framework/blob/master/padrino-helpers/README.rdoc Demonstrates how to use the `content_for` helper to capture blocks of content and render them in different locations, such as yielding assets into a layout. This is useful for dynamically including assets like stylesheets or JavaScript from view templates into a main layout file. ```erb # app/views/site/index.erb ... <% content_for :assets do %> <%= stylesheet_link_tag 'index', 'custom' %> <% end %> ... # app/views/layout.erb ... Example <%= stylesheet_link_tag 'style' %> <%= yield_content :assets %> ... ``` -------------------------------- ### Generate Padrino Project and Admin Subapplication Source: https://github.com/padrino/padrino-framework/blob/master/padrino-admin/README.rdoc Commands to create a new Padrino project and then generate the admin subapplication. This sets up the basic structure for the admin dashboard. ```bash $ padrino-gen project demo $ cd demo demo$ padrino-gen admin ``` -------------------------------- ### Adding Routes via Padrino Controllers Block Source: https://github.com/padrino/padrino-framework/blob/master/padrino-core/README.rdoc Demonstrates how to add routes to an existing Padrino application using the `SimpleApp.controllers` block. This allows for modular route definitions outside of the main application class. ```ruby # Simple Example SimpleApp.controllers do get "/test" do "Text to return" end end ``` -------------------------------- ### Open Padrino Console (CLI) Source: https://github.com/padrino/padrino-framework/blob/master/padrino-core/README.rdoc This command demonstrates how to launch an interactive Ruby console (IRB) within the context of a Padrino application. This allows for direct interaction with application models, helpers, and other components. ```bash # Bootup the Padrino console (irb) $ padrino console ``` -------------------------------- ### Constructing Forms with Form Helpers in Padrino Source: https://github.com/padrino/padrino-framework/blob/master/padrino-helpers/README.rdoc Illustrates the creation of a non-object form using Padrino's form helpers. It shows how to build a form tag with specified action and method, include flash messages, use field set tags, and create various input fields like labels, text fields, password fields, select dropdowns, and checkboxes. ```erb = form_tag '/destroy', :class => 'destroy-form', :method => 'delete' do = flash_tag(:notice) = field_set_tag do %p = label_tag :username, :class => 'first' = text_field_tag :username, :value => params[:username] %p = label_tag :password, :class => 'first' = password_field_tag :password, :value => params[:password] %p = label_tag :strategy = select_tag :strategy, :options => ['delete', 'destroy'], :selected => 'delete' %p = check_box_tag :confirm_delete = field_set_tag(:class => 'buttons') do ``` -------------------------------- ### Load YAML Configurations at Padrino Startup Source: https://github.com/padrino/padrino-framework/wiki/YML-app-own-config Ruby code snippet for Padrino applications to load YAML configuration files during the application's initialization. It uses `YAML::load` and `File.open` to read the files and sets the loaded data as application settings. Includes basic error handling. ```ruby Padrino.configure_apps do ... begin logger.info "Opening: #{Padrino.root}/config/my_main_config.yml" set :mainConfigYml, YAML::load(File.open("#{Padrino.root}/config/main.yml"))["main"] logger.info "Opening: #{Padrino.root}/config/my_other_config.yml" set :webConfigYml, YAML::load(File.open("#{Padrino.root}/config/my_other_config.yml"))["web"] rescue logger.fatal "ERROR: Cannot open config files!" exit end ... end ``` -------------------------------- ### Padrino Accept Header Handling Source: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc Improves handling of the `Accept` header by setting the status to `406` for non-provided media types and returning the first provided mime-type for `Accept: */*`. ```ruby # Set status to 406 on non-provided ACCEPTS # Returns first provided mime-type on ACCEPT = */* # Assume */* if no ACCEPT header is given ``` -------------------------------- ### Padrino URI Root and Sessions Source: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc Mentions the use of sessions for `uri_root`, which can help in managing the root URI context, potentially for multi-tenant applications or applications with complex routing. ```ruby # Use sessions for uri_root ``` -------------------------------- ### Padrino Admin Section Enhancements Source: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc Lists improvements specific to the Padrino Admin section, including better spacing for edit/delete actions, a confirm dialog to prevent mistakes, and the correct use of the DELETE method for logout. It also mentions Slim admin support. ```ruby # More space for edit/delete actions in the Admin Section # Added a nice confirm dialog to prevent mistakes in the Admin Section # Added the correct DELETE method to the logout in the Admin Section # Adds Slim admin support ``` -------------------------------- ### Run/List Padrino Rake Tasks (CLI) Source: https://github.com/padrino/padrino-framework/blob/master/padrino-core/README.rdoc This command shows how to execute or list available Rake tasks within a Padrino project. Rake tasks are commonly used for database migrations, running tests, and other project-specific automation. ```bash # Run/List tasks $ padrino rake ``` -------------------------------- ### Padrino Slim Template Integration Source: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc Adds Slim template support to Padrino Admin, allowing developers to use Slim for creating administrative interfaces. ```ruby # Added Slim template to Padrino Admin [Thanks to Matthew Winter] ``` -------------------------------- ### Generating HTML Tags with tag and content_tag in Padrino Source: https://github.com/padrino/padrino-framework/blob/master/padrino-helpers/README.rdoc Shows how to use `tag` and `content_tag` helpers for creating arbitrary HTML tags with specified attributes. `tag` is for simple tags like `
`, while `content_tag` is used when the tag needs to contain content, such as a paragraph `

`. ```erb tag(:br, :style => 'clear:both') # =>
content_tag(:p, "demo", :class => 'light') # =>

demo

``` -------------------------------- ### Padrino Slim Template Engine Support Source: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc Completes support for the Slim template engine, enabling developers to use Slim for views within Padrino applications. ```ruby # Completed support for Slim ``` -------------------------------- ### Padrino Automatic Template Rendering Source: https://github.com/padrino/padrino-framework/blob/master/padrino-core/README.rdoc Explains Padrino's automatic template lookup functionality, similar to Sinatra. It shows how to render views without explicitly specifying the template engine, allowing Padrino to find the first available template. ```ruby # searches for 'account/index.{erb,haml,...}' render 'account/index' ``` -------------------------------- ### Simple Padrino Application Definition Source: https://github.com/padrino/padrino-framework/blob/master/padrino-core/README.rdoc This Ruby code defines a basic Padrino application. It sets the PADRINO_ROOT constant and requires the Padrino library, which is the foundation for creating Padrino web applications, extending Sinatra::Application with Padrino's features. ```ruby PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT require 'padrino' ``` -------------------------------- ### Padrino File and Directory Management Source: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc Includes changes related to file and directory operations, such as the creation of empty directories for assets (`images`, `javascripts`, `stylesheets`, `tmp`), and fixing issues with the File Store cache when the directory is deleted. ```ruby # Creation of empty directories for images/javascripts/stylesheets/tmp # Fix File Store when cache dir is deleted after init ``` -------------------------------- ### Configure Padrino with Resque in config.ru Source: https://github.com/padrino/padrino-framework/wiki/Using-Padrino-With-Resque This snippet shows how to configure the `config.ru` file to integrate the Resque server with a Padrino application. It requires the 'resque/server' and maps '/resque' to the Resque server interface. Ensure `gem 'resque'` is in your Gemfile. ```ruby #!/usr/bin/env rackup # encoding: utf-8 # This file can be used to start Padrino, # just execute it from the command line. require File.expand_path("../config/boot.rb", __FILE__) require 'resque/server' run Rack::URLMap.new \ "/" => Padrino.application, "/resque" => Resque::Server.new ``` -------------------------------- ### Padrino Routing Methods: recognize_path and current_path Source: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc Introduces new routing helper methods. `recognize_path` converts a request path into controller and action components with parameters. `current_path` generates a URL with optional parameter merging. These methods aid in building more dynamic and flexible routing within Padrino applications. ```ruby recognize_path(request.referrer) # Example: => [:controller_action, { :id => 1 }] current_path(:merge => :param) # Example: => "/current/1234/merge/param" ``` -------------------------------- ### Creating Input HTML Tags with input_tag in Padrino Source: https://github.com/padrino/padrino-framework/blob/master/padrino-helpers/README.rdoc Demonstrates the use of the `input_tag` helper for generating HTML input elements. It allows specifying the input type (e.g., 'text', 'password') along with standard HTML attributes. ```erb input_tag :text, :class => "demo" # => input_tag :password, :value => "secret", :class => "demo" ``` -------------------------------- ### Padrino Template Combination Source: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc Allows combining different template engines, such as rendering a partial built with Haml from a Slim or Erubis view, providing greater flexibility in view composition. ```ruby # Allow combining different templates (ex: render a partial built with haml from a slim/erubis view) ``` -------------------------------- ### Padrino Request and Response Handling Source: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc Covers changes related to how Padrino handles requests and responses, including fixing password encryption when the password is blank, allowing `406` on `(.format)` URLs via a flag, and handling `ACCEPT` headers (`*/*` and non-provided). ```ruby # Fix no more password encryption when password is blank # Allow 406 on (.format) urls via a flag # Set status to 406 on non-provided ACCEPTS # Returns first provided mime-type on ACCEPT = */* # Assume */* if no ACCEPT header is given ``` -------------------------------- ### Padrino Rack-Flash Session Handling Source: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc Removes the enforcement of rack sessions for `Rack::Flash`, allowing more flexibility in how flash messages are handled in conjunction with session management. ```ruby # Do not enforce rack sessions for Rack:Flash ``` -------------------------------- ### Padrino Form and Tag Helpers Source: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc Details improvements to form and tag generation helpers. This includes enhancements for `select` and `select_tag` to handle ranges and grouped options, preserving spaces in `text_area`, and allowing `simple_format` to use custom tags. It also mentions adding empty rows/cols to `text_area` for W3C compliance. ```ruby # Allow select tag to take a range of options # Allow grouped options in a select_tag # Preserve spaces for text_area using admin/haml # Allow simple_format to use a custom tag instead the only p tag # Added empty rows and cols to text_area tag to be w3c ``` -------------------------------- ### Padrino Routing with Globs and Regex Source: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc Addresses fixes and improvements related to Padrino's routing system, particularly concerning globs in routes (e.g., `'/pictures/*path.html'`) and support for regex captures. It also mentions routing compatibility with Sinatra's `url` method and default `method_override` flag. ```ruby # Fixes Routes with globs that when something is after the glob i.e. get :show, :map => '/pictures/*path.html' # Support of regex captures in routes # Fixed routing issues with :index # Routing compatibility with the Sinatra 1.2 url method # Adds method_override flag to Padrino by default ``` -------------------------------- ### Generate Admin Scaffold for a Model in Padrino Source: https://github.com/padrino/padrino-framework/blob/master/padrino-admin/README.rdoc Steps to create a new 'scaffold' for a model within the Padrino admin interface. This involves generating the model, migrating the database, and creating the admin page for the model. ```bash demo$ padrino-gen model post --skip-migration demo$ padrino-gen rake dm:auto:migrate demo$ padrino-gen admin_page post ``` -------------------------------- ### Manage cache entries in Padrino Source: https://github.com/padrino/padrino-framework/blob/master/padrino-cache/README.rdoc Demonstrates basic cache management operations in Padrino, including setting a value, retrieving a value, deleting a specific entry, and clearing the entire cache. ```ruby Padrino.cache['val'] = 'test' Padrino.cache['val'] # => 'test' Padrino.cache.delete('val') Padrino.cache.clear ``` -------------------------------- ### Padrino Core and Dependency Updates Source: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc Encompasses various core framework updates, including dependency loader fixes, sub-app mounting fixes, Sinatra and HttpRouter version updates, Rubinius compatibility, and refactoring of output handlers. It also mentions allowing flexible libraries in padrino-cache and fixing the reloader's excluded list. ```ruby # Fixed dependency loader # Fixed mounting sub-apps # Updated http_router to ~> 0.7.0 # Fixes to allow flexible libraries in padrino-cache # Removed lib from excluded list of our reloader # Update Sinatra to 1.2.3 and HttpRouter to 0.6.9 # Updated plugin git command to use Grit instead # Removed ./bundle/environment stuff # Rubinius compat [Thx to Rakaur] # Fixed setting custom views path # Removed deprecated dom helpers # Fix collision with AS load_dependency # Use Sinatra::Base instead of Sinatra::Application # Padrino now requires to ~> sinatra 1.2.0 ``` -------------------------------- ### Render Haml View in Padrino Source: https://github.com/padrino/padrino-framework/blob/master/padrino-core/README.rdoc This snippet demonstrates how to render a Haml-formatted view for an account index page within a Padrino application. It utilizes the `render` method with the `:haml` symbol to specify the template engine. ```ruby render :haml, 'account/index' ``` -------------------------------- ### Padrino Debugging Support Source: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc Notes the addition of `ruby-debug19` to the `Gemfile`, facilitating debugging for Ruby 1.9 environments within Padrino projects. ```ruby # Added ruby-debug19 to Gemfile [Thanks to railsjedi] ``` -------------------------------- ### Padrino App Path Handling Source: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc Addresses an issue with fixing the application path when generating sub-applications, ensuring correct path resolution in nested Padrino structures. ```ruby # Fix app path when generating sub-applications ``` -------------------------------- ### Padrino Parameter Handling Source: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc Ensures correct handling of nested parameters sent to URLs, improving the robustness of Padrino's URL generation and parameter processing. ```ruby # Correctly work with nested parameters sent to url [Thanks to Funny-falcon] ``` -------------------------------- ### Padrino Form Builders: Basic Fields Source: https://github.com/padrino/padrino-framework/blob/master/padrino-helpers/README.rdoc Demonstrates the usage of Padrino's form_for helper with basic fields for creating user registration forms. It includes labels, text fields, password fields, checkboxes, and select dropdowns. This builder allows for object-based form construction. ```ruby = form_for @user, '/register', :id => 'register' do |f| = f.error_messages %p = f.label :username, :caption => "Nickname" = f.text_field :username %p = f.label :email = f.text_field :email %p = f.label :password = f.password_field :password %p = f.label :is_admin, :caption => "Admin User?" = f.check_box :is_admin %p = f.label :color, :caption => "Favorite Color?" = f.select :color, :options => ['red', 'black'] %p = fields_for @user.location do |location| = location.text_field :street = location.text_field :city %p = f.submit "Create", :class => 'button' ``` -------------------------------- ### Padrino Route Aliasing with Explicit URL Mapping Source: https://github.com/padrino/padrino-framework/blob/master/padrino-core/README.rdoc Explains how to map route aliases to explicit URLs in Padrino, providing flexibility in URL structure. It also shows how to access URL parameters defined in the mapped route. ```ruby # app/controllers/example.rb SimpleApp.controllers do get :index, :map => '/index' do ... end get :account, :map => '/the/accounts/:name/and/:id' do # access params[:name] and params[:index] end end ``` -------------------------------- ### Padrino Session Handling Improvements Source: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc Covers updates to Padrino's session management, including `session_path`, custom `Rack::Session::Cookie` options, and shared session support. It also notes the addition of a `session_secret` task generator. ```ruby # Added session_path and ability to use custom Rack::Session::Cookie options # Fixed shared sessions # Added session_secret task generator and as default in our app templates # Do not enforce rack sessions for Rack:Flash ``` -------------------------------- ### Padrino Form Builders: Standard Fields Source: https://github.com/padrino/padrino-framework/blob/master/padrino-helpers/README.rdoc Illustrates the use of Padrino's StandardFormBuilder with form_for, offering a more streamlined approach to form creation. It utilizes block methods for fields like text_field_block, check_box_block, select_block, and password_field_block, simplifying form markup. ```ruby = form_for @user, '/register', :id => 'register' do |f| = f.error_messages = f.text_field_block :name, :caption => "Full name" = f.text_field_block :email = f.check_box_block :remember_me = f.select_block :fav_color, :options => ['red', 'blue'] = f.password_field_block :password = f.submit_block "Create", :class => 'button' ``` -------------------------------- ### Building a Simplified form_tag Helper with capture_html and concat_content in Ruby Source: https://github.com/padrino/padrino-framework/blob/master/padrino-helpers/README.rdoc Illustrates how to create a custom `form_tag` helper using `capture_html` to capture the content within a block and `concat_content` to append the generated form HTML to the template. This approach works for both Haml and ERB templates. ```ruby # form_tag '/register' do ... end def form_tag(url, options={}, &block) # ... truncated ... inner_form_html = capture_html(&block) concat_content '
' + inner_form_html + '
' end ``` -------------------------------- ### Padrino Cache Enhancements Source: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc Details improvements to the Padrino Cache gem, including flexible library support, object storage, Redis store fixes for `expire_in`, and a global `Padrino.cache` option. It also mentions Redis and File Store compatibility improvements. ```ruby # Caching instructions in main app template Padrino.cache :redis # Padrino-Cache now is able to store ruby objects cache(:my_object_key) do @my_object = MyObject.new.complex_calculation end # Fix expire_in on redis store in Padrino Cache cache(:my_key, :expires_in => 1.hour) do "some data" end # Fix File Store when cache dir is deleted after init # Ensure cache directory exists before initialization ``` -------------------------------- ### Padrino Ajax Helpers Source: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc Mentions the addition of Ajax helpers and fixes related to AJAX request detection, specifically for `dataType: 'application/javascript'`. This improves Padrino's integration with AJAX functionalities. ```ruby # Added Ajax Helpers # Fix ajax request detection for dataType: 'application/javascript' ``` -------------------------------- ### Padrino Routing Compatibility (Sinatra 1.2) Source: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc Ensures routing compatibility with Sinatra's `url` method, version 1.2.0 and above, promoting smoother integration between the two libraries. ```ruby # Routing compatibility with the Sinatra 1.2 url method ``` -------------------------------- ### Padrino Output Handler Refactoring Source: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc Refactors the output handlers for helpers, likely improving their efficiency, maintainability, and consistency. ```ruby # Refactored the output handlers for helpers ``` -------------------------------- ### Create Helper to Access Configuration Nodes Source: https://github.com/padrino/padrino-framework/wiki/YML-app-own-config A Ruby helper method for Padrino applications designed to retrieve specific configuration values based on a provided path. It validates the path format and navigates through the loaded YAML data structure to return the requested node's value. ```ruby Myapp.helpers do def config_get(path) if !path.match /^\/(main|web).*/ logger.fatal "Config path must start with /main or /web" error 500, "Config path must start with /main or /web!" else if path.match /^(\/[[:alnum:]\-\_\.]{1,32}){1,10}$/ logger.info "Getting config path: " + path partial_config = nil for node in path.split('/').each do if node.length > 0 if partial_config.nil? if node == "web" partial_config = @webConfig elsif node == "main" partial_config = @mainConfig end else if partial_config[node].nil? logger.fatal "Undefined node '" + node + "' in path '" + path + "'" error 500, "Undefined node!" else partial_config = partial_config[node] end end end end logger.info "ConfigPath '" + path + "' --> '" + partial_config.to_s + "'" return partial_config.to_s else logger.fatal "Invalid config path: " + path error 500, "Invalid config path!" end end end end ``` -------------------------------- ### Configure Cache Store in Padrino Source: https://github.com/padrino/padrino-framework/blob/master/padrino-cache/README.rdoc Demonstrates how to configure different cache stores for a Padrino application. Supported stores include LRUHash, Memcached, Redis, and File-based caching. The File cache requires a directory path. ```ruby set :cache, Padrino::Cache.new(:LRUHash) set :cache, Padrino::Cache.new(:Memcached) set :cache, Padrino::Cache.new(:Redis) set :cache, Padrino::Cache.new(:File, :dir => Padrino.root('tmp', app_name.to_s, 'cache')) ``` -------------------------------- ### Padrino Daemonization Fixes Source: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc Includes a fix for stopping daemonized Padrino applications when they are run from a non-standard path, ensuring reliable process management. ```ruby # Fix stop daemonized padrino from non standard path ``` -------------------------------- ### Generate Padrino Controller Source: https://github.com/padrino/padrino-framework/blob/master/padrino-gen/README.rdoc Generates a new controller file for Padrino applications. This command can optionally include predefined actions like 'index', 'new', and 'create'. Controller tests are generated based on the application's chosen testing framework. Best used within Padrino-generated applications. ```bash $ padrino-gen controller Admin $ padrino-gen controller Admin get:index get:new post:create ``` -------------------------------- ### Padrino Sinatra and HttpRouter Version Update Source: https://github.com/padrino/padrino-framework/blob/master/CHANGES.rdoc Updates core dependencies: Sinatra to `1.2.3` and HttpRouter to `0.6.9`, ensuring compatibility and leveraging the latest features from these libraries. ```ruby # Update Sinatra to 1.2.3 and HttpRouter to 0.6.9 ``` -------------------------------- ### Send Quick Email from Padrino Controller Source: https://github.com/padrino/padrino-framework/blob/master/padrino-mailer/README.rdoc Demonstrates how to send a simple, one-off email directly from a Padrino controller action. This method is suitable for situations where a full mailer declaration is not necessary. It takes recipient, subject, and body as arguments. ```ruby # app/controllers/session.rb post :create do email(:to => "john@smith.com", :subject => "Successfully Registered!", :body => "Test Body") end ``` -------------------------------- ### Basic Cache Operations in Padrino Source: https://github.com/padrino/padrino-framework/blob/master/padrino-cache/README.rdoc Illustrates fundamental cache operations that can be performed from anywhere within a Padrino application using the configured cache object. This includes setting, retrieving, deleting, and clearing cached values. ```ruby MyApp.cache['val'] = 'test' MyApp.cache['val'] # => 'test' MyApp.cache.delete('val') MyApp.cache.clear ```