Class: Blacklight::Marc::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/blacklight/marc/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_marc_extension_to_solrdocumentObject

add MARC-specific extensions to the solr document



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/generators/blacklight/marc/install_generator.rb', line 36

def add_marc_extension_to_solrdocument

  insert_into_file "app/models/solr_document.rb", :after => "include Blacklight::Solr::Document" do <<EOF

  # The following shows how to setup this blacklight document to display marc documents
  extension_parameters[:marc_source_field] = :marc_ss
  extension_parameters[:marc_format_type] = :marcxml
  use_extension(Blacklight::Marc::DocumentExtension) do |document|
document.key?(SolrDocument.extension_parameters[:marc_source_field])
  end

  field_semantics.merge!(
                     :title => "title_ssm",
                     :author => "author_ssm",
                     :language => "language_ssim",
                     :format => "format"
                     )

EOF
  end
end

#assetsObject



18
19
20
21
22
23
24
25
# File 'lib/generators/blacklight/marc/install_generator.rb', line 18

def assets
  insert_into_file "app/assets/stylesheets/blacklight.scss", after: "@import 'blacklight/blacklight';" do
<<-EOF

@import 'blacklight_marc';
EOF
  end
end

#create_configuration_filesObject

Copy all files in templates/config directory to host config



28
29
30
# File 'lib/generators/blacklight/marc/install_generator.rb', line 28

def create_configuration_files
  directory("config/translation_maps")
end

#create_modelsObject



32
33
34
# File 'lib/generators/blacklight/marc/install_generator.rb', line 32

def create_models
  copy_file "app/models/marc_indexer.rb", "app/models/marc_indexer.rb"
end

#inject_blacklight_controller_behaviorObject

Add MARC behaviors to the catalog controller



59
60
61
62
63
# File 'lib/generators/blacklight/marc/install_generator.rb', line 59

def inject_blacklight_controller_behavior
  inject_into_file "app/controllers/catalog_controller.rb", after:"include Blacklight::Catalog" do
    "\n  include Blacklight::Marc::Catalog\n"
  end
end

#inject_blacklight_marc_routesObject



66
67
68
69
70
71
72
73
74
75
# File 'lib/generators/blacklight/marc/install_generator.rb', line 66

def inject_blacklight_marc_routes
  route <<-EOF
  concern :marc_viewable, Blacklight::Marc::Routes::MarcViewable.new
  EOF

  inject_into_file "config/routes.rb", after: "resources :solr_documents, only: [:show], path: '/catalog', controller: 'catalog' do" do
    "\n    concerns [:exportable, :marc_viewable]\nINJECT_FLAG"
  end
  gsub_file "config/routes.rb", /[\n]INJECT_FLAG\s+concerns \:exportable/,""
end