torba 0.3.0 → 0.3.1

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: 04e11c81ece9ca358a44330fd7ef22317bba7d3c
4
- data.tar.gz: 47cabbe91908c788a9b552459770e2faa3f52a4c
3
+ metadata.gz: 74c50af6fd600841ed420a3ffe0df1b6b471d97f
4
+ data.tar.gz: 976c74cdce2db8e851ae2e7c439bdc2ce7827b91
5
5
  SHA512:
6
- metadata.gz: b2dddf5b66d3ea94ab020fa14be5d2c04f88df1c88c6bcade53ce9d7821661b3120d235acde322030aa7d59bd1c111969cc8c581578ed4b4ead1eb4476f25ea7
7
- data.tar.gz: 08b7d6437572ac60111128b88ca5db4de13291eac917daf5d0361633024996dfe93209e48a8be143fd2519fad3f41f3e1db358426df9024e6e766a8f59ecf490
6
+ metadata.gz: a4c5a9cad8a21318f7dc823937bd046aec8cde1735831620580240b9b87d3c1dec258a009fe499e0bd639dfd43c89ccd1a1bf039c3550ed10dc19572617957a2
7
+ data.tar.gz: 73718d27fe6bf5ce7e204926397c76b40fa16487dc689554e93d2adb2838dce0fc4182f5b08fea2be211f9f0253dc6cc8a95691cc52257e507db996c9c01a5d6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## Unreleased
2
2
 
3
+ ## Version 0.3.1
4
+
5
+ ### Bug fixes
6
+
7
+ * Fix no asset found when a CSS url contains "?#iefix" or "#svg-fragment"
8
+
3
9
  ## Version 0.3.0
4
10
 
5
11
  ### Enhancements
data/README.md CHANGED
@@ -21,24 +21,22 @@ Production ready.
21
21
 
22
22
  ## Why
23
23
 
24
- De facto approach, i.e. wrapping JS and CSS libraries in a gem, requires from a
25
- maintainer to constantly track changes in upstream repository. Even more, if the
26
- maintainer stops using this gem itself, it will eventually become abandoned.
27
- Many libraries still have no gem wrappers.
24
+ De facto approach, i.e. wrapping JS and CSS libraries in a gem, requires a
25
+ maintainer to constantly track changes in an upstream repository. Even more so, if a gem
26
+ maintainer stops using that specific library, the gem will eventually become abandoned.
27
+ Additionally, many libraries still have no gem wrappers.
28
28
 
29
- Among other alternatives:
29
+ Other alternatives:
30
30
 
31
- * [rails-assets][rails-assets] project relies on Bower *and* it is quite complex,
32
- * [bower-rails][bower-rails] project relies on Bower.
31
+ * [rails-assets][rails-assets] relies on Bower *and* it is quite complex,
32
+ * [bower-rails][bower-rails] relies on Bower, see below for why this can be an issue.
33
33
 
34
34
  Problems with the Bower:
35
35
 
36
- * it is not a part of Ruby ecosystem,
37
- * frontend JS libraries are usually standalone (except for jQuery dependency), so there's
38
- no need for complex Bundler-like solution with tree-dependency resolution,
39
- * often we can't use optimistic version constraints, because JS community still doesn't
40
- fully grasp the idea of [Semver][semver]. By specifying strict versions we use Bower
41
- as a complex facade for functionality that could be done by curl.
36
+ * it is not a part of the Ruby ecosystem,
37
+ * frontend JS libraries are usually standalone (except for a potential jQuery dependency), so there's
38
+ no need for a complex Bundler-like solution with tree-dependency resolution,
39
+ * often we can't use optimistic version constraints, because the JavaScript community does not consistenly apply the principles of [Semver][semver]. By specifying strict versions we use Bower as a complex facade for functionality that could be accomplished with curl.
42
40
 
43
41
  ## External dependencies
44
42
 
@@ -49,9 +47,9 @@ Problems with the Bower:
49
47
 
50
48
  ## Design limitations
51
49
 
52
- * Torba doesn't do any version dependency resolution, it's up to you to specify correct version of
50
+ * Torba doesn't do any version dependency resolution, it's up to you to specify the correct version of
53
51
  each asset package,
