All Projects → duct-framework → Core

duct-framework / Core

The core library of the Duct framework

Programming Languages

clojure
4091 projects

Labels

Projects that are alternatives of or similar to Core

Brick
A declarative Unix terminal UI programming library written in Haskell
Stars: ✭ 1,070 (+1654.1%)
Mutual labels:  framework
Dragon
⚡A powerful HTTP router and URL matcher for building Deno web servers.
Stars: ✭ 56 (-8.2%)
Mutual labels:  framework
Broid Kit
Bot framework powered by Broid
Stars: ✭ 58 (-4.92%)
Mutual labels:  framework
Biota
A simple database framework for Fauna
Stars: ✭ 54 (-11.48%)
Mutual labels:  framework
Monster Ui
The JavaScript framework to leverages the power of Kazoo
Stars: ✭ 54 (-11.48%)
Mutual labels:  framework
Endtoend Predictive Modeling Using Python
Stars: ✭ 56 (-8.2%)
Mutual labels:  framework
Text Classification Keras
📚 Text classification library with Keras
Stars: ✭ 53 (-13.11%)
Mutual labels:  framework
Novo Elements
UI Repository for Bullhorn's Novo Theme
Stars: ✭ 59 (-3.28%)
Mutual labels:  framework
Antmove
小程序转换器,基于支付宝/微信小程序, 轻松地转换成其它平台的小程序。
Stars: ✭ 1,078 (+1667.21%)
Mutual labels:  framework
Keyboardhidemanager
Codeless manager to hide keyboard by tapping on views for iOS written in Swift
Stars: ✭ 57 (-6.56%)
Mutual labels:  framework
Framework
IONDV. Framework is a high level framework for enterprise web applications development.
Stars: ✭ 54 (-11.48%)
Mutual labels:  framework
Objcxx
Stars: ✭ 54 (-11.48%)
Mutual labels:  framework
Apprun
AppRun is a JavaScript library for developing high-performance and reliable web applications using the elm inspired architecture, events and components.
Stars: ✭ 1,087 (+1681.97%)
Mutual labels:  framework
Psychosynth
GNU Psychosynth is a a synthesizer and modular audio framework inspired by the ideas of the Reactable.
Stars: ✭ 53 (-13.11%)
Mutual labels:  framework
Danf
Danf is a Node.js full-stack isomorphic OOP framework allowing to code the same way on both client and server sides. It helps you to make deep architectures and handle asynchronous flows in order to help in producing scalable, maintainable, testable and performant applications.
Stars: ✭ 58 (-4.92%)
Mutual labels:  framework
Framework
Assely is a PHP framework which brings a little joy to the WordPress development. Develop structured, easily scalable and complex WordPress websites and web applications with true pleasure.
Stars: ✭ 53 (-13.11%)
Mutual labels:  framework
Bootstrap Dark
The Definitive Guide to Dark Mode and Bootstrap 4 - A proof of concept
Stars: ✭ 54 (-11.48%)
Mutual labels:  framework
Flexicms
Flexible site management system Flexi CMS
Stars: ✭ 61 (+0%)
Mutual labels:  framework
Assely
Assely introduces some standarized and comfortable ways for creating WordPress powered applications.
Stars: ✭ 59 (-3.28%)
Mutual labels:  framework
Zeva
a modern and minimalist ui framework for building responsive and modern frontends
Stars: ✭ 57 (-6.56%)
Mutual labels:  framework

Duct core

Build Status

The core of the next iteration of the Duct framework. It extends the Integrant micro-framework with support for modules, asset compilation and environment variables.

Installation

To install, add the following to your project :dependencies:

[duct/core "0.8.0"]

Usage

First we need to read in an Integrant configuration from a file or resource:

(require '[clojure.java.io :as io]
         '[duct.core :as duct])

(defn get-config []
  (duct/read-config (io/resource "example/config.edn")))

Once we have a configuration, we have three options. The first option is to prep-config the configuration, which will load in all relevant namespaces and apply all modules.

This is ideally used with integrant.repl:

(require '[integrant.repl :refer :all])

(set-prep! #(duct/prep-config (get-config)))

Alternatively we can prep-config then exec-config the configuration. This initiates the configuration, then blocks the current thread if the system includes any keys deriving from :duct/daemon. This is designed to be used from the -main function:

(defn -main []
  (-> (get-config) (duct/prep-config) (duct/exec-config)))

You can change the executed keys to anything you want by adding in an additional argument. This is frequently used with the parse-keys function, which parses keywords from command-line arguments:

(defn -main [& args]
  (let [keys (or (duct/parse-keys args) [:duct/daemon])]
    (-> (get-config)
        (duct/prep-config keys)
        (duct/exec-config keys))))

This allows other parts of the system to be selectively executed. For example:

lein run :duct/compiler

Would initiate all the compiler keys. And:

lein run :duct/migrator

Would initiate the migrator and run all pending migrations. If no arguments are supplied, the keys default to [:duct/daemon] in this example.

Keys

This library introduces a number of Integrant components:

  • :duct/const is a component that returns its value when initialized.
  • :duct/module denotes a Duct module (see the modules section).
  • :duct/profile denotes a Duct profile (see the profiles section).
  • :duct.core/environment specifies the environment of the configuration, and may be set to :development or :production. It does nothing on its own, but may be used by modules.
  • :duct.core/project-ns specifies the base namespace of your project. This is often used by modules for determining where to put things. For example, public web resources are typically placed in the resources/<project-ns>/public directory.

Readers

This library also introduces five new reader tags that can be used in Duct configurations:

  • #duct/env "VARNAME" allows an environment variable to be referenced in the configuration.
  • #duct/include "path" will include replace the tag with the resource at the specified path. This allows a configuration to be split up into separate files.
  • #duct/resource "path" will convert a resource path into a URL
  • #duct/displace is equivalent to ^:displace, but works with primitive values
  • #duct/replace is equivalent to ^:replace, but works with primitive values

Modules

Modules are Integrant components that initialize into a pure function. This function expects a configuration as its argument, and returns a modified configuration.

Most modules derive from :duct/module. This both identifies them, and ensures they are executed after profiles.

Here's a simple example module:

(require '[integrant.core :as ig])

(derive :duct.module/example :duct/module)

(defmethod ig/init-key :duct.module/example [_ {:keys [port]}]
  (fn [config]
    (assoc-in config [:duct.server.http/jetty :port] port)))

This above module updates the port number of the :duct.server.http/jetty key. By itself this isn't hugely useful, but modules can be made to update many different components at once.

Modules can also have dependencies, achieved using integrant.core/prep-key:

(defmethod ig/prep-key :duct.module/example [_ options]
  (assoc options ::requires (ig/ref :duct.module/parent)))

This adds a reference to the module's options, ensuring that Integrant will initialize the :duct.module/parent module before :duct.module/example.

You can also have optional dependencies with integrant.core/refset:

(defmethod ig/prep-key :duct.module/example [_ options]
  (assoc options ::requires (ig/refset #{:duct.module/parent})))

Profiles

A profile is (currently) a type of module that merges the value of the key into the resulting configuration.

There are five profile keys included in this library:

  • :duct.profile/base is the base of all new profiles
  • :duct.profile/dev is a profile for development
  • :duct.profile/local is a profile only on your local development machine
  • :duct.profile/test is a profile for testing
  • :duct.profile/prod is a profile for production

Documentation

License

Copyright © 2020 James Reeves

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].