react-asset-path 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/README.md +39 -0
- data/lib/assets/javascripts/react-asset-path.js.erb +11 -0
- data/lib/react-asset-path.rb +37 -0
- data/react-asset-path.gemspec +22 -0
- metadata +64 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4104fe3d0d1d5ff04dd551e65923b6f49326edcc
|
4
|
+
data.tar.gz: 7dd94290d3e07c2c005b0c2de4a60f290271253a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7921d0d53fa20f99311921fdf5ab9bc8af0878764ecdf9536ddbc81dae01e83ce79d7d909595cb7e9747deba8fb67288d814c3ad7fbafe349eef57654434dfbb
|
7
|
+
data.tar.gz: b9d209950e3c26481868af36118a49fb30c0ee81a1ed176907789482c6559a0899209b8678b8c59713542f3d2fcdf662223fe702e87d18079c9d0b69c0824222
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# react-asset-path
|
2
|
+
|
3
|
+
A helper to be able to use Rails' `asset_path` inside of components.
|
4
|
+
Highly inspired by [react-rails-img](https://github.com/rainchen/react-rails-img).
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'react-asset-path'
|
12
|
+
```
|
13
|
+
|
14
|
+
Require the javascript file in `app/assets/javascripts/application.js`:
|
15
|
+
|
16
|
+
```js
|
17
|
+
//= require react-asset-path
|
18
|
+
```
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
Anywhere in your JS/ES files :
|
23
|
+
|
24
|
+
```js
|
25
|
+
railsAssetPath('logo-phonoid.png')
|
26
|
+
# => /assets/phonoid-logo-c18477115655db9fa98674fc31af6050.png
|
27
|
+
```
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create a new Pull Request
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
MIT.
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module ReactAssetPath
|
2
|
+
VERSION = '0.0.1'
|
3
|
+
IMAGE_EXT = %w{.jpg .jpeg .png .ico .svg}
|
4
|
+
|
5
|
+
class Engine < ::Rails::Engine
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.perform?
|
9
|
+
Rails.env.production? || Rails.env.staging?
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.mapping
|
13
|
+
data = {}
|
14
|
+
prefix = Rails.application.config.assets.prefix
|
15
|
+
|
16
|
+
images_path = Rails.root.join('app/assets/images/')
|
17
|
+
images_dir = images_path.to_s
|
18
|
+
|
19
|
+
Dir["#{images_dir}**/*.*"].each do |file_path|
|
20
|
+
basename = File.basename(file_path)
|
21
|
+
|
22
|
+
Rails.logger.info file_path
|
23
|
+
|
24
|
+
if IMAGE_EXT.include?(File.extname(basename))
|
25
|
+
if perform?
|
26
|
+
file_path = ActionController::Base.helpers.asset_path(basename)
|
27
|
+
else
|
28
|
+
file_path = "/assets/#{basename}"
|
29
|
+
end
|
30
|
+
|
31
|
+
data[basename] = file_path
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
data
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "react-asset-path"
|
7
|
+
spec.version = '0.0.1'
|
8
|
+
|
9
|
+
spec.authors = ["Aurélien Malisart"]
|
10
|
+
spec.email = ["aurelien.malisart@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Use Rails' asset_path inside ReactJS components"
|
13
|
+
spec.description = "Use Rails' asset_path inside ReactJS components"
|
14
|
+
spec.homepage = "https://github.com/aurels/react-asset-path"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'react-rails'
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: react-asset-path
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aurélien Malisart
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: react-rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Use Rails' asset_path inside ReactJS components
|
28
|
+
email:
|
29
|
+
- aurelien.malisart@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- .gitignore
|
35
|
+
- Gemfile
|
36
|
+
- README.md
|
37
|
+
- lib/assets/javascripts/react-asset-path.js.erb
|
38
|
+
- lib/react-asset-path.rb
|
39
|
+
- react-asset-path.gemspec
|
40
|
+
homepage: https://github.com/aurels/react-asset-path
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
metadata: {}
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 2.0.14.1
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: Use Rails' asset_path inside ReactJS components
|
64
|
+
test_files: []
|