microservice_precompiler 1.0.0 → 1.0.2

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: 057e951e2e6a5c9e71f7dcdc00a77078143be3c1
4
- data.tar.gz: 949304f729f0cf6e3413a13ea78e32fd69049ecd
3
+ metadata.gz: ef65a823335e4a8bea106893aa34d02bf6b1bd1a
4
+ data.tar.gz: 024725e2fa5ce71c901498b1d19ee06941f5e56a
5
5
  SHA512:
6
- metadata.gz: 18bff90e9b509a28acbfa9fbf8c721e1ffa29765c082546a095d9d39ab76ae3596f5a37c7593bebb702ebd4830f6bca6dfdeb2e434b36cff4e5a142263138ca9
7
- data.tar.gz: a60fa823a061be41b3b694d2493b05c0d6a927e109a7f486789709710ef65fd27143871a14a3c3685cbae2637f57bd65c1ac5829d82a9cb65dc5a32deb2c081f
6
+ metadata.gz: fe7a3ef3a6d0eff74212e54ad7d580689dfdeb69ee6658db0a78499dce815f0d130f563ad87615cc60f055be374fbfda1ded489631041a80f738b579c8cf7d1a
7
+ data.tar.gz: 7f8e0db597087eb9f1039cf1ece1e54939d02dd3b3d17405802154633ccad8fc39665d0a9844ccf9de09b7d343091d3af517cf876a49fe6d0c956f7ee9c491dc
@@ -4,10 +4,22 @@ module MicroservicePrecompiler
4
4
 
5
5
  def initialize(project_root = ".", build_path = "dist", mustaches_filename = "mustaches.yml.tml")
6
6
  @project_root = project_root
7
- @build_path = File.join(@project_root, build_path)
7
+ # Compare project and build path without trailing slash,
8
+ # they cannot be the same else `cleanup` will wipe the current directory
9
+ if project_root.chomp("/") == build_path.chomp("/")
10
+ raise ArgumentError, "project_root and build_path cannot be the same"
11
+ end
12
+ @build_path = File.join(project_root, build_path)
8
13
  @mustaches_filename = mustaches_filename
9
14
  end
10
15
 
16
+ def build_path=(build_path)
17
+ if project_root.chomp("/") == build_path.chomp("/")
18
+ raise ArgumentError, "project_root and build_path cannot be the same"
19
+ end
20
+ @build_path = build_path
21
+ end
22
+
11
23
  # Convenience method runs all the compilation tasks in order
12
24
  def compile
13
25
  cleanup
@@ -72,8 +84,6 @@ module MicroservicePrecompiler
72
84
  end
73
85
  alias_method :mustache, :mustache_build
74
86
 
75
- private
76
-
77
87
  def method_missing(method_id, *args)
78
88
  if match = matches_file_exists_check?(method_id)
79
89
  File.exists?(send(method_id.to_s.gsub(/_exists\?/,"")))
@@ -82,6 +92,8 @@ module MicroservicePrecompiler
82
92
  end
83
93
  end
84
94
 
95
+ private
96
+
85
97
  # Render mustache into html for complex directory structure
86
98
  # Loop through each directory matched to a set of mustache classes/subclasses
87
99
  def mustache_build_folder_structure(logic_file, parent = nil)
@@ -156,9 +168,11 @@ module MicroservicePrecompiler
156
168
  def minify(asset, format)
157
169
  asset = asset.to_s
158
170
  # Minify JS
159
- return Uglifier.compile(asset) if format.eql?(".js")
171
+ return Uglifier.compile(asset) if format.eql?("js")
160
172
  # Minify CSS
161
- return YUI::CssCompressor.new.compress(asset) if format.eql?(".css")
173
+ return YUI::CssCompressor.new.compress(asset) if format.eql?("css")
174
+ # Return string representation if not minimizing
175
+ return asset
162
176
  end
163
177
 
164
178
  # Get the mustache config file with fullpath
@@ -1,3 +1,3 @@
1
1
  module MicroservicePrecompiler
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
17
17
  gem.version = MicroservicePrecompiler::VERSION
18
18
 
19
19
  gem.add_dependency 'compass', '~> 1.0', '>= 1.0.0'
