Skip to content

Commit 279e404

Browse files
committed
Documentation updates
1 parent 39f9b5f commit 279e404

File tree

7 files changed

+55
-22
lines changed

7 files changed

+55
-22
lines changed

GettingStarted.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
# Getting Started with ElixirScript
1+
# Getting Started
22

33
The intent of this guide is to get you started with ElixirScript. It will give you instructions on using ElixirScript.
44

5-
Adding Elixirscript to your mix project gives you the ability to add it to your list of mix compilers. This means when you `mix compile`, Elixirscript will compile your code as well.
5+
Adding ElixirScript to your mix project gives you the ability to add it to your list of mix compilers. This means when you `mix compile`, ElixirScript will compile your code as well.
66

77
Add dependency to your deps in mix.exs:
88

99
``` elixir
1010
{:elixir_script, "~> 0.30"}
1111
```
1212

13-
Elixirscript uses default output and module formats if options are not given. If you wish to change any or all options, add an `elixir_script` key to your project configuration.
13+
Next make sure to add ElixirScript to your list of compilers in mix.exs.
14+
15+
ElixirScript must be told which modules to use as the entry to your ElixirScript application. This is done by adding an `elixir_script` key to your project configuration. This must be a keyword list. Add an `input` key and make the value either the name of a module or a list of modules that are the entry modules you wish to compile to JavaScript. ElixirScript will use those modules to find what other modules and functions it needs to convert to JavaScript. ElixirScript by default places output in `priv/elixir_script/build`. If you wish to change this, add an `output` key to your ElixirScript configuration.
16+
17+
An example configuration for a project is shown below
1418

1519
``` elixir
1620
def project do
@@ -19,18 +23,22 @@ Elixirscript uses default output and module formats if options are not given. If
1923
version: "0.1.0",
2024
elixir: "~> 1.0",
2125
deps: deps,
26+
# Add elixir_script as a compilter
27+
compilers: Mix.compilers ++ [:elixir_script],
28+
# Our elixir_script configuration
2229
elixir_script: [
30+
# Entry module. Can also be a list of modules
2331
input: MyEntryModule,
32+
# Output path. Either a path to a js file or a directory
2433
output: "priv/elixir_script/build/Elixir.App.js"
25-
],
26-
compilers: Mix.compilers ++ [:elixir_script]
34+
]
2735
]
2836
end
2937
```
3038

3139
Available options are:
3240

33-
* `input`: The entry module(s) for your application or library
41+
* `input` (required): The entry module(s) for your application or library
3442

3543
* `output`: The path of the generated JavaScript file. (defaults to `priv/elixir_script/build`)
3644

@@ -53,10 +61,10 @@ Now run `mix compile` and you should see a JavaScript file named `Elixir.App.js`
5361

