hydra-tutorial 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "hydra-tutorial"
3
- s.version = "0.0.2"
3
+ s.version = "0.0.3"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = ["Chris Beer"]
6
6
  s.email = ["hydra-tech@googlegroups.com"]
@@ -41,7 +41,8 @@ class HydraOpenRepositoriesTutorialApp < Thor::Group
41
41
 
42
42
  def rails_server url = '/'
43
43
  say %Q{
44
- We'll start the Rails server for you. It should be available in your browser at:
44
+ We'll start the Rails server for you. It should be available in
45
+ your browser at:
45
46
 
46
47
  http://localhost:3000#{url}
47
48
  }, STATEMENT
@@ -57,19 +58,24 @@ class HydraOpenRepositoriesTutorialApp < Thor::Group
57
58
 
58
59
  include TutorialActions
59
60
  class_option :quick, :default => false
61
+ class_option :git, :default => false
60
62
 
61
- def welcome
63
+ def setup_parameters
62
64
  $quick = options[:quick]
65
+ $git = options[:git]
66
+ end
67
+
68
+ def welcome
63
69
  say %Q{
64
- Welcome to this Hydra tutorial. We're going to step through building a working
65
- Hydra application. We'll build the application gradually, starting by building
66
- our "business logic", wiring in HTML views, and then connecting it to our
67
- Rails application.
68
-
69
- At several points in this tutorial, as we iteratively develop our files, you may
70
- be prompted to review conflicts between versions of files. It is safe to blindly
71
- accept the changes ('y'), however you may wish to view the diff ('d') to see the
72
- things we're change.
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.
73
79
  }, STATEMENT
74
80
 
75
81
  name = ask %Q{
@@ -87,8 +93,8 @@ class HydraOpenRepositoriesTutorialApp < Thor::Group
87
93
 
88
94
  if File.exists? $application_root
89
95
  say %Q{
90
- #{$application_root} already exists. Either remove it or provide a different
91
- application name.
96
+ #{$application_root} already exists. Either remove it or provide
97
+ a different application name.
92
98
  }, Thor::Shell::Color::RED
93
99
  exit
94
100
  end
@@ -96,7 +102,7 @@ class HydraOpenRepositoriesTutorialApp < Thor::Group
96
102
  say %Q{
97
103
  We'll generate a stub application #{$application_name} into the folder
98
104
  #{$application_root}. But, first, lets check your Ruby environment.
99
- }
105
+ }, STATEMENT
100
106
 
101
107
  end
102
108
 
@@ -140,6 +146,13 @@ class HydraOpenRepositoriesTutorialApp < Thor::Group
140
146
  end
141
147
  end
142
148
 
149
+
150
+ def sprinkle_some_styling
151
+ inside $application_root do
152
+ SprinkeSomeStyling.start
153
+ end
154
+ end
155
+
143
156
  def cleanup
144
157
  inside $application_root do
145
158
  Cleanup.start
@@ -154,7 +167,8 @@ class HydraOpenRepositoriesTutorialApp < Thor::Group
154
167
 
155
168
  def start_everything
156
169
  say %Q{
157
- This is the end of the tutorial. We'll give you a final chance to look at the web application.
170
+ This is the end of the tutorial. We'll give you a final chance to look
171
+ at the web application.
158
172
  }, STATEMENT
159
173
  rake 'jetty:stop'
160
174
  rake 'jetty:start'
@@ -187,16 +201,19 @@ class HydraOpenRepositoriesTutorialApp < Thor::Group
187
201
 
188
202
  if ruby_executable =~ /rvm/ or ruby_executable =~ /rbenv/ or ruby_executable =~ /home/ or ruby_Executable =~ /Users/
189
203
  say %Q{
190
- It looks like you're using rvm/rbenv/etc. (with a gemset?) We'll use this environment to build the application.
204
+ It looks like you're using rvm/rbenv/etc. (with a gemset?) We'll use
205
+ this environment to build the application.
191
206
  }, STATEMENT
192
207
 
193
208
  else
194
209
 
