openseadragon 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/README.md +62 -11
  4. data/app/assets/javascripts/openseadragon/rails.js +42 -0
  5. data/app/helpers/openseadragon/openseadragon_helper.rb +104 -86
  6. data/app/models/openseadragon/{info.rb → open_street_map.rb} +4 -5
  7. data/lib/openseadragon/version.rb +1 -1
  8. data/openseadragon.gemspec +1 -0
  9. data/spec/helpers/openseadragon_helper_spec.rb +79 -145
  10. data/spec/models/openseadragon/open_street_map.rb +11 -0
  11. metadata +20 -113
  12. data/spec/internal/.generated_engine_cart +0 -1
  13. data/spec/internal/.gitignore +0 -16
  14. data/spec/internal/Gemfile +0 -46
  15. data/spec/internal/README.rdoc +0 -28
  16. data/spec/internal/Rakefile +0 -6
  17. data/spec/internal/app/assets/images/.keep +0 -0
  18. data/spec/internal/app/assets/javascripts/application.js +0 -16
  19. data/spec/internal/app/assets/stylesheets/application.css +0 -13
  20. data/spec/internal/app/controllers/application_controller.rb +0 -5
  21. data/spec/internal/app/controllers/concerns/.keep +0 -0
  22. data/spec/internal/app/helpers/application_helper.rb +0 -2
  23. data/spec/internal/app/mailers/.keep +0 -0
  24. data/spec/internal/app/models/.keep +0 -0
  25. data/spec/internal/app/models/concerns/.keep +0 -0
  26. data/spec/internal/app/views/layouts/application.html.erb +0 -14
  27. data/spec/internal/bin/bundle +0 -3
  28. data/spec/internal/bin/rails +0 -4
  29. data/spec/internal/bin/rake +0 -4
  30. data/spec/internal/config.ru +0 -4
  31. data/spec/internal/config/application.rb +0 -23
  32. data/spec/internal/config/boot.rb +0 -4
  33. data/spec/internal/config/database.yml +0 -25
  34. data/spec/internal/config/environment.rb +0 -5
  35. data/spec/internal/config/environments/development.rb +0 -29
  36. data/spec/internal/config/environments/production.rb +0 -80
  37. data/spec/internal/config/environments/test.rb +0 -36
  38. data/spec/internal/config/initializers/backtrace_silencers.rb +0 -7
  39. data/spec/internal/config/initializers/filter_parameter_logging.rb +0 -4
  40. data/spec/internal/config/initializers/inflections.rb +0 -16
  41. data/spec/internal/config/initializers/mime_types.rb +0 -5
  42. data/spec/internal/config/initializers/secret_token.rb +0 -12
  43. data/spec/internal/config/initializers/session_store.rb +0 -3
  44. data/spec/internal/config/initializers/wrap_parameters.rb +0 -14
  45. data/spec/internal/config/locales/en.yml +0 -23
  46. data/spec/internal/config/routes.rb +0 -56
  47. data/spec/internal/db/schema.rb +0 -16
  48. data/spec/internal/db/seeds.rb +0 -7
  49. data/spec/internal/lib/assets/.keep +0 -0
  50. data/spec/internal/lib/tasks/.keep +0 -0
  51. data/spec/internal/log/.keep +0 -0
  52. data/spec/internal/public/404.html +0 -58
  53. data/spec/internal/public/422.html +0 -58
  54. data/spec/internal/public/500.html +0 -57
  55. data/spec/internal/public/favicon.ico +0 -0
  56. data/spec/internal/public/robots.txt +0 -5
  57. data/spec/internal/test/controllers/.keep +0 -0
  58. data/spec/internal/test/fixtures/.keep +0 -0
  59. data/spec/internal/test/helpers/.keep +0 -0
  60. data/spec/internal/test/integration/.keep +0 -0
  61. data/spec/internal/test/mailers/.keep +0 -0
  62. data/spec/internal/test/models/.keep +0 -0
  63. data/spec/internal/test/test_helper.rb +0 -15
  64. data/spec/internal/vendor/assets/javascripts/.keep +0 -0
  65. data/spec/internal/vendor/assets/stylesheets/.keep +0 -0
  66. data/spec/models/openseadragon/info_spec.rb +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e12e9c50a4a9023440e3b37865b4bf09048664dc
4
- data.tar.gz: f07185164b09b31209832bac80e8eed41ae996bc
3
+ metadata.gz: dc2f571409c5211449a6282bb40f910577d61c54
4
+ data.tar.gz: 95071d5309b293c0de161fcf75d7dc04a3bc1a65
5
5
  SHA512:
6
- metadata.gz: 028ed72ab4f4c9d35552afc06d2e544be1640242c425ad56cd0013e09e647cdb8f7c17e16fbace4981de56b9710d50768200b7f150b245f2cdffd6cfea63154a
7
- data.tar.gz: a5469f0c71b0ac59751474272bdceef7c00b6c17aefec9e35f7e3b35a4c51551622bf0973161e18aabc832c2c8d4c12bd7dfa0fbbf0688b9dd66237630440ea7
6
+ metadata.gz: c7ed4e37466254b265e47581d5e8a1253031f1ea2470013119900c28d39aaa71e1fe27ca30ce7618895bdf9c0c5b27a8d08ccbcbfe71129482b8264817967f56
7
+ data.tar.gz: 23a828bdd797015e43b8c8aeb24514d0c668ee7864801b8362e82790d4166545d910635eb300c82bbee07fc4c546243ea2a84ae700b8cc0330633eaae9231487
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ spec/internal
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
- # Setup
7
+ # Usage
8
8
 
