openseadragon 0.0.1

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.
Files changed (94) hide show
  1. data/.gitignore +17 -0
  2. data/.travis.yml +11 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +24 -0
  6. data/Rakefile +9 -0
  7. data/app/helpers/openseadragon/openseadragon_helper.rb +114 -0
  8. data/app/models/openseadragon/image.rb +23 -0
  9. data/lib/openseadragon.rb +5 -0
  10. data/lib/openseadragon/engine.rb +6 -0
  11. data/lib/openseadragon/version.rb +3 -0
  12. data/openseadragon.gemspec +30 -0
  13. data/spec/helpers/openseadragon_helper_spec.rb +145 -0
  14. data/spec/internal/.generated_engine_cart +1 -0
  15. data/spec/internal/.gitignore +16 -0
  16. data/spec/internal/Gemfile +46 -0
  17. data/spec/internal/README.rdoc +28 -0
  18. data/spec/internal/Rakefile +6 -0
  19. data/spec/internal/app/assets/images/.keep +0 -0
  20. data/spec/internal/app/assets/javascripts/application.js +16 -0
  21. data/spec/internal/app/assets/stylesheets/application.css +13 -0
  22. data/spec/internal/app/controllers/application_controller.rb +5 -0
  23. data/spec/internal/app/controllers/concerns/.keep +0 -0
  24. data/spec/internal/app/helpers/application_helper.rb +2 -0
  25. data/spec/internal/app/mailers/.keep +0 -0
  26. data/spec/internal/app/models/.keep +0 -0
  27. data/spec/internal/app/models/concerns/.keep +0 -0
  28. data/spec/internal/app/views/layouts/application.html.erb +14 -0
  29. data/spec/internal/bin/bundle +3 -0
  30. data/spec/internal/bin/rails +4 -0
  31. data/spec/internal/bin/rake +4 -0
  32. data/spec/internal/config.ru +4 -0
  33. data/spec/internal/config/application.rb +23 -0
  34. data/spec/internal/config/boot.rb +4 -0
  35. data/spec/internal/config/database.yml +25 -0
  36. data/spec/internal/config/environment.rb +5 -0
  37. data/spec/internal/config/environments/development.rb +29 -0
  38. data/spec/internal/config/environments/production.rb +80 -0
  39. data/spec/internal/config/environments/test.rb +36 -0
  40. data/spec/internal/config/initializers/backtrace_silencers.rb +7 -0
  41. data/spec/internal/config/initializers/filter_parameter_logging.rb +4 -0
  42. data/spec/internal/config/initializers/inflections.rb +16 -0
  43. data/spec/internal/config/initializers/mime_types.rb +5 -0
  44. data/spec/internal/config/initializers/secret_token.rb +12 -0
  45. data/spec/internal/config/initializers/session_store.rb +3 -0
  46. data/spec/internal/config/initializers/wrap_parameters.rb +14 -0
  47. data/spec/internal/config/locales/en.yml +23 -0
  48. data/spec/internal/config/routes.rb +56 -0
  49. data/spec/internal/db/schema.rb +16 -0
  50. data/spec/internal/db/seeds.rb +7 -0
  51. data/spec/internal/lib/assets/.keep +0 -0
  52. data/spec/internal/lib/tasks/.keep +0 -0
  53. data/spec/internal/log/.keep +0 -0
  54. data/spec/internal/public/404.html +58 -0
  55. data/spec/internal/public/422.html +58 -0
  56. data/spec/internal/public/500.html +57 -0
  57. data/spec/internal/public/favicon.ico +0 -0
  58. data/spec/internal/public/robots.txt +5 -0
  59. data/spec/internal/test/controllers/.keep +0 -0
  60. data/spec/internal/test/fixtures/.keep +0 -0
  61. data/spec/internal/test/helpers/.keep +0 -0
  62. data/spec/internal/test/integration/.keep +0 -0
  63. data/spec/internal/test/mailers/.keep +0 -0
  64. data/spec/internal/test/models/.keep +0 -0
  65. data/spec/internal/test/test_helper.rb +15 -0
  66. data/spec/internal/vendor/assets/javascripts/.keep +0 -0
  67. data/spec/internal/vendor/assets/stylesheets/.keep +0 -0
  68. data/spec/spec_helper.rb +27 -0
  69. data/vendor/assets/images/openseadragon/fullpage_grouphover.png +0 -0
  70. data/vendor/assets/images/openseadragon/fullpage_hover.png +0 -0
  71. data/vendor/assets/images/openseadragon/fullpage_pressed.png +0 -0
  72. data/vendor/assets/images/openseadragon/fullpage_rest.png +0 -0
  73. data/vendor/assets/images/openseadragon/home_grouphover.png +0 -0
  74. data/vendor/assets/images/openseadragon/home_hover.png +0 -0
  75. data/vendor/assets/images/openseadragon/home_pressed.png +0 -0
  76. data/vendor/assets/images/openseadragon/home_rest.png +0 -0
  77. data/vendor/assets/images/openseadragon/next_grouphover.png +0 -0
  78. data/vendor/assets/images/openseadragon/next_hover.png +0 -0
  79. data/vendor/assets/images/openseadragon/next_pressed.png +0 -0
  80. data/vendor/assets/images/openseadragon/next_rest.png +0 -0
  81. data/vendor/assets/images/openseadragon/previous_grouphover.png +0 -0
  82. data/vendor/assets/images/openseadragon/previous_hover.png +0 -0
  83. data/vendor/assets/images/openseadragon/previous_pressed.png +0 -0
  84. data/vendor/assets/images/openseadragon/previous_rest.png +0 -0
  85. data/vendor/assets/images/openseadragon/zoomin_grouphover.png +0 -0
  86. data/vendor/assets/images/openseadragon/zoomin_hover.png +0 -0
  87. data/vendor/assets/images/openseadragon/zoomin_pressed.png +0 -0
  88. data/vendor/assets/images/openseadragon/zoomin_rest.png +0 -0
  89. data/vendor/assets/images/openseadragon/zoomout_grouphover.png +0 -0
  90. data/vendor/assets/images/openseadragon/zoomout_hover.png +0 -0
  91. data/vendor/assets/images/openseadragon/zoomout_pressed.png +0 -0
  92. data/vendor/assets/images/openseadragon/zoomout_rest.png +0 -0
  93. data/vendor/assets/javascripts/openseadragon.js +12279 -0
  94. metadata +299 -0
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ rvm:
2
+ - 2.1.0
3
+ - 2.0.0
4
+ - 1.9.3
5
+
6
+ notifications:
7
+ irc: "irc.freenode.org#blacklight"
8
+
9
+ env:
10
+ global:
11
+ - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in openseadragon.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # OpenSeadragon
2
+
3
+ OpenSeadragon is a javascript library for displaying tiling images. This gem packages those assets and some Rails helpers for using them.
4
+
5
+ http://openseadragon.github.io/
6
+
7
+ # Setup
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.
10
+
11
+ ```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
18
+
19
+ # register the resolver
20
+ Openseadragon::Image.file_resolver = ImageResolver
21
+ ```
22
+
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`
24
+
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/setup'
2
+ require 'rspec/core/rake_task'
3
+ require 'engine_cart/rake_task'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task ci: ['engine_cart:generate', :spec]
9
+ task default: :ci
@@ -0,0 +1,114 @@
1
+ module Openseadragon
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)
17
+ end
18
+
19
+ collection_options = {
20
+ id: html_options[:id],
21
+ prefixUrl: '/assets/openseadragon/',
22
+ tileSources: tile_sources,
23
+ }.deep_merge(options.except(:html, :tileSources))
24
+
25
+ js_options = options_to_js(collection_options.except(:options_with_raw_js),
26
+ collection_options[:options_with_raw_js])
27
+
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
+ 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") + "}"
51
+ end
52
+
53
+
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
59
+ val.inspect
60
+ when Symbol
61
+ val.to_s.inspect
62
+ else
63
+ raise ArgumentError, "Unexpected value #{val.inspect}"
64
+ end
65
+ end
66
+ else
67
+ def json_dump(val)
68
+ JSON.dump(val)
69
+ end
70
+ end
71
+
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
87
+
88
+ private
89
+
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.find(id_or_image)
97
+ when Image
98
+ id_or_image
99
+ end
100
+ {
101
+ identifier: image.id,
102
+ width: image.width,
103
+ height: image.height,
104
+ scale_factors: [1, 2, 3, 4, 5],
105
+ formats: [:jpg, :png],
106
+ qualities: [:native, :bitonal, :grey, :color],
107
+ profile: "http://library.stanford.edu/iiif/image-api/compliance.html#level3",
108
+ tile_width: 1024,
109
+ tile_height: 1024,
110
+ image_host: '/image-service',
111
+ }.merge(options)
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,23 @@
1
+ module Openseadragon
2
+ class Image
3
+ attr_accessor :id, :width, :height
4
+
5
+ class_attribute :file_resolver
6
+
7
+ class << self
8
+ def find(id)
9
+ file_resolver.find(id)
10
+ end
11
+ end
12
+
13
+ def initialize(attributes = {})
14
+ self.id = attributes[:id]
15
+ self.width = attributes[:width]
16
+ self.height = attributes[:height]
17
+ end
18
+
19
+ def as_json
20
+ { id: id}
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ require "openseadragon/version"
2
+ require "openseadragon/engine"
3
+
4
+ module Openseadragon
5
+ end
@@ -0,0 +1,6 @@
1
+ module Openseadragon
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Openseadragon
4
+ end
5
+ end
6
+
@@ -0,0 +1,3 @@
1
+ module Openseadragon
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'openseadragon/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "openseadragon"
8
+ spec.version = Openseadragon::VERSION
9
+ spec.authors = ["Justin Coyne", "Brian Maddy"]
10
+ spec.email = ["justin@curationexperts.com"]
11
+ spec.summary = %q{OpenSeadragon assets and helpers for Rails. http://openseadragon.github.io/}
12
+ spec.description = %q{OpenSeadragon is a javascript library for displaying tiling images. This gem packages those assets and some Rails helpers for using them}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "engine_cart"
24
+ spec.add_development_dependency "rspec-rails"
25
+ spec.add_development_dependency "sqlite3"
26
+
27
+ spec.add_dependency 'rails', '> 3.2.0'
28
+
29
+
30
+ end
@@ -0,0 +1,145 @@
1
+ require 'spec_helper'
2
+
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)))
8
+ end
9
+
10
+ def self.data(id)
11
+ { 'world' => {height: 400, width: 800},
12
+ 'irises' => {height: 3282, width: 4264}}[id]
13
+ end
14
+ 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" /><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 not crash when there's no tileSources" do
63
+ openseadragon_collection_viewer(['world', 'irises'], {extraOption: :some_stuff})
64
+ openseadragon_collection_viewer(['world', 'irises'],
65
+ {extraOption: :some_stuff,
66
+ rawOption: "(1 + 1)",
67
+ options_with_raw_js: [:rawOption]})
68
+ end
69
+
70
+ it "should draw the collection viewer" do
71
+ out = openseadragon_collection_viewer(['world', 'irises'],
72
+ {tileSources: [{profile: :foo}, {profile: :bar}],
73
+ extraOption: :some_stuff,
74
+ rawOption: "(1 + 1)",
75
+ options_with_raw_js: [:rawOption]})
76
+ out.should == '<div id="openseadragon1" /><script>
77
+ //<![CDATA[
78
+ function initOpenSeadragon() {
79
+ OpenSeadragon({
80
+ "id": "openseadragon1",
81
+ "prefixUrl": "/assets/openseadragon/",
82
+ "tileSources": [
83
+ {
84
+ "identifier": "world",
85
+ "width": 800,
86
+ "height": 400,
87
+ "scale_factors": [
88
+ 1,
89
+ 2,
90
+ 3,
91
+ 4,
92
+ 5
93
+ ],
94
+ "formats": [
95
+ "jpg",
96
+ "png"
97
+ ],
98
+ "qualities": [
99
+ "native",
100
+ "bitonal",
101
+ "grey",
102
+ "color"
103
+ ],
104
+ "profile": "foo",
105
+ "tile_width": 1024,
106
+ "tile_height": 1024,
107
+ "image_host": "/image-service"
108
+ },
109
+ {
110
+ "identifier": "irises",
111
+ "width": 4264,
112
+ "height": 3282,
113
+ "scale_factors": [
114
+ 1,
115
+ 2,
116
+ 3,
117
+ 4,
118
+ 5
119
+ ],
120
+ "formats": [
121
+ "jpg",
122
+ "png"
123
+ ],
124
+ "qualities": [
125
+ "native",
126
+ "bitonal",
127
+ "grey",
128
+ "color"
129
+ ],
130
+ "profile": "bar",
131
+ "tile_width": 1024,
132
+ "tile_height": 1024,
133
+ "image_host": "/image-service"
134
+ }
135
+ ],
136
+ "extraOption": "some_stuff",
137
+ rawOption: (1 + 1)});
138
+ }
139
+ window.onload = initOpenSeadragon;
140
+ document.addEventListener("page:load", initOpenSeadragon); // Initialize when using turbolinks
141
+
142
+ //]]>
143
+ </script>'
144
+ end
145
+ end
@@ -0,0 +1 @@
1
+ true
@@ -0,0 +1,16 @@
1
+ # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile '~/.gitignore_global'
6
+
7
+ # Ignore bundler config.
8
+ /.bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ /db/*.sqlite3
12
+ /db/*.sqlite3-journal
13
+
14
+ # Ignore all logfiles and tempfiles.
15
+ /log/*.log
16
+ /tmp