rails_external_assets 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +18 -11
- data/lib/rails_external_assets/asset_finder.rb +7 -4
- data/lib/rails_external_assets/rails/view_helpers.rb +6 -2
- data/lib/rails_external_assets/sprockets/directive_processor.rb +25 -1
- data/lib/rails_external_assets/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a8296d0928ee3d04fbba98fa47115bfb94ab2fd
|
4
|
+
data.tar.gz: 2a7ecabde06eb56b5a277999e50cceb6b81f55b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e4c283b7a59685d4bb0af2d9cd4f1300c4d822a277bf7b56763cff2aa6b7ff5103ecde44d49b99a0b5c46f50b60b0b672abdbb62e9cb698113be65213aada90
|
7
|
+
data.tar.gz: 93af807ba4ad0a0c95091b861f089364c2828fc5ead67148900cfd6660c12f681ad7716782780a280430c4fab25d74b15bc986a5a496663d358c95a439e9e2bf
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 0.3.0 (2016-6-2)
|
4
|
+
|
5
|
+
Added:
|
6
|
+
|
7
|
+
- Added `external_require_directory` and `external_require_tree` Sprockets directives. [c8adab7](../../commit/c8adab7)
|
8
|
+
|
9
|
+
Changed:
|
10
|
+
|
11
|
+
- Rails view helpers `external_asset_js` and `external_asset_css` no longer require file extensions. [5bb278b](../../commit/5bb278b)
|
12
|
+
- `external_require` Sprockets directive does not need an explicit extension. It will be inferred if not provided. [d8be100](../../commit/d8be100)
|
data/README.md
CHANGED
@@ -9,7 +9,8 @@ RailsExternalAssets allows you to use the frontend build tool of your choice ([w
|
|
9
9
|
{
|
10
10
|
"js/module.js": "builds/js/module-12312abc.js",
|
11
11
|
"js/react-component.jsx": "builds/components/react-component-ab123x.js",
|
12
|
-
"css/styling.sass": "builds/styles/styling-129xha.css"
|
12
|
+
"css/styling.sass": "builds/styles/styling-129xha.css",
|
13
|
+
"pathToPreBuiltAsset": "pathToBuiltAsset"
|
13
14
|
}
|
14
15
|
```
|
15
16
|
|
@@ -45,7 +46,7 @@ RailsExternalAssets will also hook into the `assets:precompile` Rake command and
|
|
45
46
|
|
46
47
|
#### JavaScript
|
47
48
|
|
48
|
-
You can include a JavaScript file with `external_asset_js`. Note that the
|
49
|
+
You can include a JavaScript file with `external_asset_js`. Note that the string argument must correspond to an entry in the manifest file, including the file extension. If you do not include a file extension, `js` will be used by default.
|
49
50
|
|
50
51
|
```erb
|
51
52
|
<%= external_asset_js 'myFile.js' %>
|
@@ -53,15 +54,15 @@ You can include a JavaScript file with `external_asset_js`. Note that the name o
|
|
53
54
|
|
54
55
|
#### CSS
|
55
56
|
|
56
|
-
You can include a CSS file with `external_asset_css`. Note that the
|
57
|
+
You can include a CSS file with `external_asset_css`. Note that the string argument must correspond to an entry in the manifest file, including the file extension. If you do not include a file extension, `css` will be used by default.
|
57
58
|
|
58
59
|
```erb
|
59
|
-
<%= external_asset_css 'myFile.
|
60
|
+
<%= external_asset_css 'myFile.css' %>
|
60
61
|
```
|
61
62
|
|
62
63
|
#### Image
|
63
64
|
|
64
|
-
You can include a Image file with `external_asset_img`. Note that the
|
65
|
+
You can include a Image file with `external_asset_img`. Note that the string argument must correspond to an entry in the manifest file, including the file extension.
|
65
66
|
|
66
67
|
```erb
|
67
68
|
<%= external_asset_img 'myFile.jpg' %>
|
@@ -71,27 +72,33 @@ You can include a Image file with `external_asset_img`. Note that the name of th
|
|
71
72
|
|
72
73
|
By default, you can use the `external_require` directive in JavaScript and CSS manifest files, but you can add more (Sass, SCSS, CoffeeScript, etc) by setting the configuration (check out the configuration docks for `sprockets_directives`).
|
73
74
|
|
74
|
-
In any file type you configure the Sprockets directive to be available in you, can use the `external_require`
|
75
|
+
In any file type you configure the Sprockets directive to be available in you, can use the `external_require` directives to include an external asset in the Sprockets manifest. If you do not include an extension, Sprockets will try to use an extension based on the extension of the file you required it in. Sprockets will also ensure that each file is only included once, even if directives overlap and require the file more than once.
|
76
|
+
|
77
|
+
The available directives are, `external_require`, `external_require_directory`, and `external_require_tree`, corresponding to the build in directives, `require`, `require_directory`, and `require_tree`.
|
75
78
|
|
76
79
|
An example `application.js` Sprockets manifest file:
|
77
80
|
|
78
81
|
```js
|
79
82
|
//= require normalAsset
|
80
|
-
//= require more/anotherAsset
|
81
|
-
//= external_require externals/firstAsset
|
82
|
-
//= external_require externals/anotherAsset
|
83
|
+
//= require more/anotherAsset
|
84
|
+
//= external_require externals/firstAsset
|
85
|
+
//= external_require externals/anotherAsset
|
86
|
+
//= external_require_directory externals/myFolder
|
87
|
+
//= external_require_tree externals/folderWithMoreFolders
|
83
88
|
```
|
84
89
|
|
85
|
-
This will include the first two JS assets, `normalAsset` and `anotherAsset` from Rails' asset pipeline, and the
|
90
|
+
This will include the first two JS assets, `normalAsset` and `anotherAsset` from Rails' asset pipeline, and the other JS assets, `firstAsset`, `anotherAsset`, all JS files directly in `externals/myFolder`, and all JS files in the tree `externals/folderWithMoreFolders` from your external assets. The external assets are resolved by looking up these files in the asset manifest JSON file provided.
|
86
91
|
|
87
92
|
## With Plain Ruby
|
88
93
|
|
89
|
-
RailsExternalAssets::AssetFinder provides
|
94
|
+
`RailsExternalAssets::AssetFinder` provides three methods for your disposal.
|
90
95
|
|
91
96
|
`asset_path` takes a path to an external asset file, and returns the corresponding built asset path by looking up the key in the asset manifest JSON file.
|
92
97
|
|
93
98
|
`exeternal_asset` takes a path and returns the built asset path (the result of `asset_path`) and joins it with the base path. If a block is provided, the external asset path is passed to the block and the resulting value is returned.
|
94
99
|
|
100
|
+
`asset_manifest` is used by `asset_path`, and returns the asset manifest file parsed as JSON.
|
101
|
+
|
95
102
|
## Configuration
|
96
103
|
|
97
104
|
Configuration settings can be modified within the `RailsExternalAssets.configure` block. Or set directly off of `RailsExternalAssets.config`
|
@@ -8,14 +8,17 @@ module RailsExternalAssets
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def asset_path(path)
|
11
|
-
manifest_file = RailsExternalAssets.config.manifest_file
|
12
|
-
throw_invalid_manifest(manifest_file) unless File.file? manifest_file
|
13
|
-
asset_manifest = JSON.parse(File.read manifest_file)
|
14
11
|
new_path = asset_manifest[path]
|
15
|
-
throw_unknown_path(path, manifest_file) unless new_path
|
12
|
+
throw_unknown_path(path, RailsExternalAssets.config.manifest_file) unless new_path
|
16
13
|
new_path
|
17
14
|
end
|
18
15
|
|
16
|
+
def asset_manifest
|
17
|
+
manifest_file = RailsExternalAssets.config.manifest_file
|
18
|
+
throw_invalid_manifest(manifest_file) unless File.file? manifest_file
|
19
|
+
JSON.parse(File.read manifest_file)
|
20
|
+
end
|
21
|
+
|
19
22
|
|
20
23
|
private
|
21
24
|
|
@@ -4,11 +4,15 @@ module RailsExternalAssets
|
|
4
4
|
include RailsExternalAssets::AssetFinder
|
5
5
|
|
6
6
|
def external_asset_js(path)
|
7
|
-
|
7
|
+
ext_name = File.extname(path)
|
8
|
+
ext = ext_name.empty? ? '.js' : ''
|
9
|
+
external_asset("#{path}#{ext}") { |p| javascript_include_tag p }
|
8
10
|
end
|
9
11
|
|
10
12
|
def external_asset_css(path)
|
11
|
-
|
13
|
+
ext_name = File.extname(path)
|
14
|
+
ext = ext_name.empty? ? '.css' : ''
|
15
|
+
external_asset("#{path}#{ext}") { |p| stylesheet_link_tag p }
|
12
16
|
end
|
13
17
|
|
14
18
|
def external_asset_img(path)
|
@@ -4,9 +4,33 @@ module RailsExternalAssets
|
|
4
4
|
include RailsExternalAssets::AssetFinder
|
5
5
|
|
6
6
|
def process_external_require_directive(path)
|
7
|
-
|
7
|
+
ext_name = File.extname(path)
|
8
|
+
ext = ext_name.empty? ? file_extension : ''
|
9
|
+
new_path = asset_path("#{path}#{ext}")
|
8
10
|
process_require_directive new_path
|
9
11
|
end
|
12
|
+
|
13
|
+
def process_external_require_directory_directive(path)
|
14
|
+
selected_paths = asset_manifest.keys
|
15
|
+
.select { |key| key.match "#{File.join(path, '[^/]+\..+')}" }
|
16
|
+
.select { |path| File.extname(path) == file_extension }
|
17
|
+
selected_paths.each { |path| process_external_require_directive path }
|
18
|
+
end
|
19
|
+
|
20
|
+
def process_external_require_tree_directive(path)
|
21
|
+
selected_paths = asset_manifest.keys
|
22
|
+
.select { |key| key.match File.join(path) }
|
23
|
+
.select { |path| File.extname(path) == file_extension }
|
24
|
+
selected_paths.each { |path| process_external_require_directive path }
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def file_extension
|
31
|
+
mime_ext = @environment.mime_exts.find { |_, value| value == @content_type }
|
32
|
+
mime_ext && mime_ext[0]
|
33
|
+
end
|
10
34
|
end
|
11
35
|
end
|
12
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_external_assets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Lehman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- ".gitignore"
|
64
64
|
- ".rspec"
|
65
65
|
- ".travis.yml"
|
66
|
+
- CHANGELOG.md
|
66
67
|
- CODE_OF_CONDUCT.md
|
67
68
|
- Gemfile
|
68
69
|
- LICENSE.txt
|