elm-compiler 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c3b619b99ad5ff48857c4062bcdea5627896d82
4
- data.tar.gz: 02a695886391374ca47cb378f31c99a9ea668565
3
+ metadata.gz: a22cb64058f5d0317d5eca7e70d53e0eb05819a8
4
+ data.tar.gz: 66bf2ee4d3349832e6ec155fdbf2fdcf227617b5
5
5
  SHA512:
6
- metadata.gz: 84fdab3fc8742cad7bef8e73551c512a6a3e577081f1b7bc3c63772ee8afbdd83b0139b2308e924aad96f775bfe2aece41bb30d81f862e5c179ebafcd3b15583
7
- data.tar.gz: a5aa22da7f87a4b50eec7ab5d979ed5c4aba7435bd1c0c62b7d036b178eb9df039e5e2efc105fc806dfa4c8a5e1c32adac884fb87f37cf1f93334366d0e2a501
6
+ metadata.gz: 6cc9ae96a797f4249b066e5bd6976b823ac7129efd18fc884791b5948541d0e60c09cc6715d56cdf1675f656dcb2d2b0adc62f474ffe73a6c3b07bb14431439c
7
+ data.tar.gz: 07fbb644d45b8571da8202db901ff309d2abc514edafea7c25ba67e3aebc45dfbbae1282539aa31ee9ce9aeaf6f0b66897cc3341e23e7160ae310cfe6c4d71ee
data/.gitignore CHANGED
@@ -8,6 +8,5 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  /elm-stuff/
11
- /elm-package.json
12
11
  /elm.js
13
- *.gem
12
+ *.gem
data/.travis.yml CHANGED
@@ -3,8 +3,9 @@ cache: bundler
3
3
  rvm:
4
4
  - 2.2.3
5
5
  sudo: false
6
- before_install: gem install bundler -v 1.11.2
6
+ before_install:
7
+ - gem install bundler -v 1.11.2
7
8
  install:
8
- - npm install elm
9
9
  - bundle install
10
+ - npm install -g elm@0.17
10
11
  - elm-package install --yes
data/README.md CHANGED
@@ -1,13 +1,17 @@
1
- # Elm::Compiler
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
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/elm/compiler`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ Ruby wrapper for the [Elm language compiler](https://github.com/elm-lang/elm-compiler).
6
6
 
7
- TODO: Delete this and the text above, and describe your gem
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
- TODO: Write usage instructions here
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
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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/[USERNAME]/elm-compiler.
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 = nil)
10
- fail ExecutableNotFound unless elm_executable_exists?
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
- !find_executable0('elm-make').nil?
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
- output = File.read tempfile.path
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('elm-make', *elm_files, '--yes', '--output', output_path) do |_stdin, _stdout, stderr, wait_thr|
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
@@ -1,5 +1,5 @@
1
1
  module Elm
2
2
  class Compiler
3
- VERSION = '0.1.2'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
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.1.2
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: 2015-12-26 00:00:00.000000000 Z
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