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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f6b3908ee26c462eb0cbcd34da47c990948a85bc
4
- data.tar.gz: 274dfeffd0cbda284189f3b27ae721b80efe19c8
3
+ metadata.gz: dcfdbe46d9d4458b5896ffcadebc506d5c510d0f
4
+ data.tar.gz: 224033190de49c60f3da41e4437060233f043af4
5
5
  SHA512:
6
- metadata.gz: 88656c7aa0f1591c63fdbb97a7a7aacba6d7beb433a7183adc8ebbcc5ea641054a7dc157a1951a652a959b420c8aeaf924e9d709ed61be36958d19502b459e55
7
- data.tar.gz: e4df60f4a2866b0c18dbd244ec34722419d23b5c4dec6c54c2881b12c95252ecc3f6cea0dae225f6514c9c227816e63dbfa1e91b53975c832ec9f4e14839ce1e
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
@@ -1,3 +1,3 @@
1
1
  module AssetsRails
2
- VERSION = "0.0.1"
2
+ VERSION = '0.1.0'
3
3
  end
@@ -1,4 +1,32 @@
1
- # desc "Explaining what the task does"
2
- # task :assets_rails do
3
- # # Task goes here
4
- # end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assets_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shoya Tanaka