triannon 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c07f371ee48e9009a0939488713930cf86ceb374
4
- data.tar.gz: 8c8fcd9dd0f6df80a1c254894cd34090a4f96bcc
3
+ metadata.gz: feb01d17b07570a2f93644aa4f630272df6281f8
4
+ data.tar.gz: 707da73463f69cc9f28b0f6fafe8b6e0d94d1756
5
5
  SHA512:
6
- metadata.gz: d8a3a250a33f946a1c9704af4fcd554bacb7154fb804457de64df9d948a0210365c0072261bede0ac3c6904e732881a0a71811fdaaa05d3bede2f6144a497aa5
7
- data.tar.gz: c86be08cdcab1acfc2a2ce32ffe6374ac0bac1813c715862f2d33c18d2e07b9400c84b311bfb22ca8e65701d3c5f1dd6f7360e323d4ba246c4bd1915f8f18e7e
6
+ metadata.gz: a89db206c12919c93630d4377ac6204583c042bfae99379ad73c3ff0da2a3e61bbace6306f4c47853da3fd018893a0d487eeabbf02c2ff7ef4599b770754795c
7
+ data.tar.gz: c29ddde43c40c2e536140c41f67019957632da471b1449d5dbe3a5c6d5904f3a0b9d5e97520146d07e76f38fadf0c6e2b193396953effe05a3cf1d4a00817d8d
@@ -14,7 +14,7 @@ module Triannon
14
14
  # GET /annotations/annotations/1
15
15
  def show
16
16
  respond_to do |format|
17
- format.jsonld { render :json => @annotation.graph.to_jsonld }
17
+ format.jsonld { render_jsonld_per_context (params[:jsonld_context]) }
18
18
  format.ttl {
19
19
  accept_return_type = mime_type_from_accept(["application/x-turtle", "text/turtle"])
20
20
  render :body => @annotation.graph.to_ttl, content_type: accept_return_type if accept_return_type }
@@ -23,7 +23,7 @@ module Triannon
23
23
  render :body => @annotation.graph.to_rdfxml, content_type: accept_return_type if accept_return_type }
24
24
  format.json {
25
25
  accept_return_type = mime_type_from_accept(["application/json", "text/x-json", "application/jsonrequest"])
26
- render :json => @annotation.graph.to_jsonld, content_type: accept_return_type if accept_return_type }
26
+ render_jsonld_per_context(params[:jsonld_context], accept_return_type) }
27
27
  format.xml {
28
28
  accept_return_type = mime_type_from_accept(["application/xml", "text/xml", "application/x-xml"])
29
29
  render :xml => @annotation.graph.to_rdfxml, content_type: accept_return_type if accept_return_type }
@@ -36,9 +36,10 @@ module Triannon
36
36
  @annotation = Annotation.new
37
37
  end
38
38
 
39
- # GET /annotations/annotations/1/edit
40
- def edit
41
- end
39
+ # NOT YET IMPLEMENTED
40
+ # GET /annotations/annotations/1/edit
41
+ # def edit
42
+ # end
42
43
 
43
44
  # POST /annotations/annotations
44
45
  def create
@@ -61,14 +62,15 @@ module Triannon
61
62
  end
62
63
  end
63
64
 
65
+ # NOT YET IMPLEMENTED
64
66
  # PATCH/PUT /annotations/annotations/1
65
- def update
66
- if @annotation.update(params)
67
- redirect_to @annotation, notice: 'Annotation was successfully updated.'
68
- else
69
- render :edit
70
- end
71
- end
67
+ # def update
68
+ # if @annotation.update(params)
69
+ # redirect_to @annotation, notice: 'Annotation was successfully updated.'
70
+ # else
71
+ # render :edit
72
+ # end
73
+ # end
72
74
 
73
75
  # DELETE /annotations/annotations/1
74
76
  def destroy
@@ -106,5 +108,31 @@ module Triannon
106
108
  def ext_ref_error(exception)
107
109
  render plain: exception.message, status: 403
108
110
  end
111
+
112
+ # render json_ld respecting requested context
113
+ # @param [String] req_context set to "iiif" or "oa". Default is OA
114
+ # @param [String] mime_type the mime type to be set in the Content-Type header of the HTTP response
115
+ def render_jsonld_per_context (req_context, mime_type=nil)
116
+ case req_context
117
+ when "iiif", "IIIF"
118
+ if mime_type
119
+ render :json => @annotation.jsonld_iiif, content_type: mime_type
120
+ else
121
+ render :json => @annotation.jsonld_iiif
122
+ end
123
+ when "oa", "OA"
124
+ if mime_type
125
+ render :json => @annotation.jsonld_oa, content_type: mime_type
126
+ else
127
+ render :json => @annotation.jsonld_oa
128
+ end
129
+ else
130
+ if mime_type
131
+ render :json => @annotation.jsonld_oa, content_type: mime_type
132
+ else
133
+ render :json => @annotation.jsonld_oa
134
+ end
135
+ end
136
+ end
109
137
  end
110
138
  end
@@ -70,13 +70,17 @@ module Triannon
70
70
  # @return json-ld representation of graph with OpenAnnotation context as a url
71
71
  def jsonld_oa
72
72
  inline_context = graph.dump(:jsonld, :context => "http://www.w3.org/ns/oa.jsonld")
