hydra-editor 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +11 -0
- data/README.md +2 -1
- data/Rakefile +9 -16
- data/app/controllers/concerns/records_controller_behavior.rb +46 -39
- data/config/routes.rb +0 -1
- data/lib/hydra-editor.rb +12 -0
- data/lib/hydra_editor/controller_resource.rb +18 -0
- data/lib/hydra_editor/engine.rb +5 -3
- data/lib/hydra_editor/version.rb +1 -1
- metadata +11 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d4df6ff1905911d18d55cf3a29f90110ed2e9f6
|
4
|
+
data.tar.gz: 6fe5727b88830e9bffdeb14def5086b424a879c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eea2175ee9783b6da57c28fe8ba8bb74ede02a8bf324a5f7e2c3770755e5472a01e49f6b2783e2483b07958b9a8ab9038693d9fd46d855152bcee411cfa2abad
|
7
|
+
data.tar.gz: c3ae9b2431484a4c62c5b8302614ab587ebd3e56c0e55baf6f181015dc3b9e07031e0b07bcba4c520e197e2be20b20c62d452888284dd3d208dac4ee08a686ca
|
data/History.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# History of hydra-editor releases
|
2
|
+
|
3
|
+
## 0.0.2
|
4
|
+
* Requiring active-fedora >= 6.3.0 in order to have the .required? method on ActiveFedora::Base:q
|
5
|
+
|
6
|
+
## 0.1.0
|
7
|
+
* RecordsControllerBehavior made more easily reusable outside of RecordsController.
|
8
|
+
|
9
|
+
### 0.1.1
|
10
|
+
* Correctly account for modifications made by initialize_fields when processing form data. Fixes #14.
|
11
|
+
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
# HydraEditor [![Gem Version](https://badge.fury.io/rb/hydra-editor.png)](http://badge.fury.io/rb/hydra-editor)
|
1
|
+
# HydraEditor [![Gem Version](https://badge.fury.io/rb/hydra-editor.png)](http://badge.fury.io/rb/hydra-editor) [![Build Status](https://travis-ci.org/projecthydra/hydra-editor.png)](https://travis-ci.org/projecthydra/hydra-editor)
|
2
|
+
|
2
3
|
|
3
4
|
To use add to your gemfile:
|
4
5
|
|
data/Rakefile
CHANGED
@@ -35,27 +35,20 @@ desc "Generate the dummy app"
|
|
35
35
|
task :setup do
|
36
36
|
unless File.exists?("#{dummy}/Rakefile")
|
37
37
|
`rails new #{dummy}`
|
38
|
-
`cp -r spec/support/Gemfile #{dummy}/`
|
39
38
|
`cp -r spec/support/lib/generators #{dummy}/lib`
|
40
39
|
Dir.chdir(dummy) do
|
41
|
-
|
42
|
-
sh "rails g hydra:head -f"
|
43
|
-
sh "rm spec/models/user_spec.rb" # generated by devise
|
44
|
-
puts "Generating test app"
|
40
|
+
puts "Generating test app ..."
|
45
41
|
sh "rails generate test_app"
|
46
|
-
|
47
|
-
sh 'rake db:migrate db:test:prepare'
|
48
|
-
sh "touch public/test.html" # for spec/features/record_editing_spec.rb
|
42
|
+
sh "touch public/test.html" # for spec/features/record_editing_spec.rb
|
49
43
|
end
|
50
44
|
end
|
51
45
|
end
|
52
46
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
Bundler.with_clean_env do
|
58
|
-
sh "bundle exec rspec --color -I#{here}/spec #{here}/spec"
|
59
|
-
end
|
60
|
-
end
|
47
|
+
require 'rspec/core/rake_task'
|
48
|
+
|
49
|
+
RSpec::Core::RakeTask.new(:spec => :setup) do |t|
|
50
|
+
t.pattern = 'spec/**/*_spec.rb'
|
61
51
|
end
|
52
|
+
|
53
|
+
|
54
|
+
task :default => :spec
|
@@ -1,18 +1,24 @@
|
|
1
1
|
module RecordsControllerBehavior
|
2
2
|
extend ActiveSupport::Concern
|
3
|
-
|
3
|
+
|
4
4
|
included do
|
5
|
-
|
6
|
-
end
|
5
|
+
load_and_authorize_resource only: [:new, :edit, :update, :create], instance_name: resource_instance_name
|
7
6
|
|
8
|
-
|
9
|
-
authorize! :create, ActiveFedora::Base
|
10
|
-
unless has_valid_type?
|
7
|
+
rescue_from HydraEditor::InvalidType do
|
11
8
|
render 'records/choose_type'
|
12
|
-
return
|
13
9
|
end
|
10
|
+
end
|
14
11
|
|
15
|
-
|
12
|
+
module ClassMethods
|
13
|
+
def cancan_resource_class
|
14
|
+
HydraEditor::ControllerResource
|
15
|
+
end
|
16
|
+
def resource_instance_name
|
17
|
+
name.sub("Controller", "").underscore.split('/').last.singularize
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def new
|
16
22
|
initialize_fields
|
17
23
|
render 'records/new'
|
18
24
|
end
|
@@ -23,23 +29,15 @@ module RecordsControllerBehavior
|
|
23
29
|
end
|
24
30
|
|
25
31
|
def create
|
26
|
-
authorize! :create, ActiveFedora::Base
|
27
|
-
unless has_valid_type?
|
28
|
-
redirect_to(respond_to?(:hydra_editor) ? hydra_editor.new_record_path : new_record_path, flash: {error: "Lost the type"})
|
29
|
-
return
|
30
|
-
end
|
31
|
-
@record = params[:type].constantize.new
|
32
32
|
set_attributes
|
33
33
|
|
34
34
|
respond_to do |format|
|
35
|
-
if
|
35
|
+
if resource.save
|
36
36
|
format.html { redirect_to redirect_after_create, notice: 'Object was successfully created.' }
|
37
|
-
|
38
|
-
data = @record.terms_for_editing.inject({}) { |h,term| h[term] = @record[term]; h }
|
39
|
-
format.json { render json: data, status: :created, location: redirect_after_create }
|
37
|
+
format.json { render json: object_as_json, status: :created, location: redirect_after_create }
|
40
38
|
else
|
41
39
|
format.html { render action: "new" }
|
42
|
-
format.json { render json:
|
40
|
+
format.json { render json: resource.errors, status: :unprocessable_entity }
|
43
41
|
end
|
44
42
|
end
|
45
43
|
|
@@ -48,50 +46,44 @@ module RecordsControllerBehavior
|
|
48
46
|
def update
|
49
47
|
set_attributes
|
50
48
|
respond_to do |format|
|
51
|
-
if
|
49
|
+
if resource.save
|
52
50
|
format.html { redirect_to redirect_after_update, notice: 'Object was successfully updated.' }
|
53
51
|
format.json { head :no_content }
|
54
52
|
else
|
55
53
|
format.html { render action: "edit" }
|
56
|
-
format.json { render json:
|
54
|
+
format.json { render json: resource.errors, status: :unprocessable_entity }
|
57
55
|
end
|
58
56
|
end
|
59
57
|
end
|
60
58
|
|
61
59
|
protected
|
62
60
|
|
63
|
-
def
|
64
|
-
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
|
-
def load_record
|
69
|
-
@record = ActiveFedora::Base.find(params[:id], cast: true)
|
70
|
-
end
|
71
|
-
|
72
|
-
def authorize_record!
|
73
|
-
authorize! params[:action].to_sym, @record
|
61
|
+
def object_as_json
|
62
|
+
# ActiveFedora::Base#to_json causes a circular reference (before 7.0). Do something easy
|
63
|
+
resource.terms_for_editing.each_with_object({}) { |term, h| h[term] = resource[term] }
|
74
64
|
end
|
75
65
|
|
76
66
|
# Override this method if you want to set different metadata on the object
|
77
67
|
def set_attributes
|
78
|
-
|
68
|
+
resource.attributes = collect_form_attributes
|
79
69
|
end
|
80
70
|
|
81
71
|
def collect_form_attributes
|
82
|
-
|
72
|
+
raw_attributes = params[ActiveModel::Naming.singular(resource)]
|
73
|
+
# we could probably do this with strong parameters if the gemspec depends on Rails 4+
|
74
|
+
permitted_attributes = resource.terms_for_editing.each_with_object({}) { |key, attrs| attrs[key] = raw_attributes[key] if raw_attributes[key] }
|
83
75
|
# removes attributes that were only changed by initialize_fields
|
84
|
-
|
76
|
+
permitted_attributes.reject { |key, value| resource[key].empty? and value == [""] }
|
85
77
|
end
|
86
78
|
|
87
79
|
# Override to redirect to an alternate location after create
|
88
80
|
def redirect_after_create
|
89
|
-
main_app.catalog_path
|
81
|
+
main_app.catalog_path resource
|
90
82
|
end
|
91
83
|
|
92
84
|
# Override to redirect to an alternate location after update
|
93
85
|
def redirect_after_update
|
94
|
-
main_app.catalog_path
|
86
|
+
main_app.catalog_path resource
|
95
87
|
end
|
96
88
|
|
97
89
|
def has_valid_type?
|
@@ -99,9 +91,24 @@ module RecordsControllerBehavior
|
|
99
91
|
end
|
100
92
|
|
101
93
|
def initialize_fields
|
102
|
-
|
94
|
+
resource.terms_for_editing.each do |key|
|
103
95
|
# if value is empty, we create an one element array to loop over for output
|
104
|
-
|
96
|
+
resource[key] = [''] if resource[key].empty?
|
105
97
|
end
|
106
98
|
end
|
99
|
+
|
100
|
+
def resource
|
101
|
+
get_resource_ivar
|
102
|
+
end
|
103
|
+
|
104
|
+
# Get resource ivar based on the current resource controller.
|
105
|
+
#
|
106
|
+
def get_resource_ivar #:nodoc:
|
107
|
+
instance_variable_get("@#{resource_instance_name}")
|
108
|
+
end
|
109
|
+
|
110
|
+
def resource_instance_name
|
111
|
+
self.class.resource_instance_name
|
112
|
+
end
|
113
|
+
|
107
114
|
end
|
data/config/routes.rb
CHANGED
data/lib/hydra-editor.rb
CHANGED
@@ -1,7 +1,15 @@
|
|
1
|
+
require "cancan"
|
1
2
|
require "hydra_editor/engine"
|
2
3
|
require "bootstrap_forms"
|
3
4
|
|
4
5
|
module HydraEditor
|
6
|
+
|
7
|
+
class InvalidType < RuntimeError; end
|
8
|
+
|
9
|
+
extend ActiveSupport::Autoload
|
10
|
+
|
11
|
+
autoload :ControllerResource
|
12
|
+
|
5
13
|
def self.models= val
|
6
14
|
@models = val
|
7
15
|
end
|
@@ -9,4 +17,8 @@ module HydraEditor
|
|
9
17
|
def self.models
|
10
18
|
@models ||= []
|
11
19
|
end
|
20
|
+
|
21
|
+
def self.valid_model?(type)
|
22
|
+
models.include? type
|
23
|
+
end
|
12
24
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class HydraEditor::ControllerResource < CanCan::ControllerResource
|
2
|
+
def find_resource
|
3
|
+
ActiveFedora::Base.find(id_param, cast: true)
|
4
|
+
end
|
5
|
+
|
6
|
+
def resource_class
|
7
|
+
raise HydraEditor::InvalidType, "Lost the type" unless has_valid_type?
|
8
|
+
type_param.constantize
|
9
|
+
end
|
10
|
+
|
11
|
+
def has_valid_type?
|
12
|
+
HydraEditor.valid_model? type_param
|
13
|
+
end
|
14
|
+
|
15
|
+
def type_param
|
16
|
+
@params[:type]
|
17
|
+
end
|
18
|
+
end
|
data/lib/hydra_editor/engine.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
module HydraEditor
|
2
2
|
class Engine < ::Rails::Engine
|
3
3
|
engine_name 'hydra_editor'
|
4
|
-
config.
|
5
|
-
|
6
|
-
|
4
|
+
config.autoload_paths += %W(
|
5
|
+
#{config.root}/app/helpers/concerns
|
6
|
+
#{config.root}/app/controllers/concerns
|
7
|
+
#{config.root}/app/models/concerns
|
8
|
+
)
|
7
9
|
end
|
8
10
|
end
|
data/lib/hydra_editor/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hydra-editor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Coyne
|
8
|
+
- David Chandek-Stark
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2014-01-02 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: rails
|
@@ -87,21 +88,7 @@ dependencies:
|
|
87
88
|
- !ruby/object:Gem::Version
|
88
89
|
version: '0'
|
89
90
|
- !ruby/object:Gem::Dependency
|
90
|
-
name:
|
91
|
-
requirement: !ruby/object:Gem::Requirement
|
92
|
-
requirements:
|
93
|
-
- - '>='
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
version: '0'
|
96
|
-
type: :development
|
97
|
-
prerelease: false
|
98
|
-
version_requirements: !ruby/object:Gem::Requirement
|
99
|
-
requirements:
|
100
|
-
- - '>='
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
version: '0'
|
103
|
-
- !ruby/object:Gem::Dependency
|
104
|
-
name: sqlite3
|
91
|
+
name: factory_girl_rails
|
105
92
|
requirement: !ruby/object:Gem::Requirement
|
106
93
|
requirements:
|
107
94
|
- - '>='
|
@@ -115,7 +102,7 @@ dependencies:
|
|
115
102
|
- !ruby/object:Gem::Version
|
116
103
|
version: '0'
|
117
104
|
- !ruby/object:Gem::Dependency
|
118
|
-
name:
|
105
|
+
name: capybara
|
119
106
|
requirement: !ruby/object:Gem::Requirement
|
120
107
|
requirements:
|
121
108
|
- - '>='
|
@@ -156,9 +143,9 @@ dependencies:
|
|
156
143
|
- - '>='
|
157
144
|
- !ruby/object:Gem::Version
|
158
145
|
version: '0'
|
159
|
-
description: A basic
|
146
|
+
description: A basic metadata editor for hydra-head
|
160
147
|
email:
|
161
|
-
-
|
148
|
+
- hydra-tech@googlegroups.com
|
162
149
|
executables: []
|
163
150
|
extensions: []
|
164
151
|
extra_rdoc_files: []
|
@@ -182,11 +169,13 @@ files:
|
|
182
169
|
- config/locales/hydra_editor.yml
|
183
170
|
- config/routes.rb
|
184
171
|
- lib/hydra-editor.rb
|
172
|
+
- lib/hydra_editor/controller_resource.rb
|
185
173
|
- lib/hydra_editor/engine.rb
|
186
174
|
- lib/hydra_editor/version.rb
|
187
175
|
- lib/tasks/hydra-editor_tasks.rake
|
188
176
|
- Rakefile
|
189
177
|
- README.md
|
178
|
+
- History.md
|
190
179
|
homepage: http://github.com/projecthydra/hydra-editor
|
191
180
|
licenses: []
|
192
181
|
metadata: {}
|
@@ -206,8 +195,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
206
195
|
version: '0'
|
207
196
|
requirements: []
|
208
197
|
rubyforge_project:
|
209
|
-
rubygems_version: 2.
|
198
|
+
rubygems_version: 2.1.11
|
210
199
|
signing_key:
|
211
200
|
specification_version: 4
|
212
|
-
summary: A basic
|
201
|
+
summary: A basic metadata editor for hydra-head
|
213
202
|
test_files: []
|