9
- In order to display a file, OpenSeadragon needs to know the full dimension of the image. In order to do this we need to inject an image resolver. Here's an example.
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
- module ImageResolver
13
- def self.find(id)
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
- # register the resolver
20
- Openseadragon::Image.file_resolver = ImageResolver
53
+ ```html
54
+ <picture data-openseadragon="true">
55
+ <source media="openseadragon" src="page1.jpg" />
56
+ </picture>
21
57
  ```
22
58
 
23
- The image resolver only needs to implement the `find` method. It takes an id as a parameter and returns a new instance of `Openseadragon::Image`
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="{&quot;preserveViewport&quot;:true,&quot;visibilityRatio&quot;: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="{&quot;Image&quot;:{&quot;xmlns&quot;:&quot;...&quot;,&quot;Url&quot;:&quot;...&quot;,&quot;Format&quot;:&quot;jpg&quot;,&quot;Overlap&quot;: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
- # @param id [String] the image identifier
5
- # @param options [Hash]
6
- # @option options [String] :id ('openseadragon1') HTML id
7
- # @option options [Hash] :html HTML attributes
8
- # @option options [String] :prefixUrl
9
- # @option options [Array] :tileSources ([])
10
- # @option options [Hash] :options_with_raw_js
11
- def openseadragon_collection_viewer(ids_or_images, options={})
12
- html_options = (options[:html] or {})
13
- html_options[:id] = (options[:id] or 'openseadragon1')
14
-
15
- tile_sources = ids_or_images.zip((options[:tileSources] or [])).map do |id_or_image, opts|
16
- image_options(id_or_image, opts)
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
- collection_options = {
20
- id: html_options[:id],
21
- prefixUrl: '/assets/openseadragon/',
22
- tileSources: tile_sources,
23
- }.deep_merge(options.except(:html, :tileSources))
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
- js_options = options_to_js(collection_options.except(:options_with_raw_js),
26
- collection_options[:options_with_raw_js])
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
- js =<<-EOF
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
- # This hack is necessary for ruby 1.9.3. Just use JSON.dump(val) if Ruby >= 2.0
55
- if RUBY_VERSION < "2.0.0"
56
- def json_dump(val)
57
- case val
58
- when String, Integer, true, false
59
- val.inspect
60
- when Symbol
61
- val.to_s.inspect
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
- raise ArgumentError, "Unexpected value #{val.inspect}"
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
- # @param id_or_image [String,Image] the image identifier or an image object
73
- # @param options [Hash]
74
- # @option options [String] :html_id HTML id
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
- private
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
- # @param id_or_image [String,Image] the image identifier or an image object
91
- # @param options [Hash]
92
- def image_options(id_or_image, options)
93
- options ||= {}
94
- image = case id_or_image
95
- when String
96
- image_options(Image.find(id_or_image), options)
97
- when Image
98
- id_or_image.to_tilesource.merge(options)
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
@@ -1,13 +1,12 @@
1
1
  module Openseadragon
2
- class Info
3
- attr_accessor :id
4
-
2
+ class OpenStreetMap
5
3
  def initialize(attributes = {})
6
- self.id = attributes[:id]
7
4
  end
8
5
 
9
6
  def to_tilesource
10
- id
7
+ {
8
+ type: 'openstreetmaps'
9
+ }
11
10
  end
12
11
  end
13
12
  end
@@ -1,3 +1,3 @@
1
1
  module Openseadragon
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -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
- before do
5
- module SpecResolver
6
- def self.find(id)
7
- Openseadragon::Image.new({ id: id }.merge(data(id)))
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
- def self.data(id)
11
- { 'world' => {height: 400, width: 800},
12
- 'irises' => {height: 3282, width: 4264}}[id]
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
- it "should draw the collection viewer" do
80
- out = openseadragon_collection_viewer(['world', 'irises'],
81
- {tileSources: [{profile: :foo}, {profile: :bar}],
82
- extraOption: :some_stuff,
83
- rawOption: "(1 + 1)",
84
- options_with_raw_js: [:rawOption]})
85
- out.should == '<div id="openseadragon1"></div><script>
86
- //<![CDATA[
87
- function initOpenSeadragon() {
88
- OpenSeadragon({
89
- "id": "openseadragon1",
90
- "prefixUrl": "/assets/openseadragon/",
91
- "tileSources": [
92
- {
93
- "identifier": "world",
94
- "width": 800,
95
- "height": 400,
96
- "scale_factors": [
97
- 1,
98
- 2,
99
- 3,
100
- 4,
101
- 5
102
- ],
103
- "formats": [
104
- "jpg",
105
- "png"
106
- ],
107
- "qualities": [
108
- "native",
109
- "bitonal",
110
- "grey",
111
- "color"
112
- ],
113
- "profile": "foo",
114
- "tile_width": 1024,
115
- "tile_height": 1024,
116
- "image_host": "/image-service"
117
- },
118
- {
119
- "identifier": "irises",
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