73
- inline_context.sub(/@context.*@graph/m, "@context\": \"http://www.w3.org/ns/oa.jsonld\",\n \"@graph")
73
+ hash_from_json = JSON.parse(inline_context)
74
+ hash_from_json["@context"] = "http://www.w3.org/ns/oa.jsonld"
75
+ hash_from_json.to_json
74
76
  end
75
77
 
76
78
  # @return json-ld representation of graph with IIIF context as a url
77
79
  def jsonld_iiif
78
80
  inline_context = graph.dump(:jsonld, :context => "http://iiif.io/api/presentation/2/context.json")
79
- inline_context.sub(/@context.*@graph/m, "@context\": \"http://iiif.io/api/presentation/2/context.json\",\n \"@graph")
81
+ hash_from_json = JSON.parse(inline_context)
82
+ hash_from_json["@context"] = "http://iiif.io/api/presentation/2/context.json"
83
+ hash_from_json.to_json
80
84
  end
81
85
 
82
86
  # query for a subject with type of RDF::OpenAnnotation.Annotation
@@ -122,7 +126,7 @@ private
122
126
  if data
123
127
  data.strip!
124
128
  case data
125
- when /\A\{.+\}\Z/m
129
+ when /\A\{.+\}\Z/m # (Note: \A and \Z and m are needed instead of ^$ due to \n in data)
126
130
  g ||= RDF::Graph.new << JSON::LD::API.toRdf(json_ld) if json_ld
127
131
  self.data = g.dump(:ttl) if g
128
132
  when /\A<.+>\Z/m # (Note: \A and \Z and m are needed instead of ^$ due to \n in data)
@@ -138,7 +142,7 @@ private
138
142
  end
139
143
  g
140
144
  end
141
-
145
+
142
146
  def json_ld
143
147
  if data.match(/"@context"\s*\:\s*"http\:\/\/www\.w3\.org\/ns\/oa-context-20130208\.json"/)
144
148
  data.sub!("\"http://www.w3.org/ns/oa-context-20130208.json\"", json_oa_context)
@@ -1,5 +1,18 @@
1
1
  Triannon::Engine.routes.draw do
2
2
  root to: 'annotations#index'
3
3
 
4
- resources :annotations
4
+ # show action must explicitly forbid "iiif" or "oa" as id values; couldn't
5
+ # figure out how to do it with regexp constraint since beginning and end
6
+ # matchers aren't allowed when enforcing formats for segment (e.g. :id)
7
+ get '/annotations/:id(.:format)', to: 'annotations#show',
8
+ constraints: lambda { |request|
9
+ id = request.env["action_dispatch.request.path_parameters"][:id]
10
+ id !~ /^iiif$/ && id !~ /^oa$/
11
+ }
12
+
13
+ resources :annotations, :except => [:update, :edit, :show]
14
+
15
+ # allow jsonld context in path
16
+ get '/annotations/:jsonld_context/:id(.:format)', to: 'annotations#show', jsonld_context: /iiif|oa/
17
+
5
18
  end
@@ -1,3 +1,3 @@
1
1
  module Triannon
2
- VERSION = "0.3.2"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: triannon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
8
8
  - Naomi Dushay
9
+ - Willy Mene
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2014-11-25 00:00:00.000000000 Z
13
+ date: 2014-12-03 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: rails
@@ -17,14 +18,14 @@ dependencies:
17
18
  requirements:
18
19
  - - "~>"
19
20
  - !ruby/object:Gem::Version
20
- version: 4.2.0.beta1
21
+ version: 4.2.0.rc1
21
22
  type: :runtime
22
23
  prerelease: false
23
24
  version_requirements: !ruby/object:Gem::Requirement
24
25
  requirements:
25
26
  - - "~>"
26
27
  - !ruby/object:Gem::Version
27
- version: 4.2.0.beta1
28
+ version: 4.2.0.rc1
28
29
  - !ruby/object:Gem::Dependency
29
30
  name: linkeddata
30
31
  requirement: !ruby/object:Gem::Requirement
@@ -109,20 +110,6 @@ dependencies:
109
110
  - - ">="
110
111
  - !ruby/object:Gem::Version
111
112
  version: '0'
112
- - !ruby/object:Gem::Dependency
113
- name: sass-rails
114
- requirement: !ruby/object:Gem::Requirement
115
- requirements:
116
- - - ">="
117
- - !ruby/object:Gem::Version
118
- version: 5.0.0.beta1
119
- type: :runtime
120
- prerelease: false
121
- version_requirements: !ruby/object:Gem::Requirement
122
- requirements:
123
- - - ">="
124
- - !ruby/object:Gem::Version
125
- version: 5.0.0.beta1
126
113
  - !ruby/object:Gem::Dependency
127
114
  name: faraday
128
115
  requirement: !ruby/object:Gem::Requirement
@@ -253,6 +240,7 @@ description:
253
240
  email:
254
241
  - cabeer@stanford.edu
255
242
  - ndushay@stanford.edu
243
+ - wmene@stanford.edu
256
244
  executables: []
257
245
  extensions: []
258
246
  extra_rdoc_files: []
@@ -315,5 +303,5 @@ rubyforge_project:
315
303
  rubygems_version: 2.4.3
316
304
  signing_key:
317
305
  specification_version: 4
318
- summary: Rails engine for working with storage of OpenAnnotations stored in Fedora4
306
+ summary: Rails engine for working with OpenAnnotations stored in Fedora4
319
307
  test_files: []