195
210
  say %Q{
196
- We checked, and it looks like you might be using a system-wide ruby. We suggest
197
- you use somethng like rvm [1], rbenv [2], etc to manage your ruby projects.
211
+ We checked, and it looks like you might be using a system-wide ruby.
212
+ We suggest you use somethng like rvm [1], rbenv [2], etc to manage
213
+ your ruby projects.
198
214
 
199
- You can continue and hope for the best, or go install one of these ruby managers, which may make your life easier.
215
+ You can continue and hope for the best, or go install one of these
216
+ ruby managers, which may make your life easier.
200
217
 
201
218
  [1] http://rvm.io/
202
219
  [2] https://github.com/sstephenson/rbenv/
@@ -210,7 +227,8 @@ class HydraOpenRepositoriesTutorialApp < Thor::Group
210
227
 
211
228
  def install_bundler_and_rails
212
229
  say %Q{
213
- We're going to install some prerequisite gems in order to create our skeleton Rails application.
230
+ We're going to install some prerequisite gems in order to create our
231
+ skeleton Rails application.
214
232
  }, STATEMENT
215
233
  run 'gem install bundler rails'
216
234
  end
@@ -226,8 +244,8 @@ class HydraOpenRepositoriesTutorialApp < Thor::Group
226
244
  def out_of_the_box
227
245
  return if $quick
228
246
  say %Q{
229
- Here's a chance to look around. You can see the structure of a Rails application.
230
- In particular, look at:
247
+ Here's a chance to look around. You can see the structure of
248
+ a Rails application. In particular, look at:
231
249
  ./app
232
250
  ./config
233
251
  ./lib
@@ -236,8 +254,8 @@ class HydraOpenRepositoriesTutorialApp < Thor::Group
236
254
 
237
255
 
238
256
  say %Q{
239
- If we launched the Rails application server, we can see the application running in the browser
240
- and you can see if everything is working.
257
+ If we launched the Rails application server, we can see the application
258
+ running in the browser and you can see if everything is working.
241
259
  }, STATEMENT
242
260
 
243
261
 
@@ -260,8 +278,9 @@ class HydraOpenRepositoriesTutorialApp < Thor::Group
260
278
  def adding_dependencies
261
279
 
262
280
  say %Q{
263
- Fedora runs as a Java servlet inside a container like Tomcat or Jetty. Hydra provides a bundled
264
- version of Fedora and Solr for testing and development.
281
+ Fedora runs as a Java servlet inside a container like Tomcat or Jetty.
282
+ Hydra provides a bundled version of Fedora and Solr for
283
+ testing and development.
265
284
  }, STATEMENT
266
285
 
267
286
  say %Q{
@@ -276,7 +295,8 @@ class HydraOpenRepositoriesTutorialApp < Thor::Group
276
295
 
277
296
  def jetty_configuration
278
297
  say %Q{
279
- We'll add some configuration yml files with information to connect to Solr and Fedora.
298
+ We'll add some configuration yml files with information to connect
299
+ to Solr and Fedora.
280
300
  }, STATEMENT
281
301
 
282
302
  copy_file 'solr.yml', 'config/solr.yml'
@@ -295,11 +315,12 @@ class HydraOpenRepositoriesTutorialApp < Thor::Group
295
315
  rake 'jetty:start'
296
316
 
297
317
  say %Q{
298
- Take a look around. Jetty should be running on port 8983. You can see the Fedora server at
318
+ Take a look around. Jetty should be running on port 8983. You can see
319
+ the Fedora server at:
299
320
 
300
321
  http://localhost:8983/fedora/
301
322
 
302
- And a Solr index at
323
+ And a Solr index at:
303
324
 
304
325
  http://localhost:8983/solr/development/admin/
305
326
  }, STATEMENT
@@ -326,9 +347,10 @@ class HydraOpenRepositoriesTutorialApp < Thor::Group
326
347
 
327
348
  def add_activefedora
328
349
  say %Q{
329
- The active-fedora gem provides a way to model Fedora objects within Ruby. It will help
330
- you create Ruby models for creating, updating and reading objects from Fedora using a
331
- domain-specific language (DSL) similar to the Rails' ActiveRecord.
350
+ The active-fedora gem provides a way to model Fedora objects within Ruby.
351
+ It will help you create Ruby models for creating, updating and reading
352
+ objects from Fedora using a domain-specific language (DSL) similar
353
+ to the Rails' ActiveRecord.
332
354
 
333
355
  The om gem provides mechanisms for mapping XML documents into Ruby.
334
356
 
@@ -357,31 +379,32 @@ class HydraOpenRepositoriesTutorialApp < Thor::Group
357
379
  def rails_console_tour
358
380
 
359
381
  say %Q{
360
- Now we'll give you a chance to look at the Record model. If you launch the
361
- Rails interactive console, we can create and manipulate our object:
382
+ Now we'll give you a chance to look at the Record model. If you
383
+ launch the Rails interactive console (`rails c`), we can create
384
+ and manipulate our object:
362
385
 
363
- ## CREATE
364
- > obj = Record.new
365
- # => #<Record:1571331701243443635 @pid="__DO_NOT_USE__" >
366
- > obj.descMetadata.content = 'e.g. <my_xml_content />'
367
- > obj.save
386
+ ## CREATE
387
+ > obj = Record.new
388
+ # => #<Record:1571331701243443635 @pid="__DO_NOT_USE__" >
389
+ > obj.descMetadata.content = 'e.g. <my_xml_content />'
390
+ > obj.save
368
391
 
369
- > obj.pid
370
- # => e.g. 'changeme:1'
392
+ > obj.pid
393
+ # => e.g. 'changeme:1'
371
394
 
372
- ## RETRIEVE
373
- > obj = Record.find('changeme:1')
374
- > ds = obj.descMetadata
375
- # => #<ActiveFedora::NokogiriDatastream:3283711306477137919 @pid="changeme:1" @dsid="descMetadata" @controlGroup="X" @dirty="false" @mimeType="text/xml" >
376
- > ds.content
377
- # => (should be the XML document you added before)
395
+ ## RETRIEVE
396
+ > obj = Record.find('changeme:1')
397
+ > ds = obj.descMetadata
398
+ # => #<ActiveFedora::NokogiriDatastream:3283711306477137919 ...>
399
+ > ds.content
400
+ # => (should be the XML document you added before)
378
401
 
379
- ## UPDATE
380
- # manipulating XML:
381
- > ds.ng_xml.xpath('//my_xml_content')
402
+ ## UPDATE
403
+ # manipulating XML:
404
+ > ds.ng_xml.xpath('//my_xml_content')
382
405
 
383
- ## DELETE
384
- > obj.delete
406
+ ## DELETE
407
+ > obj.delete
385
408
 
386
409
  }, STATEMENT
387
410
 
@@ -391,17 +414,17 @@ class HydraOpenRepositoriesTutorialApp < Thor::Group
391
414
 
392
415
  def enhance_model_with_contrieved_descmd
393
416
  say %Q{
394
- Instead of working with the Nokogiri XML document directly, we can use OM to
395
- make querying an XML document easier. We'll replace the previous Record with a
396
- OM-enabled document.
417
+ Instead of working with the Nokogiri XML document directly, we
418
+ can use OM to make querying an XML document easier. We'll replace the
419
+ previous Record with a OM-enabled document.
397
420
  }
398
421
  copy_file "basic_om_model.rb", "app/models/record.rb"
399
422
  end
400
423
 
401
424
  def testing_the_contrieved_descmd
402
425
  say %Q{
403
- If you launch the Rails interactive console, we can now create and manipulate our object
404
- using methods provided by OM.
426
+ If you launch the Rails interactive console, we can now create and
427
+ manipulate our object using methods provided by OM.
405
428
 
406
429
  > obj = Record.new
407
430
  > obj.descMetadata.title = "My object title"
@@ -415,7 +438,8 @@ class HydraOpenRepositoriesTutorialApp < Thor::Group
415
438
 
416
439
  def use_the_delegate_method
417
440
  say %Q{
418
- We can use the #delegate method to tell the model-object how to access these attributes.
441
+ We can use the #delegate method to tell the model-object how
442
+ to access these attributes.
419
443
 
420
444
  > obj = Record.new
421
445
  > obj.title = "My object title"
@@ -442,8 +466,8 @@ class HydraOpenRepositoriesTutorialApp < Thor::Group
442
466
  copy_file "mods_desc_metadata.rb", "app/models/mods_desc_metadata.rb"
443
467
 
444
468
  say %Q{
445
- If you launch the Rails interactive console, we can now create and manipulate our object
446
- using methods provided by OM.
469
+ If you launch the Rails interactive console, we can now create
470
+ and manipulate our object using methods provided by OM.
447
471
 
448
472
  > obj = Record.new
449
473
  > obj.title = "My object title"
@@ -467,20 +491,23 @@ class HydraOpenRepositoriesTutorialApp < Thor::Group
467
491
 
468
492
  def record_generator
469
493
  say %Q{
470
- Now that we've set up our model and successfully added content into Fedora, now we want to
471
- connect the model to a Rails web application.
494
+ Now that we've set up our model and successfully added content
495
+ into Fedora, now we want to connect the model to a Rails web application.
472
496
 
473
- We'll start by using the standard Rails generators to create a scaffold controller and views,
474
- which will give us a place to start working.
497
+ We'll start by using the standard Rails generators to create
498
+ a scaffold controller and views, which will give us a
499
+ place to start working.
475
500
  }, STATEMENT
476
501
 
477
502
  generate "scaffold_controller Record --no-helper --skip-test-framework"
478
503
  route "resources :records"
479
504
 
480
505
  say %Q{
481
- If you look in ./app/views/records, you can see a set of Rails ERB templates.
506
+ If you look in ./app/views/records, you can see a set of
507
+ Rails ERB templates.
482
508
 
483
- ./app/controlers/records_controller.rb contains the controller that ties the model to the views.
509
+ ./app/controlers/records_controller.rb contains the controller
510
+ that ties the model to the views.
484
511
  }, STATEMENT
485
512
 
486
513
  continue_prompt unless $quick
@@ -489,8 +516,8 @@ class HydraOpenRepositoriesTutorialApp < Thor::Group
489
516
  def add_new_form
490
517
 
491
518
  say %Q{
492
- The scaffold just provided the basic outline for an application, so we need to provide the guts for the
493
- web form. Here's a simple one:
519
+ The scaffold just provided the basic outline for an application, so
520
+ we need to provide the guts for the web form. Here's a simple one:
494
521
  }, STATEMENT
495
522
 
496
523
  copy_file "_form.html.erb", "app/views/records/_form.html.erb"
@@ -500,8 +527,10 @@ class HydraOpenRepositoriesTutorialApp < Thor::Group
500
527
  def check_it_out
501
528
 
502
529
  say %Q{
503
- If we start the Rails server, we should now be able to visit the records in the browser, create new records,
504
- and edit existing records. Start by creating a new record:
530
+ If we start the Rails server, we should now be able to visit the records
531
+ in the browser, create new records, and edit existing records.
532
+
533
+ Start by creating a new record:
505
534
  }, STATEMENT
506
535
 
507
536
  rails_server '/records/new' unless $quick
@@ -516,19 +545,29 @@ class HydraOpenRepositoriesTutorialApp < Thor::Group
516
545
 
517
546
  def add_gems
518
547
  say %Q{
519
- Thus far, we've been using component parts of the Hydra framework, but now we'll add in the whole framework so
520
- we can take advantage of common patterns that have emerged in the Hydra community, including search, gated discovery,
521
- etc.
548
+ Thus far, we've been using component parts of the Hydra framework, but
549
+ now we'll add in the whole framework so we can take advantage of common
550
+ patterns that have emerged in the Hydra community, including search,
551
+ gated discovery, etc.
522
552
 
523
553
  We'll add a few new gems:
524
554
 
525
555
  - blacklight provides a discovery interface on top of the Solr index
556
+
526
557
  - hydra-head provides a number of common Hydra patterns
527
- - devise is a standard Ruby gem for providing user-related functions, like registration, sign-in, etc.
558
+
559
+ - devise is a standard Ruby gem for providing user-related
560
+ functions, like registration, sign-in, etc.
528
561
 
529
562
  }, STATEMENT
530
- gem 'blacklight'
531
- gem 'hydra-head'
563
+
564
+ if $git
565
+ gem 'blacklight', :git => "git://github.com/projectblacklight/blacklight.git"
566
+ gem 'hydra-head', :git => "git://github.com/projecthydra/hydra-head.git"
567
+ else
568
+ gem 'blacklight'
569
+ gem 'hydra-head'
570
+ end
532
571
  gem 'devise'
533
572
 
534
573
  run 'bundle install'
@@ -537,8 +576,8 @@ class HydraOpenRepositoriesTutorialApp < Thor::Group
537
576
  def run_generators
538
577
 
539
578
  say %Q{
540
- These gems provide generators for adding basic views, styles, and override points into your application. We'll run these
541
- generators now.
579
+ These gems provide generators for adding basic views, styles, and override
580
+ points into your application. We'll run these generators now.
542
581
  }, STATEMENT
543
582
  run 'rm config/solr.yml' # avoid meaningless conflict
544
583
  generate 'blacklight', '--devise'
@@ -548,7 +587,8 @@ class HydraOpenRepositoriesTutorialApp < Thor::Group
548
587
 
549
588
  def db_migrate
550
589
  say %Q{
551
- Blacklight uses a SQL database for keeping track of user bookmarks, searches, etc. We'll run the migrations next:
590
+ Blacklight uses a SQL database for keeping track of user bookmarks,
591
+ searches, etc. We'll run the migrations next:
552
592
  }, STATEMENT
553
593
  rake 'db:migrate'
554
594
  rake 'db:test:prepare'
@@ -572,8 +612,8 @@ class HydraOpenRepositoriesTutorialApp < Thor::Group
572
612
  def do_it
573
613
 
574
614
  say %Q{
575
- We need to make a couple changes to our controller and model to make them fully-compliant objects by
576
- teaching them about access rights.
615
+ We need to make a couple changes to our controller and model to make
616
+ them fully-compliant objects by teaching them about access rights.
577
617
  }, STATEMENT
578
618
 
579
619
  inject_into_class "app/controllers/records_controller.rb", 'RecordsController' do
@@ -591,13 +631,23 @@ class HydraOpenRepositoriesTutorialApp < Thor::Group
591
631
  "
592
632
  end
593
633
 
634
+ say %Q{
635
+ We'll also update our controller to provide access controls on records.
636
+ }
637
+
638
+ inject_into_class "app/controllers/records_controller.rb", 'RecordsController' do
639
+ " include Hydra::AccessControlsEnforcement\n" +
640
+ " before_filter :enforce_access_controls\n"
641
+ end
642
+
594
643
  end
595
644
 
596
645
  def look_at_it
597
646
  say %Q{
598
- Blacklight and Hydra-Head have added some new functionality to the application. We can now look at a search interface
599
- (provided by Blacklight) and use gated discovery over our repository. By default, objects are only visible to their
600
- creator.
647
+ Blacklight and Hydra-Head have added some new functionality to the
648
+ application. We can now look at a search interface (provided
649
+ by Blacklight) and use gated discovery over our repository. By default,
650
+ objects are only visible to their creator.
601
651
 
602
652
  Create some new objects, and then check out the search catalog at:
603
653
 
@@ -644,11 +694,32 @@ class HydraOpenRepositoriesTutorialApp < Thor::Group
644
694
 
645
695
  end
646
696
 
647
- class AddFileAssets
697
+ class AddFileAssets < Thor::Group
698
+ include Thor::Actions
699
+ include Rails::Generators::Actions
700
+ include TutorialActions
701
+
702
+ def self.source_paths
703
+ [File.join($base_templates_path, "add_tests")]
704
+ end
705
+
648
706
 
649
707
  end
650
708
 
651
- class SprinkeSomeBootstrapCSS
709
+ class SprinkeSomeStyling < Thor::Group
710
+ include Thor::Actions
711
+ include Rails::Generators::Actions
712
+ include TutorialActions
713
+
714
+ def self.source_paths
715
+ [File.join($base_templates_path, "sprinkle_some_styling")]
716
+ end
717
+
718
+
719
+ def fix_add_assets_links
720
+ copy_file "_add_assets_links.html.erb", "app/views/_add_assets_links.html.erb"
721
+ end
722
+
652
723
 
653
724
  end
654
725
 
@@ -0,0 +1,8 @@
1
+ <div id="select-item-box">
2
+ <a class="add-new-asset" href="#">Add a New Asset</a>
3
+ <ul id="select-item-list">
4
+ <li>
5
+ <%= link_to 'Add a Record', new_record_path, :class => 'create_asset' %>
6
+ </li>
7
+ </ul>
8
+ </div>
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.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-10 00:00:00.000000000 Z
12
+ date: 2012-07-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -82,6 +82,7 @@ files:
82
82
  - or_templates/building_a_basic_rails_app/fedora.yml
83
83
  - or_templates/building_a_basic_rails_app/solr.yml
84
84
  - or_templates/records_controller.rb
85
+ - or_templates/sprinkle_some_styling/_add_assets_links.html.erb
85
86
  - or_templates/wiring_it_into_rails/_form.html.erb
86
87
  - or_templates/wiring_it_into_rails/show.html.erb
87
88
  - templates/application/dataset_hydra_mods_om.rb
@@ -108,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
109
  version: '0'
109
110
  segments:
110
111
  - 0
111
- hash: 920607215486974428
112
+ hash: -1217986211987918299
112
113
  required_rubygems_version: !ruby/object:Gem::Requirement
113
114
  none: false
114
115
  requirements:
@@ -117,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
118
  version: '0'
118
119
  segments:
119
120
  - 0
120
- hash: 920607215486974428
121
+ hash: -1217986211987918299
121
122
  requirements: []
122
123
  rubyforge_project:
123
124
  rubygems_version: 1.8.24