assets_rails 0.0.1 → 0.1.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 +4 -4
- data/README.md +63 -0
- data/lib/assets_rails/version.rb +1 -1
- data/lib/tasks/assets_rails_tasks.rake +32 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcfdbe46d9d4458b5896ffcadebc506d5c510d0f
|
4
|
+
data.tar.gz: 224033190de49c60f3da41e4437060233f043af4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4cf54457765797b45acb2157edabd72560acdf1ec995e3d61958a9ba84cdc7bf7b3052602e24cca0322069aa78959267dc4be240cf91022b39b93e5be89ed48
|
7
|
+
data.tar.gz: e0eb7cacf54db42959df35bb36cd44a0fc9970859738f139ef2003435a840a6b2f6e5e74ff20254afe29e99effa4268daf10076eb538d69fabea767737963a83
|
data/README.md
CHANGED
@@ -0,0 +1,63 @@
|
|
1
|
+
# assets_rails
|
2
|
+
|
3
|
+
**Requirements**
|
4
|
+
|
5
|
+
- [node](http://nodejs.org)
|
6
|
+
|
7
|
+
**Compatible**
|
8
|
+
- [bower](https://github.com/bower/bower)
|
9
|
+
- [npm](https://www.npmjs.com)
|
10
|
+
- others(pnpm, ied...)
|
11
|
+
|
12
|
+
**Install**
|
13
|
+
|
14
|
+
in Gemfile
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'assets_rails'
|
18
|
+
```
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
add `config/application.rb`
|
23
|
+
```ruby
|
24
|
+
config.assets.paths << Rails.root.join('node_modules') # if use npm
|
25
|
+
config.assets.paths << Rails.root.join('bower_components') # if use bower
|
26
|
+
config.assets.components = %w(npm bower) # if use npm and bower
|
27
|
+
```
|
28
|
+
|
29
|
+
example for npm
|
30
|
+
```sh
|
31
|
+
npm init -y
|
32
|
+
npm install bootstrap --save
|
33
|
+
```
|
34
|
+
|
35
|
+
example for bower
|
36
|
+
```sh
|
37
|
+
bower init -y
|
38
|
+
bower install bootstrap --save
|
39
|
+
```
|
40
|
+
|
41
|
+
## Capistrano 3 Configuration
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
namespace :assets_rails do
|
45
|
+
desc 'Install assets and resolve assets'
|
46
|
+
task :install do
|
47
|
+
on roles(:web) do
|
48
|
+
within release_path do
|
49
|
+
execute :rake, 'assets_rails:install assets_rails:resolve RAILS_ENV=production'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
before 'deploy:compile_assets', 'assets_rails:install'
|
55
|
+
```
|
56
|
+
|
57
|
+
## Contributing
|
58
|
+
|
59
|
+
1. Fork it ( https://github.com/8398a7/assets_rails/fork )
|
60
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
61
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
62
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
63
|
+
5. Create a new Pull Request
|
data/lib/assets_rails/version.rb
CHANGED
@@ -1,4 +1,32 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
#
|
1
|
+
namespace :assets_rails do
|
2
|
+
task :install do
|
3
|
+
Rails.application.config.assets.components.each do |component|
|
4
|
+
sh "#{component} install"
|
5
|
+
end
|
6
|
+
end
|
7
|
+
task :resolve do
|
8
|
+
Rails.application.config.assets.paths.each do |components_directory|
|
9
|
+
resolve_asset_paths(components_directory)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def resolve_asset_paths(root_directory)
|
14
|
+
Dir["#{root_directory}/**/*.css"].each do |filename|
|
15
|
+
contents = File.read(filename) if FileTest.file?(filename)
|
16
|
+
url_regex = /url\((?!\#)\s*['"]?(?![a-z]+:)([^'"\)]*)['"]?\s*\)/
|
17
|
+
|
18
|
+
next unless contents =~ url_regex
|
19
|
+
directory_path = Pathname.new(File.dirname(filename)).relative_path_from(Pathname.new(root_directory))
|
20
|
+
|
21
|
+
new_contents = contents.gsub(url_regex) do |match|
|
22
|
+
relative_path = Regexp.last_match[1]
|
23
|
+
image_path = directory_path.join(relative_path).cleanpath
|
24
|
+
puts "#{match} => #{image_path}"
|
25
|
+
"url(<%= asset_path '#{image_path}' %>)"
|
26
|
+
end
|
27
|
+
|
28
|
+
FileUtils.rm(filename)
|
29
|
+
File.write(filename + '.erb', new_contents)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|