github.com/maiha/active-scaffold.cr

ActiveScaffold for Amber on Crystal

2 stars
0 dependents
License: MIT

Installation

# Add this to your shard.yml
dependencies:
  active_scaffold:
    github: maiha/active-scaffold.cr
    version: ~> 0.3.7

Then run:

shards install

shard.yml

Crystal
no constraint declared
License
MIT
Author
maiha

Dependencies

Runtime Dependencies

  • db~> 0.5.0github: crystal-lang/crystal-db
  • var>= 0.2.1github: maiha/var.cr
  • amber~> 0.6.7github: amberframework/amber
  • pretty>= 0.5.6github: maiha/pretty.cr
  • granite_orm*github: maiha/granite-orm, branch: master

Development Dependencies

  • sqlite3*github: crystal-lang/crystal-sqlite3dev

README

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
    • [x] ActiveScaffold::Data::Action(T)
    • [x] ActiveScaffold::Data::Actions(T)
    • [x] ActiveScaffold::Data::ActionLink(T)
    • [x] ActiveScaffold::Data::ActionLinks(T)
    • [x] ActiveScaffold::Data::Column(T)
    • [x] ActiveScaffold::Data::Columns(T)
  • config
    • [x] ActiveScaffold::Configure(T)
    • [x] ActiveScaffold::Config::Base(T)
    • [x] ActiveScaffold::Config::Core(T)
    • [x] ActiveScaffold::Config::Edit(T)
    • [x] ActiveScaffold::Config::List(T)
    • [ ] ActiveScaffold::Config::Search(T)
    • [x] ActiveScaffold::Config::Show(T)
  • actions
    • [x] ActiveScaffold::Actions::Create(T)
    • [x] ActiveScaffold::Actions::Delete(T)
    • [x] ActiveScaffold::Actions::Edit(T)
    • [x] ActiveScaffold::Actions::List(T)
    • [x] ActiveScaffold::Actions::New(T)
    • [x] ActiveScaffold::Actions::Show(T)
    • [x] ActiveScaffold::Actions::Update(T)
  • features
    • [x] debug
    • [x] pagination
    • [x] sorting
    • [x] 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