Basic Setup

After the release of Clojure 1.9 and the introduction of the clj command, I have decided to modify and formalize my recommendations for a local setup of Liquid, in local environment. 

 

The approach I will introduce, will also encapsulate a structured way to manage Liquid extensions. 

Prerequisites

For this tutorial, I will assume the following is already installed on your system: 

 

  • Java
  • Git
  • Clojure 1.9 with clj command. See clojure.org
  •  

    Further more, I will assume you are running Ubuntu with username "liana". (Please adjust according to your own environment. Also create folders, if they do not exist yet.) 

     

    If nothing else is specified, the commands I provide probably needs to be executed in a terminal. 

     

    To check the clj command works, execute: clj --help and verify that Clojure help is shown. 

    Step 1: Clone liquid

    In the folder /home/liana/proj execute: 

     

    git clone https://github.com/mogenslund/liquid.git
    

     

    This will download Liquid into /home/liana/proj/liquid

    Step 2: Clone an extension

    To illustrate how an extensions can be added, I will use the additives extension. 

     

    In the folder /home/liana/proj execute: 

     

    git clone https://github.com/mogenslund/additives.git
    

     

    This will download Additives into /home/liana/proj/additives

    Step 3: Create an area for local customizations

    Create the folder /home/liana/liq. (In practice it could be any folder.) 

     

    Create a deps.edn file in the folder, where load paths can be specified. 

     

    The content of deps.edn corresponds to the classpath concept for Java and with the option to also specify Maven/Clojars resources. It was introduces together with Clojure 1.9 and the "clj" command. 

     

    Set content of /home/liana/liq/deps.edn to: 

     

    {:deps {org.clojure/data.json {:mvn/version "0.2.6"}
            org.clojure/core.async {:mvn/version "0.3.465"}}
     :paths ["src"
             "../proj/liquid/src"
             "../proj/liquid/resources"
             "../proj/additives/src"]}
    

     

    The org.clojure/data.json and org.clojure/core.async dependencies I have included as example of, how internet resources can be included. 

     

    The paths are relative inclusions of Liquid, Additives and a local "src" folder, for your own scripts. 

    Step 4: Customize the start up and add your own scripts

    Create the folders and file /home/liana/liq/src/liana/core.clj

     

    Instead of loading Liquid directly we will load it through liana.core, to make it possible to customize it. 

     

    Set the content of /home/liana/liq/src/liana/core.clj to: 

     

    (ns liana.core
      (:require [dk.salza.liq.editor :as editor]
                [dk.salza.liq.core]))
    
    (defn -main
      [& args]
      (apply dk.salza.liq.core/startup args)
      (dk.salza.liq.core/init-editor)
      (editor/add-snippet "I am Liana")
      (editor/updated))
    
    (ns user
      (:require [dk.salza.liq.tools.cshell :refer :all]
                [dk.salza.additives.blob :refer :all]))
    

     

    When executed this script will do the following: 

     

  • Load some defaults from dk.salza.liq.core
  • Use default initialization from dk.salza.liq.core
  • Make the snippet "I am Liana" available from the C-Space typeahead
  • Load functions from cshell and blob into the user namespace
  •  

    Calling the core functions startup and init-editor is recommended to load the basic features of the editor. But in cases where you want complete flexibility, you might skip the steps and replace them with your own implementations. (This I will consider advanced customizations, like implementing vim in Liquid.) 

    Step 5: Running Liquid with customizations

    To execute Liquid with the new setup cd to /home/liana/liq and execute 

     

    clj -m liana.core
    

     

    This will start Liquid with the extensions and custom functions. The first time it is called it will download the dependencies from the internet. 

     

    Try C-Space to see that "I am Liana" is available as snippet. 

     

    Enter the text (today) and execute it by typing "e" in navigation mode (blue cursor), while the cursor is inside the expression. This will display the date in the prompt. This shows that cshell has been loaded into user namespace. 

     

    If for some reason you want to start vanilla Liquid just start it with: 

     

    clj -m dk.salza.liq.core
    

     

    It will just load the defaults, but still with the classpaths available, but no "I am Liana".