jekyll_elm 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/elm_compiler.rb +73 -0
  3. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c8a5cd0f205d069219956b96942bee861b889081
4
- data.tar.gz: 712612012dc2a9631a103f834ae4a5bb9dc9c5f6
3
+ metadata.gz: 04645041ed715c885ea66f3aad90d998124623e4
4
+ data.tar.gz: e6ac664c265bcb9e39f36ad09880e4c998e036c2
5
5
  SHA512:
6
- metadata.gz: fb5deda22e5e89f58232efaa64b5d9b0efc1d84c4543f2594230587308ae5a6c88f54c943b3b570f999ad3f53ca2f710cfa283a538a301ad8030899910b425b9
7
- data.tar.gz: 073a0dac94090d2b617f518d6fb7321149ad1ffbd1284f6f854dddd370027deba1b31428885f7fbcf860421a8fd703a3ab025f450d239f61dec6141616508506
6
+ metadata.gz: 0edb43f93080c609105eec2654ff731ffeb5747a28dbe65f871f413cf0d2240c4f37cbb03634b01df218a83ee54e9b87d439b52333b002120f74bf12116838ba
7
+ data.tar.gz: bcfd832a49f2686e8af7f03a30ca8cd6f36522d4005bf42f1b94de99308af7a59336e50a575c8f803ed6070b08c32cb4efec3e9d26da0f1c92b225d0ab7b4325
@@ -0,0 +1,73 @@
1
+ require 'open3'
2
+ require 'securerandom'
3
+
4
+ class ElmCompiler
5
+ def initialize(content)
6
+ setup_dir
7
+
8
+ @content = content
9
+ end
10
+
11
+ def process!
12
+ output = '', status = nil
13
+
14
+ with_error_handling do
15
+ File.open(tmp_path, 'w') { |f| f.write(@content) }
16
+
17
+ in_elm_dir do
18
+ out, err, status = Open3.capture3("elm --make --runtime=/javascripts/elm-runtime.js #{tmp_file}.elm")
19
+
20
+ unless status.success?
21
+ puts '*** ERROR: Elm'
22
+ puts "** OUT:\n#{out}"
23
+ puts "** ERR:\n#{err}"
24
+ end
25
+ end
26
+
27
+ if status.success?
28
+ output = File.read(dest_path)
29
+ File.delete(dest_path)
30
+ end
31
+ end
32
+
33
+ output
34
+ end
35
+
36
+ private
37
+
38
+ def setup_dir
39
+ Dir.mkdir(elm_dir) unless File.exist?(elm_dir) && File.directory?(elm_dir)
40
+ end
41
+
42
+ def with_error_handling
43
+ begin
44
+ yield
45
+ rescue Errno::ENOENT => e
46
+ puts "*** ERROR Elm: #{e.inspect}"
47
+ ensure
48
+ File.delete(tmp_path)
49
+ end
50
+ end
51
+
52
+ def in_elm_dir
53
+ Dir.chdir(elm_dir)
54
+ yield
55
+ Dir.chdir('..')
56
+ end
57
+
58
+ def elm_dir
59
+ '_elm'
60
+ end
61
+
62
+ def tmp_file
63
+ @tmp_file ||= SecureRandom.hex(16)
64
+ end
65
+
66
+ def tmp_path
67
+ File.join(elm_dir, "#{tmp_file}.elm")
68
+ end
69
+
70
+ def dest_path
71
+ File.join(elm_dir, 'build', "#{tmp_file}.html")
72
+ end
73
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_elm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sonny Michaud
@@ -17,6 +17,7 @@ extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
19
  - lib/jekyll_elm.rb
20
+ - lib/elm_compiler.rb
20
21
  homepage:
21
22
  licenses:
22
23
  - MIT