retina_image 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 85a37773ab9ca391ddde0d42273fc50c5c127008
4
+ data.tar.gz: 106a2410703b7e108bdecae785cac85e001c964b
5
+ SHA512:
6
+ metadata.gz: 99bda0cab407ca085ba0a080af48067ce64488e8b318c86e80e5c41f94c818246246df5a39d39229f96a2533c7a5b332b028a0670e661f9dd257967f784ac7c6
7
+ data.tar.gz: 8e06248e07aad4341a781d83b9d8b57394c47dd8e14daf22ccdcd085643aa9a442385590c9f9a8c6d514be8fc460dea61792a2afdd9908734a1567e83e8d2048
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 Palm Stable
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # RetinaImage
2
+ Retina Image is a simple retina image tag that supports high resolution images using assets pipeline.
3
+ Also, this gem does not override your original image_tag.
4
+
5
+
6
+ ## Usage
7
+ ```ruby
8
+ <%= retina_image_tag 'example.png' %>
9
+ ```
10
+
11
+ ## Installation
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'retina_image'
16
+ ```
17
+
18
+ And then execute:
19
+ ```bash
20
+ $ bundle
21
+ ```
22
+
23
+ Or install it yourself as:
24
+ ```bash
25
+ $ gem install retina_image
26
+ ```
27
+
28
+ ## Contributing
29
+ Contribution directions go here.
30
+
31
+ ## License
32
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'RetinaImage'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,3 @@
1
+ module RetinaImage
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,36 @@
1
+ module RetinaImage
2
+ def retina_tag(source, options = {})
3
+ options.reverse_merge!(include_srcsets: true)
4
+
5
+ # if options[:include_srcsets] != true
6
+ # need to cast to bool incase truthy/falsey strings are passed
7
+ return image_tag unless options.delete(:include_srcsets).to_bool
8
+
9
+ srcset = srcset_from_source(source)
10
+ options[:srcset] = srcset.keys.map { |k| "#{srcset[k]} #{k}" }.join(', ')
11
+ options.reverse_merge!(alt: alt(source))
12
+ image_tag(srcset["1x"], options)
13
+ end
14
+
15
+ private def srcset_from_source(source)
16
+ dir, file, extension = split_path(source)
17
+
18
+ (1..3).each_with_object({}) do |i, srcset|
19
+ scale = "#{i}x"
20
+ srcset[scale] = build_image_path(dir, "#{file}_#{scale}#{extension}")
21
+ end
22
+ end
23
+
24
+ private def split_path(source)
25
+ [
26
+ File.dirname(source),
27
+ File.basename(source, '.*'),
28
+ File.extname(source)
29
+ ]
30
+ end
31
+
32
+ private def build_image_path(dirname, filename)
33
+ asset_path = (dirname == '.' ? filename : File.join(dirname, filename))
34
+ image_path(asset_path)
35
+ end
36
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :retina_image do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: retina_image
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Palm Stable
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.0.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.0.2
27
+ description: A simple retina image tag
28
+ email:
29
+ - songsukeja@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - lib/retina_image.rb
38
+ - lib/retina_image/version.rb
39
+ - lib/tasks/retina_image_tasks.rake
40
+ homepage: https://github.com/songsuke/retina_image
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.6.8
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Retina Image supports high resolution images
64
+ test_files: []