Class: Atrium::AtriumGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/atrium/atrium_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object

Implement the required interface for Rails::Generators::Migration. taken from github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/generators/atrium/atrium_generator.rb', line 66

def self.next_migration_number(dirname)
  unless @previous_migration_nr
    if ActiveRecord::Base.timestamped_migrations
      @previous_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
    else
      @previous_migration_nr = "%.3d" % (current_migration_number(dirname) + 1).to_i
    end
  else
    @previous_migration_nr +=1
  end
  @previous_migration_nr.to_s
end

Instance Method Details

#add_mime_typesObject

Register mimetypes required by hydra-head



50
51
52
53
54
55
56
57
58
# File 'lib/generators/atrium/atrium_generator.rb', line 50

def add_mime_types
  puts "Updating Mime Types"
  insert_into_file "config/initializers/mime_types.rb", :before => 'Mime::Type.register_alias "text/plain", :refworks_marc_txt' do <<EOF
Mime::Type.register_alias "text/html", :textile
Mime::Type.register_alias "text/html", :inline

EOF
  end
end

#copy_migrationsObject

Setup the database migrations



125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/generators/atrium/atrium_generator.rb', line 125

def copy_migrations
  # Can't get this any more DRY, because we need this order.
  better_migration_template "create_atrium_collections.rb"
  better_migration_template "create_atrium_search_facets.rb"
  better_migration_template "create_atrium_exhibits.rb"
  better_migration_template "create_atrium_showcases.rb"
  better_migration_template "create_atrium_showcase_items.rb"
  better_migration_template "create_atrium_showcase_facet_selections.rb"
  better_migration_template "create_atrium_browse_levels.rb"
  better_migration_template "create_atrium_descriptions.rb"
  better_migration_template "create_atrium_essays.rb"
end

#copy_public_assetsObject

Copy all files in templates/public/ directory to public/ Call external generator in AssetsGenerator, so we can leave that callable seperately too.



45
46
47
# File 'lib/generators/atrium/atrium_generator.rb', line 45

def copy_public_assets
  generate "atrium:assets"
end

#create_configuration_filesObject

Config Files & Initializers

Copy all files in templates/config directory to host config



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/generators/atrium/atrium_generator.rb', line 28

def create_configuration_files
  # Role Mappings
  copy_file "config/role_map_cucumber.yml", "config/role_map_cucumber.yml"
  copy_file "config/role_map_development.yml", "config/role_map_development.yml"
  copy_file "config/role_map_production.yml", "config/role_map_production.yml"
  copy_file "config/role_map_test.yml", "config/role_map_test.yml"

  # Solr config
  copy_file "config/solr.yml", "config/solr.yml"

  # Themes
  copy_file "themes/example.html.erb", "app/views/layouts/atrium_themes/example.html.erb"
end

#inject_atrium_catalog_behaviorObject

Add Atrium behaviors and Filters to CatalogController



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/generators/atrium/atrium_generator.rb', line 90

def inject_atrium_catalog_behavior
  puts "Adding Atrium behaviors to CatalogController"
  controller_name = "catalog_controller"
  file_path = "app/controllers/#{controller_name.underscore}.rb"
  if File.exists?(file_path)
    insert_into_file file_path, :after => "require 'blacklight/catalog'" do
      "\nrequire 'atrium/catalog'"
    end
    insert_into_file file_path, :after => 'include Blacklight::Catalog' do
      "\n  # Extend Blacklight::Catalog with Atrium behaviors (primarily editing)." +
      "\n  include Atrium::Catalog"
    end
  else
    puts " \e[31mFailure\e[0m Could not find #{model_name.underscore}.rb. To add Atrium behaviors to your Blacklight::Catalog Controllers, you must include the Atrium::Controller module in the Controller class definition."
  end
end

#inject_atrium_controller_behaviorObject

Add Atrium to the application controller



108
109
110
111
112
113
# File 'lib/generators/atrium/atrium_generator.rb', line 108

def inject_atrium_controller_behavior
  inject_into_class "app/controllers/application_controller.rb", "ApplicationController" do
    "  # Adds Atrium behaviors into the application controller \n " +
    "  include Atrium::Controller\n\n"
  end
end

#inject_atrium_helper_behaviorObject

Add Atrium behaviors and Filters to ApplicationHelper



80
81
82
83
84
85
86
87
# File 'lib/generators/atrium/atrium_generator.rb', line 80

def inject_atrium_helper_behavior
  insert_into_file "app/helpers/application_helper.rb", :after => 'module ApplicationHelper' do
  "\n  # Adds a atrium collections behaviors into the application helper \n " +
    "  include Atrium::ApplicationHelper\n" +
    "  include Atrium::CollectionsHelper\n" +
    "  include CatalogHelper\n"
  end
end

#inject_atrium_routesObject

Inject call to Atrium.add_routes in config/routes.rb



116
117
118
119
120
121
122
# File 'lib/generators/atrium/atrium_generator.rb', line 116

def inject_atrium_routes
  puts "here"
  insert_into_file "config/routes.rb", :after => 'Blacklight.add_routes(self)' do
    "\n  # Add Atrium routes."
    "\n  Atrium.add_routes(self)"
  end
end