elm-rails 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a446fca378352a423aed0ba62e2b44d53c25faa
4
- data.tar.gz: aeae455d36ae171cbfa33a145e75c7feb04af7c1
3
+ metadata.gz: 592fe0f86123f0ad238f843c561347cf32199e00
4
+ data.tar.gz: 6022ce54d4354c1318d1568b886e5158061510f0
5
5
  SHA512:
6
- metadata.gz: 4f3ffd0c6847c752395fee6ef6f18c51c466d79cbf076c1cef33e5d3a49debe9e5195b46395623a3a66dcd8817fc4bc89430462940b692495d0ee49394d286a1
7
- data.tar.gz: 139ed8a20fda5d77591b20e1dd411516425fd01a5846ed9d6e7d77cb2ff2d99fe36daecb443a384c35104a23dc440784d26bfa7d4e1f17b0e483be9a37bd6160
6
+ metadata.gz: 5d26269dfbbfc7a8a2d3a74e3c29e36a8f6c3d5c1c6154354d675b2a490096764b0642d454cc6ec5b5af085c4d934a4d7dba77c9d4f5abc1c3eb9577b4df673a
7
+ data.tar.gz: 032b7dc7d53ddb166253810de041d9b1a889cfe35d092c6f6360c57cc3b99d355add224279f763c336699de4c4d66ff71bf082e5f212fbef735b7176d2b527cb
data/Rakefile CHANGED
@@ -2,7 +2,8 @@ require "bundler/gem_tasks"
2
2
  require "rake/testtask"
3
3
 
4
4
  Rake::TestTask.new do |t|
5
- t.pattern = "test/*_test.rb"
5
+ t.pattern = "**/*_test.rb"
6
6
  end
7
7
 
8
- task :default => [:test]
8
+ task :default => :test
9
+
data/lib/elm/rails.rb CHANGED
@@ -1,2 +1,8 @@
1
1
  require "elm/rails/helper"
2
2
  require "elm/rails/railtie"
3
+
4
+ module Elm
5
+ module Rails
6
+ mattr_accessor(:elm_make_path) { "elm-make" }
7
+ end
8
+ end
@@ -24,37 +24,53 @@ module Elm
24
24
  end
25
25
 
26
26
  def call(input)
27
- context = input[:environment].context_class.new(input)
28
- add_elm_dependencies(input[:filename], input[:load_path], context)
29
- context.metadata.merge(data: Elm::Compiler.compile(input[:filename]))
27
+ context = input[:environment].context_class.new(input)
28
+ DependencyGraph.new(input[:filename], input[:load_path]).each do |dependency|
29
+ context.depend_on dependency
30
+ end
31
+ compiled = Elm::Compiler.compile(input[:filename], {
32
+ debug: debug_flag,
33
+ elm_make_path: Elm::Rails.elm_make_path
34
+ })
35
+ context.metadata.merge data: compiled
30
36
  end
31
37
 
32
38
  private
33
39
 
34
- # Add all Elm modules imported in the target file as dependencies, then
35
- # recursively do the same for each of those dependent modules.
36
- def add_elm_dependencies(filename, load_path, context)
37
- File.read(filename).each_line.flat_map do |line|
38
- # e.g. `import Quiz.QuestionStore exposing (..)`
39
- match = line.match(/^import\s+([^\s]+)/)
40
-
41
- next [] if match.nil?
40
+ def debug_flag
41
+ case ENV['ELM_RAILS_DEBUG']
42
+ when nil, /^false$/i, '0'
43
+ false
44
+ else
45
+ true
46
+ end
47
+ end
42
48
 
43
- # e.g. Quiz.QuestionStore
44
- module_name = match.captures[0]
49
+ class DependencyGraph < Struct.new(:filename, :load_path)
50
+ def each &block
51
+ recurse File.read(filename), block
52
+ end
45
53
 
46
- # e.g. Quiz/QuestionStore
47
- dependency_logical_name = module_name.gsub(".", "/")
54
+ private
48
55
 
49
- # e.g. ~/NoRedInk/app/assets/javascripts/Quiz/QuestionStore.elm
50
- dependency_filepath = load_path + "/" + dependency_logical_name + ".elm"
56
+ def recurse source, block
57
+ source.scan(import_regex) do |(module_name)|
58
+ logical_name = module_name.gsub(".", "/")
59
+ filepath = load_path + "/" + logical_name + ".elm"
51
60
 
52
- # If we don't find the dependency in our filesystem, assume it's because
53
- # it comes in through a third-party package rather than our sources.
54
- if File.file? dependency_filepath
55
- context.depend_on(dependency_logical_name)
61
+ # If we don't find the dependency in our filesystem, assume it's because
62
+ # it comes in through a third-party package rather than our sources.
63
+ if File.file?(filepath)
64
+ block.call logical_name
65
+ recurse File.read(filepath), block
66
+ end
56
67
  end
57
68
  end
69
+
70
+ def import_regex
71
+ # `import Quiz.Question exposing (..)`
72
+ /^import\s+([^\s]+)/
73
+ end
58
74
  end
59
75
  end
60
76
  end
@@ -1,5 +1,5 @@
1
1
  module Elm
2
2
  module Rails
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elm-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Bonetti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-10 00:00:00.000000000 Z
11
+ date: 2018-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -30,14 +30,42 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.1.2
33
+ version: 0.3.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.1.2
40
+ version: 0.3.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: appraisal
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  description: Description of ElmRails.
42
70
  email:
43
71
  - frank.r.bonetti@gmail.com
@@ -73,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
101
  version: '0'
74
102
  requirements: []
75
103
  rubyforge_project:
76
- rubygems_version: 2.5.1
104
+ rubygems_version: 2.6.8
77
105
  signing_key:
78
106
  specification_version: 4
79
107
  summary: Summary of ElmRails.