5462
If your browser does not yet support ES modules directly, use a tool such as [webpack](https://webpack.js.org/) or [brunch](http://brunch.io/) to convert it into something that can be used in the browser
5563

56-
### Macros
57-
58-
Elixirscript supports all macros
59-
6064
### JavaScript Interop
6165

6266
Check out the [JavaScript Interoperability](JavascriptInterop.html) documentation
67+
68+
### Limitations
69+
70+
ElixirScript does not support `receive` or any of OTP at this time.

JavascriptInterop.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
### ElixirScript.JS module
66

77
The `ElixirScript.JS` module has functions and macros that help with interacting with JavaScript.
8-
These mostly correspond to JavaScript keywords that may be useful.
8+
Most of them correspond to JavaScript keywords that may be useful.
99

1010
```elixir
1111
# Calling the JavaScript Debugger
@@ -17,7 +17,7 @@ ElixirScript.JS.typeof(my_value)
1717

1818
### Foreign Function Interface
1919

20-
ElixirScript calls JavaScript modules through a Foreign Function Interface (FFI). A foreign module is defined by creating a new module and adding `use ElixirScript.FFI` to it.
20+
ElixirScript calls JavaScript modules through a Foreign Function Interface (FFI). A foreign module is defined by creating a new Elixir module and adding `use ElixirScript.FFI` to it.
2121

2222
Here is an example of a foreign module for a JSON module
2323

lib/elixir_script/compiler.ex

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
defmodule ElixirScript.Compiler do
22
@moduledoc """
3-
Compiles the given modules to JavaScript.
3+
The entry point for the ElixirScript compilation process.
4+
Takes the given module(s) and compiles them and all modules
5+
and functions they use into JavaScript
46
"""
57

68
@doc """
79
Takes either a module name or a list of module names as
810
the entry point(s) of an application/library. From there
911
it will determine which modules and functions are needed
1012
to be compiled.
13+
14+
Available options are:
15+
* `output`: The path of the generated JavaScript file.
16+
17+
If output is `nil`, then generated code is sent to standard out
18+
19+
If output is a path, the generated code placed in that path.
20+
If path ends in `.js` then that will be the name of the file.
21+
If a directory is given, file will be named `Elixir.App.js`
22+
23+
* `root`: Optional root for imports of FFI JavaScript modules. Defaults to `.`.
1124
"""
12-
@spec compile([atom], []) :: nil
25+
@spec compile(atom | [atom], []) :: nil
1326
def compile(entry_modules, opts \\ []) do
1427
opts = build_compiler_options(opts, entry_modules)
1528
{:ok, pid} = ElixirScript.State.start_link(opts)

lib/elixir_script/ffi.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
defmodule ElixirScript.FFI do
22
@moduledoc """
3-
The foreign function interface for interacting with JavaScript
3+
The Foreign Function Interface (FFI) for interacting with JavaScript
44
55
To define a foreign module, make a new module and add `use ElixirScript.FFI`. to it
66
To define external functions, use the `defexternal` macro.

lib/elixir_script/lib/js.ex

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ defmodule ElixirScript.JS do
1010
@doc """
1111
Creates new JavaScript objects.
1212
13-
ex:
14-
ElixirScript.JS.new User, ["first_name", "last_name"]
13+
```elixir
14+
ElixirScript.JS.new User, ["first_name", "last_name"]
15+
```
1516
"""
1617
defexternal new(module, params)
1718

@@ -42,8 +43,10 @@ defmodule ElixirScript.JS do
4243

4344
@doc """
4445
Mutates an existing JavaScript object.
45-
ex:
46-
ElixirScript.JS.mutate elem, "width", 100
46+
47+
```elixir
48+
ElixirScript.JS.mutate elem, "width", 100
49+
```
4750
"""
4851
defexternal mutate(object, key, value)
4952

@@ -52,8 +55,11 @@ defmodule ElixirScript.JS do
5255
Takes the given map and returns an object
5356
Throws an error if any key is not a
5457
number, binary, or atom
55-
ex:
56-
ElixirScript.JS.map_to_object(%{my: "map"})
58+
59+
60+
```elixir
61+
ElixirScript.JS.map_to_object(%{my: "map"})
62+
```
5763
"""
5864
defexternal map_to_object(object)
5965
end

lib/elixir_script/watcher.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ defmodule ElixirScript.Watcher do
33
require Logger
44

55
@moduledoc """
6-
Watches the input folder for changes and calls the ElixirScript compiler
6+
Watches for code changes and calls the ElixirScript compiler.
7+
8+
This module watches for changes in BEAM files. When there is a change,
9+
it calls the ElixirScript compiler to recompile.
710
"""
811

912

lib/mix/tasks/compile.elixir_script.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ defmodule Mix.Tasks.Compile.ElixirScript do
2626
If path ends in `.js` then that will be the name of the file. If a directory is given,
2727
file will be named `Elixir.App.js`
2828
29+
* `root`: Optional root for imports of FFI JavaScript modules.
30+
Defaults to `.`. If using output directly in a browser, you may want to make it something like `/js` or some uri.
31+
2932
The mix compiler will also compile any dependencies that have the elixirscript compiler in its mix compilers as well
3033
"""
3134

0 commit comments

Comments
 (0)