torba 0.2.1 → 0.3.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: 4c495a0072204461b990b7402bb14d18532d464f
4
- data.tar.gz: 38c7b6bc9fea332a25043558988d14ca31a4165e
3
+ metadata.gz: 04e11c81ece9ca358a44330fd7ef22317bba7d3c
4
+ data.tar.gz: 47cabbe91908c788a9b552459770e2faa3f52a4c
5
5
  SHA512:
6
- metadata.gz: 2768e4344d21e27a85fffdae4a7e50d7b9782ea543f6c4b76eeff7241b33f7bf350eed98bad56cb50243a2c366d60125c3e098a9af17bf8913109aa58978a0b7
7
- data.tar.gz: f9d1fe96818b48f069f8f2de44217ea696a0a1f731c3017ce0af0c379e372cba7176caf0897be20d4857c31187968348e672f748a43fbacb69e2b300c0960cb5
6
+ metadata.gz: b2dddf5b66d3ea94ab020fa14be5d2c04f88df1c88c6bcade53ce9d7821661b3120d235acde322030aa7d59bd1c111969cc8c581578ed4b4ead1eb4476f25ea7
7
+ data.tar.gz: 08b7d6437572ac60111128b88ca5db4de13291eac917daf5d0361633024996dfe93209e48a8be143fd2519fad3f41f3e1db358426df9024e6e766a8f59ecf490
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ test/Torbafile
1
2
  /.bundle/
2
3
  /.yardoc
3
4
  /Gemfile.lock
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  ## Unreleased
2
2
 
3
+ ## Version 0.3.0
4
+
5
+ ### Enhancements
6
+
7
+ * Rails setup automatically populates `Rails.application.config.assets.precompile`
8
+ If libraries added via Torba have image/font content, you can remove it from
9
+ that list, no need for manual manipulation
10
+ * Support .tar.gz remote sources
11
+ * Support npm packages
12
+
3
13
  ## Version 0.2.1
4
14
 
5
15
  ### Bug fixes
@@ -13,11 +13,11 @@ of a JS/CSS library and puts it under Sprockets' [load path][sprockets-load-path
13
13
 
14
14
  ## Status
15
15
 
16
- Not tested in production.
16
+ Production ready.
17
17
 
18
18
  ## Documentation
19
19
 
