hydra-tutorial 0.2.0 → 0.2.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.
- data/HISTORY.md +15 -0
- data/development_notes.txt +23 -457
- data/hydra-tutorial.gemspec +1 -1
- data/templates/_form.wiring_it_into_rails.html.erb +15 -9
- data/templates/basic_mods_model.rb +7 -8
- data/templates/index.html.erb +24 -0
- data/tutorial.thor +121 -71
- metadata +6 -4
data/HISTORY.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
h3. 0.2.1
|
2
|
+
|
3
|
+
* Minor edits to various messages and user prompts.
|
4
|
+
* Improved the index view.
|
5
|
+
* Modified edit view to agree with Record model.
|
6
|
+
* Added the --thru option, mainly for developer use.
|
7
|
+
|
8
|
+
h3. 0.2.0
|
9
|
+
|
10
|
+
* Added ability to run tutorial step-by-step.
|
11
|
+
* Added Git to generated Rails app so user can diff changes between steps.
|
12
|
+
|
13
|
+
h3. 0.1.0
|
14
|
+
|
15
|
+
* Initial versions.
|
data/development_notes.txt
CHANGED
@@ -1,476 +1,42 @@
|
|
1
|
-
|
2
|
-
- Incorporate enhancements from notes.txt info tutorial.
|
1
|
+
Incorporate the edits from the last commit (00b010bb) of hydra_walkthrough.
|
3
2
|
|
4
|
-
|
5
|
-
- Remove monkey-patch to hydra-head.
|
6
|
-
- Write method to extract long messages from the tutorial code.
|
7
|
-
- Support the --pop option.
|
8
|
-
- Implement a --help option.
|
9
|
-
- Support control over verbosity, and tie it to :capture declarations.
|
10
|
-
- Improve tutorial unit tests.
|
11
|
-
- Improve the views in the tutorial.
|
12
|
-
- Write unit tests for the tutorial script itself.
|
13
|
-
- Write an integration test for the entire tutorial.
|
3
|
+
See issues submitted by users on Github.
|
14
4
|
|
5
|
+
Improve README.
|
15
6
|
|
16
|
-
|
7
|
+
Remove monkey-patch of hydra-head.
|
17
8
|
|
18
|
-
|
9
|
+
Write method to extract long messages from the tutorial code.
|
19
10
|
|
20
|
-
|
11
|
+
Support the --pop option.
|
21
12
|
|
22
|
-
|
13
|
+
Implement a --list option.
|
23
14
|
|
24
|
-
|
25
|
-
rvm use --rvmrc --create 1.9.3@hydra_walkthrough
|
15
|
+
Implement a --help option.
|
26
16
|
|
27
|
-
|
28
|
-
gem list
|
17
|
+
Support control over verbosity, and tie it to :capture declarations.
|
29
18
|
|
30
|
-
|
31
|
-
gem install bundler rails
|
19
|
+
Improve tutorial unit tests.
|
32
20
|
|
33
|
-
|
34
|
-
gem list
|
21
|
+
Improve the views in the tutorial.
|
35
22
|
|
36
|
-
|
37
|
-
rails new hydra_walkthrough
|
23
|
+
Write unit tests for the tutorial script itself.
|
38
24
|
|
39
|
-
|
40
|
-
mv .rvmrc hydra_walkthrough
|
25
|
+
Write an integration test for the entire tutorial.
|
41
26
|
|
42
|
-
|
43
|
-
...
|
27
|
+
Edit desc() commands: search for FIX.
|
44
28
|
|
45
|
-
|
46
|
-
git clone git://github.com/projecthydra/hydra-jetty.git
|
29
|
+
Use delegate_to().
|
47
30
|
|
48
|
-
|
49
|
-
cp -r hydra-jetty hydra_walkthrough/jetty
|
31
|
+
Make resources(:records) a separate Git commit.
|
50
32
|
|
51
|
-
|
52
|
-
|
33
|
+
Various problems evident after the check_the_new_form step:
|
34
|
+
- Delete links are not working.
|
35
|
+
- Keywords are not being saved.
|
36
|
+
- The view has multiple problems and is not in synce with the model.
|
53
37
|
|
54
|
-
|
55
|
-
jetty
|
56
|
-
.rvmrc
|
57
|
-
Gemfile.lock
|
38
|
+
run_hydra_generators() produces a large commit. Can we break this apart?
|
58
39
|
|
59
|
-
|
60
|
-
git init
|
61
|
-
git add .
|
62
|
-
git commit -m 'Initial commit'
|
40
|
+
write_model_test()
|
63
41
|
|
64
|
-
|
65
|
-
rails server
|
66
|
-
open http://localhost:3000
|
67
|
-
|
68
|
-
# Check before we add some gems.
|
69
|
-
rake -T
|
70
|
-
|
71
|
-
# Add some lines to Gemfile.
|
72
|
-
# In the :assets block.
|
73
|
-
gem 'execjs'
|
74
|
-
gem 'therubyracer', :platforms => :ruby
|
75
|
-
|
76
|
-
# In the :development block.
|
77
|
-
gem 'jettywrapper'
|
78
|
-
gem 'debugger'
|
79
|
-
|
80
|
-
# Git.
|
81
|
-
git add .
|
82
|
-
git commit -m 'Added some gems: execjs, therubyracer, jettywrapper, debugger'
|
83
|
-
|
84
|
-
# Set up SOLR and Fedora config files.
|
85
|
-
cp ../resources/solr.yml config
|
86
|
-
cp ../resources/fedora.yml config
|
87
|
-
|
88
|
-
# Git.
|
89
|
-
git add -A
|
90
|
-
git commit -m 'Created SOLR and Fedora config files'
|
91
|
-
|
92
|
-
# Bundle.
|
93
|
-
bundle install
|
94
|
-
|
95
|
-
# Check after: note the jetty tasks.
|
96
|
-
rake -T
|
97
|
-
|
98
|
-
# Start the Jetty server that will run Fedora and SOLR.
|
99
|
-
rake jetty:start
|
100
|
-
|
101
|
-
# Check them out.
|
102
|
-
open http://localhost:8983/fedora/
|
103
|
-
open http://localhost:8983/solr/development/admin/
|
104
|
-
|
105
|
-
# More Gemile.
|
106
|
-
gem 'active-fedora'
|
107
|
-
gem 'om'
|
108
|
-
|
109
|
-
# Bundle.
|
110
|
-
bundle install
|
111
|
-
|
112
|
-
# Git.
|
113
|
-
git add .
|
114
|
-
git commit -m 'Added active-fedora and OM gems'
|
115
|
-
|
116
|
-
# Create a basic model.
|
117
|
-
cp ../resources/basic_af_model.rb app/models/record.rb
|
118
|
-
|
119
|
-
# Git.
|
120
|
-
git add -A
|
121
|
-
git commit -m 'Created a basic Record model with a descMetadata datastream'
|
122
|
-
|
123
|
-
# Check it out.
|
124
|
-
rails console
|
125
|
-
|
126
|
-
## CREATE
|
127
|
-
> obj = Record.new
|
128
|
-
> xml = '<xyz><foo>ABC</foo><foo>DEF</foo><bar>123</bar></xyz>'
|
129
|
-
> obj.descMetadata.content = xml
|
130
|
-
> obj.save
|
131
|
-
|
132
|
-
> pid = obj.pid
|
133
|
-
|
134
|
-
## RETRIEVE
|
135
|
-
> obj = Record.find(pid)
|
136
|
-
> ds = obj.descMetadata
|
137
|
-
> puts ds.content
|
138
|
-
|
139
|
-
## UPDATE
|
140
|
-
> doc = ds.ng_xml
|
141
|
-
> elements = doc.xpath '//foo'
|
142
|
-
> elements.each { |e| puts e }
|
143
|
-
> exit
|
144
|
-
|
145
|
-
# Check it out in the browser.
|
146
|
-
open http://localhost:8983/fedora/objects/
|
147
|
-
-> click search
|
148
|
-
-> click the hyperlink of the object's PID (eg, 'changeme:1')
|
149
|
-
-> click hyperlink to view the object's datastreams list
|
150
|
-
-> click hyperlink to view the content of the descMetadata datastream
|
151
|
-
|
152
|
-
# Back in the Rails console:
|
153
|
-
|
154
|
-
rails console
|
155
|
-
|
156
|
-
## DELETE
|
157
|
-
> obj = Record.find('changeme:1')
|
158
|
-
> obj.delete
|
159
|
-
> exit
|
160
|
-
|
161
|
-
# Check it out in the browser.
|
162
|
-
# And click search button.
|
163
|
-
open http://localhost:8983/fedora/objects/
|
164
|
-
|
165
|
-
# Enhance our datastream.
|
166
|
-
cp ../resources/basic_om_model.rb app/models/record.rb
|
167
|
-
|
168
|
-
# Git.
|
169
|
-
git commit -am 'Added an OM terminology'
|
170
|
-
|
171
|
-
# Check it out.
|
172
|
-
rails console
|
173
|
-
|
174
|
-
> obj = Record.new
|
175
|
-
> obj.descMetadata.title = "My object title"
|
176
|
-
> obj.save
|
177
|
-
> puts obj.descMetadata.content
|
178
|
-
> obj.delete
|
179
|
-
> exit
|
180
|
-
|
181
|
-
# Modify record.rb
|
182
|
-
# Add this after the has_metadata call.
|
183
|
-
|
184
|
-
delegate :title, :to => 'descMetadata'
|
185
|
-
|
186
|
-
# Git.
|
187
|
-
git commit -am 'Added delegate() to the model'
|
188
|
-
|
189
|
-
# Check it out.
|
190
|
-
rails console
|
191
|
-
|
192
|
-
> obj = Record.new
|
193
|
-
> obj.title = "My object title"
|
194
|
-
> obj.save
|
195
|
-
> puts obj.descMetadata.content
|
196
|
-
> puts obj.title.inspect
|
197
|
-
> obj.delete
|
198
|
-
> exit
|
199
|
-
|
200
|
-
# Use delegate_to().
|
201
|
-
# Replace the delete() line.
|
202
|
-
|
203
|
-
delegate_to 'descMetadata', [:title, :author, :url, :description], :unique => true
|
204
|
-
|
205
|
-
# Git.
|
206
|
-
git commit -am 'Switched to delegate_to()'
|
207
|
-
|
208
|
-
# Check it out.
|
209
|
-
rails console
|
210
|
-
|
211
|
-
> obj = Record.new
|
212
|
-
> obj.title = "Some title"
|
213
|
-
> obj.title
|
214
|
-
> obj.author = 'Some author'
|
215
|
-
> obj.save
|
216
|
-
> puts obj.descMetadata.contnet
|
217
|
-
> puts obj.descMetadata.content
|
218
|
-
> obj.delete
|
219
|
-
> exit
|
220
|
-
|
221
|
-
# Enhance our model.
|
222
|
-
# This example is too complicated.
|
223
|
-
# Also, it undoes the delegate_to().
|
224
|
-
cp ../resources/basic_mods_model.rb app/models/record.rb
|
225
|
-
cp ../resources/mods_desc_metadata.rb app/models/mods_desc_metadata.rb
|
226
|
-
|
227
|
-
# Git.
|
228
|
-
git add -A
|
229
|
-
git commit -m 'Added a more extensive OM example'
|
230
|
-
|
231
|
-
# Check it out.
|
232
|
-
rails console
|
233
|
-
|
234
|
-
> obj = Record.new
|
235
|
-
> obj.title = "My object title"
|
236
|
-
> obj.save
|
237
|
-
> puts obj.descMetadata.content
|
238
|
-
> obj.delete
|
239
|
-
> exit
|
240
|
-
|
241
|
-
# Initialize a controller and views for our Record model.
|
242
|
-
rails generate scaffold_controller Record --no-helper --skip-test-framework
|
243
|
-
|
244
|
-
# Git.
|
245
|
-
git add -A
|
246
|
-
git commit -m 'Added a basic controller and views for the Record model'
|
247
|
-
|
248
|
-
# Check files that were created.
|
249
|
-
app/controlers/records_controller.rb
|
250
|
-
app/views/records/
|
251
|
-
|
252
|
-
# Modify config/routes.rb
|
253
|
-
resources :records
|
254
|
-
|
255
|
-
# Git.
|
256
|
-
git commit -am 'Set up resourceful routing for the Record model'
|
257
|
-
|
258
|
-
# Put some files in place.
|
259
|
-
cp ../resources/_form.html.erb app/views/records/_form.html.erb
|
260
|
-
cp ../resources/show.html.erb app/views/records/show.html.erb
|
261
|
-
|
262
|
-
# Git.
|
263
|
-
git commit -am 'Fleshed out the edit form and show page'
|
264
|
-
|
265
|
-
# Try it out.
|
266
|
-
# Delete links are not working.
|
267
|
-
# Keywords are not being saved.
|
268
|
-
# The view has multiple problems and is not in synce with the model.
|
269
|
-
open http://localhost:3000/records/new
|
270
|
-
|
271
|
-
# More Gemile.
|
272
|
-
gem 'blacklight'
|
273
|
-
gem 'hydra-head'
|
274
|
-
gem 'devise'
|
275
|
-
|
276
|
-
# Git.
|
277
|
-
git commit -am 'Added blacklight, hydra-head, and devise'
|
278
|
-
|
279
|
-
# Bundle.
|
280
|
-
bundle install
|
281
|
-
|
282
|
-
# Remove some files.
|
283
|
-
rm public/index.html
|
284
|
-
rm config/solr.yml
|
285
|
-
|
286
|
-
# Set up devise.
|
287
|
-
rails generate blacklight --devise
|
288
|
-
|
289
|
-
# Git.
|
290
|
-
git add -A
|
291
|
-
git commit -m 'Set up devise'
|
292
|
-
|
293
|
-
# Remove some files.
|
294
|
-
rm config/solr.yml
|
295
|
-
rm app/controllers/catalog_controller.rb
|
296
|
-
|
297
|
-
# Set up a User model for hydra-head.
|
298
|
-
rails generate hydra:head User
|
299
|
-
|
300
|
-
# Do some stuff.
|
301
|
-
rake db:migrate
|
302
|
-
rake db:test:prepare
|
303
|
-
rake jetty:stop
|
304
|
-
rake hydra:jetty:config
|
305
|
-
rake jetty:start
|
306
|
-
|
307
|
-
# Git.
|
308
|
-
git add -A
|
309
|
-
git commit -m 'Set up User model under hydra-head'
|
310
|
-
|
311
|
-
# Various edits:
|
312
|
-
|
313
|
-
# app/controllers/records_controller.rb
|
314
|
-
include Hydra::AssetsControllerHelper
|
315
|
-
include Hydra::AccessControlsEnforcement
|
316
|
-
before_filter :enforce_access_controls
|
317
|
-
|
318
|
-
# app/controllers/records_controller.rb
|
319
|
-
# In create(), after @record is set.
|
320
|
-
apply_depositor_metadata(@record)
|
321
|
-
|
322
|
-
# app/models/record.rb
|
323
|
-
include Hydra::ModelMixins::CommonMetadata
|
324
|
-
include Hydra::ModelMethods
|
325
|
-
|
326
|
-
# app/models/solr_document.rb
|
327
|
-
# After other includes.
|
328
|
-
include Hydra::Solr::Document
|
329
|
-
|
330
|
-
# app/assets/javascripts/application.js
|
331
|
-
# At end of file.
|
332
|
-
Blacklight.do_search_context_behavior = function() { }
|
333
|
-
|
334
|
-
# Git.
|
335
|
-
git commit -am 'Included hydra-head into our model, controller, etc.'
|
336
|
-
|
337
|
-
# Check it out.
|
338
|
-
# Needed to edit hydra-head: _user_util_links.html.erb
|
339
|
-
open http://localhost:3000/records/new
|
340
|
-
-> Click sign up.
|
341
|
-
-> Enter any email and password.
|
342
|
-
|
343
|
-
# Add some gems for testing.
|
344
|
-
# In the :test group (and :development group?)
|
345
|
-
gem 'rspec'
|
346
|
-
gem 'rspec-rails'
|
347
|
-
|
348
|
-
# Git.
|
349
|
-
git commit -am 'Added rspec gem'
|
350
|
-
|
351
|
-
# Bundle
|
352
|
-
bundle install
|
353
|
-
|
354
|
-
# Set up rspec.
|
355
|
-
rails generate rspec:install
|
356
|
-
|
357
|
-
# Git.
|
358
|
-
git add -A
|
359
|
-
git commit -m 'Initialized rspec directory'
|
360
|
-
|
361
|
-
# Create a test.
|
362
|
-
# This test should do something real.
|
363
|
-
mkdir spec/controllers
|
364
|
-
cp ../resources/records_controller_spec.rb spec/controllers/records_controller_spec.rb
|
365
|
-
|
366
|
-
# Git.
|
367
|
-
git add -A
|
368
|
-
git commit -m 'Create a placeholder test'
|
369
|
-
|
370
|
-
# Run the test
|
371
|
-
rspec
|
372
|
-
|
373
|
-
# Add some gems for testing.
|
374
|
-
# In the :test group (and :development group?)
|
375
|
-
gem 'capybara'
|
376
|
-
|
377
|
-
# Bundle
|
378
|
-
bundle install
|
379
|
-
|
380
|
-
# Git.
|
381
|
-
git commit -am 'Added capybara gem'
|
382
|
-
|
383
|
-
# Create a test.
|
384
|
-
mkdir spec/integration
|
385
|
-
cp ../resources/integration_spec.rb spec/integration/integration_spec.rb
|
386
|
-
|
387
|
-
# Git.
|
388
|
-
git add -A
|
389
|
-
git commit -m 'Created a few integration tests'
|
390
|
-
|
391
|
-
# Run the tests
|
392
|
-
rspec
|
393
|
-
|
394
|
-
# Create a ci rake task.
|
395
|
-
cp ../resources/ci.rake lib/tasks/ci.rake
|
396
|
-
|
397
|
-
# Git.
|
398
|
-
git add -A
|
399
|
-
git commit -m 'Created a ci rake task'
|
400
|
-
|
401
|
-
# Run it.
|
402
|
-
rake jetty:stop
|
403
|
-
rake ci
|
404
|
-
rake jetty:start
|
405
|
-
|
406
|
-
# Add a gem for test coverage.
|
407
|
-
# In the :test group (and :development group?)
|
408
|
-
gem 'simplecov'
|
409
|
-
|
410
|
-
# Bundle
|
411
|
-
bundle install
|
412
|
-
|
413
|
-
# Git.
|
414
|
-
git commit -am 'Added simplecov gem'
|
415
|
-
|
416
|
-
# ci.rake
|
417
|
-
# After Rails.env is set.
|
418
|
-
ENV['COVERAGE'] ||= 'true'
|
419
|
-
|
420
|
-
# spec/spec_helper.rb
|
421
|
-
# After ENV['RAILS_ENV'] is set.
|
422
|
-
if ENV['COVERAGE'] == "true"
|
423
|
-
require 'simplecov'
|
424
|
-
SimpleCov.start do
|
425
|
-
add_filter "config/"
|
426
|
-
add_filter "spec/"
|
427
|
-
end
|
428
|
-
end
|
429
|
-
|
430
|
-
# Add to .gitignore
|
431
|
-
coverage
|
432
|
-
|
433
|
-
# Git
|
434
|
-
git commit -am 'Set up test coverage'
|
435
|
-
|
436
|
-
# Run it.
|
437
|
-
rake jetty:stop
|
438
|
-
rake ci
|
439
|
-
rake jetty:start
|
440
|
-
|
441
|
-
# Check test coverage
|
442
|
-
open coverage/index.html
|
443
|
-
|
444
|
-
# app/models/record.rb
|
445
|
-
# After has_metadata
|
446
|
-
has_file_datastream :name => 'content', :type => ActiveFedora::Datastream
|
447
|
-
|
448
|
-
# app/controllers/records_controller.rb
|
449
|
-
include Hydra::Controller::UploadBehavior
|
450
|
-
|
451
|
-
# app/controllers/records_controller.rb
|
452
|
-
# After: apply_depositor_metadata().
|
453
|
-
@record.label = params[:record][:title] # this is a bad hack to work around an AF bug
|
454
|
-
add_posted_blob_to_asset(@record, params[:filedata]) if params.has_key?(:filedata)
|
455
|
-
|
456
|
-
# app/views/records/_form.html.erb
|
457
|
-
# Delete first line. Use this instead:
|
458
|
-
<%= form_for(@record, :html => { :multipart => true } ) do |f| -%>
|
459
|
-
<h2>File</h2>
|
460
|
-
<%= file_field_tag "filedata" %>
|
461
|
-
|
462
|
-
# Get stuff.
|
463
|
-
cp ../resources/_add_assets_links.html.erb app/views/_add_assets_links.html.erb
|
464
|
-
|
465
|
-
# Git.
|
466
|
-
git add -A
|
467
|
-
git commit -m 'Add some styling and link to new Record in the header of the layout'
|
468
|
-
|
469
|
-
# Run the app.
|
470
|
-
rake jetty:stop
|
471
|
-
rake jetty:start
|
472
|
-
rails server
|
473
|
-
|
474
|
-
# Wrap up.
|
475
|
-
Shut down rails server (CTRL-C)
|
476
|
-
rake jetty:stop
|
42
|
+
run_integration_test_fail(): seems to small of a step: combine with previous?
|
data/hydra-tutorial.gemspec
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
<%= form_for(@record) do |f| -%>
|
2
|
-
<h2>Title</h2>
|
2
|
+
<h2>Title and Author</h2>
|
3
|
+
|
3
4
|
<div class="row">
|
4
5
|
<%= f.label :title, "Title" %>
|
5
6
|
<%= f.text_area :title, :value=>@record.title, :required => true %>
|
6
7
|
</div>
|
7
8
|
|
8
|
-
<h2>Abstract and keywords</h2>
|
9
|
-
|
10
9
|
<div class="row">
|
11
|
-
|
12
|
-
|
10
|
+
<%= f.label :author, "Author" %>
|
11
|
+
<%= f.text_area :author, :value=>@record.author, :required => true %>
|
13
12
|
</div>
|
14
13
|
|
14
|
+
<h2>Abstract</h2>
|
15
|
+
|
15
16
|
<div class="row">
|
16
|
-
<%=
|
17
|
-
<%=
|
18
|
-
<div class="help">separate keywords with commas</div>
|
17
|
+
<%= f.label :abstract %>
|
18
|
+
<%= f.text_area :abstract, :value=>@record.abstract, :required=>true %>
|
19
19
|
</div>
|
20
20
|
|
21
|
-
<h2>
|
21
|
+
<h2>Citation and related URL</h2>
|
22
|
+
|
22
23
|
<div class="row">
|
23
24
|
<%= f.label :preferred_citation, "Preferred citation for this object", :class => "hidden-tablet" %>
|
24
25
|
<%= f.text_area :preferred_citation, :value=>@record.preferred_citation %>
|
25
26
|
</div>
|
26
27
|
|
28
|
+
<div class="row">
|
29
|
+
<%= f.label :related_url, "URL of related item", :class => "hidden-tablet" %>
|
30
|
+
<%= f.text_area :related_url, :value=>@record.related_url %>
|
31
|
+
</div>
|
32
|
+
|
27
33
|
<input type="submit" class="btn btn-small save-edits" name="save" id="save" />
|
28
34
|
|
29
35
|
<% end %>
|
@@ -1,13 +1,12 @@
|
|
1
1
|
class Record < ActiveFedora::Base
|
2
2
|
|
3
|
-
has_metadata :name =>
|
4
|
-
|
5
|
-
delegate :title,
|
6
|
-
delegate :
|
7
|
-
delegate :
|
8
|
-
delegate :
|
9
|
-
delegate :
|
10
|
-
delegate :description, :to=>'descMetadata', :at => [:abstract], :unique=>true
|
3
|
+
has_metadata :name => 'descMetadata', :type => ModsDescMetadata
|
4
|
+
|
5
|
+
delegate :title, :to => 'descMetadata', :unique=>true, :at => [:mods, :titleInfo, :title]
|
6
|
+
delegate :author, :to => 'descMetadata', :unique=>true, :at => [:name, :namePart]
|
7
|
+
delegate :abstract, :to => 'descMetadata', :unique=>true
|
8
|
+
delegate :preferred_citation, :to => 'descMetadata', :unique=>true
|
9
|
+
delegate :related_url, :to => 'descMetadata', :unique=>true, :at => [:relatedItem, :location, :url]
|
11
10
|
|
12
11
|
end
|
13
12
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<h1>Listing records</h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<tr>
|
5
|
+
<th>Actions</th>
|
6
|
+
<th>Title</th>
|
7
|
+
</tr>
|
8
|
+
|
9
|
+
<% @records.each do |record| %>
|
10
|
+
<tr>
|
11
|
+
<td>
|
12
|
+
<%= link_to 'Show', record %> |
|
13
|
+
<%= link_to 'Edit', edit_record_path(record) %> |
|
14
|
+
<%= link_to 'Delete', record, method: :delete, data: { confirm: 'Are you sure?' } %>
|
15
|
+
</td>
|
16
|
+
<td><%= record.title %></td>
|
17
|
+
</tr>
|
18
|
+
|
19
|
+
<% end %>
|
20
|
+
</table>
|
21
|
+
|
22
|
+
<br />
|
23
|
+
|
24
|
+
<%= link_to 'New Record', new_record_path %>
|
data/tutorial.thor
CHANGED
@@ -29,7 +29,7 @@ module HydraTutorialHelpers
|
|
29
29
|
def rails_console
|
30
30
|
return if @@conf.quick
|
31
31
|
say %Q{
|
32
|
-
We'll launch the console again
|
32
|
+
We'll launch the console again.\n}, STATEMENT
|
33
33
|
say %Q{
|
34
34
|
Hit Ctrl-D (^D) to stop the Rails console and continue this tutorial.\n}, WAIT
|
35
35
|
run "rails c"
|
@@ -132,6 +132,7 @@ class HydraTutorial < Thor
|
|
132
132
|
HTConf = Struct.new(
|
133
133
|
# Command-line options.
|
134
134
|
:run_all, # If true, run all remaining tasks rather than only the next task.
|
135
|
+
:thru, # Implies :run_all and stores name of last task to be run.
|
135
136
|
:quick, # If true, bypass interactive user confirmations.
|
136
137
|
:reset, # If true, reset the tutorial back to the beginning.
|
137
138
|
:gems_from_git, # If true, get a couple of gems directly from github.
|
@@ -150,6 +151,7 @@ class HydraTutorial < Thor
|
|
150
151
|
desc('main: FIX', 'FIX')
|
151
152
|
method_options(
|
152
153
|
:run_all => :boolean,
|
154
|
+
:thru => :string,
|
153
155
|
:quick => :boolean,
|
154
156
|
:reset => :boolean,
|
155
157
|
:gems_from_git => :boolean,
|
@@ -190,6 +192,9 @@ class HydraTutorial < Thor
|
|
190
192
|
# Persist the fact that the task was run to the YAML progress file.
|
191
193
|
@@conf.done << t
|
192
194
|
File.open(@@conf.progress_file, "w") { |f| f.puts(@@conf.to_yaml) }
|
195
|
+
|
196
|
+
# Exit loop if we just ran the task user supplied with --thru option.
|
197
|
+
break if t == @@conf.thru
|
193
198
|
end
|
194
199
|
|
195
200
|
# Inform user if the tutorial is finished.
|
@@ -206,6 +211,7 @@ class HydraTutorial < Thor
|
|
206
211
|
def self.initialize_config(opts)
|
207
212
|
@@conf = HTConf.new
|
208
213
|
@@conf.run_all = opts[:run_all]
|
214
|
+
@@conf.thru = opts[:thru]
|
209
215
|
@@conf.quick = opts[:quick]
|
210
216
|
@@conf.reset = opts[:reset]
|
211
217
|
@@conf.gems_from_git = opts[:gems_from_git]
|
@@ -216,6 +222,7 @@ class HydraTutorial < Thor
|
|
216
222
|
@@conf.progress_file = (opts[:progress_file] || '.hydra-tutorial-progress')
|
217
223
|
@@conf.done = nil
|
218
224
|
@@conf.templates_path = File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
225
|
+
@@conf.run_all = true if @@conf.thru
|
219
226
|
end
|
220
227
|
|
221
228
|
# Initializes the YAML progress file that keeps track of which
|
@@ -270,21 +277,16 @@ class HydraTutorial < Thor
|
|
270
277
|
def welcome
|
271
278
|
say %Q{
|
272
279
|
Welcome to this Hydra tutorial. We're going to step through building a
|
273
|
-
working Hydra application. We'll build the application gradually, starting
|
274
|
-
|
275
|
-
|
280
|
+
working Hydra application. We'll build the application gradually, starting by
|
281
|
+
building our "business logic", wiring in HTML views, and then connecting it
|
282
|
+
to our Rails application.
|
276
283
|
|
277
|
-
|
278
|
-
|
279
|
-
safe to blindly accept the changes ('y'), however you may wish to view
|
280
|
-
the diff ('d') to see the things we're change.
|
284
|
+
We'll generate a stub application in the #{@@conf.app} folder. You can change
|
285
|
+
that using the --app option.
|
281
286
|
|
282
287
|
This tutorial, a README file, and our bug tracker are at:
|
283
288
|
|
284
|
-
https://github.com/projecthydra/hydra-tutorial
|
285
|
-
|
286
|
-
We'll generate a stub application in the #{@@conf.app}
|
287
|
-
folder. You can change that using the --app option.\n}, STATEMENT
|
289
|
+
https://github.com/projecthydra/hydra-tutorial\n}, STATEMENT
|
288
290
|
end
|
289
291
|
|
290
292
|
desc('install_ruby: FIX', 'FIX')
|
@@ -337,8 +339,8 @@ class HydraTutorial < Thor
|
|
337
339
|
|
338
340
|
if File.exists? @@conf.app
|
339
341
|
say %Q{
|
340
|
-
|
341
|
-
|
342
|
+
#{@@conf.app} already exists. Either remove it or provide
|
343
|
+
a different application name using the --app option.}, WARNING
|
342
344
|
exit
|
343
345
|
end
|
344
346
|
|
@@ -382,8 +384,12 @@ class HydraTutorial < Thor
|
|
382
384
|
|
383
385
|
desc('adding_dependencies: FIX', 'FIX')
|
384
386
|
def adding_dependencies
|
385
|
-
|
386
|
-
|
387
|
+
say %Q{
|
388
|
+
Now we'll add some Javascript dependencies.\n}, STATEMENT
|
389
|
+
gem_group :assets do
|
390
|
+
gem 'execjs'
|
391
|
+
gem 'therubyracer'
|
392
|
+
end
|
387
393
|
run_git('Added gems for Javascript: execjs and therubyracer')
|
388
394
|
end
|
389
395
|
|
@@ -417,19 +423,24 @@ class HydraTutorial < Thor
|
|
417
423
|
copy_file 'fedora.yml', 'config/fedora.yml'
|
418
424
|
|
419
425
|
say %Q{
|
420
|
-
|
426
|
+
And we will add the 'jettywrapper' gem, which adds Rake tasks to start
|
427
|
+
and stop Jetty.\n}, STATEMENT
|
421
428
|
|
422
|
-
|
429
|
+
gem_group :development, :test do
|
430
|
+
gem 'jettywrapper'
|
431
|
+
end
|
423
432
|
run 'bundle install', :capture => false
|
424
433
|
run_git('Solr and Fedora configuration')
|
434
|
+
end
|
425
435
|
|
436
|
+
desc('starting_jetty: FIX', 'FIX')
|
437
|
+
def starting_jetty
|
426
438
|
say %Q{
|
427
|
-
|
439
|
+
Now we'll start Jetty.\n}, STATEMENT
|
428
440
|
rake 'jetty:start'
|
429
441
|
|
430
442
|
say %Q{
|
431
|
-
|
432
|
-
the Fedora server at:
|
443
|
+
Jetty should be running on port 8983. You can see the Fedora server at:
|
433
444
|
|
434
445
|
http://localhost:8983/fedora/
|
435
446
|
|
@@ -442,6 +453,8 @@ class HydraTutorial < Thor
|
|
442
453
|
|
443
454
|
desc('remove_public_index: FIX', 'FIX')
|
444
455
|
def remove_public_index
|
456
|
+
say %Q{
|
457
|
+
Removing the default home page from Rails. We will replace it later.\n}, STATEMENT
|
445
458
|
remove_file 'public/index.html'
|
446
459
|
run_git('Removed the Rails index.html file')
|
447
460
|
end
|
@@ -478,28 +491,37 @@ class HydraTutorial < Thor
|
|
478
491
|
launch the Rails interactive console (`rails c`), we can create
|
479
492
|
and manipulate our object:
|
480
493
|
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
494
|
+
# CREATE
|
495
|
+
> obj = Record.new
|
496
|
+
> xml = '<xyz><foo>ABC</foo><foo>DEF</foo><bar>123</bar></xyz>'
|
497
|
+
> obj.descMetadata.content = xml
|
498
|
+
> obj.save
|
499
|
+
|
500
|
+
> pid = obj.pid
|
501
|
+
|
502
|
+
# RETRIEVE
|
503
|
+
> obj = Record.find(pid)
|
504
|
+
> ds = obj.descMetadata
|
505
|
+
> puts ds.content
|
486
506
|
|
487
|
-
|
488
|
-
|
507
|
+
# UPDATE
|
508
|
+
> doc = ds.ng_xml
|
509
|
+
> elements = doc.xpath '//foo'
|
510
|
+
> elements.each { |e| puts e }
|
489
511
|
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
512
|
+
# Now check the Fedora object in the browser.
|
513
|
+
# -> open http://localhost:8983/fedora/objects
|
514
|
+
# -> click search
|
515
|
+
# -> click the hyperlink of the object's PID (eg, 'changeme:1')
|
516
|
+
# -> click hyperlink to view the object's datastreams list
|
517
|
+
# -> click hyperlink to view the content of the descMetadata datastream
|
496
518
|
|
497
|
-
|
498
|
-
|
499
|
-
|
519
|
+
# Back in the Rails console.
|
520
|
+
|
521
|
+
# DELETE
|
522
|
+
> obj.delete
|
523
|
+
> exit\n}, STATEMENT
|
500
524
|
|
501
|
-
## DELETE
|
502
|
-
> obj.delete\n}, STATEMENT
|
503
525
|
rails_console
|
504
526
|
end
|
505
527
|
|
@@ -518,34 +540,52 @@ class HydraTutorial < Thor
|
|
518
540
|
desc('experiment_with_om_descmd: FIX', 'FIX')
|
519
541
|
def experiment_with_om_descmd
|
520
542
|
say %Q{
|
521
|
-
If
|
543
|
+
If we launch the Rails interactive console, you can now create and
|
522
544
|
manipulate our object using methods provided by OM.
|
523
545
|
|
524
546
|
> obj = Record.new
|
525
547
|
> obj.descMetadata.title = "My object title"
|
526
548
|
> obj.save
|
527
|
-
|
528
|
-
|
549
|
+
|
550
|
+
Notice also that OM also makes it easy to instantiate an empty version
|
551
|
+
of a datastream. This behavior is controlled by the code in the
|
552
|
+
xml_template() method of our Record model. Having set a value for
|
553
|
+
the title and saved the object, you can now take a look at the entire
|
554
|
+
datastream spawned by OM according to the instructions in the
|
555
|
+
xml_template() method:
|
556
|
+
|
557
|
+
> puts obj.descMetadata.content
|
558
|
+
|
559
|
+
> obj.delete
|
560
|
+
> exit\n}, STATEMENT
|
529
561
|
rails_console
|
530
562
|
end
|
531
563
|
|
532
564
|
desc('use_the_delegate_method: FIX', 'FIX')
|
533
565
|
def use_the_delegate_method
|
534
566
|
say %Q{
|
535
|
-
We can use the
|
536
|
-
to access
|
567
|
+
We can use the delegate() method to tell the model object how
|
568
|
+
to access its descMetadata attributes.\n\n}, STATEMENT
|
569
|
+
|
570
|
+
loc = %Q{\nend\n}
|
571
|
+
insert_into_file "app/models/record.rb", :before => loc do
|
572
|
+
"\n delegate :title, :to => 'descMetadata'"
|
573
|
+
end
|
574
|
+
run_git('Modify Record model to delegate title to descMetadata')
|
575
|
+
|
576
|
+
say %Q{
|
577
|
+
Back in the Rails console you can now access the title attribute directly
|
578
|
+
from the object:
|
537
579
|
|
538
580
|
> obj = Record.new
|
539
581
|
> obj.title = "My object title"
|
540
582
|
> obj.save
|
541
|
-
> obj.descMetadata.content
|
542
|
-
|
583
|
+
> puts obj.descMetadata.content
|
584
|
+
> puts obj.title.inspect
|
585
|
+
> obj.delete
|
586
|
+
> exit\n}, STATEMENT
|
543
587
|
|
544
|
-
|
545
|
-
insert_into_file "app/models/record.rb", :after => loc do
|
546
|
-
"delegate :title, :to => 'descMetadata'\n"
|
547
|
-
end
|
548
|
-
run_git('Modify Record model to delegate title to descMetadata')
|
588
|
+
rails_console
|
549
589
|
end
|
550
590
|
|
551
591
|
desc('add_mods_model_with_mods_descmd: FIX', 'FIX')
|
@@ -573,8 +613,8 @@ class HydraTutorial < Thor
|
|
573
613
|
> obj = Record.new
|
574
614
|
> obj.title = "My object title"
|
575
615
|
> obj.save
|
576
|
-
> obj.descMetadata.content
|
577
|
-
|
616
|
+
> puts obj.descMetadata.content
|
617
|
+
> exit\n}, STATEMENT
|
578
618
|
rails_console
|
579
619
|
end
|
580
620
|
|
@@ -593,11 +633,12 @@ class HydraTutorial < Thor
|
|
593
633
|
run_git('Used Rails generator to create controller and views for the Record model')
|
594
634
|
|
595
635
|
say %Q{
|
596
|
-
|
597
|
-
|
636
|
+
You can see a set of Rails ERB templates, along with a controller that
|
637
|
+
ties the Record model to those view, if you look in the following
|
638
|
+
directories of the application:
|
598
639
|
|
599
|
-
|
600
|
-
|
640
|
+
app/controlers/records_controller.rb
|
641
|
+
app/views/records/\n}, STATEMENT
|
601
642
|
|
602
643
|
continue_prompt
|
603
644
|
end
|
@@ -605,11 +646,12 @@ class HydraTutorial < Thor
|
|
605
646
|
desc('add_new_form: FIX', 'FIX')
|
606
647
|
def add_new_form
|
607
648
|
say %Q{
|
608
|
-
The scaffold
|
609
|
-
we need to provide the guts for the web form
|
649
|
+
The scaffold provided only the basic outline for an application, so
|
650
|
+
we need to provide the guts for the web form.\n\n}, STATEMENT
|
610
651
|
files = [
|
611
652
|
["_form.wiring_it_into_rails.html.erb", "app/views/records/_form.html.erb"],
|
612
653
|
["show.html.erb", "app/views/records/show.html.erb"],
|
654
|
+
["index.html.erb", "app/views/records/index.html.erb"],
|
613
655
|
]
|
614
656
|
files.each do |src, dst|
|
615
657
|
remove_file dst
|
@@ -636,7 +678,7 @@ class HydraTutorial < Thor
|
|
636
678
|
patterns that have emerged in the Hydra community, including search,
|
637
679
|
gated discovery, etc.
|
638
680
|
|
639
|
-
We'll add a few
|
681
|
+
We'll add a few gems:
|
640
682
|
|
641
683
|
- blacklight provides a discovery interface on top of the Solr index
|
642
684
|
|
@@ -684,7 +726,7 @@ class HydraTutorial < Thor
|
|
684
726
|
desc('hydra_jetty_config: FIX', 'FIX')
|
685
727
|
def hydra_jetty_config
|
686
728
|
say %Q{
|
687
|
-
Hydra provides some configuration for Solr and Fedora.
|
729
|
+
Hydra provides some configuration for Solr and Fedora. We will use them.\n}, STATEMENT
|
688
730
|
rake 'jetty:stop'
|
689
731
|
rake 'hydra:jetty:config'
|
690
732
|
rake 'jetty:start'
|
@@ -735,11 +777,19 @@ include Hydra::Solr::Document
|
|
735
777
|
def check_catalog
|
736
778
|
say %Q{
|
737
779
|
Blacklight and Hydra-Head have added some new functionality to the
|
738
|
-
application. We can now look at a search interface (provided
|
739
|
-
|
740
|
-
|
780
|
+
application. We can now look at a search interface (provided by Blacklight)
|
781
|
+
and use gated discovery over our repository. By default, objects are only
|
782
|
+
visible to their creator.
|
741
783
|
|
742
|
-
|
784
|
+
First create a new user account:
|
785
|
+
|
786
|
+
http://localhost:3000/users/sign_up
|
787
|
+
|
788
|
+
Then create some Record objects:
|
789
|
+
|
790
|
+
http://localhost:3000/records/new
|
791
|
+
|
792
|
+
And then check the search catalog:
|
743
793
|
|
744
794
|
http://localhost:3000/catalog\n}, STATEMENT
|
745
795
|
|
@@ -767,12 +817,12 @@ include Hydra::Solr::Document
|
|
767
817
|
end
|
768
818
|
|
769
819
|
# TODO: write the test.
|
770
|
-
desc('write_model_test: FIX', 'FIX')
|
771
|
-
def write_model_test
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
end
|
820
|
+
# desc('write_model_test: FIX', 'FIX')
|
821
|
+
# def write_model_test
|
822
|
+
# # copy_file 'record_test.rb', 'spec/models/record_test.rb'
|
823
|
+
# # run_git('Added a model test')
|
824
|
+
# run 'rspec'
|
825
|
+
# end
|
776
826
|
|
777
827
|
# TODO: this test should do something.
|
778
828
|
desc('write_controller_test: FIX', 'FIX')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hydra-tutorial
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-10-
|
13
|
+
date: 2012-10-23 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: thor
|
@@ -70,6 +70,7 @@ extra_rdoc_files: []
|
|
70
70
|
files:
|
71
71
|
- .gitignore
|
72
72
|
- Gemfile
|
73
|
+
- HISTORY.md
|
73
74
|
- README.md
|
74
75
|
- Rakefile
|
75
76
|
- bin/hydra-tutorial
|
@@ -94,6 +95,7 @@ files:
|
|
94
95
|
- templates/ci.rake
|
95
96
|
- templates/ci_with_coverage.rake
|
96
97
|
- templates/fedora.yml
|
98
|
+
- templates/index.html.erb
|
97
99
|
- templates/integration_spec.rb
|
98
100
|
- templates/mods_desc_metadata.rb
|
99
101
|
- templates/records_controller.rb
|
@@ -115,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
115
117
|
version: '0'
|
116
118
|
segments:
|
117
119
|
- 0
|
118
|
-
hash:
|
120
|
+
hash: -2393405687621414256
|
119
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
122
|
none: false
|
121
123
|
requirements:
|
@@ -124,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
126
|
version: '0'
|
125
127
|
segments:
|
126
128
|
- 0
|
127
|
-
hash:
|
129
|
+
hash: -2393405687621414256
|
128
130
|
requirements: []
|
129
131
|
rubyforge_project:
|
130
132
|
rubygems_version: 1.8.24
|