Giter VIP home page Giter VIP logo

dekorator's Introduction

Komposable

Maintainability

Komposable allows you to quickly build a modular back-office for your Rails app. It offers standard features and allows you to implement you own specific needs easily.

It's based on the following existing gems:

This gem has been inspired by fae. It is developed by Ouvrages and Etamin Studio.

Getting started

# Gemfile

gem "komposable"

# For now, we have to add it manually
# TODO: include it in the gemspec dependencies
gem 'meta-tags', github: 'etaminstudio/meta-tags', branch: 'rename-title-helper'

Copy and run the migrations from the engine:

bin/rails komposable:install:migrations
bin/rails db:migrate

Add at the beginning of the routes:

# config/routes.rb

namespace :admin do
  root "pages#index"
  resources :pages
end

mount Komposable::Engine => "/admin"

Add at the end of the file:

# config/initializers/assets.rb

Rails.application.config.assets.precompile += %w( admin.js admin.css )

Add the engine path to resolved paths for webpacker and postcss:

# config/webpacker.yml

  resolved_paths:
    - frontend
    - vendor/komposable/frontend
# .postcssrc.yml

  postcss-import: {
    path: [
      'frontend',
      'vendor/komposable/frontend'
    ]
  }

Create a new javascript pack:

// frontend/packs/admin.js

import "komposable/frontend/packs/admin";

Navigation

To define your own navigation in the admin, you can override the admin/header component.

$ mkdir frontend/components/admin
$ cp -r vendor/komposable/frontend/components/admin/header frontend/components/admin

dekorator's People

Contributors

dependabot[bot] avatar nicolas-brousse avatar spone avatar tbuehlmann avatar tcsthemechanic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

tbuehlmann

dekorator's Issues

Improve Railtie

We should update the Railtie to update the autoload path as following.

config.after_initialize do |app|
  app.config.paths.add 'app/decorators', eager_load: true
end

Avoid deep decoration

decorate(decorate(Post.new)) should not decorate the decorated object.

def decorate(object_or_collection, with: nil)
  return object_or_collection if object_or_collection.blank? || object_or_collection.is_a?(Dekorator::Base) || object_or_collection.is_a?(DecoratedEnumerableProxy)

  ...
end

Additional SQL query for AR Relations

Hey there,

playing with dekorator for the first time. I was exploring the source code and found the following method:

def decorable?(object_or_enumerable)
return false if object_or_enumerable.respond_to?(:empty?) && object_or_enumerable.empty?
return false if !object_or_enumerable
return false if object_or_enumerable.is_a?(Dekorator::Base)
true
end

I'm interested in the design decision for object_or_enumerable.respond_to?(:empty?) && object_or_enumerable.empty?. I see how it can be useful for basic arrays (although iterating over an empty array isn't bad either), but when passing an AR Relation, that line will perform an additional query:

[1] pry(main)> Dekorator::Base.decorate(User.all)
  User Exists? (0.6ms)  SELECT 1 AS one FROM "users" LIMIT $1  [["LIMIT", 1]]
  User Load (0.4ms)  SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT $1  [["LIMIT", 1]]

[2] pry(main)> Dekorator::Base.decorate(User.all.to_a)
  User Load (0.5ms)  SELECT "users".* FROM "users"

Is that intended behaviour?

Test generators

  • Do specs to test dekorator:install and decorator generators.
  • Generate a dummy_app one time, then duplicate it to do tests from scrash

Concern to have #decorated on model

Does a concern could be a nice to have for model to access decorated object by itself.

Something like

module Decorable
  def decorated
    @decorate ||= decorate_class.decorate(self)
  end

  def decorator_class
    @decorator_class ||= "#{object_or_enumerable.class}Decorator".safe_constantize
  end
end

So in a model

class User < ApplicationRecord
  include Decorable
  ...

  def decorator_class
    CustomDecorator
  end
end

user = User.first # => User
user.decorated # => CustomDecorator

Better benchmark

In #28 we implement a benchmark and did some optimization.

I think our benchmark could be improved. It the first time I did one, so I'm sure it's not perfect.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.