20
- http://rubydoc.info/github/torba-rb/torba/
20
+ [Released version](http://rubydoc.info/gems/torba/0.3.0)
21
21
 
22
22
  ## Why
23
23
 
@@ -44,6 +44,8 @@ Problems with the Bower:
44
44
 
45
45
  * curl
46
46
  * unzip
47
+ * gzip
48
+ * tar
47
49
 
48
50
  ## Design limitations
49
51
 
@@ -87,6 +89,8 @@ it config/application.rb
87
89
  3. Add "require" [Sprockets directives][sprockets-directives] to your "application.js"
88
90
  and/or "@import" [Sass directives][sass-import] to "application.css".
89
91
 
92
+ 4. Non JS/CSS assets are automatically added to precompile list, nothing to do here.
93
+
90
94
  If any changes made to the Torbafile, run `bundle exec torba pack` again.
91
95
 
92
96
  ### Torbafile
@@ -94,7 +98,8 @@ If any changes made to the Torbafile, run `bundle exec torba pack` again.
94
98
  Torbafile is an assets specification. It is a plain text file that contains one or more
95
99
  sections, each of them describes one remote source of assets.
96
100
 
97
- Currently only zip archives and [Github releases][github-releases] are supported.
101
+ Currently only zip, tar.gz archives, [Github releases][github-releases] and
102
+ [npm packages][npm] are supported.
98
103
 
99
104
  #### Zip archive package
100
105
 
@@ -112,6 +117,20 @@ where "name" is an arbitrary name for the package, more on "import" below. For e
112
117
  zip "scroll_magic", url: "https://github.com/janpaepke/ScrollMagic/archive/v2.0.0.zip"
113
118
  ```
114
119
 
120
+ #### Tar.gz archive package
121
+
122
+ The syntax is same as for a zip package:
123
+
124
+ ```
125
+ targz "name", url: "..." [, import: %w(...)]
126
+ ```
127
+
128
+ for example,
129
+
130
+ ```
131
+ targz "scroll_magic", url: "https://github.com/janpaepke/ScrollMagic/archive/v2.0.0.tar.gz"
132
+ ```
133
+
115
134
  #### Github release package
116
135
 
117
136
  This is a more readable version/shortcut for "https://github.com/.../archive/..." URLs.
@@ -135,6 +154,29 @@ You can omit the name, it will be equal to the repository name:
135
154
  gh_release source: "janpaepke/ScrollMagic", tag: "v.2.0.0" # "ScrollMagic" is assumed
136
155
  ```
137
156
 
157
+ #### npm package
158
+
159
+ Allows to download packages from npm registry.
160
+
161
+ The syntax is:
162
+
163
+ ```
164
+ npm "name", package: "...", version: "..." [, import: %w(...)]
165
+ ```
166
+
167
+ where "package" is the package name as published on npm registry and "version" is its version,
168
+ more on "import" below. For example,
169
+
170
+ ```
171
+ npm "coffee", package: "coffee-script", version: "1.9.2"
172
+ ```
173
+
174
+ You can omit the name, it will be equal to the package name:
175
+
176
+ ```
177
+ npm package: "coffee-script", version: "1.9.2"
178
+ ```
179
+
138
180
  ### "Packing the torba" process
139
181
 
140
182
  When you run `torba pack` the following happens:
@@ -158,7 +200,7 @@ duplication:
158
200
  //= require 'underscore/underscore'
159
201
  ```
160
202
 
161
- Hint: use "require_directory" if you strongly against such duplication:
203
+ Hint: use "require_directory" if you're strongly against such duplication:
162
204
 
163
205
  ```javascript
164
206
  //= require_directory 'underscore'
@@ -187,7 +229,7 @@ gh_release "lightslider", source: "sachinchoolur/lightslider", tag: "1.1.2", imp
187
229
  ```
188
230
 
189
231
  Such files will be copied directly to the package root (i.e. file tree becomes flatten), thus you
190
- can omit unnesseccary paths:
232
+ can omit unnecessary paths:
191
233
 
192
234
  ```css
193
235
  @import 'lightslider/lightslider';
@@ -204,14 +246,27 @@ gh_release "lightslider", source: "sachinchoolur/lightslider", tag: "1.1.2", imp
204
246
 
205
247
  In addition to this "path/" is treated as a shortcut for "path/**/*" glob pattern.
206
248
 
249
+ Be careful to **import only that you really need**. Everything that is non JS or CSS asset is
250
+ going to be precompiled by Sprockets and accessible publicly. See [Rails ticket][rails-ticket-vendoring]
251
+ that explains this problem (and why Rails >= 4 precompiles only application.js/css in vendor by
252
+ default), except that Torba does have a way to specify exact list of files to import.
253
+
254
+ ## Deployment
255
+
256
+ 1. Specify `TORBA_HOME_PATH` env variable pointing to a persistent directory writable by your
257
+ deploy user. For Capistrano it should be `shared/`.
258
+ 2. Add `bundle exec torba pack` to your deployment script right after `bundle install`. It's safe
259
+ and fairly cheap to run it unconditionally on each deployment.
207
260
 
208
261
  [bower]: http://bower.io/
209
- [sprockets]: https://github.com/sstephenson/sprockets/
210
- [sprockets-load-path]: https://github.com/sstephenson/sprockets#the-load-path
262
+ [sprockets]: https://github.com/rails/sprockets/
263
+ [sprockets-load-path]: https://github.com/rails/sprockets#the-load-path
211
264
  [torba-pronounce]: http://upload.wikimedia.org/wikipedia/commons/2/28/Uk-%D1%82%D0%BE%D1%80%D0%B1%D0%B0.ogg
212
265
  [github-releases]: https://help.github.com/articles/about-releases/
213
- [sprockets-directives]: https://github.com/sstephenson/sprockets#the-directive-processor
266
+ [sprockets-directives]: https://github.com/rails/sprockets#the-directive-processor
214
267
  [sass-import]: http://sass-lang.com/documentation/file.SASS_REFERENCE.html#import
215
268
  [rails-assets]: https://rails-assets.org/
216
269
  [bower-rails]: https://github.com/rharriso/bower-rails
217
270
  [semver]: http://semver.org/
271
+ [rails-ticket-vendoring]: https://github.com/rails/rails/pull/7968
272
+ [npm]: https://npmjs.com
@@ -1,6 +1,6 @@
1
1
  module Torba
2
2
  # Parses content of CSS file and converts its image assets paths into Sprockets'
3
- # {https://github.com/sstephenson/sprockets#logical-paths logical paths}.
3
+ # {https://github.com/rails/sprockets#logical-paths logical paths}.
4
4
  class CssUrlToErbAssetPath
5
5
  URL_RE =
6
6
  /
@@ -5,10 +5,14 @@ module Torba
5
5
 
6
6
  # Represents a list of assets to be imported from a remote source.
7
7
  class ImportList
8
- class Asset < Struct.new(:absolute_path, :subpath)
8
+ class Asset < Struct.new(:absolute_path, :logical_path)
9
9
  def css?
10
10
  absolute_path.end_with?(".css")
11
11
  end
12
+
13
+ def js?
14
+ absolute_path.end_with?(".js")
15
+ end
12
16
  end
13
17
 
14
18
  # @return [Array<Asset>] full list of assets to be imported.
@@ -34,5 +38,12 @@ module Torba
34
38
  def non_css_assets
35
39
  assets.find_all { |asset| !asset.css? }
36
40
  end
41
+
42
+ # @return [Array<Asset>] list of assets to be imported except javascripts and
43
+ # stylesheets.
44
+ # @since 0.3.0
45
+ def non_js_css_assets
46
+ assets.find_all { |asset| !(asset.js? || asset.css?) }
47
+ end
37
48
  end
38
49
  end
@@ -1,6 +1,8 @@
1
1
  require "torba/package"
2
2
  require "torba/remote_sources/zip"
3
3
  require "torba/remote_sources/github_release"
4
+ require "torba/remote_sources/targz"
5
+ require "torba/remote_sources/npm"
4
6
 
5
7
  module Torba
6
8
  # Represents Torbafile.
@@ -50,6 +52,29 @@ module Torba
50
52
  packages << Package.new(name, remote_source, options)
51
53
  end
52
54
 
55
+ # Adds {Package} with {RemoteSources::Targz} to {#packages}
56
+ # @since 0.3.0
57
+ def targz(name, options = {})
58
+ url = options.fetch(:url)
59
+ remote_source = RemoteSources::Targz.new(url)
60
+ packages << Package.new(name, remote_source, options)
61
+ end
62
+
63
+ # Adds {Package} with {RemoteSources::Npm} to {#packages}
64
+ # @since 0.3.0
65
+ def npm(name = nil, options = {})
66
+ if name.is_a?(Hash)
67
+ options, name = name, nil
68
+ end
69
+
70
+ package_name = options.fetch(:package)
71
+ version = options.fetch(:version)
72
+ remote_source = RemoteSources::Npm.new(package_name, version)
73
+
74
+ name ||= remote_source.package
75
+ packages << Package.new(name, remote_source, options)
76
+ end
77
+
53
78
  # Builds all {#packages}
54
79
  # @return [void]
55
80
  def pack
@@ -62,6 +87,19 @@ module Torba
62
87
  packages.map(&:load_path)
63
88
  end
64
89
 
90
+ # @return [Array<String>] logical paths that packages contain except JS ans CSS.
91
+ # It should be appended to the Sprockets' precompile list. Packages' JS and CSS
92
+ # are meant to be included into application.js/.css and not to be compiled
93
+ # alone (you can add them by hand though).
94
+ # @note Avoid importing everything from a package as it'll be precompiled and accessible
95
+ # publicly.
96
+ # @see Package#import_paths
97
+ # @see Package#non_js_css_logical_paths
98
+ # @since 0.3.0
99
+ def non_js_css_logical_paths
100
+ packages.flat_map(&:non_js_css_logical_paths)
101
+ end
102
+
65
103
  # Verifies all {#packages}
66
104
  # @return [void]
67
105
  def verify
data/lib/torba/package.rb CHANGED
@@ -37,6 +37,9 @@ module Torba
37
37
  # ["build/*.js", "**/*.css"]
38
38
  # @example Any file within directory (including subdirectories)
39
39
  # ["build/"] # same as ["build/**/*"]
40
+ # @note Put in this list only files that are absolutely necessary to you as
41
+ # {Manifest#non_js_css_logical_paths} depends on it.
42
+ # @see #build
40
43
  attr_reader :import_paths
41
44
 
42
45
  # @param name [String] see {#name}
@@ -92,6 +95,20 @@ module Torba
92
95
  @load_path ||= File.join(Torba.home_path, folder_name)
93
96
  end
94
97
 
98
+ # @return [Array<String>] {https://github.com/rails/sprockets#logical-paths logical paths} that
99
+ # the package contains.
100
+ # @since 0.3.0
101
+ def logical_paths
102
+ import_list.assets.map(&:logical_path)
103
+ end
104
+
105
+ # @return [Array<String>] {https://github.com/rails/sprockets#logical-paths logical paths} that the
106
+ # package contains except JS ans CSS.
107
+ # @since 0.3.0
108
+ def non_js_css_logical_paths
109
+ import_list.non_js_css_assets.map(&:logical_path)
110
+ end
111
+
95
112
  # @return [ImportList]
96
113
  def import_list
97
114
  @import_list ||= build_import_list
@@ -126,7 +143,7 @@ module Torba
126
143
  relative_path.sub(path_wo_glob_metacharacters, "")
127
144
  end
128
145
 
129
- ImportList::Asset.new(absolute_path, subpath)
146
+ ImportList::Asset.new(absolute_path, with_namespace(subpath))
130
147
  end
131
148
 
132
149
  if assets.empty?
@@ -145,10 +162,10 @@ module Torba
145
162
 
146
163
  new_content = CssUrlToErbAssetPath.call(content, asset.absolute_path) do |image_file_path|
147
164
  image_asset = import_list.find_by_absolute_path(image_file_path)
148
- with_namespace(image_asset.subpath)
165
+ image_asset.logical_path
149
166
  end
150
167
 
151
- new_absolute_path = File.join(load_path, with_namespace(asset.subpath + ".erb"))
168
+ new_absolute_path = File.join(load_path, asset.logical_path + ".erb")
152
169
  ensure_directory(new_absolute_path)
153
170
  File.write(new_absolute_path, new_content)
154
171
  end
@@ -156,7 +173,7 @@ module Torba
156
173
 
157
174
  def process_other_assets
158
175
  import_list.non_css_assets.each do |asset|
159
- new_absolute_path = File.join(load_path, with_namespace(asset.subpath))
176
+ new_absolute_path = File.join(load_path, asset.logical_path)
160
177
  ensure_directory(new_absolute_path)
161
178
  FileUtils.cp(asset.absolute_path, new_absolute_path)
162
179
  end
data/lib/torba/rails.rb CHANGED
@@ -2,6 +2,7 @@ module Torba
2
2
  class Engine < Rails::Engine
3
3
  initializer "torba.assets" do |app|
4
4
  Rails.application.config.assets.paths.concat(Torba.load_path)
5
+ Rails.application.config.assets.precompile.concat(Torba.non_js_css_logical_paths)
5
6
  end
6
7
  end
7
8
  end
@@ -0,0 +1,24 @@
1
+ require "tempfile"
2
+
3
+ module Torba
4
+ module RemoteSources
5
+ # File downloading abstraction
6
+ # @since 0.3.0
7
+ class GetFile
8
+ # @param url [String] to be downloaded.
9
+ # @return [Tempfile] temporarily stored content of the URL.
10
+ # @raise [Errors::ShellCommandFailed] if failed to fetch the URL
11
+ def self.process(url)
12
+ tempfile = Tempfile.new("torba")
13
+ tempfile.close
14
+
15
+ Torba.ui.info "downloading '#{url}'"
16
+
17
+ command = "curl -Lf -o #{tempfile.path} #{url}"
18
+ system(command) || raise(Errors::ShellCommandFailed.new(command))
19
+
20
+ tempfile
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,28 @@
1
+ require "torba/remote_sources/targz"
2
+
3
+ module Torba
4
+ module RemoteSources
5
+ # Represents {https://npmjs.com npm package}.
6
+ # @since 0.3.0
7
+ class Npm < Targz
8
+ # @return [String] package name.
9
+ # @example
10
+ # "coffee-script"
11
+ attr_reader :package
12
+
13
+ # @return [String] package version.
14
+ # @example
15
+ # "1.8.3"
16
+ attr_reader :version
17
+
18
+ # @param package see {#package}
19
+ # @param version see {#version}
20
+ def initialize(package, version)
21
+ @package = package
22
+ @version = version
23
+ super("https://registry.npmjs.org/#{package}/-/#{package}-#{version}.tgz")
24
+ @digest = "#{package}-#{Torba.digest(url)}"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,37 @@
1
+ require "fileutils"
2
+
3
+ require "torba/remote_sources/common"
4
+ require "torba/remote_sources/get_file"
5
+
6
+ module Torba
7
+ module RemoteSources
8
+ # Represents remote tar.gz archive.
9
+ # @since 0.3.0
10
+ class Targz
11
+ include Common
12
+
13
+ attr_reader :url, :digest
14
+
15
+ def initialize(url)
16
+ @url = url
17
+ @digest = "#{File.basename(url).sub(/\.(tgz|tar\.gz)$/, '')}-#{Torba.digest(url)}"
18
+ end
19
+
20
+ private
21
+
22
+ def ensure_cached
23
+ unless Dir.exist?(cache_path)
24
+ FileUtils.mkdir_p(cache_path)
25
+
26
+ tempfile = GetFile.process(url)
27
+
28
+ command = "gzip -qcd #{tempfile.path} | tar -mxpf - --strip-components=1 -C #{cache_path}"
29
+ system(command) || raise(Errors::ShellCommandFailed.new(command))
30
+ end
31
+ rescue
32
+ FileUtils.rm_rf(cache_path)
33
+ raise
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,13 +1,9 @@
1
- require "tempfile"
2
1
  require "fileutils"
3
2
 
4
3
  require "torba/remote_sources/common"
4
+ require "torba/remote_sources/get_file"
5
5
 
6
6
  module Torba
7
- module Errors
8
- ShellCommandFailed = Class.new(StandardError)
9
- end
10
-
11
7
  module RemoteSources
12
8
  # Represents remote zip archive.
13
9
  class Zip
@@ -26,17 +22,10 @@ module Torba
26
22
  unless Dir.exist?(cache_path)
27
23
  FileUtils.mkdir_p(cache_path)
28
24
 
29
- tempfile = Tempfile.new("torba")
30
- tempfile.close
31
-
32
- Torba.ui.info "downloading '#{url}'"
25
+ tempfile = GetFile.process(url)
33
26
 
34
- [
35
- "curl -Lf -o #{tempfile.path} #{url}",
36
- "unzip -oqq -d #{cache_path} #{tempfile.path}",
37
- ].each do |command|
38
- system(command) || raise(Errors::ShellCommandFailed.new(command))
39
- end
27
+ command = "unzip -oqq -d #{cache_path} #{tempfile.path}"
28
+ system(command) || raise(Errors::ShellCommandFailed.new(command))
40
29
 
41
30
  get_rid_of_top_level_directory
42
31
  end
data/lib/torba.rb CHANGED
@@ -5,6 +5,10 @@ require "torba/manifest"
5
5
 
6
6
  # @since 0.1.0
7
7
  module Torba
8
+ module Errors
9
+ ShellCommandFailed = Class.new(StandardError)
10
+ end
11
+
8
12
  # @return [String] root path to prepared asset packages. By default it's ".torba" within
9
13
  # your OS home directory (i.e. packages are shared between projects).
10
14
  # @note use "TORBA_HOME_PATH" env variable to override default value
@@ -46,6 +50,12 @@ module Torba
46
50
  manifest.load_path
47
51
  end
48
52
 
53
+ # @see Manifest#non_js_css_logical_paths
54
+ # @since 0.3.0
55
+ def self.non_js_css_logical_paths
56
+ manifest.non_js_css_logical_paths
57
+ end
58
+
49
59
  # @see Manifest#verify
50
60
  def self.verify
51
61
  manifest.verify
@@ -6,38 +6,82 @@ module Torba
6
6
  @manifest ||= Manifest.build("test/Torbafile")
7
7
  end
8
8
 
9
- def find(file_path)
9
+ def find_path(file_path)
10
10
  manifest.load_path.map{ |lp| File.join(lp, file_path) }.find{ |full_path| File.exists?(full_path) }
11
11
  end
12
12
 
13
13
  def assert_exists(file_path)
14
- assert find(file_path)
14
+ assert find_path(file_path), "'#{file_path}' should exist"
15
15
  end
16
16
 
17
17
  def refute_exists(file_path)
18
- refute find(file_path)
18
+ refute find_path(file_path), "'#{file_path}' should not exist"
19
19
  end
20
20
 
21
- def read(file_path)
22
- File.read(find(file_path))
21
+ def read_path(file_path)
22
+ File.read(find_path(file_path))
23
23
  end
24
24
 
25
- def test_pack
25
+ def pack_torbafile(content)
26
+ File.write("test/Torbafile", content)
26
27
  manifest.pack
28
+ end
29
+
30
+ def test_zip
31
+ pack_torbafile <<-TORBA
32
+ zip "trumbowyg-from-zip",
33
+ url: "https://github.com/torba-rb/Trumbowyg/archive/1.1.6.zip",
34
+ import: ["dist/trumbowyg.js"]
35
+ TORBA
27
36
 
28
37
  assert_exists "trumbowyg-from-zip/trumbowyg.js"
29
38
  refute_exists "trumbowyg-from-zip/trumbowyg.css.erb"
30
39
  refute_exists "trumbowyg-from-zip/icons.png"
31
40
  refute_exists "trumbowyg-from-zip/icons-2x.png"
41
+ end
42
+
43
+ def test_gh_release
44
+ pack_torbafile <<-TORBA
45
+ gh_release "trumbowyg", source: "torba-rb/Trumbowyg", tag: "1.1.7", import: %w[
46
+ dist/trumbowyg.js
47
+ dist/ui/*.css
48
+ dist/ui/images/
49
+ ]
50
+ TORBA
32
51
 
33
52
  assert_exists "trumbowyg/trumbowyg.js"
34
53
  assert_exists "trumbowyg/trumbowyg.css.erb"
35
54
  assert_exists "trumbowyg/icons.png"
36
55
  assert_exists "trumbowyg/icons-2x.png"
37
56
 
38
- css = read "trumbowyg/trumbowyg.css.erb"
57
+ css = read_path "trumbowyg/trumbowyg.css.erb"
39
58
  assert_includes css, "background: transparent url('<%= asset_path('trumbowyg/icons.png') %>') no-repeat;"
40
59
  assert_includes css, "background-image: url('<%= asset_path('trumbowyg/icons-2x.png') %>')"
41
60
  end
61
+
62
+ def test_targz
63
+ pack_torbafile <<-TORBA
64
+ targz "trumbowyg-from-tar",
65
+ url: "https://github.com/torba-rb/Trumbowyg/archive/1.1.7.tar.gz",
66
+ import: ["dist/ui/"]
67
+ TORBA
68
+
69
+ refute_exists "trumbowyg-from-tar/trumbowyg.js"
70
+ assert_exists "trumbowyg-from-tar/trumbowyg.css.erb"
71
+ assert_exists "trumbowyg-from-tar/images/icons.png"
72
+ assert_exists "trumbowyg-from-tar/images/icons-2x.png"
73
+
74
+ css = read_path "trumbowyg-from-tar/trumbowyg.css.erb"
75
+ assert_includes css, "background: transparent url('<%= asset_path('trumbowyg-from-tar/images/icons.png') %>') no-repeat;"
76
+ assert_includes css, "background-image: url('<%= asset_path('trumbowyg-from-tar/images/icons-2x.png') %>')"
77
+ end
78
+
79
+ def test_npm
80
+ pack_torbafile <<-TORBA
81
+ npm "lo_dash", package: "lodash", version: "0.1.0", import: ["lodash.js"]
82
+ TORBA
83
+
84
+ assert_exists "lo_dash/lodash.js"
85
+ end
42
86
  end
43
87
  end
@@ -35,5 +35,11 @@ module Torba
35
35
  list = ImportList.new([js_asset, css_asset])
36
36
  assert [js_asset], list.non_css_assets
37
37
  end
38
+
39
+ def test_non_js_css_assets
40
+ img_asset = ImportList::Asset.new("/dir/image.png", "image.png")
41
+ list = ImportList.new([js_asset, css_asset, img_asset])
42
+ assert [img_asset], list.non_js_css_assets
43
+ end
38
44
  end
39
45
  end
@@ -23,6 +23,15 @@ module Torba
23
23
  assert_equal "http://angularjs.com/angularjs.zip", remote.url
24
24
  end
25
25
 
26
+ def test_targz
27
+ manifest.targz "angular", url: "http://angularjs.com/angularjs.targz"
28
+
29
+ assert_equal 1, manifest.packages.size
30
+ assert_equal "angular", package.name
31
+ assert_instance_of RemoteSources::Targz, remote
32
+ assert_equal "http://angularjs.com/angularjs.targz", remote.url
33
+ end
34
+
26
35
  def test_zip_wo_url
27
36
  assert_raises(KeyError) do
28
37
  manifest.zip "angular"
@@ -55,5 +64,43 @@ module Torba
55
64
  manifest.gh_release "underscore", source: "jashkenas/underscore"
56
65
  end
57
66
  end
67
+
68
+ def test_npm
69
+ manifest.npm "coffee", package: "coffee-script", version: "1.8.3"
70
+
71
+ assert_equal 1, manifest.packages.size
72
+ assert_equal "coffee", package.name
73
+ assert_instance_of RemoteSources::Npm, remote
74
+ assert_equal "coffee-script", remote.package
75
+ assert_equal "1.8.3", remote.version
76
+ end
77
+
78
+ def test_npm_implicit_name
79
+ manifest.npm package: "coffee-script", version: "1.8.3"
80
+ assert_equal "coffee-script", package.name
81
+ end
82
+
83
+ def test_npm_wo_package
84
+ assert_raises(KeyError) do
85
+ manifest.npm version: "1.8.3"
86
+ end
87
+ end
88
+
89
+ def test_npm_wo_version
90
+ assert_raises(KeyError) do
91
+ manifest.npm package: "underscore"
92
+ end
93
+ end
94
+
95
+ def test_non_js_css_logical_paths
96
+ manifest.zip "angular", url: "http://angularjs.com/angularjs.zip"
97
+ manifest.zip "backbone", url: "http://backbonejs.com/backbonejs.zip"
98
+
99
+ manifest.packages[0].stub :non_js_css_logical_paths, ["angular.png"] do
100
+ manifest.packages[1].stub :non_js_css_logical_paths, ["backbone.png"] do
101
+ assert_equal %w[angular.png backbone.png], manifest.non_js_css_logical_paths
102
+ end
103
+ end
104
+ end
58
105
  end
59
106
  end
@@ -20,7 +20,7 @@ module Torba
20
20
  list = Package.new("package", remote_source, import: ["hello.js"]).import_list
21
21
  assert_equal 1, list.assets.size
22
22
  item = list.assets.first
23
- assert_equal "hello.js", item.subpath
23
+ assert_equal "package/hello.js", item.logical_path
24
24
  assert_equal File.join(source_dir, "hello.js"), item.absolute_path
25
25
  end
26
26
 
@@ -30,7 +30,7 @@ module Torba
30
30
  list = Package.new("package", remote_source, import: ["build/hello.js"]).import_list
31
31
  assert_equal 1, list.assets.size
32
32
  item = list.assets.first
33
- assert_equal "hello.js", item.subpath
33
+ assert_equal "package/hello.js", item.logical_path
34
34
  assert_equal File.join(source_dir, "build/hello.js"), item.absolute_path
35
35
 
36
36
  touch("build/standalone/hello.js")
@@ -38,7 +38,7 @@ module Torba
38
38
  list = Package.new("package", remote_source, import: ["build/standalone/hello.js"]).import_list
39
39
  assert_equal 1, list.assets.size
40
40
  item = list.assets.first
41
- assert_equal "hello.js", item.subpath
41
+ assert_equal "package/hello.js", item.logical_path
42
42
  assert_equal File.join(source_dir, "build/standalone/hello.js"), item.absolute_path
43
43
  end
44
44
 
@@ -48,14 +48,14 @@ module Torba
48
48
  list = Package.new("package", remote_source, import: ["build/"]).import_list
49
49
  assert_equal 1, list.assets.size
50
50
  item = list.assets.first
51
- assert_equal "standalone/hello.js", item.subpath
51
+ assert_equal "package/standalone/hello.js", item.logical_path
52
52
  assert_equal File.join(source_dir, "build/standalone/hello.js"), item.absolute_path
53
53
 
54
54
 
55
55
  list = Package.new("package", remote_source, import: ["build/standalone/"]).import_list
56
56
  assert_equal 1, list.assets.size
57
57
  item = list.assets.first
58
- assert_equal "hello.js", item.subpath
58
+ assert_equal "package/hello.js", item.logical_path
59
59
  assert_equal File.join(source_dir, "build/standalone/hello.js"), item.absolute_path
60
60
  end
61
61
 
@@ -67,11 +67,11 @@ module Torba
67
67
  assert_equal 2, list.assets.size
68
68
 
69
69
  first_item = list.assets[0]
70
- assert_equal "images/first.png", first_item.subpath
70
+ assert_equal "package/images/first.png", first_item.logical_path
71
71
  assert_equal File.join(source_dir, "build/images/first.png"), first_item.absolute_path
72
72
 
73
73
  second_item = list.assets[1]
74
- assert_equal "images/second.png", second_item.subpath
74
+ assert_equal "package/images/second.png", second_item.logical_path
75
75
  assert_equal File.join(source_dir, "build/images/second.png"), second_item.absolute_path
76
76
  end
77
77
 
@@ -83,11 +83,11 @@ module Torba
83
83
  assert_equal 2, list.assets.size
84
84
 
85
85
  first_item = list.assets[0]
86
- assert_equal "one.jpg", first_item.subpath
86
+ assert_equal "package/one.jpg", first_item.logical_path
87
87
  assert_equal File.join(source_dir, "images/one.jpg"), first_item.absolute_path
88
88
 
89
89
  second_item = list.assets[1]
90
- assert_equal "script.js", second_item.subpath
90
+ assert_equal "package/script.js", second_item.logical_path
91
91
  assert_equal File.join(source_dir, "js/script.js"), second_item.absolute_path
92
92
  end
93
93
 
@@ -98,13 +98,13 @@ module Torba
98
98
  list = Package.new("package", remote_source, import: ["**/*.{js,coffee}"]).import_list
99
99
  assert_equal 1, list.assets.size
100
100
  item = list.assets.first
101
- assert_equal "js/hello.js", item.subpath
101
+ assert_equal "package/js/hello.js", item.logical_path
102
102
  assert_equal File.join(source_dir, "js/hello.js"), item.absolute_path
103
103
 
104
104
  list = Package.new("package", remote_source, import: ["build/**/*.css"]).import_list
105
105
  assert_equal 1, list.assets.size
106
106
  item = list.assets.first
107
- assert_equal "css/bye.css", item.subpath
107
+ assert_equal "package/css/bye.css", item.logical_path
108
108
  assert_equal File.join(source_dir, "build/css/bye.css"), item.absolute_path
109
109
  end
110
110
 
@@ -0,0 +1,28 @@
1
+ require "test_helper"
2
+
3
+ module Torba
4
+ class PackageLogicalPathsTest < Minitest::Test
5
+ def import_list
6
+ js_asset = ImportList::Asset.new("/dir/script.js", "script.js")
7
+ css_asset = ImportList::Asset.new("/dir/stylesheet.css", "stylesheet.css")
8
+ img_asset = ImportList::Asset.new("/dir/image.svg", "image.svg")
9
+ ImportList.new([js_asset, css_asset, img_asset])
10
+ end
11
+
12
+ def package
13
+ @package ||= Package.new("hello", nil)
14
+ end
15
+
16
+ def test_logical_paths
17
+ package.stub :import_list, import_list do
18
+ assert_equal %w[script.js stylesheet.css image.svg], package.logical_paths
19
+ end
20
+ end
21
+
22
+ def test_non_js_css_logical_paths
23
+ package.stub :import_list, import_list do
24
+ assert_equal %w[image.svg], package.non_js_css_logical_paths
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,12 @@
1
+ require "test_helper"
2
+
3
+ module Torba
4
+ class GetFileTest < Minitest::Test
5
+ def test_404
6
+ exception = assert_raises(Errors::ShellCommandFailed) do
7
+ RemoteSources::GetFile.process("http://jquery.com/jquery.zip")
8
+ end
9
+ assert_includes exception.message, "curl"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,34 @@
1
+ require "test_helper"
2
+
3
+ module Torba
4
+ class NpmTest < Minitest::Test
5
+ def remote
6
+ RemoteSources::Npm.new("coffee-script", "2.0.0")
7
+ end
8
+
9
+ def test_package
10
+ assert_equal "coffee-script", remote.package
11
+ end
12
+
13
+ def test_tag
14
+ assert_equal "2.0.0", remote.version
15
+ end
16
+
17
+ def test_url
18
+ assert_equal "https://registry.npmjs.org/coffee-script/-/coffee-script-2.0.0.tgz", remote.url
19
+ end
20
+
21
+ def test_unique_digest
22
+ remote = RemoteSources::Npm.new("coffee-script", "2.0.0")
23
+ same_remote = RemoteSources::Npm.new("coffee-script", "2.0.0")
24
+ assert_equal remote.digest, same_remote.digest
25
+
26
+ another_remote = RemoteSources::Npm.new("coffee-script", "2.0.1")
27
+ refute_equal remote.digest, another_remote.digest
28
+ end
29
+
30
+ def test_digest_contains_repository_name
31
+ assert_match /^coffee-script-/, remote.digest
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,29 @@
1
+ require "test_helper"
2
+
3
+ module Torba
4
+ class TargzTest < Minitest::Test
5
+ def test_url
6
+ remote = RemoteSources::Targz.new("http://jquery.com/jquery.tar.gz")
7
+ assert_equal "http://jquery.com/jquery.tar.gz", remote.url
8
+ end
9
+
10
+ def test_unique_digest
11
+ remote = RemoteSources::Targz.new("http://jquery.com/jquery.tar.gz")
12
+ same_remote = RemoteSources::Targz.new("http://jquery.com/jquery.tar.gz")
13
+
14
+ assert_equal remote.digest, same_remote.digest
15
+
16
+ another_remote = RemoteSources::Targz.new("http://zeptojs.com/jquery.tar.gz")
17
+
18
+ refute_equal remote.digest, another_remote.digest
19
+ end
20
+
21
+ def test_digest_contains_filename
22
+ remote = RemoteSources::Targz.new("http://jquery.com/jquery.tar.gz")
23
+ assert_match /^jquery-/, remote.digest
24
+
25
+ remote = RemoteSources::Targz.new("http://jquery.com/jquery.tgz")
26
+ assert_match /^jquery-/, remote.digest
27
+ end
28
+ end
29
+ end
@@ -22,12 +22,5 @@ module Torba
22
22
  remote = RemoteSources::Zip.new("http://jquery.com/jquery.zip")
23
23
  assert_match /^jquery-/, remote.digest
24
24
  end
25
-
26
- def test_404
27
- exception = assert_raises(Errors::ShellCommandFailed) do
28
- RemoteSources::Zip.new("http://jquery.com/jquery.zip")["*"]
29
- end
30
- assert_includes exception.message, "curl"
31
- end
32
25
  end
33
26
  end
data/torba.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "torba"
3
- spec.version = "0.2.1"
3
+ spec.version = "0.3.0"
4
4
  spec.authors = ["Andrii Malyshko"]
5
5
  spec.email = ["mail@nashbridges.me"]
6
6
  spec.description = "Bundler for Sprockets"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: torba
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrii Malyshko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-09 00:00:00.000000000 Z
11
+ date: 2015-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -81,8 +81,8 @@ files:
81
81
  - CONTRIBUTING.md
82
82
  - Gemfile
83
83
  - LICENSE.txt
84
+ - README.md
84
85
  - Rakefile
85
- - Readme.md
86
86
  - bin/torba
87
87
  - lib/torba.rb
88
88
  - lib/torba/cli.rb
@@ -92,18 +92,24 @@ files:
92
92
  - lib/torba/package.rb
93
93
  - lib/torba/rails.rb
94
94
  - lib/torba/remote_sources/common.rb
95
+ - lib/torba/remote_sources/get_file.rb
95
96
  - lib/torba/remote_sources/github_release.rb
97
+ - lib/torba/remote_sources/npm.rb
98
+ - lib/torba/remote_sources/targz.rb
96
99
  - lib/torba/remote_sources/zip.rb
97
100
  - lib/torba/ui.rb
98
101
  - lib/torba/verify.rb
99
- - test/Torbafile
100
102
  - test/acceptance_test.rb
101
103
  - test/css_url_to_erb_asset_path_test.rb
102
104
  - test/import_list_test.rb
103
105
  - test/manifest_test.rb
104
106
  - test/package/import_list_test.rb
107
+ - test/package/logical_paths_test.rb
105
108
  - test/remote_sources/common_test.rb
109
+ - test/remote_sources/get_file_test.rb
106
110
  - test/remote_sources/github_release_test.rb
111
+ - test/remote_sources/npm_test.rb
112
+ - test/remote_sources/targz_test.rb
107
113
  - test/remote_sources/zip_test.rb
108
114
  - test/test_helper.rb
109
115
  - torba.gemspec
@@ -132,14 +138,17 @@ signing_key:
132
138
  specification_version: 4
133
139
  summary: Bundler for Sprockets
134
140
  test_files:
135
- - test/Torbafile
136
141
  - test/acceptance_test.rb
137
142
  - test/css_url_to_erb_asset_path_test.rb
138
143
  - test/import_list_test.rb
139
144
  - test/manifest_test.rb
140
145
  - test/package/import_list_test.rb
146
+ - test/package/logical_paths_test.rb
141
147
  - test/remote_sources/common_test.rb
148
+ - test/remote_sources/get_file_test.rb
142
149
  - test/remote_sources/github_release_test.rb
150
+ - test/remote_sources/npm_test.rb
151
+ - test/remote_sources/targz_test.rb
143
152
  - test/remote_sources/zip_test.rb
144
153
  - test/test_helper.rb
145
154
  has_rdoc:
data/test/Torbafile DELETED
@@ -1,7 +0,0 @@
1
- zip "trumbowyg-from-zip", url: "https://github.com/torba-rb/Trumbowyg/archive/1.1.6.zip", import: ["dist/trumbowyg.js"]
2
-
3
- gh_release "trumbowyg", source: "torba-rb/Trumbowyg", tag: "1.1.7", import: %w[
4
- dist/trumbowyg.js
5
- dist/ui/*.css
6
- dist/ui/images/
7
- ]