slimline 0.1.6

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: e691cb372c001d5942752407d73173453a7fa2c7
4
+ data.tar.gz: ccf5e09939fd898c0b94425fdb6f2a9af01bd808
5
+ SHA512:
6
+ metadata.gz: 49f6a381821154bc35a4300e434b60f26c8ad20439693c76a529766bb70ea8bf49692bfe9f5593ad1ada3382e0d94c8f46827a86b0428f1823ccfa1f4ac91c4c
7
+ data.tar.gz: 4eaad94fc0e64827599d0c45f6f629130ed5621e7aa5de094d5f4239ddbac8cc0980f5b57e73be6ed6541b62cf7c2af7f1b43fae08ba622c41f23d0f1d3c1d08
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2018
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,69 @@
1
+ # Slimline
2
+ A small basic helper to allow progressively loading images, Nothing really special this was done more as a test to myself to create a rails gem :)
3
+
4
+ ## Installation
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'slimline'
9
+ ```
10
+
11
+ And then execute:
12
+ ```bash
13
+ $ bundle
14
+ ```
15
+
16
+ Or install it yourself as:
17
+ ```bash
18
+ $ gem install slimline
19
+ ```
20
+
21
+ Once installed to make sure that your images still work when javascript isn't active add the following to the head tag
22
+
23
+ ```erb
24
+ class="<%= slimline_js_check_class %>"
25
+ ```
26
+
27
+ Then in the `<html>` section before any css rendering enter:
28
+ ```erb
29
+ <%= slimline_js_check %>
30
+ ```
31
+
32
+ # Usage
33
+
34
+ Now you have installed the about, you will be able to call in the body the `slimine_image_tag` like:
35
+
36
+ ```erb
37
+ <%= slimline_image_tag 'test.jpg', width: 1000, small_image: 'test_small.jpg', alt: "Hello World" %>
38
+ ```
39
+
40
+ Below is a crude example how to use this:
41
+ ```erb
42
+ <!DOCTYPE html>
43
+ <html class="<%= slimline_js_check_class %>">
44
+ <head>
45
+ <title>Slimline</title>
46
+ <%= csrf_meta_tags %>
47
+ <%= slimline_js_check %>
48
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
49
+ <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
50
+ </head>
51
+ <body>
52
+ <%= slimline_image_tag 'test.jpg', width: 1000, small_image: 'test_small.jpg', alt: "Hello World" %>
53
+ </body>
54
+ </html>
55
+ ```
56
+
57
+ You are also able to add a srcset tag to the `slimline_image_tag` that will do srcsets too e.g:
58
+
59
+ ```erb
60
+ <%= slimline_image_tag 'test.jpg', width: 1000, small_image: 'test_small.jpg', srcset: "<%= image_path 'test_x1.jpg' %> x1, <%= image_path 'test_x2' %> x2 ", alt: "Hello World" %>
61
+ ```
62
+
63
+ ## Contributing
64
+ Tests are my next step in learning, so tests are currently not present.
65
+
66
+ To contribute, fork, make your change and do a pull request.
67
+
68
+ ## License
69
+ 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,33 @@
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 = 'Slimline'
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 << 'test'
28
+ t.pattern = 'test/**/*_test.rb'
29
+ t.verbose = false
30
+ end
31
+
32
+
33
+ task default: :test
@@ -0,0 +1,9 @@
1
+ module Slimline
2
+ class Engine < ::Rails::Engine
3
+ initializer 'slimline.initialize' do
4
+ ActiveSupport.on_load(:action_view) do
5
+ include Slimline::ViewHelper
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Slimline
2
+ VERSION = '0.1.6'
3
+ end
@@ -0,0 +1,44 @@
1
+ module Slimline
2
+ module ViewHelper
3
+ include ActionView::Context
4
+ include ActionView::Helpers::TagHelper
5
+ include ActionView::Helpers::AssetTagHelper
6
+
7
+ def slimline_js_check_class
8
+ 'slimline-no-js'
9
+ end
10
+
11
+ def slimline_js_check
12
+ content_tag :script do
13
+ raw 'document.documentElement.classList.remove("slimline-no-js");'
14
+ end
15
+ end
16
+
17
+ def slimline_image_tag(source, options = {} )
18
+ small_image = options.delete(:small_image)
19
+ srcset = options.delete(:srcset)
20
+ sizes = options.delete(:sizes)
21
+ data_options = options.delete(:data) || {}
22
+ new_options = options
23
+
24
+ new_options = new_options.merge(class: 'lazy')
25
+
26
+ if small_image
27
+ data_options = data_options.merge('src' => image_path(source))
28
+ new_source = small_image
29
+ else
30
+ new_source = source
31
+ end
32
+
33
+ data_options = data_options.merge('srcset' => srcset) if srcset
34
+ data_options = data_options.merge('sizes' => sizes) if sizes
35
+
36
+ new_options = new_options.merge(data: data_options)
37
+
38
+ image_tag(new_source, new_options) +
39
+ content_tag(:noscript) do
40
+ image_tag(source, options)
41
+ end
42
+ end
43
+ end
44
+ end
data/lib/slimline.rb ADDED
@@ -0,0 +1,10 @@
1
+
2
+ require "action_view"
3
+
4
+ require "slimline/version"
5
+ require "slimline/view_helper"
6
+ require "slimline/railtie" if defined?(Rails)
7
+
8
+ module Slimline
9
+
10
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slimline
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.6
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Deloughry
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-10-12 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: 3.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.1.0
27
+ description: Give a nice helper to progressively load images
28
+ email:
29
+ - matt@deloughry.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - lib/slimline.rb
38
+ - lib/slimline/railtie.rb
39
+ - lib/slimline/version.rb
40
+ - lib/slimline/view_helper.rb
41
+ homepage: https://deloughry.co.uk
42
+ licenses:
43
+ - MIT
44
+ metadata: {}
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 2.2.5
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Give a nice helper to progressively load images
65
+ test_files: []