One of the hidden coding challenges is organization. Code can quickly become unwieldy when not arranged and rearranged for clarity and modularity.
This short article is an introduction to how code organization seems to work for Lapis projects, and the necessary statements for accomplishing this task.
Lapis projects consist of a great many disparate components. Understanding these components in the first step towards an organized code base, which is in turn good for extending, maintaining, and debugging your project.
There are three keywords we use for pulling together code from the various folders:
While this statement is used in Lapis, it comes directly from moonscript, as documented right here.
One of the interesting things that appears to be missing from the official Lapis documentation, is the use of
require outside of accessing the built in Lapis tables. The example found throughout streak.club and elsewhere are examples like the following:
From within an app, something like:
import Users from require "models"
class Users extends Model
There are many more examples within the streak.club source code. It's well worth reading.
Our central application is
app.moon, which holds all the routes. Of course holding all routes in a single file is very bad for proper code organization. Luckily Lapis provides a solution.
We can make use of the
@include function which allows for the inclusion of sub-applications, as described in the official documentation. Thus we can hold various separable 'applications' in an applications folder. Example applications might be
The other organizational technique found in streak.club is the use of additional folder like helper, for holding reusable code snippets, like those for CSRF, or image handling, etc.
Aside from that, we also have the static as created during Lapis application creation.