/komposer

Collection of generators to create admin dashboard.

Primary LanguageRubyMIT LicenseMIT

Komposer

Installation

gem 'komposer'

In order to use Komposer in your administration panel, you need to require some dependencies.

// app/assets/javascripts/administration.js

//= require komposer
// app/assets/stylesheets/administration.scss

@import 'komposer';

Block

Usage

Generate new block with:

rails generate komposer:block title_block title:string

The previous command generates:

  • frontend/components/title_blocks/_block_form.html.slim
  • frontend/components/title_blocks/_title_block.html.slim
  • frontend/components/title_blocks/title_block.js
  • frontend/components/title_blocks/title_block.css
  • append to frontend/components/index.js

A block is very similar to component, but they have a form representation to be administrable.

To administrate the block since a back-office, you need to declare presence of blocks in model.

# app/models/article.rb

class Article < ApplicationRecord
  has_blocks([:title_blocks])
end
# app/views/articles/_form.html.slim

= bootstrap_form_for @article do |f|
  = f.blocks_form

Now in your frontend pages, you can just render blocks like normal Rails partials.

= render @article.blocks