openseadragon 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +62 -11
- data/app/assets/javascripts/openseadragon/rails.js +42 -0
- data/app/helpers/openseadragon/openseadragon_helper.rb +104 -86
- data/app/models/openseadragon/{info.rb → open_street_map.rb} +4 -5
- data/lib/openseadragon/version.rb +1 -1
- data/openseadragon.gemspec +1 -0
- data/spec/helpers/openseadragon_helper_spec.rb +79 -145
- data/spec/models/openseadragon/open_street_map.rb +11 -0
- metadata +20 -113
- data/spec/internal/.generated_engine_cart +0 -1
- data/spec/internal/.gitignore +0 -16
- data/spec/internal/Gemfile +0 -46
- data/spec/internal/README.rdoc +0 -28
- data/spec/internal/Rakefile +0 -6
- data/spec/internal/app/assets/images/.keep +0 -0
- data/spec/internal/app/assets/javascripts/application.js +0 -16
- data/spec/internal/app/assets/stylesheets/application.css +0 -13
- data/spec/internal/app/controllers/application_controller.rb +0 -5
- data/spec/internal/app/controllers/concerns/.keep +0 -0
- data/spec/internal/app/helpers/application_helper.rb +0 -2
- data/spec/internal/app/mailers/.keep +0 -0
- data/spec/internal/app/models/.keep +0 -0
- data/spec/internal/app/models/concerns/.keep +0 -0
- data/spec/internal/app/views/layouts/application.html.erb +0 -14
- data/spec/internal/bin/bundle +0 -3
- data/spec/internal/bin/rails +0 -4
- data/spec/internal/bin/rake +0 -4
- data/spec/internal/config.ru +0 -4
- data/spec/internal/config/application.rb +0 -23
- data/spec/internal/config/boot.rb +0 -4
- data/spec/internal/config/database.yml +0 -25
- data/spec/internal/config/environment.rb +0 -5
- data/spec/internal/config/environments/development.rb +0 -29
- data/spec/internal/config/environments/production.rb +0 -80
- data/spec/internal/config/environments/test.rb +0 -36
- data/spec/internal/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/internal/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/internal/config/initializers/inflections.rb +0 -16
- data/spec/internal/config/initializers/mime_types.rb +0 -5
- data/spec/internal/config/initializers/secret_token.rb +0 -12
- data/spec/internal/config/initializers/session_store.rb +0 -3
- data/spec/internal/config/initializers/wrap_parameters.rb +0 -14
- data/spec/internal/config/locales/en.yml +0 -23
- data/spec/internal/config/routes.rb +0 -56
- data/spec/internal/db/schema.rb +0 -16
- data/spec/internal/db/seeds.rb +0 -7
- data/spec/internal/lib/assets/.keep +0 -0
- data/spec/internal/lib/tasks/.keep +0 -0
- data/spec/internal/log/.keep +0 -0
- data/spec/internal/public/404.html +0 -58
- data/spec/internal/public/422.html +0 -58
- data/spec/internal/public/500.html +0 -57
- data/spec/internal/public/favicon.ico +0 -0
- data/spec/internal/public/robots.txt +0 -5
- data/spec/internal/test/controllers/.keep +0 -0
- data/spec/internal/test/fixtures/.keep +0 -0
- data/spec/internal/test/helpers/.keep +0 -0
- data/spec/internal/test/integration/.keep +0 -0
- data/spec/internal/test/mailers/.keep +0 -0
- data/spec/internal/test/models/.keep +0 -0
- data/spec/internal/test/test_helper.rb +0 -15
- data/spec/internal/vendor/assets/javascripts/.keep +0 -0
- data/spec/internal/vendor/assets/stylesheets/.keep +0 -0
- data/spec/models/openseadragon/info_spec.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc2f571409c5211449a6282bb40f910577d61c54
|
4
|
+
data.tar.gz: 95071d5309b293c0de161fcf75d7dc04a3bc1a65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7ed4e37466254b265e47581d5e8a1253031f1ea2470013119900c28d39aaa71e1fe27ca30ce7618895bdf9c0c5b27a8d08ccbcbfe71129482b8264817967f56
|
7
|
+
data.tar.gz: 23a828bdd797015e43b8c8aeb24514d0c668ee7864801b8362e82790d4166545d910635eb300c82bbee07fc4c546243ea2a84ae700b8cc0330633eaae9231487
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -4,21 +4,72 @@ OpenSeadragon is a javascript library for displaying tiling images. This gem pac
|
|
4
4
|
|
5
5
|
http://openseadragon.github.io/
|
6
6
|
|
7
|
-
#
|
7
|
+
# Usage
|
8
8
|
|
9
|
-
|
9
|
+
This gem provides two helpers, `#picture_tag` and `#openseadragon_picture_tag`.
|
10
|
+
|
11
|
+
## picture_tag
|
12
|
+
|
13
|
+
The `#picture_tag` helper creates [HTML5 <picture> tags](http://www.w3.org/TR/html-picture-element/).
|
14
|
+
|
15
|
+
In the simple case, a view like:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
picture_tag 'page1.jpg', 'page2.jpg', 'page3.jpg'
|
19
|
+
```
|
20
|
+
|
21
|
+
Creates the HTML like:
|
22
|
+
|
23
|
+
```html
|
24
|
+
<picture>
|
25
|
+
<source src="page1.jpg" />
|
26
|
+
<source src="page2.jpg" />
|
27
|
+
<source src="page3.jpg" />
|
28
|
+
</picture>
|
29
|
+
```
|
30
|
+
|
31
|
+
You can control the attributes on `<picture>` and `<source>` elements:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
picture_tag ['page1.jpg' => { id: 'first-picture'}], 'page2.jpg', 'page3.jpg', { class: "picture-image" }, { id: 'my-picture'}
|
35
|
+
```
|
36
|
+
|
37
|
+
```html
|
38
|
+
<picture id="my-picture">
|
39
|
+
<source class="picture-image" id="first-picture" src="page1.jpg">
|
40
|
+
<source class="picture-image" src="page2.jpg">
|
41
|
+
<source class="picture-image" src="page3.jpg">
|
42
|
+
</picture>
|
43
|
+
```
|
44
|
+
|
45
|
+
## openseadragon_picture_tag
|
46
|
+
|
47
|
+
If you have an OpenSeaDragon tilesource, you can use this helper to construct a HTML5 `<picture>` that will render as an OpenSeaDragon tile viewer.
|
10
48
|
|
11
49
|
```ruby
|
12
|
-
|
13
|
-
|
14
|
-
# Custom code here to find the height & width
|
15
|
-
Openseadragon::Image.new(id: id, height: 4000, width: 8000)
|
16
|
-
end
|
17
|
-
end
|
50
|
+
openseadragon_picture_tag 'page1.jpg'
|
51
|
+
```
|
18
52
|
|
19
|
-
|
20
|
-
|
53
|
+
```html
|
54
|
+
<picture data-openseadragon="true">
|
55
|
+
<source media="openseadragon" src="page1.jpg" />
|
56
|
+
</picture>
|
21
57
|
```
|
22
58
|
|
23
|
-
|
59
|
+
This gem includes some javascript that translates that markup to the OSD viewer.
|
60
|
+
|
61
|
+
As with `#picture_tag`, you can provide additional options.
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
openseadragon_picture_tag 'page1.jpg', 'path/to/info.json', ['some-custom-tilesource' => { Image: { xmlns: "...", Url: '...', Format: 'jpg', Overlap: 2}}], { class: 'osd-image'}, { data: { openseadragon: { preserveViewport: true, visibilityRatio: 1}}}
|
65
|
+
```
|
66
|
+
|
67
|
+
```html
|
68
|
+
<picture data-openseadragon="{"preserveViewport":true,"visibilityRatio":1}">
|
69
|
+
<source class="osd-image" media="openseadragon" src="page1.jpg" />
|
70
|
+
<source class="osd-image" media="openseadragon" src="path/to/info.json" />
|
71
|
+
<source class="osd-image" data-openseadragon="{"Image":{"xmlns":"...","Url":"...","Format":"jpg","Overlap":2}}" media="openseadragon" src="some-custom-tilesource" />
|
72
|
+
</picture>
|
73
|
+
```
|
24
74
|
|
75
|
+
The `src` attribute (or the JSON-encoded options given in the `data-openseadragon`) are translated into an OpenSeaDragon `tilesource` configuration.
|
@@ -0,0 +1,42 @@
|
|
1
|
+
//= require openseadragon
|
2
|
+
|
3
|
+
(function($) {
|
4
|
+
var __osd_counter = 0;
|
5
|
+
function generateOsdId() {
|
6
|
+
__osd_counter++;
|
7
|
+
|
8
|
+
return "Openseadragon" + __osd_counter;
|
9
|
+
}
|
10
|
+
|
11
|
+
function initOpenSeadragon() {
|
12
|
+
$('picture[data-openseadragon]').each(function() {
|
13
|
+
var $picture = $(this);
|
14
|
+
|
15
|
+
if (typeof $picture.attr('id') === "undefined") {
|
16
|
+
$picture.attr('id', generateOsdId());
|
17
|
+
}
|
18
|
+
|
19
|
+
var collectionOptions = $picture.data('openseadragon');
|
20
|
+
|
21
|
+
var sources = $picture.find('source[media="openseadragon"]');
|
22
|
+
|
23
|
+
var tilesources = $.map(sources, function(e) {
|
24
|
+
if ($(e).data('openseadragon')) {
|
25
|
+
return $(e).data('openseadragon');
|
26
|
+
} else {
|
27
|
+
return $(e).attr('src');
|
28
|
+
}
|
29
|
+
});
|
30
|
+
|
31
|
+
$picture.css("display", "block");
|
32
|
+
$picture.css("height", "500px");
|
33
|
+
|
34
|
+
OpenSeadragon(
|
35
|
+
$.extend({ id: $picture.attr('id') }, collectionOptions, { tileSources: tilesources })
|
36
|
+
);
|
37
|
+
});
|
38
|
+
};
|
39
|
+
|
40
|
+
window.onload = initOpenSeadragon;
|
41
|
+
document.addEventListener("page:load", initOpenSeadragon);
|
42
|
+
})(jQuery);
|
@@ -1,104 +1,122 @@
|
|
1
1
|
module Openseadragon
|
2
2
|
module OpenseadragonHelper
|
3
|
-
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
3
|
+
##
|
4
|
+
# Generate a <picture> tag containing the given sources.
|
5
|
+
# A source can be a simple string, or a hash with the key
|
6
|
+
# for the value of the src attribute and the value as the
|
7
|
+
# arguments for the tag options.
|
8
|
+
#
|
9
|
+
# The last hash is intepreted as optional arguments for the
|
10
|
+
# <picture> tag. The second to last hash is optional arguments
|
11
|
+
# to all <source> tags.
|
12
|
+
#
|
13
|
+
# @param sources [Array<String>, Array<Hash>]
|
14
|
+
# @param source_tag_options [Hash]
|
15
|
+
# @param picture_tag_options [Hash]
|
16
|
+
def picture_tag *sources
|
17
|
+
picture_options = sources.extract_options!.symbolize_keys
|
18
|
+
source_options = sources.extract_options!.symbolize_keys
|
19
|
+
sources.flatten!
|
20
|
+
content_tag :picture, picture_options do
|
21
|
+
safe_join(sources.map do |source|
|
22
|
+
tag_options = if source.is_a? Hash
|
23
|
+
src, src_options = source.first
|
24
|
+
src_options ||= {}
|
25
|
+
source_options.merge(src_options.merge(src: src))
|
26
|
+
else
|
27
|
+
source_options.merge(src: source)
|
28
|
+
end
|
29
|
+
|
30
|
+
yield tag_options if block_given?
|
31
|
+
tag :source, tag_options
|
32
|
+
end)
|
17
33
|
end
|
34
|
+
end
|
18
35
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
36
|
+
##
|
37
|
+
# Generate a <picture> tag ready to be parsed by the openseadragon/rails
|
38
|
+
# javascript and transformed into an openseadragon viewer. Openseadragon
|
39
|
+
# tile source options are passed as a JSON encoded hash on the
|
40
|
+
# data-openseadragon attribute.
|
41
|
+
#
|
42
|
+
# @see [#picture_tag]
|
43
|
+
# @param sources [Array<String>, Array<Hash>]
|
44
|
+
# @param source_tag_options [Hash]
|
45
|
+
# @param picture_tag_options [Hash]
|
46
|
+
def openseadragon_picture_tag(*sources)
|
47
|
+
picture_options = sources.extract_options!.symbolize_keys
|
48
|
+
source_options = sources.extract_options!.symbolize_keys
|
49
|
+
sources.flatten!
|
24
50
|
|
25
|
-
|
26
|
-
|
51
|
+
tile_sources = sources.map { |thing| extract_openseadragon_picture_tilesource(thing) }
|
52
|
+
|
53
|
+
picture_options[:data] ||= {}
|
54
|
+
picture_options[:data][:openseadragon] ||= true
|
27
55
|
|
28
|
-
|
29
|
-
function initOpenSeadragon() {
|
30
|
-
OpenSeadragon(#{js_options});
|
31
|
-
}
|
32
|
-
window.onload = initOpenSeadragon;
|
33
|
-
document.addEventListener("page:load", initOpenSeadragon); // Initialize when using turbolinks
|
34
|
-
EOF
|
35
|
-
content_tag(:div, '', html_options) + javascript_tag(js)
|
36
|
-
end
|
37
|
-
|
38
|
-
# converts a ruby hash to a javascript object without stringifying the raw_js_keys
|
39
|
-
# so you can put js variables in there
|
40
|
-
def options_to_js(options, raw_js_keys=[])
|
41
|
-
normal = options.except(*raw_js_keys).stringify_keys.map do |k, v|
|
42
|
-
val = if v.is_a?(Hash) or v.is_a?(Array)
|
43
|
-
JSON.pretty_generate(v)
|
44
|
-
else
|
45
|
-
json_dump(v)
|
46
|
-
end
|
47
|
-
k.to_s.inspect + ": " + val
|
48
|
-
end
|
49
|
-
raw_js = options.slice(*raw_js_keys).map{|k, v| k.to_s + ": " + v.to_s}
|
50
|
-
"{\n" + (normal + raw_js).join(",\n") + "}"
|
56
|
+
picture_tag [tile_sources], { media: 'openseadragon' }.merge(source_options), picture_options
|
51
57
|
end
|
52
58
|
|
59
|
+
private
|
53
60
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
61
|
+
##
|
62
|
+
# @overload extract_openseadragon_picture_tilesource(url)
|
63
|
+
# @param url [String]
|
64
|
+
# @overload extract_openseadragon_picture_tilesource(tilesource_obj)
|
65
|
+
# @param tilesource_obj [#to_tilesource] a tilesource-backed object that
|
66
|
+
# is either a hash of openseadragon tilesource parameters or a URL to
|
67
|
+
# a manifest containing those parameters.
|
68
|
+
# @overload extract_openseadragon_picture_tilesource(options)
|
69
|
+
# @param [Hash] options a hash of openseadragon tilesource options
|
70
|
+
# @option options [Hash] :html parameters for the <source> tag
|
71
|
+
# @overload extract_openseadragon_picture_tilesource(hash_with_tilesource)
|
72
|
+
# @param hash_with_tilesource [Hash<#to_tilesource, Hash>] the key of the hash
|
73
|
+
# is a tilesource object, and the options will be merged with the given hash
|
74
|
+
# @param [Hash] options a hash of openseadragon tilesource options, which will
|
75
|
+
# override the tilesource options
|
76
|
+
# @option options [Hash] :html parameters for the the <source> tag
|
77
|
+
def extract_openseadragon_picture_tilesource thing
|
78
|
+
if thing.respond_to? :to_tilesource
|
79
|
+
html_options ||= {}
|
80
|
+
html_options[:data] ||= {}
|
81
|
+
html_options[:data][:openseadragon] ||= {}
|
82
|
+
|
83
|
+
tilesource = thing.to_tilesource
|
84
|
+
src = "openseadragon-tilesource"
|
85
|
+
|
86
|
+
if tilesource.is_a? Hash
|
87
|
+
html_options[:data][:openseadragon].merge! tilesource
|
62
88
|
else
|
63
|
-
|
89
|
+
src = tilesource
|
64
90
|
end
|
65
|
-
end
|
66
|
-
else
|
67
|
-
def json_dump(val)
|
68
|
-
JSON.dump(val)
|
69
|
-
end
|
70
|
-
end
|
71
91
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
# @option options [String] :prefix_url
|
76
|
-
# @option options [String] :image_host
|
77
|
-
# @option options [String] :tile_width
|
78
|
-
# @option options [String] :tile_height
|
79
|
-
def openseadragon_viewer(id_or_image, options={})
|
80
|
-
opts = {}
|
81
|
-
opts[:id] = options[:html_id] if options[:html_id]
|
82
|
-
opts[:prefixUrl] = options[:prefix_url] if options[:prefix_url]
|
83
|
-
opts[:tileSources] = [options.slice(:image_host, :tile_width, :tile_height)]
|
84
|
-
opts.deep_merge!(options.except(:html_id, :prefix_url, :image_host, :tile_width, :tile_height))
|
85
|
-
openseadragon_collection_viewer([id_or_image], opts)
|
86
|
-
end
|
92
|
+
[src => html_options ]
|
93
|
+
elsif thing.is_a? Hash
|
94
|
+
src, src_options = thing.first
|
87
95
|
|
88
|
-
|
96
|
+
html_options = {}
|
97
|
+
html_options.merge! src_options.fetch(:html, {})
|
98
|
+
html_options[:data] ||= {}
|
99
|
+
|
100
|
+
osd_options = html_options[:data][:openseadragon] || {}
|
101
|
+
osd_options.merge!(src_options.except(:html))
|
89
102
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
when Info
|
100
|
-
id_or_image.to_tilesource
|
103
|
+
if src.respond_to? :to_tilesource
|
104
|
+
tilesource = src.to_tilesource
|
105
|
+
|
106
|
+
if tilesource.is_a? Hash
|
107
|
+
osd_options.reverse_merge! tilesource
|
108
|
+
src = "openseadragon-tilesource"
|
109
|
+
else
|
110
|
+
src = tilesource
|
111
|
+
end
|
101
112
|
end
|
113
|
+
|
114
|
+
html_options[:data][:openseadragon] = osd_options.to_json
|
115
|
+
|
116
|
+
[ html_options.fetch(:src, src) => html_options ]
|
117
|
+
else
|
118
|
+
thing
|
119
|
+
end
|
102
120
|
end
|
103
121
|
end
|
104
122
|
end
|
data/openseadragon.gemspec
CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "rake"
|
23
23
|
spec.add_development_dependency "engine_cart"
|
24
24
|
spec.add_development_dependency "rspec-rails"
|
25
|
+
spec.add_development_dependency "capybara"
|
25
26
|
spec.add_development_dependency "sqlite3"
|
26
27
|
|
27
28
|
spec.add_dependency 'rails', '> 3.2.0'
|
@@ -1,154 +1,88 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Openseadragon::OpenseadragonHelper do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
describe "#picture_tag" do
|
5
|
+
context "without any sources" do
|
6
|
+
it "should render an empty <picture>" do
|
7
|
+
expect(helper.picture_tag).to have_selector 'picture'
|
8
8
|
end
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
|
10
|
+
it "should use provided options" do
|
11
|
+
expect(helper.picture_tag a: 1).to have_selector 'picture[a="1"]'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "with two sources" do
|
16
|
+
it "should include both sources" do
|
17
|
+
response = helper.picture_tag 'image1.jpg', 'image2.jpg'
|
18
|
+
expect(response).to have_selector 'picture source[src="image1.jpg"]'
|
19
|
+
expect(response).to have_selector 'picture source[src="image2.jpg"]'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should use provided global options" do
|
23
|
+
response = helper.picture_tag 'image1.jpg', 'image2.jpg', { a: 1 }, {b: 2}
|
24
|
+
expect(response).to have_selector 'picture[b="2"]'
|
25
|
+
expect(response).to have_selector 'picture source[src="image1.jpg"][a="1"]'
|
26
|
+
expect(response).to have_selector 'picture source[src="image2.jpg"][a="1"]'
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
context "with a source given as a hash" do
|
32
|
+
it "should use the key of the hash for the src" do
|
33
|
+
expect(helper.picture_tag ['image1.jpg' => { }]).to have_selector 'picture source[src="image1.jpg"]'
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should use the attributes as options for the source tag" do
|
37
|
+
expect(helper.picture_tag ['image1.jpg' => { a: 1}]).to have_selector 'picture source[src="image1.jpg"][a="1"]'
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should merge the source-specific attributes with the global attributes" do
|
41
|
+
expect(helper.picture_tag ['image1.jpg' => { a: 1}], {a: 2, b: 2}, { }).to have_selector 'picture source[src="image1.jpg"][a="1"][b="2"]'
|
13
42
|
end
|
14
43
|
end
|
15
|
-
Openseadragon::Image.file_resolver = SpecResolver
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should draw the single item viewer" do
|
19
|
-
out = openseadragon_viewer('world', image_host: '/foo', html: {class: 'stuff'})
|
20
|
-
out.should == '<div class="stuff" id="openseadragon1"></div><script>
|
21
|
-
//<![CDATA[
|
22
|
-
function initOpenSeadragon() {
|
23
|
-
OpenSeadragon({
|
24
|
-
"id": "openseadragon1",
|
25
|
-
"prefixUrl": "/assets/openseadragon/",
|
26
|
-
"tileSources": [
|
27
|
-
{
|
28
|
-
"identifier": "world",
|
29
|
-
"width": 800,
|
30
|
-
"height": 400,
|
31
|
-
"scale_factors": [
|
32
|
-
1,
|
33
|
-
2,
|
34
|
-
3,
|
35
|
-
4,
|
36
|
-
5
|
37
|
-
],
|
38
|
-
"formats": [
|
39
|
-
"jpg",
|
40
|
-
"png"
|
41
|
-
],
|
42
|
-
"qualities": [
|
43
|
-
"native",
|
44
|
-
"bitonal",
|
45
|
-
"grey",
|
46
|
-
"color"
|
47
|
-
],
|
48
|
-
"profile": "http://library.stanford.edu/iiif/image-api/compliance.html#level3",
|
49
|
-
"tile_width": 1024,
|
50
|
-
"tile_height": 1024,
|
51
|
-
"image_host": "/foo"
|
52
|
-
}
|
53
|
-
]});
|
54
|
-
}
|
55
|
-
window.onload = initOpenSeadragon;
|
56
|
-
document.addEventListener("page:load", initOpenSeadragon); // Initialize when using turbolinks
|
57
|
-
|
58
|
-
//]]>
|
59
|
-
</script>'
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should draw the single item viewer for an info.json source" do
|
63
|
-
out = openseadragon_viewer(Openseadragon::Info.new(id: 'uri:to/info.json'))
|
64
|
-
expect(out).to match '' +'
|
65
|
-
"tileSources": \[
|
66
|
-
"uri:to/info.json"
|
67
|
-
\]\}\);'
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should not crash when there's no tileSources" do
|
72
|
-
openseadragon_collection_viewer(['world', 'irises'], {extraOption: :some_stuff})
|
73
|
-
openseadragon_collection_viewer(['world', 'irises'],
|
74
|
-
{extraOption: :some_stuff,
|
75
|
-
rawOption: "(1 + 1)",
|
76
|
-
options_with_raw_js: [:rawOption]})
|
77
44
|
end
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
"
|
91
|
-
"
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
"
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
"width": 4264,
|
121
|
-
"height": 3282,
|
122
|
-
"scale_factors": [
|
123
|
-
1,
|
124
|
-
2,
|
125
|
-
3,
|
126
|
-
4,
|
127
|
-
5
|
128
|
-
],
|
129
|
-
"formats": [
|
130
|
-
"jpg",
|
131
|
-
"png"
|
132
|
-
],
|
133
|
-
"qualities": [
|
134
|
-
"native",
|
135
|
-
"bitonal",
|
136
|
-
"grey",
|
137
|
-
"color"
|
138
|
-
],
|
139
|
-
"profile": "bar",
|
140
|
-
"tile_width": 1024,
|
141
|
-
"tile_height": 1024,
|
142
|
-
"image_host": "/image-service"
|
143
|
-
}
|
144
|
-
],
|
145
|
-
"extraOption": "some_stuff",
|
146
|
-
rawOption: (1 + 1)});
|
147
|
-
}
|
148
|
-
window.onload = initOpenSeadragon;
|
149
|
-
document.addEventListener("page:load", initOpenSeadragon); // Initialize when using turbolinks
|
150
|
-
|
151
|
-
//]]>
|
152
|
-
</script>'
|
45
|
+
|
46
|
+
describe "#openseadragon_picture_tag" do
|
47
|
+
it "should mark the <picture> as an openseadragon tag" do
|
48
|
+
expect(helper.openseadragon_picture_tag).to have_selector 'picture[data-openseadragon="true"]'
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should pass simple strings through" do
|
52
|
+
response = helper.openseadragon_picture_tag('image1.jpg', 'image2.jpg')
|
53
|
+
expect(response).to have_selector 'picture source[src="image1.jpg"][media="openseadragon"]'
|
54
|
+
expect(response).to have_selector 'picture source[src="image2.jpg"][media="openseadragon"]'
|
55
|
+
end
|
56
|
+
|
57
|
+
context "with tilesource objects" do
|
58
|
+
it "should convert sources to tilesources" do
|
59
|
+
source = double(to_tilesource: { a: 1})
|
60
|
+
response = helper.openseadragon_picture_tag(source)
|
61
|
+
expect(response).to have_selector 'picture source[src="openseadragon-tilesource"]'
|
62
|
+
expect(response).to match /data-openseadragon="#{helper.escape_once({a: 1}.to_json)}"/
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "with a source given as a hash" do
|
67
|
+
it "should extract html options" do
|
68
|
+
response = helper.openseadragon_picture_tag(['image1.jpg' => { html: { id: 'xyz' }}])
|
69
|
+
expect(response).to have_selector 'picture source[src="image1.jpg"][id="xyz"]'
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should pass the remaining options as encoded openseadragon options" do
|
73
|
+
response = helper.openseadragon_picture_tag(['image1.jpg' => { a: 1}])
|
74
|
+
expect(response).to have_selector 'picture source[src="image1.jpg"]'
|
75
|
+
expect(response).to have_selector 'picture source[src="image1.jpg"][data-openseadragon]'
|
76
|
+
expect(response).to match /data-openseadragon="#{helper.escape_once({a: 1}.to_json)}"/
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should merge a tilesource key with the options provided" do
|
80
|
+
source = double(to_tilesource: { a: 1, b: 1})
|
81
|
+
response = helper.openseadragon_picture_tag([source => { html: { id: 'xyz' }, b: 2, c: 3}])
|
82
|
+
expect(response).to have_selector 'picture source[src="openseadragon-tilesource"]'
|
83
|
+
expect(response).to have_selector 'picture source[src="openseadragon-tilesource"][id="xyz"]'
|
84
|
+
expect(response).to match /data-openseadragon="#{helper.escape_once({b: 2, c: 3, a: 1, }.to_json)}"/
|
85
|
+
end
|
86
|
+
end
|
153
87
|
end
|
154
88
|
end
|