54
- * Torba doesn't do any builds, use remote sources with pre-built assets.
52
+ * Torba doesn't do any builds, you should use remote sources with pre-built assets.
55
53
 
56
54
  ## Installation
57
55
 
@@ -183,16 +181,16 @@ When you run `torba pack` the following happens:
183
181
 
184
182
  1. All remote sources are cached locally.
185
183
 
186
- 2. Archives are unpacked with top level directory removed. This is done for good cause it
187
- usually contains package version, e.g. "react-0.13.2", and you don't want to reference versions
184
+ 2. Archives are unpacked with top level directory removed. This is done for good because it
185
+ usually contains the package version in the name, e.g. "react-0.13.2", and you don't want to have to reference versions
188
186
  inside your application code (except Torbafile).
189
187
 
190
188
  3. Remote source's content is copied as is to the `Torba.home_path` location with **package name used
191
189
  as a namespace**.
192
190
 
193
- This is also done for good in order to avoid name collisions (since many JS projects can have
194
- assets with the same names and all packages are placed into shared Sprockets' virtual filesystem).
195
- The downside is that you have to use namespace in each require directive, which can lead to
191
+ This is also done for good reason in order to avoid name collisions (since many JS projects can have
192
+ assets with the same names and all packages are placed into Sprockets' shared virtual filesystem).
193
+ The downside is that you have to use namespaces in each require directive, which can lead to
196
194
  duplication:
197
195
 
198
196
  ```javascript
@@ -211,8 +209,8 @@ statements.
211
209
 
212
210
  ### :import option
213
211
 
214
- Copying whole remote source's content has one disadvantage of using remote source specific paths in your
215
- require/import directives. For example, if an archive contains file in "dist/css" directory, you'll have
212
+ Copying whole remote source's content has the disadvantage of using remote source specific paths in your
213
+ require/import directives. For example, if an archive contains files in the "dist/css" directory, you'll have
216
214
  to mention it:
217
215
 
218
216
  ```css
@@ -220,7 +218,7 @@ to mention it:
220
218
  @import 'lightslider/dist/css/lightslider';
221
219
  ```
222
220
 
223
- To mitigate this you can cherry-pick files from the source via "import" option, for example:
221
+ To mitigate this you can cherry-pick files from the source via the "import" option, for example:
224
222
 
225
223
  ```
226
224
  gh_release "lightslider", source: "sachinchoolur/lightslider", tag: "1.1.2", import: %w[
@@ -4,15 +4,22 @@ module Torba
4
4
  class CssUrlToErbAssetPath
5
5
  URL_RE =
6
6
  /
7
- url\( # url(
8
- \s* # optional space
9
- (?!data) # no data URIs
10
- ['"]? # optional quote
11
- (?!\/) # only relative location
12
- ([^'"]+?) # location
13
- ['"]? # optional quote
14
- \s* # optional space
15
- \) # )
7
+ ( # $1
8
+ url\( # url(
9
+ \s* # optional space
10
+ (?!data) # no data URIs
11
+ ['"]? # optional quote
12
+ (?!\/) # only relative location
13
+ )
14
+ ( # $2
15
+ [^'"?#]+? # location
16
+ )
17
+ ( # $3
18
+ ([?#][^'"]+?)? # optional query or fragment
19
+ ['"]? # optional quote
20
+ \s* # optional space
21
+ \) # )
22
+ )
16
23
  /xm
17
24
 
18
25
  # @return [String] CSS file content where image "url(...)" paths are replaced by ERB
@@ -42,9 +49,9 @@ module Torba
42
49
  # }"
43
50
  def self.call(content, file_path)
44
51
  content.gsub(URL_RE) do
45
- absolute_image_file_path = File.expand_path($1, File.dirname(file_path))
52
+ absolute_image_file_path = File.expand_path($2, File.dirname(file_path))
46
53
  sprockets_file_path = yield absolute_image_file_path
47
- "url('<%= asset_path('#{sprockets_file_path}') %>')"
54
+ "#{$1}<%= asset_path('#{sprockets_file_path}') %>#{$3}"
48
55
  end
49
56
  end
50
57
  end
data/lib/torba.rb CHANGED
@@ -86,8 +86,8 @@ module Torba
86
86
  ui.suggest "Make sure that the path has trailing '/' if its a directory."
87
87
  exit(false)
88
88
  rescue Errors::AssetNotFound => e
89
- ui.error "Couldn't found an asset with path '#{e.message}'."
90
- ui.suggest "Make sure that you've imported all image assets mentioned in a stylesheet(-s)."
89
+ ui.error "Couldn't find an asset with path '#{e.message}'."
90
+ ui.suggest "Make sure that you've imported all image/font assets mentioned in a stylesheet(-s)."
91
91
  exit(false)
92
92
  end
93
93
  end
@@ -55,8 +55,8 @@ module Torba
55
55
  assert_exists "trumbowyg/icons-2x.png"
56
56
 
57
57
  css = read_path "trumbowyg/trumbowyg.css.erb"
58
- assert_includes css, "background: transparent url('<%= asset_path('trumbowyg/icons.png') %>') no-repeat;"
59
- assert_includes css, "background-image: url('<%= asset_path('trumbowyg/icons-2x.png') %>')"
58
+ assert_includes css, %[background: transparent url("<%= asset_path('trumbowyg/icons.png') %>") no-repeat;]
59
+ assert_includes css, %[background-image: url("<%= asset_path('trumbowyg/icons-2x.png') %>")]
60
60
  end
61
61
 
62
62
  def test_targz
@@ -72,8 +72,8 @@ module Torba
72
72
  assert_exists "trumbowyg-from-tar/images/icons-2x.png"
73
73
 
74
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') %>')"
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
77
  end
78
78
 
79
79
  def test_npm
@@ -71,5 +71,53 @@ module Torba
71
71
  end
72
72
  assert_equal "background-image: url('<%= asset_path('ui/images/icons.png') %>');", new_content
73
73
  end
74
+
75
+ def test_url_with_iefix_query
76
+ current_file = "/home/dist/ui/stylesheet.css"
77
+ css = <<-CSS
78
+ @font-face {
79
+ font-family: "Material-Design-Icons";
80
+ src: url("../font/material-design-icons/Material-Design-Icons.eot?#iefix") format("embedded-opentype");
81
+ font-weight: normal;
82
+ font-style: normal; }
83
+ CSS
84
+
85
+ new_content = filter.call(css, current_file) do |image_full_url|
86
+ assert_equal "/home/dist/font/material-design-icons/Material-Design-Icons.eot", image_full_url
87
+ "material-design-icons/Material-Design-Icons.eot"
88
+ end
89
+
90
+ assert_equal <<-CSS, new_content
91
+ @font-face {
92
+ font-family: "Material-Design-Icons";
93
+ src: url("<%= asset_path('material-design-icons/Material-Design-Icons.eot') %>?#iefix") format("embedded-opentype");
94
+ font-weight: normal;
95
+ font-style: normal; }
96
+ CSS
97
+ end
98
+
99
+ def test_url_with_svg_fragment
100
+ current_file = "/home/dist/ui/stylesheet.css"
101
+ css = <<-CSS
102
+ @font-face {
103
+ font-family: "Material-Design-Icons";
104
+ src: url("../font/material-design-icons/Material-Design-Icons.svg#Material-Design-Icons") format("svg");
105
+ font-weight: normal;
106
+ font-style: normal; }
107
+ CSS
108
+
109
+ new_content = filter.call(css, current_file) do |image_full_url|
110
+ assert_equal "/home/dist/font/material-design-icons/Material-Design-Icons.svg", image_full_url
111
+ "material-design-icons/Material-Design-Icons.svg"
112
+ end
113
+
114
+ assert_equal <<-CSS, new_content
115
+ @font-face {
116
+ font-family: "Material-Design-Icons";
117
+ src: url("<%= asset_path('material-design-icons/Material-Design-Icons.svg') %>#Material-Design-Icons") format("svg");
118
+ font-weight: normal;
119
+ font-style: normal; }
120
+ CSS
121
+ end
74
122
  end
75
123
  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.3.0"
3
+ spec.version = "0.3.1"
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.3.0
4
+ version: 0.3.1
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-15 00:00:00.000000000 Z
11
+ date: 2015-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor