maiha / active-scaffold.cr

ActiveScaffold for Amber on Crystal

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

active_scaffold.cr Build Status

ActiveScaffold for Amber on Crystal.

  • amber-0.6.7
  • granite-orm (maiha fork)
  • crystal-0.24.1

Installation

Add this to your amber application's shard.yml:

dependencies:
  active_scaffold:
    github: maiha/active_scaffold.cr
    version: 0.3.7

  granite_orm:
    #github: amberframework/granite-orm
    github: maiha/granite-orm
    branch: master

Usage

require "active_scaffold"

class UsersController < ApplicationController
  include ActiveScaffold(User)

  active_scaffold do |config|
    # config.id = "code" # primary key (default: "id")

    config.columns = ["first_name", "last_name"]
    config.actions = ["list", "show"]
    config.action_links["show"].label = "View"

    config.list.paging.order  = "id DESC"
    config.list.paging.limit  = 15
    config.list.paging.window = 5
    # config.list.paging.count = false # disable `SELECT COUNT`

    config.show.label = "user(%s)"
  end
end

Global settings

You can put global settings in ActiveScaffold::Default that sets default values to all controllers.

ActiveScaffold::Default::List::PAGING = {limit: 5}

All configurable parameters are in ActiveScaffold::Default. See https://github.com/maiha/active-scaffold.cr/wiki/API:-Global-settings

Debug

  • add ?debug parameter to the url, or
  active_scaffold do |config|
    config.debug = true

API

Install

Currently, there are no full generators. So please setup files manually as follows.

once for an application

  • public/dist/active_scaffold.css -> ../../lib/active_scaffold/src/active_scaffold/assets/stylesheets/active_scaffold.css
(cd public/dist && ln -s ../../lib/active_scaffold/src/active_scaffold/assets/stylesheets/active_scaffold.css)
  • src/views/layouts/application.slang
    • add css to the end of head part
    • add js to the end of body part
link rel="stylesheet" href="/dist/active_scaffold.css"
script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"

Put into shard.yml.

targets:
  active_scaffold:
    main: lib/active_scaffold/bin/gen.cr

Then, build it.

shards build

each controllers

For example, please run following command for UsersController and User model.

./bin/active_scaffold users

This writes following files if missing.

  • config/routes.cr
  • src/models/user.cr
  • src/controllers/users_controller.cr
  • src/views/users -> ../../lib/active_scaffold/src/active_scaffold/views

TODO

  • data
    • ActiveScaffold::Data::Action(T)
    • ActiveScaffold::Data::Actions(T)
    • ActiveScaffold::Data::ActionLink(T)
    • ActiveScaffold::Data::ActionLinks(T)
    • ActiveScaffold::Data::Column(T)
    • ActiveScaffold::Data::Columns(T)
  • config
    • ActiveScaffold::Configure(T)
    • ActiveScaffold::Config::Base(T)
    • ActiveScaffold::Config::Core(T)
    • ActiveScaffold::Config::Edit(T)
    • ActiveScaffold::Config::List(T)
    • ActiveScaffold::Config::Search(T)
    • ActiveScaffold::Config::Show(T)
  • actions
    • ActiveScaffold::Actions::Create(T)
    • ActiveScaffold::Actions::Delete(T)
    • ActiveScaffold::Actions::Edit(T)
    • ActiveScaffold::Actions::List(T)
    • ActiveScaffold::Actions::New(T)
    • ActiveScaffold::Actions::Show(T)
    • ActiveScaffold::Actions::Update(T)
  • features
    • debug
    • pagination
    • sorting
    • global settings
    • ajax
    • search
    • in place editor
    • assosications
    • nested
    • generators
    • auths and roles
    • localizations

Development

crystal spec -v

Contributing

  1. Fork it ( https://github.com/maiha/active_scaffold.cr/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • maiha maiha - creator, maintainer

About

ActiveScaffold for Amber on Crystal

License:MIT License


Languages

Language:CSS 49.9%Language:Crystal 48.6%Language:Makefile 1.5%