GithubHelp home page GithubHelp logo

kotlin-ace-wrapper's Introduction

Release npm version Build Status

Kotlin + Ace (wrapper)

Ace is a great embeddable code editor which provides a ton of themes and language modes to work with. However, writing new modes or syntax validators is not always easy. Especially since in most cases, you end up writing one parser for the front-end (data entry) and then another for the back-end (data processing). To get rid of this duplicity, we want to use the same language for both front-end and back-end: Kotlin.

Due to various design decisions made by Ace and Kotlin teams, this isn't always as easy as it could be. This library takes away the pain of working with Ace editor inside Kotlin by exposing Ace's API as standard Kotlin classes.

Project structure

The library supports two contexts: web and worker. Web is the standard Ace environment while worker provides a reduced set of features for syntax validation web-workers. Furthermore, there is a common module for shared classes and declarations and a loader module which allows importing the Ace classes when using webpack.

Finally, there is a demo worker and demo web module which illustrate the intended usage. The demo provides a very simple custom highlighter and validator which allow you to enter arbitrary arithmetic expression (numbers, +, -, /, *, parenthesis) and check that the parenthesis are correctly nested and closed. You can try the demo here.

Getting started

The library is designed to work with the Kotlin frontend plugin as demonstrated in the demo module. If you don't want to use the frontend plugin, you can still use the library with plain old webpack.

Unfortunately, in order to properly load all Ace classes into the Kotlin context, a custom loader has to be used. When using webpack, this is facilitated by the provided loader. If not using webpack, you will have to declare these modules in some other way. In case of problems, feel free to create a new issue.

To start working with the web context in a gradle project, you simply have to add Jitpack into your list of repositories and include the dependency:

repositories {
   ...
   maven { url 'https://jitpack.io' }
}

dependencies {
   ...
   implementation 'com.github.daemontus.kotlin-ace-wrapper:kotlin-ace-web:1.3.36'
}

// If you are using the frontend plugin, inlude also the NPM dependency:
kotlinFrontend {
   npm {
      dependency("kotlin-ace-web", "1.3.36")
   }
}

Then, you can start using Ace in your Kotlin code just as you would in JS:

val editor = Ace.edit("editor")
val mode = MyCustomMode(editor)
editor.getSession().setMode(mode)

For web workers, the process is a little more complicated (the web worker has to be created as a separate module, because the contexts can't mix). For full description, head to the custom web worker tutorial.

Tutorials

To see how to use the wrapper efficiently, please refer to some of the following tutorials:

Maintaining, completeness, documentation, versioning

Currently, the wrapper exposes most methods documented in the Ace API reference and also some undocumented APIs which are necessary for extending Ace's basic functionality. However, there is no comprehensive documentation for the wrapper itself. It would be awesome to have a more detailed documentation in the future. However, this is just a small sideproject, so I mainly maintain and test the features I actually need and the documentation focuses mainly on tutorials. If you find some inconsistency with the actual Ace API or some missing features, feel free to send a pull request or create an issue. Ideally, please provide a use case for testing this problem too.

The version numbers always match the used version of Ace suffixed with a patch version of the library. So a version 1.3.36 uses Ace 1.3.3 and it is the 6th patch version. While this is not ideal, for now, it seems to be the best solution which also correctly works with the semantic versioning used by npm.

kotlin-ace-wrapper's People

Contributors

daemontus avatar xian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

mxj4 baaahs

kotlin-ace-wrapper's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.