scrivito_picture_widget 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 +7 -0
- data/LICENSE +4 -0
- data/Rakefile +35 -0
- data/app/assets/images/widgets/scrivito_picture_widget.png +0 -0
- data/app/assets/stylesheets/picture_widget.scss +3 -0
- data/app/assets/stylesheets/scrivito_picture_widget/application.scss +15 -0
- data/app/helpers/scrivito_picture_widget_helper.rb +37 -0
- data/app/models/picture_widget.rb +6 -0
- data/app/views/picture_widget/details.html.erb +17 -0
- data/app/views/picture_widget/show.html.erb +22 -0
- data/app/views/picture_widget/thumbnail.html.erb +3 -0
- data/lib/scrivito_picture_widget.rb +21 -0
- data/lib/scrivito_picture_widget/configuration.rb +20 -0
- data/lib/scrivito_picture_widget/engine.rb +9 -0
- data/lib/scrivito_picture_widget/version.rb +3 -0
- data/lib/tasks/scrivito_picture_widget_tasks.rake +4 -0
- metadata +73 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5e4c06410b8aadb0b8c468bfc0432bdf14ca36fd
|
4
|
+
data.tar.gz: 987967e70e8bbd2c202996dca0b016bf7e6f51ac
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2b888962d5770f97312f314c4c59870c815544bf6e391aa5c1a63c473fc31e5195505c9e82552cadebcc0606bde1d2dcb8bfc15d368f3b82111a2eb3ba14d3cf
|
7
|
+
data.tar.gz: e6a43c86046fee3f92964627fddc7a47549a39b08143abcf0fdb8ada9e0bd27c2708fdab89e079c2c39c83e27454bb2c50c8672dc1c3fe0d2f5f24b2d5e7dcce
|
data/LICENSE
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
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 = 'ScrivitoPictureWidget'
|
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
|
+
load 'rails/tasks/statistics.rake'
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
require 'bundler/gem_tasks'
|
24
|
+
|
25
|
+
require 'rake/testtask'
|
26
|
+
|
27
|
+
Rake::TestTask.new(:test) do |t|
|
28
|
+
t.libs << 'lib'
|
29
|
+
t.libs << 'test'
|
30
|
+
t.pattern = 'test/**/*_test.rb'
|
31
|
+
t.verbose = false
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
task default: :test
|
Binary file
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module ScrivitoPictureWidgetHelper
|
2
|
+
def image_srcset(widget)
|
3
|
+
widths = ScrivitoPictureWidget.configuration.desktop_srcsets
|
4
|
+
|
5
|
+
image_srcset_for(widget, widget.image, widths)
|
6
|
+
end
|
7
|
+
|
8
|
+
def mobile_image_srcset(widget)
|
9
|
+
widths = ScrivitoPictureWidget.configuration.mobile_srcsets
|
10
|
+
|
11
|
+
image_srcset_for(widget, widget.mobile_image || widget.image, widths, :crop)
|
12
|
+
end
|
13
|
+
|
14
|
+
def tablet_image_srcset(widget)
|
15
|
+
widths = ScrivitoPictureWidget.configuration.tablet_srcsets
|
16
|
+
|
17
|
+
image_srcset_for(widget, widget.tablet_image || widget.image, widths, :crop)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def image_srcset_for(widget, obj, widths, fit=nil)
|
22
|
+
image = obj.try(:binary)
|
23
|
+
return unless image
|
24
|
+
|
25
|
+
widths.map do |width|
|
26
|
+
if(fit && obj.id == widget.image.id)
|
27
|
+
height = (width*image.meta_data[:height])/widths.map(&:to_i).max
|
28
|
+
transformed_image = image.transform(width: width, height: height, fit: fit, crop: widget.crop)
|
29
|
+
else
|
30
|
+
transformed_image = image.transform(width: width)
|
31
|
+
end
|
32
|
+
url = scrivito_url(transformed_image)
|
33
|
+
|
34
|
+
"#{url} #{width}w"
|
35
|
+
end.join(", ")
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<%= scrivito_details_for t('scrivito_picture_wigdet.details.crop', default: 'Crop') do %>
|
2
|
+
<%= scrivito_tag :div, widget, :crop %>
|
3
|
+
<% end %>
|
4
|
+
|
5
|
+
<%= scrivito_details_for t('scrivito_picture_wigdet.details.image', default: 'Image') do %>
|
6
|
+
<%= scrivito_tag :div, widget, :image %>
|
7
|
+
<% end %>
|
8
|
+
|
9
|
+
<%= scrivito_details_for t('scrivito_picture_wigdet.details.mobile_image', default: 'Mobile image') do %>
|
10
|
+
<div class="alert alert-info"><%= t('scrivito_picture_wigdet.details.transform_info', default: 'Set if the automatic transformed image does not fit') %></div>
|
11
|
+
<%= scrivito_tag :div, widget, :mobile_image %>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<%= scrivito_details_for t('scrivito_picture_wigdet.details.tablet_image', default: 'Tablet image') do %>
|
15
|
+
<div class="alert alert-info"><%= t('scrivito_picture_wigdet.details.transform_info', default: 'Set if the automatic transformed image does not fit') %></div>
|
16
|
+
<%= scrivito_tag :div, widget, :tablet_image %>
|
17
|
+
<% end %>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<% if widget.image %>
|
2
|
+
<picture class="img-responsive">
|
3
|
+
<source media='(max-width: <%= ScrivitoPictureWidget.configuration.mobile_breakpoint %>px) and (orientation: portrait)'
|
4
|
+
sizes='100vw'
|
5
|
+
srcset='<%= mobile_image_srcset(widget) %>' class="img-responsive">
|
6
|
+
|
7
|
+
<source media='(max-width: <%= ScrivitoPictureWidget.configuration.mobile_breakpoint %>px) and (orientation: landscape)'
|
8
|
+
sizes='100vw'
|
9
|
+
srcset='<%= tablet_image_srcset(widget) %>' class="img-responsive">
|
10
|
+
|
11
|
+
<source media='(min-width: <%= ScrivitoPictureWidget.configuration.mobile_breakpoint + 1 %>px) and (max-width: <%= ScrivitoPictureWidget.configuration.tablet_breakpoint %>px)'
|
12
|
+
sizes='100vw'
|
13
|
+
srcset='<%= tablet_image_srcset(widget) %>' class="img-responsive">
|
14
|
+
|
15
|
+
<img
|
16
|
+
src='<%= scrivito_path(widget.image.binary.transform(width: 1170)) %>'
|
17
|
+
alt='This is a cool image'
|
18
|
+
srcset='<%= image_srcset(widget) %>' class="img-responsive">
|
19
|
+
</picture>
|
20
|
+
<% else %>
|
21
|
+
<div class="alert alert-warning">No image is set. Go to the details view and select one.</div>
|
22
|
+
<% end %>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "scrivito_picture_widget/engine"
|
2
|
+
require "scrivito_picture_widget/configuration"
|
3
|
+
|
4
|
+
module ScrivitoPictureWidget
|
5
|
+
class << self
|
6
|
+
attr_writer :configuration
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.configuration
|
10
|
+
@configuration ||= Configuration.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.reset
|
14
|
+
@configuration = Configuration.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.configure
|
18
|
+
yield(configuration)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module ScrivitoPictureWidget
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :image_fallback_size
|
4
|
+
attr_accessor :mobile_breakpoint
|
5
|
+
attr_accessor :mobile_srcsets
|
6
|
+
attr_accessor :tablet_breakpoint
|
7
|
+
attr_accessor :tablet_srcsets
|
8
|
+
attr_accessor :desktop_srcsets
|
9
|
+
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@image_fallback_size = 1170
|
13
|
+
@mobile_breakpoint = 700
|
14
|
+
@mobile_srcsets = [900, 700, 500, 300]
|
15
|
+
@tablet_breakpoint = 992
|
16
|
+
@tablet_srcsets = [1300, 1000, 800, 500]
|
17
|
+
@desktop_srcsets = [1900, 1600, 1400, 1200]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: scrivito_picture_widget
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Scrivito
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: scrivito
|
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: A responsive image widget for scrivito using the picture tag
|
28
|
+
email:
|
29
|
+
- support@scrivito.de
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- LICENSE
|
35
|
+
- Rakefile
|
36
|
+
- app/assets/images/widgets/scrivito_picture_widget.png
|
37
|
+
- app/assets/stylesheets/picture_widget.scss
|
38
|
+
- app/assets/stylesheets/scrivito_picture_widget/application.scss
|
39
|
+
- app/helpers/scrivito_picture_widget_helper.rb
|
40
|
+
- app/models/picture_widget.rb
|
41
|
+
- app/views/picture_widget/details.html.erb
|
42
|
+
- app/views/picture_widget/show.html.erb
|
43
|
+
- app/views/picture_widget/thumbnail.html.erb
|
44
|
+
- lib/scrivito_picture_widget.rb
|
45
|
+
- lib/scrivito_picture_widget/configuration.rb
|
46
|
+
- lib/scrivito_picture_widget/engine.rb
|
47
|
+
- lib/scrivito_picture_widget/version.rb
|
48
|
+
- lib/tasks/scrivito_picture_widget_tasks.rake
|
49
|
+
homepage: https://scrivito.com
|
50
|
+
licenses:
|
51
|
+
- LGPL-3
|
52
|
+
metadata: {}
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 2.5.1
|
70
|
+
signing_key:
|
71
|
+
specification_version: 4
|
72
|
+
summary: A responsive image widget for scrivito using the picture tag
|
73
|
+
test_files: []
|