hydra-tutorial 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/README.md +92 -22
- data/bin/hydra-tutorial +4 -2
- data/development_notes.txt +476 -0
- data/hydra-tutorial.gemspec +9 -11
- data/{templates → old_tutorial/templates}/application/dataset_hydra_mods_om.rb +0 -0
- data/{templates → old_tutorial/templates}/application/dataset_hydra_om.rb +0 -0
- data/{templates → old_tutorial/templates}/application/datasets_controller.rb +0 -0
- data/{or_templates/adding_our_models → old_tutorial/templates/application}/mods_desc_metadata.rb +0 -0
- data/{templates → old_tutorial/templates}/building_a_basic_rails_app/dataset_af_om.rb +0 -0
- data/{templates → old_tutorial/templates}/building_a_basic_rails_app/dataset_simple_om.rb +0 -0
- data/{or_templates → old_tutorial/templates}/building_a_basic_rails_app/fedora.yml +0 -0
- data/{templates → old_tutorial/templates}/building_a_basic_rails_app/om_record.rb +0 -0
- data/{or_templates → old_tutorial/templates}/building_a_basic_rails_app/solr.yml +0 -0
- data/old_tutorial/tutorial.thor +493 -0
- data/{or_templates/sprinkle_some_styling → templates}/_add_assets_links.html.erb +0 -0
- data/{or_templates/add_file_upload/_form.html.erb → templates/_form.add_file_upload.html.erb} +0 -0
- data/{or_templates/wiring_it_into_rails/_form.html.erb → templates/_form.wiring_it_into_rails.html.erb} +0 -0
- data/{or_templates/adding_our_models → templates}/basic_af_model.rb +0 -0
- data/{or_templates/adding_our_models → templates}/basic_mods_model.rb +0 -0
- data/{or_templates/adding_our_models → templates}/basic_om_model.rb +0 -0
- data/{or_templates/add_tests → templates}/ci.rake +0 -0
- data/{or_templates/add_tests → templates}/ci_with_coverage.rake +0 -0
- data/templates/{building_a_basic_rails_app/fedora.yml → fedora.yml} +0 -0
- data/{or_templates/add_tests → templates}/integration_spec.rb +0 -0
- data/templates/{application/mods_desc_metadata.rb → mods_desc_metadata.rb} +0 -0
- data/{or_templates → templates}/records_controller.rb +0 -0
- data/{or_templates/add_tests → templates}/records_controller_spec.rb +0 -0
- data/{or_templates/wiring_it_into_rails → templates}/show.html.erb +0 -0
- data/templates/{building_a_basic_rails_app/solr.yml → solr.yml} +0 -0
- data/tutorial.thor +806 -341
- metadata +32 -30
- data/open-repositories-tutorial.thor +0 -888
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hydra-tutorial
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Chris Beer
|
9
|
+
- Monty Hindman
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2012-
|
13
|
+
date: 2012-10-19 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: thor
|
@@ -72,32 +73,33 @@ files:
|
|
72
73
|
- README.md
|
73
74
|
- Rakefile
|
74
75
|
- bin/hydra-tutorial
|
76
|
+
- development_notes.txt
|
75
77
|
- hydra-tutorial.gemspec
|
76
|
-
-
|
77
|
-
-
|
78
|
-
-
|
79
|
-
-
|
80
|
-
-
|
81
|
-
-
|
82
|
-
-
|
83
|
-
-
|
84
|
-
-
|
85
|
-
-
|
86
|
-
-
|
87
|
-
-
|
88
|
-
-
|
89
|
-
-
|
90
|
-
-
|
91
|
-
-
|
92
|
-
- templates/
|
93
|
-
- templates/
|
94
|
-
- templates/
|
95
|
-
- templates/
|
96
|
-
- templates/
|
97
|
-
- templates/
|
98
|
-
- templates/
|
99
|
-
- templates/
|
100
|
-
- templates/
|
78
|
+
- old_tutorial/templates/application/dataset_hydra_mods_om.rb
|
79
|
+
- old_tutorial/templates/application/dataset_hydra_om.rb
|
80
|
+
- old_tutorial/templates/application/datasets_controller.rb
|
81
|
+
- old_tutorial/templates/application/mods_desc_metadata.rb
|
82
|
+
- old_tutorial/templates/building_a_basic_rails_app/dataset_af_om.rb
|
83
|
+
- old_tutorial/templates/building_a_basic_rails_app/dataset_simple_om.rb
|
84
|
+
- old_tutorial/templates/building_a_basic_rails_app/fedora.yml
|
85
|
+
- old_tutorial/templates/building_a_basic_rails_app/om_record.rb
|
86
|
+
- old_tutorial/templates/building_a_basic_rails_app/solr.yml
|
87
|
+
- old_tutorial/tutorial.thor
|
88
|
+
- templates/_add_assets_links.html.erb
|
89
|
+
- templates/_form.add_file_upload.html.erb
|
90
|
+
- templates/_form.wiring_it_into_rails.html.erb
|
91
|
+
- templates/basic_af_model.rb
|
92
|
+
- templates/basic_mods_model.rb
|
93
|
+
- templates/basic_om_model.rb
|
94
|
+
- templates/ci.rake
|
95
|
+
- templates/ci_with_coverage.rake
|
96
|
+
- templates/fedora.yml
|
97
|
+
- templates/integration_spec.rb
|
98
|
+
- templates/mods_desc_metadata.rb
|
99
|
+
- templates/records_controller.rb
|
100
|
+
- templates/records_controller_spec.rb
|
101
|
+
- templates/show.html.erb
|
102
|
+
- templates/solr.yml
|
101
103
|
- tutorial.thor
|
102
104
|
homepage: http://projecthydra.org
|
103
105
|
licenses: []
|
@@ -113,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
113
115
|
version: '0'
|
114
116
|
segments:
|
115
117
|
- 0
|
116
|
-
hash:
|
118
|
+
hash: 1291579110055489875
|
117
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
120
|
none: false
|
119
121
|
requirements:
|
@@ -122,10 +124,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
124
|
version: '0'
|
123
125
|
segments:
|
124
126
|
- 0
|
125
|
-
hash:
|
127
|
+
hash: 1291579110055489875
|
126
128
|
requirements: []
|
127
129
|
rubyforge_project:
|
128
|
-
rubygems_version: 1.8.
|
130
|
+
rubygems_version: 1.8.24
|
129
131
|
signing_key:
|
130
132
|
specification_version: 3
|
131
133
|
summary: Hydra head tutorial walkthrough
|
@@ -1,888 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'thor'
|
5
|
-
require 'thor/group'
|
6
|
-
require 'rails/generators/actions'
|
7
|
-
require 'active_support/core_ext/array/extract_options'
|
8
|
-
require 'active_support/core_ext/string/inflections'
|
9
|
-
|
10
|
-
$base_templates_path = File.expand_path(File.join(File.dirname(__FILE__), 'or_templates'))
|
11
|
-
$application_name = ''
|
12
|
-
$application_root = ''
|
13
|
-
|
14
|
-
STATEMENT = Thor::Shell::Color::YELLOW
|
15
|
-
QUESTION = Thor::Shell::Color::GREEN
|
16
|
-
WAIT = Thor::Shell::Color::CYAN
|
17
|
-
|
18
|
-
class HydraOpenRepositoriesTutorialApp < Thor::Group
|
19
|
-
include Thor::Actions
|
20
|
-
include Rails::Generators::Actions
|
21
|
-
|
22
|
-
module TutorialActions
|
23
|
-
def continue_prompt
|
24
|
-
ask %Q{
|
25
|
-
HIT <ENTER> KEY TO CONTINUE
|
26
|
-
}, WAIT
|
27
|
-
end
|
28
|
-
|
29
|
-
def rails_console
|
30
|
-
say %Q{
|
31
|
-
We'll launch the console again. Give some of those commands a try.
|
32
|
-
}, STATEMENT
|
33
|
-
|
34
|
-
say %Q{
|
35
|
-
|
36
|
-
Hit Ctrl-D (^D) to stop the Rails console and continue this tutorial.
|
37
|
-
}, WAIT
|
38
|
-
|
39
|
-
run "rails c"
|
40
|
-
end
|
41
|
-
|
42
|
-
def rails_server url = '/'
|
43
|
-
say %Q{
|
44
|
-
We'll start the Rails server for you. It should be available in
|
45
|
-
your browser at:
|
46
|
-
|
47
|
-
http://localhost:3000#{url}
|
48
|
-
}, STATEMENT
|
49
|
-
|
50
|
-
say %Q{
|
51
|
-
|
52
|
-
Hit Ctrl-C (^C) to stop the Rails server and continue this tutorial.
|
53
|
-
}, WAIT
|
54
|
-
|
55
|
-
run "rails s"
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
include TutorialActions
|
60
|
-
class_option :quick, :default => false
|
61
|
-
class_option :git, :default => false
|
62
|
-
|
63
|
-
def setup_parameters
|
64
|
-
$quick = options[:quick]
|
65
|
-
$git = options[:git]
|
66
|
-
end
|
67
|
-
|
68
|
-
def welcome
|
69
|
-
say %Q{
|
70
|
-
Welcome to this Hydra tutorial. We're going to step through building a
|
71
|
-
working Hydra application. We'll build the application gradually, starting
|
72
|
-
by building our "business logic", wiring in HTML views, and then
|
73
|
-
connecting it to our Rails application.
|
74
|
-
|
75
|
-
At several points in this tutorial, as we iteratively develop our files,
|
76
|
-
you may be prompted to review conflicts between versions of files. It is
|
77
|
-
safe to blindly accept the changes ('y'), however you may wish to view
|
78
|
-
the diff ('d') to see the things we're change.
|
79
|
-
|
80
|
-
This tutorial, a README file, and our bug tracker are at:
|
81
|
-
|
82
|
-
https://github.com/projecthydra/hydra-tutorial
|
83
|
-
|
84
|
-
}, STATEMENT
|
85
|
-
|
86
|
-
name = ask %Q{
|
87
|
-
What do you want to call your application?
|
88
|
-
}, QUESTION unless $quick
|
89
|
-
|
90
|
-
name = name.to_s.strip
|
91
|
-
name = 'hydra_tutorial_app' if name.empty?
|
92
|
-
|
93
|
-
|
94
|
-
$application_name = name
|
95
|
-
|
96
|
-
dir = $application_name.parameterize('_')
|
97
|
-
$application_root = dir
|
98
|
-
|
99
|
-
if File.exists? $application_root
|
100
|
-
say %Q{
|
101
|
-
#{$application_root} already exists. Either remove it or provide
|
102
|
-
a different application name.
|
103
|
-
}, Thor::Shell::Color::RED
|
104
|
-
exit
|
105
|
-
end
|
106
|
-
|
107
|
-
say %Q{
|
108
|
-
We'll generate a stub application #{$application_name} into the folder
|
109
|
-
#{$application_root}. But, first, lets check your Ruby environment.
|
110
|
-
}, STATEMENT
|
111
|
-
|
112
|
-
end
|
113
|
-
|
114
|
-
def prerequisites
|
115
|
-
Prerequisites.start
|
116
|
-
end
|
117
|
-
|
118
|
-
def building_a_basic_rails_app
|
119
|
-
inside $application_root do
|
120
|
-
BuildingABasicRailsApp.start
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
def adding_our_models
|
125
|
-
inside $application_root do
|
126
|
-
AddingOurModels.start
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
def wiring_it_into_rails
|
131
|
-
inside $application_root do
|
132
|
-
WiringItIntoRails.start
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
def add_blacklight_and_hydra
|
137
|
-
inside $application_root do
|
138
|
-
AddBlacklightAndHydra.start
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
def fixup_for_hydra
|
143
|
-
inside $application_root do
|
144
|
-
FixupForHydra.start
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
def add_tests
|
149
|
-
inside $application_root do
|
150
|
-
AddTests.start
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
def add_file_upload
|
155
|
-
inside $application_root do
|
156
|
-
AddFileUpload.start
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
def sprinkle_some_styling
|
161
|
-
inside $application_root do
|
162
|
-
SprinkeSomeStyling.start
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
def cleanup
|
167
|
-
inside $application_root do
|
168
|
-
Cleanup.start
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
class Cleanup < Thor::Group
|
173
|
-
|
174
|
-
include Thor::Actions
|
175
|
-
include Rails::Generators::Actions
|
176
|
-
include TutorialActions
|
177
|
-
|
178
|
-
def start_everything
|
179
|
-
say %Q{
|
180
|
-
This is the end of the tutorial. We'll give you a final chance to look
|
181
|
-
at the web application.
|
182
|
-
}, STATEMENT
|
183
|
-
rake 'jetty:stop'
|
184
|
-
rake 'jetty:start'
|
185
|
-
rails_server
|
186
|
-
end
|
187
|
-
|
188
|
-
def stop_jetty
|
189
|
-
rake 'jetty:stop'
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
class Prerequisites < Thor::Group
|
194
|
-
include Thor::Actions
|
195
|
-
include Rails::Generators::Actions
|
196
|
-
include TutorialActions
|
197
|
-
|
198
|
-
def install_ruby
|
199
|
-
return if $quick
|
200
|
-
say %Q{
|
201
|
-
Obviously, if you can run this tutorial, you have already installed ruby.
|
202
|
-
}, STATEMENT
|
203
|
-
|
204
|
-
|
205
|
-
ruby_executable = run 'which ruby', :capture => true
|
206
|
-
|
207
|
-
say %Q{
|
208
|
-
You are running this using:
|
209
|
-
#{ruby_executable}
|
210
|
-
}, STATEMENT
|
211
|
-
|
212
|
-
if ruby_executable =~ /rvm/ or ruby_executable =~ /rbenv/ or ruby_executable =~ /home/ or ruby_executable =~ /Users/
|
213
|
-
say %Q{
|
214
|
-
It looks like you're using rvm/rbenv/etc. (with a gemset?) We'll use
|
215
|
-
this environment to build the application.
|
216
|
-
}, STATEMENT
|
217
|
-
|
218
|
-
else
|
219
|
-
|
220
|
-
say %Q{
|
221
|
-
We checked, and it looks like you might be using a system-wide ruby.
|
222
|
-
We suggest you use somethng like rvm [1], rbenv [2], etc to manage
|
223
|
-
your ruby projects.
|
224
|
-
|
225
|
-
You can continue and hope for the best, or go install one of these
|
226
|
-
ruby managers, which may make your life easier.
|
227
|
-
|
228
|
-
[1] http://rvm.io/
|
229
|
-
[2] https://github.com/sstephenson/rbenv/
|
230
|
-
}, Thor::Shell::Color::RED
|
231
|
-
|
232
|
-
continue_prompt unless $quick
|
233
|
-
|
234
|
-
end
|
235
|
-
|
236
|
-
end
|
237
|
-
|
238
|
-
def install_bundler_and_rails
|
239
|
-
say %Q{
|
240
|
-
We're going to install some prerequisite gems in order to create our
|
241
|
-
skeleton Rails application.
|
242
|
-
}, STATEMENT
|
243
|
-
run 'gem install bundler rails'
|
244
|
-
end
|
245
|
-
|
246
|
-
def new_rails_app
|
247
|
-
say %Q{
|
248
|
-
Now we'll create the application.
|
249
|
-
}, Thor::Shell::Color::YELLOW
|
250
|
-
run "rails new #{$application_root}"
|
251
|
-
run "cd #{$application_root}"
|
252
|
-
end
|
253
|
-
|
254
|
-
def out_of_the_box
|
255
|
-
return if $quick
|
256
|
-
say %Q{
|
257
|
-
Here's a chance to look around. You can see the structure of
|
258
|
-
a Rails application. In particular, look at:
|
259
|
-
./app
|
260
|
-
./config
|
261
|
-
./lib
|
262
|
-
Gemfile
|
263
|
-
}, STATEMENT
|
264
|
-
|
265
|
-
|
266
|
-
say %Q{
|
267
|
-
If we launched the Rails application server, we can see the application
|
268
|
-
running in the browser and you can see if everything is working.
|
269
|
-
}, STATEMENT
|
270
|
-
|
271
|
-
|
272
|
-
inside $application_root do
|
273
|
-
rails_server unless $quick
|
274
|
-
end
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
class BuildingABasicRailsApp < Thor::Group
|
279
|
-
include Thor::Actions
|
280
|
-
include Rails::Generators::Actions
|
281
|
-
include TutorialActions
|
282
|
-
|
283
|
-
def self.source_paths
|
284
|
-
[File.join($base_templates_path, "building_a_basic_rails_app")]
|
285
|
-
end
|
286
|
-
|
287
|
-
|
288
|
-
def adding_dependencies
|
289
|
-
gem 'execjs'
|
290
|
-
gem 'therubyracer'
|
291
|
-
end
|
292
|
-
|
293
|
-
def add_fedora_and_solr_with_hydrajetty
|
294
|
-
|
295
|
-
say %Q{
|
296
|
-
Fedora runs as a Java servlet inside a container like Tomcat or Jetty.
|
297
|
-
Hydra provides a bundled version of Fedora and Solr for
|
298
|
-
testing and development.
|
299
|
-
}, STATEMENT
|
300
|
-
|
301
|
-
say %Q{
|
302
|
-
We'll download a copy now. It may take awhile.
|
303
|
-
}, STATEMENT
|
304
|
-
unless File.exists? '../jetty'
|
305
|
-
git :clone => '-b 4.x git://github.com/projecthydra/hydra-jetty.git ../jetty'
|
306
|
-
end
|
307
|
-
run 'cp -R ../jetty jetty'
|
308
|
-
|
309
|
-
end
|
310
|
-
|
311
|
-
def jetty_configuration
|
312
|
-
say %Q{
|
313
|
-
We'll add some configuration yml files with information to connect
|
314
|
-
to Solr and Fedora.
|
315
|
-
}, STATEMENT
|
316
|
-
|
317
|
-
copy_file 'solr.yml', 'config/solr.yml'
|
318
|
-
copy_file 'fedora.yml', 'config/fedora.yml'
|
319
|
-
|
320
|
-
say %Q{
|
321
|
-
Add the 'jettywrapper' gem, which adds Rake tasks for start and stop Jetty.
|
322
|
-
}, STATEMENT
|
323
|
-
|
324
|
-
gem 'jettywrapper'
|
325
|
-
run 'bundle install'
|
326
|
-
|
327
|
-
say %Q{
|
328
|
-
Starting Jetty
|
329
|
-
}, STATEMENT
|
330
|
-
rake 'jetty:start'
|
331
|
-
|
332
|
-
say %Q{
|
333
|
-
Take a look around. Jetty should be running on port 8983. You can see
|
334
|
-
the Fedora server at:
|
335
|
-
|
336
|
-
http://localhost:8983/fedora/
|
337
|
-
|
338
|
-
And a Solr index at:
|
339
|
-
|
340
|
-
http://localhost:8983/solr/development/admin/
|
341
|
-
}, STATEMENT
|
342
|
-
|
343
|
-
continue_prompt unless $quick
|
344
|
-
|
345
|
-
end
|
346
|
-
|
347
|
-
# and then clean up some cruft
|
348
|
-
def remove_public_index
|
349
|
-
remove_file 'public/index.html'
|
350
|
-
end
|
351
|
-
|
352
|
-
end
|
353
|
-
|
354
|
-
class AddingOurModels < Thor::Group
|
355
|
-
include Thor::Actions
|
356
|
-
include Rails::Generators::Actions
|
357
|
-
include TutorialActions
|
358
|
-
|
359
|
-
def self.source_paths
|
360
|
-
[File.join($base_templates_path, "adding_our_models")]
|
361
|
-
end
|
362
|
-
|
363
|
-
def add_activefedora
|
364
|
-
say %Q{
|
365
|
-
The active-fedora gem provides a way to model Fedora objects within Ruby.
|
366
|
-
It will help you create Ruby models for creating, updating and reading
|
367
|
-
objects from Fedora using a domain-specific language (DSL) similar
|
368
|
-
to the Rails' ActiveRecord.
|
369
|
-
|
370
|
-
The om gem provides mechanisms for mapping XML documents into Ruby.
|
371
|
-
|
372
|
-
We'll add both of these to the Gemfile.
|
373
|
-
}, STATEMENT
|
374
|
-
|
375
|
-
gem 'active-fedora'
|
376
|
-
gem 'om'
|
377
|
-
run 'bundle install'
|
378
|
-
end
|
379
|
-
|
380
|
-
def add_initial_model
|
381
|
-
say %Q{
|
382
|
-
Now we'll add a basic ActiveFedora stub model for a 'Record'.
|
383
|
-
}, STATEMENT
|
384
|
-
|
385
|
-
copy_file "basic_af_model.rb", "app/models/record.rb"
|
386
|
-
|
387
|
-
say %Q{
|
388
|
-
It looks like this:
|
389
|
-
}, STATEMENT
|
390
|
-
|
391
|
-
print_wrapped File.read('app/models/record.rb')
|
392
|
-
end
|
393
|
-
|
394
|
-
def rails_console_tour
|
395
|
-
|
396
|
-
say %Q{
|
397
|
-
Now we'll give you a chance to look at the Record model. If you
|
398
|
-
launch the Rails interactive console (`rails c`), we can create
|
399
|
-
and manipulate our object:
|
400
|
-
|
401
|
-
## CREATE
|
402
|
-
> obj = Record.new
|
403
|
-
# => #<Record:1571331701243443635 @pid="__DO_NOT_USE__" >
|
404
|
-
> obj.descMetadata.content = e.g. '<my_xml_content />'
|
405
|
-
> obj.save
|
406
|
-
|
407
|
-
> obj.pid
|
408
|
-
# => e.g. 'changeme:1'
|
409
|
-
|
410
|
-
## RETRIEVE
|
411
|
-
> obj = Record.find('changeme:1')
|
412
|
-
> ds = obj.descMetadata
|
413
|
-
# => #<ActiveFedora::NokogiriDatastream:3283711306477137919 ...>
|
414
|
-
> ds.content
|
415
|
-
# => (should be the XML document you added before)
|
416
|
-
|
417
|
-
## UPDATE
|
418
|
-
# manipulating XML:
|
419
|
-
> ds.ng_xml.xpath('//my_xml_content')
|
420
|
-
|
421
|
-
## DELETE
|
422
|
-
> obj.delete
|
423
|
-
|
424
|
-
}, STATEMENT
|
425
|
-
|
426
|
-
|
427
|
-
rails_console unless $quick
|
428
|
-
end
|
429
|
-
|
430
|
-
def enhance_model_with_contrieved_descmd
|
431
|
-
say %Q{
|
432
|
-
Instead of working with the Nokogiri XML document directly, we
|
433
|
-
can use OM to make querying an XML document easier. We'll replace the
|
434
|
-
previous Record with a OM-enabled document.
|
435
|
-
}, STATEMENT
|
436
|
-
copy_file "basic_om_model.rb", "app/models/record.rb"
|
437
|
-
end
|
438
|
-
|
439
|
-
def testing_the_contrieved_descmd
|
440
|
-
say %Q{
|
441
|
-
If you launch the Rails interactive console, we can now create and
|
442
|
-
manipulate our object using methods provided by OM.
|
443
|
-
|
444
|
-
> obj = Record.new
|
445
|
-
> obj.descMetadata.title = "My object title"
|
446
|
-
> obj.save
|
447
|
-
> obj.descMetadata.content
|
448
|
-
# => An XML document with the title "My object title"
|
449
|
-
}, STATEMENT
|
450
|
-
|
451
|
-
rails_console unless $quick
|
452
|
-
end
|
453
|
-
|
454
|
-
def use_the_delegate_method
|
455
|
-
say %Q{
|
456
|
-
We can use the #delegate method to tell the model-object how
|
457
|
-
to access these attributes.
|
458
|
-
|
459
|
-
> obj = Record.new
|
460
|
-
> obj.title = "My object title"
|
461
|
-
> obj.save
|
462
|
-
> obj.descMetadata.content
|
463
|
-
# => An XML document with the title "My object title"
|
464
|
-
}, STATEMENT
|
465
|
-
|
466
|
-
insert_into_file "app/models/record.rb", :after => %Q{has_metadata :name => "descMetadata", :type => DatastreamMetadata\n} do
|
467
|
-
"delegate :title, :to => 'descMetadata'\n"
|
468
|
-
end
|
469
|
-
end
|
470
|
-
|
471
|
-
def add_mods_model_with_mods_descmd
|
472
|
-
say %Q{
|
473
|
-
We'll now replace the contrieved XML metadata schema with a simple
|
474
|
-
MODS-based example, using an OM terminology we prepared earlier.
|
475
|
-
|
476
|
-
We'll put the MODS datastream in a separate module and file, so that
|
477
|
-
it can be easily reused in other ActiveFedora-based objects.
|
478
|
-
}, STATEMENT
|
479
|
-
|
480
|
-
copy_file "basic_mods_model.rb", "app/models/record.rb"
|
481
|
-
copy_file "mods_desc_metadata.rb", "app/models/mods_desc_metadata.rb"
|
482
|
-
|
483
|
-
say %Q{
|
484
|
-
If you launch the Rails interactive console, we can now create
|
485
|
-
and manipulate our object using methods provided by OM.
|
486
|
-
|
487
|
-
> obj = Record.new
|
488
|
-
> obj.title = "My object title"
|
489
|
-
> obj.save
|
490
|
-
> obj.descMetadata.content
|
491
|
-
# => A MODS XML document
|
492
|
-
}, STATEMENT
|
493
|
-
|
494
|
-
rails_console unless $quick
|
495
|
-
end
|
496
|
-
end
|
497
|
-
|
498
|
-
class WiringItIntoRails < Thor::Group
|
499
|
-
include Thor::Actions
|
500
|
-
include Rails::Generators::Actions
|
501
|
-
include TutorialActions
|
502
|
-
|
503
|
-
def self.source_paths
|
504
|
-
[File.join($base_templates_path, "wiring_it_into_rails")]
|
505
|
-
end
|
506
|
-
|
507
|
-
def record_generator
|
508
|
-
say %Q{
|
509
|
-
Now that we've set up our model and successfully added content
|
510
|
-
into Fedora, now we want to connect the model to a Rails web application.
|
511
|
-
|
512
|
-
We'll start by using the standard Rails generators to create
|
513
|
-
a scaffold controller and views, which will give us a
|
514
|
-
place to start working.
|
515
|
-
}, STATEMENT
|
516
|
-
|
517
|
-
generate "scaffold_controller Record --no-helper --skip-test-framework"
|
518
|
-
route "resources :records"
|
519
|
-
|
520
|
-
say %Q{
|
521
|
-
If you look in ./app/views/records, you can see a set of
|
522
|
-
Rails ERB templates.
|
523
|
-
|
524
|
-
./app/controlers/records_controller.rb contains the controller
|
525
|
-
that ties the model to the views.
|
526
|
-
}, STATEMENT
|
527
|
-
|
528
|
-
continue_prompt unless $quick
|
529
|
-
end
|
530
|
-
|
531
|
-
def add_new_form
|
532
|
-
|
533
|
-
say %Q{
|
534
|
-
The scaffold just provided the basic outline for an application, so
|
535
|
-
we need to provide the guts for the web form. Here's a simple one:
|
536
|
-
}, STATEMENT
|
537
|
-
|
538
|
-
copy_file "_form.html.erb", "app/views/records/_form.html.erb"
|
539
|
-
copy_file "show.html.erb", "app/views/records/show.html.erb"
|
540
|
-
end
|
541
|
-
|
542
|
-
def check_it_out
|
543
|
-
|
544
|
-
say %Q{
|
545
|
-
If we start the Rails server, we should now be able to visit the records
|
546
|
-
in the browser, create new records, and edit existing records.
|
547
|
-
|
548
|
-
Start by creating a new record:
|
549
|
-
}, STATEMENT
|
550
|
-
|
551
|
-
rails_server '/records/new' unless $quick
|
552
|
-
end
|
553
|
-
|
554
|
-
end
|
555
|
-
|
556
|
-
class AddBlacklightAndHydra < Thor::Group
|
557
|
-
include Thor::Actions
|
558
|
-
include Rails::Generators::Actions
|
559
|
-
include TutorialActions
|
560
|
-
|
561
|
-
def add_gems
|
562
|
-
say %Q{
|
563
|
-
Thus far, we've been using component parts of the Hydra framework, but
|
564
|
-
now we'll add in the whole framework so we can take advantage of common
|
565
|
-
patterns that have emerged in the Hydra community, including search,
|
566
|
-
gated discovery, etc.
|
567
|
-
|
568
|
-
We'll add a few new gems:
|
569
|
-
|
570
|
-
- blacklight provides a discovery interface on top of the Solr index
|
571
|
-
|
572
|
-
- hydra-head provides a number of common Hydra patterns
|
573
|
-
|
574
|
-
- devise is a standard Ruby gem for providing user-related
|
575
|
-
functions, like registration, sign-in, etc.
|
576
|
-
|
577
|
-
}, STATEMENT
|
578
|
-
|
579
|
-
if $git
|
580
|
-
gem 'blacklight', :git => "git://github.com/projectblacklight/blacklight.git"
|
581
|
-
gem 'hydra-head', :git => "git://github.com/projecthydra/hydra-head.git"
|
582
|
-
else
|
583
|
-
gem 'blacklight'
|
584
|
-
gem 'hydra-head', ">= 4.1.1"
|
585
|
-
end
|
586
|
-
gem 'devise'
|
587
|
-
|
588
|
-
run 'bundle install'
|
589
|
-
end
|
590
|
-
|
591
|
-
def run_generators
|
592
|
-
|
593
|
-
say %Q{
|
594
|
-
These gems provide generators for adding basic views, styles, and override
|
595
|
-
points into your application. We'll run these generators now.
|
596
|
-
}, STATEMENT
|
597
|
-
run 'rm config/solr.yml' # avoid meaningless conflict
|
598
|
-
generate 'blacklight', '--devise'
|
599
|
-
run 'rm config/solr.yml' # avoid meaningless conflict
|
600
|
-
generate 'hydra:head', 'User'
|
601
|
-
end
|
602
|
-
|
603
|
-
def db_migrate
|
604
|
-
say %Q{
|
605
|
-
Blacklight uses a SQL database for keeping track of user bookmarks,
|
606
|
-
searches, etc. We'll run the migrations next:
|
607
|
-
}, STATEMENT
|
608
|
-
rake 'db:migrate'
|
609
|
-
rake 'db:test:prepare'
|
610
|
-
end
|
611
|
-
|
612
|
-
def hydra_jetty_conf
|
613
|
-
say %Q{
|
614
|
-
Hydra provides some configuration for Solr and Fedora. Use them.
|
615
|
-
}, STATEMENT
|
616
|
-
rake 'jetty:stop'
|
617
|
-
rake 'hydra:jetty:config'
|
618
|
-
rake 'jetty:start'
|
619
|
-
end
|
620
|
-
end
|
621
|
-
|
622
|
-
class FixupForHydra < Thor::Group
|
623
|
-
include Thor::Actions
|
624
|
-
include Rails::Generators::Actions
|
625
|
-
include TutorialActions
|
626
|
-
|
627
|
-
def do_it
|
628
|
-
|
629
|
-
say %Q{
|
630
|
-
We need to make a couple changes to our controller and model to make
|
631
|
-
them fully-compliant objects by teaching them about access rights.
|
632
|
-
}, STATEMENT
|
633
|
-
|
634
|
-
inject_into_class "app/controllers/records_controller.rb", 'RecordsController' do
|
635
|
-
" include Hydra::AssetsControllerHelper\n"
|
636
|
-
end
|
637
|
-
|
638
|
-
insert_into_file "app/controllers/records_controller.rb", :after => "@record = Record.new(params[:record])\n" do
|
639
|
-
" apply_depositor_metadata(@record)\n"
|
640
|
-
end
|
641
|
-
|
642
|
-
inject_into_class "app/models/record.rb", "Record" do
|
643
|
-
"
|
644
|
-
include Hydra::ModelMixins::CommonMetadata
|
645
|
-
include Hydra::ModelMethods
|
646
|
-
"
|
647
|
-
end
|
648
|
-
|
649
|
-
insert_into_file "app/models/solr_document.rb", :after => "include Blacklight::Solr::Document\n" do
|
650
|
-
"
|
651
|
-
include Hydra::Solr::Document
|
652
|
-
"
|
653
|
-
end
|
654
|
-
insert_into_file "app/assets/javascripts/application.js", :after => "//= require_tree .\n" do
|
655
|
-
"Blacklight.do_search_context_behavior = function() { }\n"
|
656
|
-
end
|
657
|
-
say %Q{
|
658
|
-
We'll also update our controller to provide access controls on records.
|
659
|
-
}
|
660
|
-
|
661
|
-
inject_into_class "app/controllers/records_controller.rb", 'RecordsController' do
|
662
|
-
" include Hydra::AccessControlsEnforcement\n" +
|
663
|
-
" before_filter :enforce_access_controls\n"
|
664
|
-
end
|
665
|
-
|
666
|
-
end
|
667
|
-
|
668
|
-
def look_at_it
|
669
|
-
say %Q{
|
670
|
-
Blacklight and Hydra-Head have added some new functionality to the
|
671
|
-
application. We can now look at a search interface (provided
|
672
|
-
by Blacklight) and use gated discovery over our repository. By default,
|
673
|
-
objects are only visible to their creator.
|
674
|
-
|
675
|
-
Create some new objects, and then check out the search catalog at:
|
676
|
-
|
677
|
-
http://localhost:3000/catalog
|
678
|
-
|
679
|
-
}, STATEMENT
|
680
|
-
|
681
|
-
rails_server('/records/new') unless $quick
|
682
|
-
end
|
683
|
-
|
684
|
-
end
|
685
|
-
|
686
|
-
class AddTests < Thor::Group
|
687
|
-
include Thor::Actions
|
688
|
-
include Rails::Generators::Actions
|
689
|
-
include TutorialActions
|
690
|
-
|
691
|
-
def self.source_paths
|
692
|
-
[File.join($base_templates_path, "add_tests")]
|
693
|
-
end
|
694
|
-
|
695
|
-
|
696
|
-
def install_rspec
|
697
|
-
say %Q{
|
698
|
-
One of the great things about the Rails framework is the strong
|
699
|
-
testing ethic. We'll use rspec to write a couple tests for
|
700
|
-
this application.
|
701
|
-
}, STATEMENT
|
702
|
-
gem_group :development, :test do
|
703
|
-
gem 'rspec'
|
704
|
-
gem 'rspec-rails'
|
705
|
-
end
|
706
|
-
run 'bundle install'
|
707
|
-
|
708
|
-
generate 'rspec:install'
|
709
|
-
end
|
710
|
-
|
711
|
-
def write_our_first_test
|
712
|
-
say %Q{
|
713
|
-
Here's a quick example of a test.
|
714
|
-
}
|
715
|
-
copy_file 'records_controller_spec.rb', 'spec/controllers/records_controller_spec.rb'
|
716
|
-
run 'rspec'
|
717
|
-
end
|
718
|
-
|
719
|
-
def a_model_test
|
720
|
-
# copy_file 'record_test.rb', 'spec/models/record_test.rb'
|
721
|
-
#run 'rspec'
|
722
|
-
end
|
723
|
-
|
724
|
-
def install_capybara
|
725
|
-
say %Q{
|
726
|
-
We also want to write integration tests to test the end-result that
|
727
|
-
a user may see. We'll add the capybara gem to do that.
|
728
|
-
}, STATEMENT
|
729
|
-
gem_group :development, :test do
|
730
|
-
gem 'capybara'
|
731
|
-
end
|
732
|
-
run 'bundle install'
|
733
|
-
# inject_into_file 'spec/spec_helper.rb' do
|
734
|
-
# " require 'capybara/rails'\n"
|
735
|
-
# end
|
736
|
-
end
|
737
|
-
|
738
|
-
def an_integration_test
|
739
|
-
say %Q{
|
740
|
-
Here's a quick integration test that proves deposit works.
|
741
|
-
}, STATEMENT
|
742
|
-
copy_file 'integration_spec.rb', 'spec/integration/integration_spec.rb'
|
743
|
-
end
|
744
|
-
|
745
|
-
def run_tests_x3
|
746
|
-
say %Q{
|
747
|
-
Now that the integration spec is in place, when we try to run rspec,
|
748
|
-
we'll get a test failure because it can't connect to Fedora.
|
749
|
-
}, STATEMENT
|
750
|
-
run 'rspec'
|
751
|
-
end
|
752
|
-
|
753
|
-
def add_jettywrapper_ci_task
|
754
|
-
say %Q{
|
755
|
-
Instead, we need to add a new Rake task that knows how to wrap the
|
756
|
-
test suite -- start jetty before running the tests and stop jetty
|
757
|
-
at the end. We can use a feature provided by jettywrapper to do this.
|
758
|
-
}, STATEMENT
|
759
|
-
copy_file 'ci.rake', 'lib/tasks/ci.rake'
|
760
|
-
|
761
|
-
rake 'jetty:stop'
|
762
|
-
rake 'ci'
|
763
|
-
rake 'jetty:start'
|
764
|
-
end
|
765
|
-
|
766
|
-
def add_coverage_stats
|
767
|
-
say %Q{
|
768
|
-
Now that we have tests, we also want to have some coverage statistics.
|
769
|
-
}, STATEMENT
|
770
|
-
|
771
|
-
gem_group :development, :test do
|
772
|
-
gem 'simplecov'
|
773
|
-
end
|
774
|
-
|
775
|
-
run 'bundle install'
|
776
|
-
|
777
|
-
copy_file 'ci_with_coverage.rake', 'lib/tasks/ci.rake'
|
778
|
-
insert_into_file "spec/spec_helper.rb", :after => "ENV[\"RAILS_ENV\"] ||= 'test'\n"do
|
779
|
-
%Q{
|
780
|
-
if ENV['COVERAGE'] == "true"
|
781
|
-
require 'simplecov'
|
782
|
-
SimpleCov.start do
|
783
|
-
add_filter "config/"
|
784
|
-
add_filter "spec/"
|
785
|
-
end
|
786
|
-
end
|
787
|
-
}
|
788
|
-
end
|
789
|
-
|
790
|
-
rake 'jetty:stop'
|
791
|
-
rake 'ci'
|
792
|
-
rake 'jetty:start'
|
793
|
-
end
|
794
|
-
|
795
|
-
def coverage_prompt
|
796
|
-
say %Q{
|
797
|
-
Go take a look at the coverage report, open the file ./coverage/index.html
|
798
|
-
in your browser.
|
799
|
-
}, STATEMENT
|
800
|
-
continue_prompt
|
801
|
-
end
|
802
|
-
end
|
803
|
-
|
804
|
-
class SprinkeSomeStyling < Thor::Group
|
805
|
-
include Thor::Actions
|
806
|
-
include Rails::Generators::Actions
|
807
|
-
include TutorialActions
|
808
|
-
|
809
|
-
def self.source_paths
|
810
|
-
[File.join($base_templates_path, "sprinkle_some_styling")]
|
811
|
-
end
|
812
|
-
|
813
|
-
|
814
|
-
def fix_add_assets_links
|
815
|
-
say %Q{
|
816
|
-
We'll add a little styling to the Hydra app and add a link to add a new
|
817
|
-
Record in the header of the layout.
|
818
|
-
}, STATEMENT
|
819
|
-
copy_file "_add_assets_links.html.erb", "app/views/_add_assets_links.html.erb"
|
820
|
-
end
|
821
|
-
|
822
|
-
|
823
|
-
end
|
824
|
-
|
825
|
-
class AddCollections
|
826
|
-
def add_collection_model
|
827
|
-
|
828
|
-
end
|
829
|
-
|
830
|
-
def add_collection_controller
|
831
|
-
|
832
|
-
end
|
833
|
-
|
834
|
-
def add_collection_reference_to_record
|
835
|
-
|
836
|
-
end
|
837
|
-
end
|
838
|
-
|
839
|
-
class AddFileUpload < Thor::Group
|
840
|
-
include Thor::Actions
|
841
|
-
include Rails::Generators::Actions
|
842
|
-
include TutorialActions
|
843
|
-
|
844
|
-
def self.source_paths
|
845
|
-
[File.join($base_templates_path, "add_file_upload")]
|
846
|
-
end
|
847
|
-
|
848
|
-
def add_file_uploads
|
849
|
-
say %Q{
|
850
|
-
Now that we have a basic Hydra application working with metadata-only, we
|
851
|
-
want to enhance that with the ability to upload files. Let's add a new
|
852
|
-
datastream to our model.
|
853
|
-
}, STATEMENT
|
854
|
-
inject_into_class 'app/models/record.rb', 'Record' do
|
855
|
-
"has_file_datastream :name => 'content', :type => ActiveFedora::Datastream\n"
|
856
|
-
end
|
857
|
-
end
|
858
|
-
|
859
|
-
def add_file_upload_controller
|
860
|
-
say %Q{
|
861
|
-
And educate our controller for managing file objects.
|
862
|
-
}, STATEMENT
|
863
|
-
inject_into_class "app/controllers/records_controller.rb", "RecordsController" do
|
864
|
-
" include Hydra::Controller::UploadBehavior\n"
|
865
|
-
end
|
866
|
-
insert_into_file "app/controllers/records_controller.rb", :after => "apply_depositor_metadata(@record)\n" do
|
867
|
-
" @record.label = params[:record][:title] # this is a bad hack to work around an AF bug\n" +
|
868
|
-
" add_posted_blob_to_asset(@record, params[:filedata]) if params.has_key?(:filedata)\n"
|
869
|
-
end
|
870
|
-
end
|
871
|
-
|
872
|
-
def add_file_upload_ui
|
873
|
-
say %Q{
|
874
|
-
And add a file upload field on the form.
|
875
|
-
}, STATEMENT
|
876
|
-
copy_file "_form.html.erb", "app/views/records/_form.html.erb"
|
877
|
-
end
|
878
|
-
end
|
879
|
-
|
880
|
-
class AddTechnicalMetadata
|
881
|
-
def add_datastream_and_terminology
|
882
|
-
|
883
|
-
end
|
884
|
-
|
885
|
-
end
|
886
|
-
end
|
887
|
-
|
888
|
-
HydraOpenRepositoriesTutorialApp.start
|