elm-compiler 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -2
- data/.travis.yml +3 -2
- data/README.md +42 -9
- data/elm-package.json +15 -0
- data/lib/elm/compiler.rb +12 -15
- data/lib/elm/compiler/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a22cb64058f5d0317d5eca7e70d53e0eb05819a8
|
4
|
+
data.tar.gz: 66bf2ee4d3349832e6ec155fdbf2fdcf227617b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cc9ae96a797f4249b066e5bd6976b823ac7129efd18fc884791b5948541d0e60c09cc6715d56cdf1675f656dcb2d2b0adc62f474ffe73a6c3b07bb14431439c
|
7
|
+
data.tar.gz: 07fbb644d45b8571da8202db901ff309d2abc514edafea7c25ba67e3aebc45dfbbae1282539aa31ee9ce9aeaf6f0b66897cc3341e23e7160ae310cfe6c4d71ee
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,13 +1,17 @@
|
|
1
|
-
#
|
1
|
+
# elm-compiler
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/fbonetti/ruby-elm-compiler.svg?branch=master)](https://travis-ci.org/fbonetti/ruby-elm-compiler)
|
4
4
|
|
5
|
-
|
5
|
+
Ruby wrapper for the [Elm language compiler](https://github.com/elm-lang/elm-compiler).
|
6
6
|
|
7
|
-
|
7
|
+
The project is heavily inspired by the [sprockets-elm](https://github.com/NoRedInk/sprockets-elm/blob/0752748904edee0c25f2dd49cc39186c2ef61b08/lib/elm_compiler.rb) repository, written by [rtfeldman](https://github.com/rtfeldman).
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
11
|
+
Install the Elm platform:
|
12
|
+
|
13
|
+
http://elm-lang.org/install
|
14
|
+
|
11
15
|
Add this line to your application's Gemfile:
|
12
16
|
|
13
17
|
```ruby
|
@@ -24,20 +28,49 @@ Or install it yourself as:
|
|
24
28
|
|
25
29
|
## Usage
|
26
30
|
|
27
|
-
|
31
|
+
> NOTE: Make sure [Elm](http://elm-lang.org/install) is installed. If the `elm-make` executable can't be found in the current `PATH` or via the `elm_make_path` option, the exception `Elm::Compiler::ExecutableNotFound` will be thrown.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
Elm::Compiler.compile(elm_files, output_path: nil, elm_make_path: nil)
|
35
|
+
```
|
36
|
+
|
37
|
+
* `elm_files`: Accepts a single file path or an array of file paths.
|
38
|
+
* `output_path`: Path to the output file. If left blank, the compiled Javascript will be returned as a string.
|
39
|
+
* `elm_make_path`: Path to the `elm-make` executable. If left blank, the executable will be looked up in the current `PATH`.
|
28
40
|
|
29
|
-
## Development
|
30
41
|
|
31
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
32
42
|
|
33
|
-
|
43
|
+
## Examples
|
44
|
+
|
45
|
+
Compile to string of Javascript:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
Elm::Compiler.compile("Clock.elm")
|
49
|
+
```
|
50
|
+
|
51
|
+
Compile multiple files to a string of Javascript:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
Elm::Compiler.compile(["Clock.elm", "Counter.elm"])
|
55
|
+
```
|
56
|
+
|
57
|
+
Compile to file:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
Elm::Compiler.compile("Clock.elm", output_path: "elm.js")
|
61
|
+
```
|
62
|
+
|
63
|
+
Compile multiple files to file:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
Elm::Compiler.compile(["Clock.elm", "Counter.elm"], output_path: "elm.js")
|
67
|
+
```
|
34
68
|
|
35
69
|
## Contributing
|
36
70
|
|
37
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
71
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/fbonetti/elm-compiler.
|
38
72
|
|
39
73
|
|
40
74
|
## License
|
41
75
|
|
42
76
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
43
|
-
|
data/elm-package.json
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
{
|
2
|
+
"version": "1.0.0",
|
3
|
+
"summary": "elm-package.json for rspec test suite",
|
4
|
+
"repository": "https://github.com/user/project.git",
|
5
|
+
"license": "BSD3",
|
6
|
+
"source-directories": [
|
7
|
+
"."
|
8
|
+
],
|
9
|
+
"exposed-modules": [],
|
10
|
+
"dependencies": {
|
11
|
+
"elm-lang/core": "4.0.0 <= v < 5.0.0",
|
12
|
+
"elm-lang/html": "1.0.0 <= v < 2.0.0"
|
13
|
+
},
|
14
|
+
"elm-version": "0.17.0 <= v < 0.18.0"
|
15
|
+
}
|
data/lib/elm/compiler.rb
CHANGED
@@ -6,35 +6,32 @@ require 'mkmf'
|
|
6
6
|
module Elm
|
7
7
|
class Compiler
|
8
8
|
class << self
|
9
|
-
def compile(elm_files, output_path
|
10
|
-
|
9
|
+
def compile(elm_files, output_path: nil, elm_make_path: nil)
|
10
|
+
elm_executable = elm_make_path || find_executable0("elm-make")
|
11
|
+
fail ExecutableNotFound unless elm_executable_exists?(elm_executable)
|
11
12
|
|
12
13
|
if output_path
|
13
|
-
elm_make(elm_files, output_path)
|
14
|
+
elm_make(elm_executable, elm_files, output_path)
|
14
15
|
else
|
15
|
-
compile_to_string(elm_files)
|
16
|
+
compile_to_string(elm_executable, elm_files)
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
19
20
|
private
|
20
21
|
|
21
|
-
def elm_executable_exists?
|
22
|
-
|
22
|
+
def elm_executable_exists?(elm_executable)
|
23
|
+
File.executable?(elm_executable)
|
23
24
|
end
|
24
25
|
|
25
|
-
def compile_to_string(elm_files)
|
26
|
-
output = ''
|
27
|
-
|
26
|
+
def compile_to_string(elm_executable, elm_files)
|
28
27
|
Tempfile.open(['elm', '.js']) do |tempfile|
|
29
|
-
elm_make(elm_files, tempfile.path)
|
30
|
-
|
28
|
+
elm_make(elm_executable, elm_files, tempfile.path)
|
29
|
+
return File.read tempfile.path
|
31
30
|
end
|
32
|
-
|
33
|
-
output
|
34
31
|
end
|
35
32
|
|
36
|
-
def elm_make(elm_files, output_path)
|
37
|
-
Open3.popen3(
|
33
|
+
def elm_make(elm_executable, elm_files, output_path)
|
34
|
+
Open3.popen3({"LANG" => "en_US.UTF8" }, elm_executable, *elm_files, '--yes', '--output', output_path) do |_stdin, _stdout, stderr, wait_thr|
|
38
35
|
fail CompileError, stderr.gets(nil) if wait_thr.value.exitstatus != 0
|
39
36
|
end
|
40
37
|
end
|
data/lib/elm/compiler/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elm-compiler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frank Bonetti
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- bin/rubocop
|
87
87
|
- bin/setup
|
88
88
|
- elm-compiler.gemspec
|
89
|
+
- elm-package.json
|
89
90
|
- lib/elm-compiler.rb
|
90
91
|
- lib/elm/compiler.rb
|
91
92
|
- lib/elm/compiler/exceptions.rb
|