Padrino Framework

repository·master·Indexed 25 days ago

https://github.com/padrino/padrino-framework

A framework providing Padrino Admin, a management dashboard and authentication system that is ORM-agnostic and template-agnostic. It includes Padrino::Admin for account authentication, permission management, and scaffolding, as well as padrino-performance for detecting conflicting JSON libraries and monitoring application memory usage upon startup.

Tokens
21.6K
Snippets
64
Records
179
Agent score
85%

What's inside padrino-framework

  1. Use padrino-performance suites

    master

    The padrino-performance tool wraps your Padrino commands to run specific performance suites. The syntax is:

    bundle exec padrino-performance SUITE -- bundle exec padrino COMMAND

    Available suites:

    • JSON suite (-j or --json): Detects conflicting JSON libraries declared in your Gemfile that perform similar functions.
    • Memory suite (-m or --mem): Prints the memory usage of your application upon startup.
  2. Overview of Padrino framework features

    master

    Padrino is a Ruby framework built on top of Sinatra, designed to provide a standard library of tools for complex applications while maintaining Sinatra's lightweight philosophy. Key features include:

    • Agnosticism: Supports various testing, templating, mocking, and data storage choices.
    • Generators: Use padrino-gen to create applications, models, and controllers.
    • Mountable: Designed to mount multiple applications.
    • Routing: Supports named routes, named params, and before/after filters.
    • Helpers: Includes Tag, Asset, Form, and Text helpers (e.g., link_to, form_for, sanitize_html).
    • Mailer: Fast and simple email delivery support.
    • Caching: Route and fragment caching.
    • Admin: Built-in admin interface.
    • Localization: Full I18n support with automatic locale setting.
    • Reloading: Automatic server code reloading during development.
  3. Configure CSRF protection and sessions

    master

    Padrino includes built-in CSRF protection. By default, :protect_from_csrf and :sessions are disabled.

    To enable CSRF protection, you must also enable sessions:

    enable :sessions
    enable :protect_from_csrf

    If you are using a custom session store and want to suppress the warning that occurs when protect_from_csrf is active without standard sessions, set the following constant in your boot.rb:

    Padrino::IGNORE_CSRF_SETUP_WARNING = true
  4. Generate I18n translation files for Mongoid models

    master

    The mi:translate task automates the creation of I18n YAML files for your Mongoid models. It scans your app/models directory, identifies classes that include Mongoid::Document, and generates translation files in app/locale/models/{model_name}/{locale}.yml.

    Features:

    • Creates directory structures for each model.
    • Populates the YAML with the model's human name and its field names (excluding fields matching /id/i).
    • If the translation file already exists, it appends missing field translations instead of overwriting the entire file.
    • Supports the current I18n.locale.
  5. Configure SMTP delivery for padrino-mailer

    master

    By default, padrino-mailer uses the server's built-in sendmail command. To use SMTP (e.g., for Gmail), configure the :delivery_method setting in your application. Once defined, this becomes the default delivery method, though it can be overridden per message using the via option.

    set :delivery_method, smtp: {
      address:              "smtp.gmail.com",
      port:                 587,
      domain:               'your.host.name',
      user_name:            '<username>',
      password:             '<password>',
      authentication:       'plain',
      enable_starttls_auto: true
    }
  6. Configure the Padrino logger

    master

    You can replace the default Padrino logger with a custom logger. If you use a custom logger, you must manually extend it with Padrino::Logger::Extensions to maintain features like colorization and specialized logging methods.

    Alternatively, you can configure the logger before the framework loads by setting the PADRINO_LOGGER environment variable with a configuration hash.

    # Using a standard Ruby logger
    require 'logger'
    new_logger = ::Logger.new(STDOUT)
    new_logger.extend(Padrino::Logger::Extensions)
    Padrino.logger = new_logger
    
    # Using ActiveSupport BufferedLogger
    require 'active_support/buffered_logger'
    Padrino.logger = Buffered.new(STDOUT)
    
    # Using a custom class
    require 'logger'
    class CustomLogger < ::Logger
      include Padrino::Logger::Extensions
    end
    Padrino.logger = CustomLogger.new(STDOUT)