react-rails-img 0.1.1
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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/README.md +65 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/react/rails/img.rb +2 -0
- data/lib/react/rails/img/engine.rb +8 -0
- data/lib/react/rails/img/version.rb +7 -0
- data/react-rails-img.gemspec +24 -0
- data/vendor/assets/javascripts/react_rails_img.js.jsx.erb +88 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c1554ede34a6b1d68694d316e02526b9cd0479ee
|
4
|
+
data.tar.gz: 219be609a27b582a86d78af74eae37875ba446b6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 36c0eefb568f45b10a6e8a2c7b07c42ab228cac20bdaaa7d3ff32709d6ff39266d4e2ceb144501f5b87793715f0e4b5ccb0b82396bcff31700a31b85f3cb5d9e
|
7
|
+
data.tar.gz: e3fc9155fd6f91b1dd2a63bcf7a2f89bb4007e45062642ec8ccb8ffb569d83e560c65000d185d074aac377b90c5eae9811f344834996ef239d0eba34e28a48e2
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# react-rails-img
|
2
|
+
|
3
|
+
Simple image helpers for the rails project using react, make it easily just like using the `<img>` tag.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
1. Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'react-rails-img'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
2. Require the javascript file in `app/assets/javascripts/application.js`:
|
18
|
+
|
19
|
+
```js
|
20
|
+
//= require react_rails_img
|
21
|
+
```
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
### React Component Style
|
26
|
+
|
27
|
+
the asset adds a `<Img>` component
|
28
|
+
|
29
|
+
1. base usage: e.g.: `<Img src="/assets/logo.png" />`
|
30
|
+
2. with props: e.g.: `<Img src="/assets/logo.png" alt="logo" className="logo" id="logo" width=100 height=50 />`
|
31
|
+
3. advance usage - using cssSprite: e.g.: `<Img src="/assets/css_sprite/logo.png" />`
|
32
|
+
|
33
|
+
1) this feature requires gem 'css_sprite'
|
34
|
+
|
35
|
+
2) css_sprite images should be placed in dir `assets/images/css_sprite/`
|
36
|
+
|
37
|
+
3) put the string `css_sprite` after `/assets/` in the path
|
38
|
+
|
39
|
+
### JS funtion Style
|
40
|
+
|
41
|
+
just similar to rails helper `image_tag`
|
42
|
+
|
43
|
+
1. base usage: e.g.: `imageTag('logo.png')`
|
44
|
+
2. with props: e.g.: `imageTag('path/logo.png', {alt: 'logo', className: 'logo', id: 'logo', width: 100, height: 50})`
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
## Acknowledgements
|
49
|
+
|
50
|
+
the image path will respect `Rails.env`, for development it will be sth like
|
51
|
+
|
52
|
+
`/assets/logo.png`
|
53
|
+
|
54
|
+
and for production, it will be contains the timestamp as
|
55
|
+
|
56
|
+
`/assets/logo-be1f67ffd42a4c1a41bdcc547c5705a3423a2f24bfe930f00398077fe518e6c0.png`
|
57
|
+
|
58
|
+
|
59
|
+
## Contributing
|
60
|
+
|
61
|
+
1. Fork it ( https://github.com/[my-github-username]/react-rails-img/fork )
|
62
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
63
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
64
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
65
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "react/rails/img"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'react/rails/img/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "react-rails-img"
|
8
|
+
spec.version = React::Rails::Img::VERSION
|
9
|
+
spec.authors = ["RainChen"]
|
10
|
+
spec.email = ["hirainchen@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{simple image helpers for the rails project using react}
|
13
|
+
spec.description = %q{simple image helpers for the rails project using react, make it easily just like using the <img> tag}
|
14
|
+
spec.homepage = "https://github.com/rainchen/react-rails-img"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
<%
|
2
|
+
images = {}
|
3
|
+
prefix = Rails.application.config.assets.prefix
|
4
|
+
should_compute_assets_path = Rails.env.production? # for performance
|
5
|
+
if should_compute_assets_path
|
6
|
+
images_dir = Rails.root.join('app/assets/images/').to_s
|
7
|
+
assets.each_file do |file_path|
|
8
|
+
if file_path.starts_with?(images_dir)
|
9
|
+
file_name = file_path.sub(images_dir, '')
|
10
|
+
file_path =
|
11
|
+
if Rails.application.config.assets.digest
|
12
|
+
File.join('/', prefix, Rails.application.assets[file_name].digest_path)
|
13
|
+
else
|
14
|
+
File.join('/', prefix, file_name)
|
15
|
+
end
|
16
|
+
images[file_name] = file_path
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
%>
|
21
|
+
// usage: <Img className="tip" src="/assets/ui-tip.png" alt="private event tip" />
|
22
|
+
// using cssSprite: <Img src="/assets/css_sprite/where-b.png" /> =>
|
23
|
+
// <img class="where-b" data-reactid=".0.1.$0.3.0.1.0">, where-b.png should be placed in `assets/images/css_sprite`
|
24
|
+
var Img = React.createClass({
|
25
|
+
statics: {
|
26
|
+
// usage: Img.assetPath('logo.png') => "/assets/logo.png"
|
27
|
+
assetPath: function (path) {
|
28
|
+
var paths = <%= images.to_json %>;
|
29
|
+
return paths[path] || "/assets/"+path;
|
30
|
+
}
|
31
|
+
},
|
32
|
+
|
33
|
+
propTypes: {
|
34
|
+
src: React.PropTypes.string
|
35
|
+
},
|
36
|
+
|
37
|
+
src: function(){
|
38
|
+
var src = this.props.src;
|
39
|
+
if(src.match("/assets/")){
|
40
|
+
src = src.replace("/assets/", '');
|
41
|
+
}
|
42
|
+
src = Img.assetPath(src);
|
43
|
+
return src;
|
44
|
+
},
|
45
|
+
|
46
|
+
isUsingCssSprite: function (src) {
|
47
|
+
return src.match(/css_sprite/);
|
48
|
+
},
|
49
|
+
|
50
|
+
useCssSprite: function (src, className) {
|
51
|
+
// "/assets/ui-right-w.png" => "ui-right-w"
|
52
|
+
var baseName = src.replace(/\/assets\/(.*)\..*$/, '$1');
|
53
|
+
var cssSpriteClassName = baseName.replace(/css_sprite\//, '');
|
54
|
+
if(className){
|
55
|
+
className = cssSpriteClassName + " "+className;
|
56
|
+
}else{
|
57
|
+
className = cssSpriteClassName;
|
58
|
+
}
|
59
|
+
src = Img.assetPath('css_sprite_holder.png');
|
60
|
+
//src = null; // disable the src
|
61
|
+
return {src: src, className: className};
|
62
|
+
},
|
63
|
+
|
64
|
+
render: function() {
|
65
|
+
var className = this.props.className;
|
66
|
+
var src = this.src();
|
67
|
+
// using css_sprite
|
68
|
+
if(this.isUsingCssSprite(src)){
|
69
|
+
// src should be url like "/assets/css_sprite/xxx.png"
|
70
|
+
var result = this.useCssSprite(this.props.src, className);
|
71
|
+
src = result.src;
|
72
|
+
className = result.className;
|
73
|
+
}
|
74
|
+
return <img src={src} id={this.props.id} alt={this.props.alt} className={className} size={this.props.size} width={this.props.width} height={this.props.height} />;
|
75
|
+
}
|
76
|
+
});
|
77
|
+
|
78
|
+
|
79
|
+
// similar to rails helper `image_tag`, e.g.: {imageTag('placeholder/active-01.png')}
|
80
|
+
// the function will return for development:
|
81
|
+
// /assets/placeholder/active-01.png
|
82
|
+
// and for production
|
83
|
+
// /assets/placeholder/active-01-be1f67ffd42a4c1a41bdcc547c5705a3423a2f24bfe930f00398077fe518e6c0.png
|
84
|
+
function imageTag (source, options) {
|
85
|
+
if(!options)options = {};
|
86
|
+
var src = "/assets/"+source;
|
87
|
+
return <Img src={src} id={options.id} alt={options.alt} className={options.className} size={options.size} width={options.width} height={options.height} />;
|
88
|
+
}
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: react-rails-img
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- RainChen
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: simple image helpers for the rails project using react, make it easily
|
42
|
+
just like using the <img> tag
|
43
|
+
email:
|
44
|
+
- hirainchen@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- ".rspec"
|
51
|
+
- ".travis.yml"
|
52
|
+
- Gemfile
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- bin/console
|
56
|
+
- bin/setup
|
57
|
+
- lib/react/rails/img.rb
|
58
|
+
- lib/react/rails/img/engine.rb
|
59
|
+
- lib/react/rails/img/version.rb
|
60
|
+
- react-rails-img.gemspec
|
61
|
+
- vendor/assets/javascripts/react_rails_img.js.jsx.erb
|
62
|
+
homepage: https://github.com/rainchen/react-rails-img
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.4.6
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: simple image helpers for the rails project using react
|
86
|
+
test_files: []
|