20
- gem.add_dependency 'sprockets', '~> 3.0', '>= 3.0.0'
20
+ gem.add_dependency 'sprockets', '>= 3.0.0'
21
21
  gem.add_dependency 'uglifier', '~> 2.7', '>= 2.7.1'
22
22
  gem.add_dependency 'mustache', '>= 0.99.4'
23
23
  gem.add_dependency 'yui-compressor', '~> 0.12', '>= 0.12.0'
@@ -18,6 +18,7 @@ class BuilderTest < Test::Unit::TestCase
18
18
  assert_equal(precompiler.build_path, @project_root + "/dist")
19
19
  assert_not_nil(precompiler.mustaches_filename)
20
20
  assert_equal(precompiler.mustaches_filename, "mustaches.yml.tml")
21
+ assert_raises(ArgumentError){ precompiler = MicroservicePrecompiler::Builder.new(".", "./") }
21
22
  end
22
23
 
23
24
  def test_cleanup
@@ -45,7 +46,8 @@ class BuilderTest < Test::Unit::TestCase
45
46
  assert((File.size("#{@project_root}/stylesheets/screen.css") > File.size("#{@project_root}/dist/stylesheets/screen.css")), "Stylesheets were not minimized.")
46
47
  assert((File.exists? "#{@project_root}/dist/javascripts"), "No javascripts folder found, sprockets build failed")
47
48
  #Check that the files in javascripts are minimized
48
- #TODO
49
+ assert((File.exists? "#{@project_root}/dist/javascripts/sample.js"), "Compiled javascript not found, sprockets build failed")
50
+ assert((File.size("#{@project_root}/javascripts/sample.js.coffee") < File.size("#{@project_root}/dist/javascripts/sample.js")), "Javascripts were not minimized.")
49
51
  end
50
52
 
51
53
  def test_mustache_build
@@ -56,5 +58,26 @@ class BuilderTest < Test::Unit::TestCase
56
58
  assert((File.exists? "#{@project_root}/dist/templates/Sample.html"), "File not found.")
57
59
  end
58
60
 
61
+ def test_build_path
62
+ assert_nothing_raised(){ @precompiler.build_path = "./dist" }
63
+ assert_raises(ArgumentError){ @precompiler.build_path = @project_root }
64
+ end
65
+
66
+ def test_compile
67
+ assert_nothing_raised(){ mustache = @precompiler.compile }
68
+ assert((File.exists? "#{@project_root}/dist"), "The build path does not exist")
69
+ assert((File.exists? "#{@project_root}/dist/javascripts"), "No javascripts folder found")
70
+ assert((File.exists? "#{@project_root}/dist/stylesheets"), "No stylesheets folder found")
71
+ assert((File.exists? "#{@project_root}/dist/templates"), "No templates folder found")
72
+ end
73
+
74
+ def test_method_missing
75
+ assert_raises(NoMethodError) { @precompiler.no_method }
76
+ end
77
+
78
+ def test_minify
79
+ assert_equal(@precompiler.send(:minify, "Test value to not minimize", "html"), "Test value to not minimize", "Minify did not correctly pass through the test value")
80
+ end
81
+
59
82
 
60
83
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: microservice_precompiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - barnabyalter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-29 00:00:00.000000000 Z
11
+ date: 2016-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: compass
@@ -34,9 +34,6 @@ dependencies:
34
34
  name: sprockets
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: '3.0'
40
37
  - - ">="
41
38
  - !ruby/object:Gem::Version
42
39
  version: 3.0.0
@@ -44,9 +41,6 @@ dependencies:
44
41
  prerelease: false
45
42
  version_requirements: !ruby/object:Gem::Requirement
46
43
  requirements:
47
- - - "~>"
48
- - !ruby/object:Gem::Version
49
- version: '3.0'
50
44
  - - ">="
51
45
  - !ruby/object:Gem::Version
52
46
  version: 3.0.0
@@ -194,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
188
  version: '0'
195
189
  requirements: []
196
190
  rubyforge_project:
197
- rubygems_version: 2.2.3
191
+ rubygems_version: 2.6.6
198
192
  signing_key:
199
193
  specification_version: 4
200
194
  summary: The microservice precompiler uses a handful of technologies to compile Javascripts