Vizir / carnival

[no longer maintained] An easy-to-use and extensible Rails Engine to speed up the development of data management interfaces.
MIT License
31 stars 16 forks source link

Carnival

By Vizir Logo

Carnival is an easy-to-use and extensible Rails Engine to speed up the development of data management interfaces. It provides a managing infra-structure for your application.

When you use Carnival you'll benefit from a set of features out-of-the-box. If you need to change anything, you can write your own version of the code, using real Ruby code in Rails standard components without worrying about a specific syntax or DSL.

Requirements

Features

Detailed features

Additional Docs

You can find more detailed docs in the links below:

Getting started

Add the gem to your Gemfile:

gem 'carnival'

Run bundle install.

Then, execute rails generate carnival:install to generate the initializer.

Basic Usage

Carnival started relying only on MVC model. As we developed it, we realized that a Presenter would better describe our models. We used the presenter to avoid fat models to emerge on our design.

Model

It is a regular Active Record model. We only have to include the Carnival Helper:

module Admin
  class Company < ActiveRecord::Base
    include Carnival::ModelHelper
  end
end

Controller

It is also a regular Controller, with some minor differences:

module Admin
  class CompaniesController < Carnival::BaseAdminController
    layout 'carnival/admin'

    # ...

    private

    def permitted_params
      params.permit(admin_company: [:name])
    end
  end
end

See more about the Controller at Controller Properties

Presenter

All the "magic" of Carnival happens at Presenter. Each model managed under Carnival Admin will have a presenter associated to it. The presenter describes how the model's attributes will be presented.

module Admin
  class CompanyPresenter < Carnival::BaseAdminPresenter
    field :id,
          actions: [:index, :show], sortable: false,
          advanced_search: { operator: :equal }
    field :name,
          actions: [:index, :new, :edit, :show],
          advanced_search: { operator: :like }
    field :created_at, actions: [:index, :show]

    action :show
    action :edit
    action :destroy
    action :new
  end
end

See more about the Presenter at Presenter Properties.

Menu

The menu of Carnival can be configured in the 'config/initializers/carnival_initializers.rb' file.

Eg.:

config.menu = {
  city: {
    label: 'city',
    class: '',
    link: 'admin_cities_path', # You can use the route name as String to define the link
    subs: [
      {
        label: 'custom_city',
        class: '',
        link: 'admin/custom/cities', # You can also use the full path
      },
      {
        label: 'google',
        class: '',
        link: 'http://www.google.com'
      }
    ]
  },

  # ...
}

Customizing Carnival

Custom Views

Carnival permits that you specify some partials for your page, you just need to add your partial in the app/views/carnival/extra_header.html.haml.

Possible Partials:

Configurations

Custom AdminUser

If you want to have your own AdminUser class or need to add methods to that class, you need to do the following steps:

  config.devise_class_name = 'MyAdminClass'

Custom Root Action

  config.root_action = 'my_controller#my_action'

Application Name

  config.app_name = 'Application Name'

I18n

You can add custom translations for the actions [:new, :show, :edit, :destroy]

  company:
    new: Create New company
    show: Show company

Integrations

It can be easily integrated with gems that you already know and use.

Authentication

Rich Text Editor

File upload