images 0.0.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 +14 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +66 -0
- data/Rakefile +6 -0
- data/app/assets/javascripts/images.js.erb +22 -0
- data/circle.yml +0 -0
- data/images.gemspec +25 -0
- data/lib/images/builder.rb +50 -0
- data/lib/images/engine.rb +6 -0
- data/lib/images/url_helper.rb +11 -0
- data/lib/images/version.rb +3 -0
- data/lib/images.rb +18 -0
- data/test/builder_test.rb +32 -0
- data/test/fixtures/image1.jpg +0 -0
- data/test/fixtures/image2.svg +0 -0
- data/test/fixtures/nested/Image3.bmp +0 -0
- data/test/fixtures/nested/Image4.bmp +0 -0
- data/test/fixtures/nested/deeply_nested/Image5.svg +0 -0
- metadata +139 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: feedb77e3f8fe894b5e6aa2aee41612a4c4c1d96
|
4
|
+
data.tar.gz: 034a32f25d188816a098f64b3ea6b176f57b1720
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aa4a02ad345e990d47a2966b041a32ad334ebf8206552e1762438b090755ae8c9660a0fe892a6f258618b81c09b6a60797b6a688fca8489b07b0e4580f910d74
|
7
|
+
data.tar.gz: 2694d27281087b4e5faea5486ca9ca9c815229055a5ca8b703d613cc2de198a46d2a3aeb2e46a8b900487c38fc2fb40d2899ff9d945b7e649eeef6d6fd0a6e4e
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Gabe Scholz, Brewhouse Software
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# Images
|
2
|
+
|
3
|
+
Loads all image urls in your Rails project into a global JavaScript constant.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'images'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install images
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Add `//= require images` line to your `application.js`. It will create an
|
24
|
+
`Images` global JavaScript variable with urls for all images in your
|
25
|
+
`app/assets/images` folder.
|
26
|
+
|
27
|
+
For example, given that you have an image folder structure such as this:
|
28
|
+
|
29
|
+
```
|
30
|
+
.
|
31
|
+
└── app
|
32
|
+
└── assets
|
33
|
+
└── images
|
34
|
+
└── nested
|
35
|
+
| ├── Image3.bmp
|
36
|
+
| ├── Image4.bmp
|
37
|
+
| └── deeply_nested
|
38
|
+
| └── Image5.svg
|
39
|
+
├── image1.jpg
|
40
|
+
└── image2.svg
|
41
|
+
```
|
42
|
+
|
43
|
+
Will create:
|
44
|
+
|
45
|
+
```js
|
46
|
+
// window.Images
|
47
|
+
{
|
48
|
+
nested: {
|
49
|
+
Image3_bmp_path: "/assets/Image3-...",
|
50
|
+
Image4_bmp_path: "/assets/Image4-...",
|
51
|
+
deeply_nested: {
|
52
|
+
Image5_svg_path: "/assets/Image5-..."
|
53
|
+
}
|
54
|
+
},
|
55
|
+
image1_jpg_path: "/assets/image1-...",
|
56
|
+
image2_svg_path: "/assets/image2-..."
|
57
|
+
}
|
58
|
+
```
|
59
|
+
|
60
|
+
## Contributing
|
61
|
+
|
62
|
+
1. Fork it ( https://github.com/BrewhouseTeam/images/fork )
|
63
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
64
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
65
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
66
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
(function (window, undefined) {
|
2
|
+
var Images = <%= Images.load.to_json %>;
|
3
|
+
|
4
|
+
function deepFreeze (obj) {
|
5
|
+
Object.freeze(obj);
|
6
|
+
for (var propKey in obj) {
|
7
|
+
var prop = obj[propKey];
|
8
|
+
if (!obj.hasOwnProperty(propKey) || !(typeof prop === 'object') || Object.isFrozen(prop)) {
|
9
|
+
continue;
|
10
|
+
}
|
11
|
+
deepFreeze(prop);
|
12
|
+
}
|
13
|
+
return obj;
|
14
|
+
}
|
15
|
+
|
16
|
+
if (Object.freeze !== undefined && Object.isFrozen !== undefined) {
|
17
|
+
deepFreeze(Images);
|
18
|
+
}
|
19
|
+
|
20
|
+
window.Images = Images;
|
21
|
+
|
22
|
+
}(window));
|
data/circle.yml
ADDED
File without changes
|
data/images.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "images/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "images"
|
8
|
+
spec.version = Images::VERSION
|
9
|
+
spec.authors = ["Gabe Scholz"]
|
10
|
+
spec.email = ["gabe@brewhouse.io"]
|
11
|
+
spec.summary = %q{Loads all image urls in your Rails project into a global JavaScript constant.}
|
12
|
+
spec.description = %q{Loads all image urls in your Rails project into a global JavaScript constant.}
|
13
|
+
spec.homepage = "https://www.github.com/BrewhouseTeam/images"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_development_dependency "minitest", "~> 5.7.0"
|
23
|
+
spec.add_dependency "rails", "~> 4"
|
24
|
+
spec.add_dependency "actionview", "~> 4"
|
25
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Images
|
2
|
+
class Builder
|
3
|
+
|
4
|
+
def initialize(args)
|
5
|
+
@directory = args.fetch(:directory)
|
6
|
+
@helper = args.fetch(:helper)
|
7
|
+
end
|
8
|
+
|
9
|
+
def call
|
10
|
+
images_paths
|
11
|
+
.map { |path| get_short_path(path) }
|
12
|
+
.reduce({}) { |acc, path|
|
13
|
+
split = split_path(path)
|
14
|
+
asset = @helper.call(path)
|
15
|
+
append_nested_path(acc, split, asset)
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def get_short_path(path)
|
22
|
+
Pathname.new(path).relative_path_from(@directory)
|
23
|
+
end
|
24
|
+
|
25
|
+
def split_path(path)
|
26
|
+
*folders, file = path.to_s.split(File::SEPARATOR)
|
27
|
+
folders + [file.gsub(".", "_") + "_path"]
|
28
|
+
end
|
29
|
+
|
30
|
+
def append_nested_path(acc, path, asset)
|
31
|
+
acc ||= {}
|
32
|
+
key = path.shift
|
33
|
+
|
34
|
+
value = if path.length > 0
|
35
|
+
append_nested_path(acc[key], path, asset)
|
36
|
+
else
|
37
|
+
asset
|
38
|
+
end
|
39
|
+
|
40
|
+
acc[key] = value
|
41
|
+
acc
|
42
|
+
end
|
43
|
+
|
44
|
+
def images_paths
|
45
|
+
paths = @directory.join("**/*.*")
|
46
|
+
Dir.glob(paths)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
data/lib/images.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "images/version"
|
2
|
+
require "images/engine"
|
3
|
+
require "images/url_helper"
|
4
|
+
require "images/builder"
|
5
|
+
|
6
|
+
module Images
|
7
|
+
|
8
|
+
def load
|
9
|
+
directory = ::Rails.root.join('app', 'assets', 'images')
|
10
|
+
helper = Images::UrlHelper.new
|
11
|
+
|
12
|
+
Images::Builder.new({
|
13
|
+
directory: directory,
|
14
|
+
helper: helper
|
15
|
+
}).call
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
require "pathname"
|
3
|
+
require_relative "../lib/images/builder"
|
4
|
+
|
5
|
+
class Images::BuilderTest < Minitest::Test
|
6
|
+
def setup
|
7
|
+
@directory = Pathname.new(Dir.pwd).join("test", "fixtures")
|
8
|
+
@helper = ->(path) { "stub" }
|
9
|
+
|
10
|
+
@builder = Images::Builder.new({
|
11
|
+
directory: @directory,
|
12
|
+
helper: @helper
|
13
|
+
})
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_builder
|
17
|
+
result = @builder.call
|
18
|
+
expected = {
|
19
|
+
"nested" => {
|
20
|
+
"Image3_bmp_path" => "stub",
|
21
|
+
"Image4_bmp_path" => "stub",
|
22
|
+
"deeply_nested" => {
|
23
|
+
"Image5_svg_path" => "stub"
|
24
|
+
}
|
25
|
+
},
|
26
|
+
"image1_jpg_path" => "stub",
|
27
|
+
"image2_svg_path" => "stub"
|
28
|
+
}
|
29
|
+
|
30
|
+
assert_equal(result, expected)
|
31
|
+
end
|
32
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: images
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gabe Scholz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-29 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 5.7.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 5.7.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: actionview
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '4'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '4'
|
83
|
+
description: Loads all image urls in your Rails project into a global JavaScript constant.
|
84
|
+
email:
|
85
|
+
- gabe@brewhouse.io
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- app/assets/javascripts/images.js.erb
|
96
|
+
- circle.yml
|
97
|
+
- images.gemspec
|
98
|
+
- lib/images.rb
|
99
|
+
- lib/images/builder.rb
|
100
|
+
- lib/images/engine.rb
|
101
|
+
- lib/images/url_helper.rb
|
102
|
+
- lib/images/version.rb
|
103
|
+
- test/builder_test.rb
|
104
|
+
- test/fixtures/image1.jpg
|
105
|
+
- test/fixtures/image2.svg
|
106
|
+
- test/fixtures/nested/Image3.bmp
|
107
|
+
- test/fixtures/nested/Image4.bmp
|
108
|
+
- test/fixtures/nested/deeply_nested/Image5.svg
|
109
|
+
homepage: https://www.github.com/BrewhouseTeam/images
|
110
|
+
licenses:
|
111
|
+
- MIT
|
112
|
+
metadata: {}
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 2.4.1
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: Loads all image urls in your Rails project into a global JavaScript constant.
|
133
|
+
test_files:
|
134
|
+
- test/builder_test.rb
|
135
|
+
- test/fixtures/image1.jpg
|
136
|
+
- test/fixtures/image2.svg
|
137
|
+
- test/fixtures/nested/Image3.bmp
|
138
|
+
- test/fixtures/nested/Image4.bmp
|
139
|
+
- test/fixtures/nested/deeply_nested/Image5.svg
|