forked from nbgallery/nbgallery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgallery.rb
executable file
·78 lines (70 loc) · 2.98 KB
/
gallery.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Make sure directories exist
if(!GalleryConfig.storage.database_notebooks)
%i[cache change_requests staging repo].each do |dir|
FileUtils.mkdir_p(GalleryConfig.directories[dir])
end
end
FileUtils.mkdir_p(Rails.root.join('app', 'assets', 'javascripts', 'custom'))
FileUtils.mkdir_p(Rails.root.join('app', 'assets', 'stylesheets', 'custom'))
FileUtils.mkdir_p(Rails.root.join('app', 'assets', 'images', 'custom_images'))
#Otherwise passing in any value other than "true" by environment varialbe still makes this evaluate to true
if GalleryConfig.storage.track_revisions || GalleryConfig.storage.track_revisions == "true"
GalleryConfig.storage.track_revisions = true
else
GalleryConfig.storage.track_revisions = false
end
# Load extensions
# Note: extension configs already loaded in application.rb
GalleryLib.extensions.each do |name, info|
Rails.logger.info("Loading extension: #{name}")
if Rails.env.development?
load info[:file]
else
require info[:file]
end
migrations = File.join(info[:dir], 'migrate')
if File.exist?(migrations) # rubocop: disable Style/Next
Rails.logger.debug(" Adding migrations for #{name}")
# This list is what rake looks at
ActiveRecord::Tasks::DatabaseTasks.migrations_paths.push(migrations)
# This list is what rails looks at
ActiveRecord::Migrator.migrations_paths.push(migrations)
end
end
# Create stubs for optional extension files
stubs = [
'app/views/application/_custom_upload_fields.slim',
'app/views/application/_custom_message_fields.slim',
'app/views/application/_custom_banner.slim',
'app/views/application/_custom_footer.slim',
'app/views/application/_custom_fields.slim',
'app/views/application/_custom_buttons.slim',
'app/views/application/_custom_links.slim',
'app/views/application/_custom_notebook_banner.slim',
'app/views/application/_custom_webtracking.slim',
'app/views/static_pages/_custom_overview_modal.slim',
'app/views/static_pages/_custom_home_search_fields.slim',
'app/views/application/_custom_change_request_approval_fields.slim',
'app/views/application/_custom_change_request_warning.slim',
'app/assets/stylesheets/custom/_custom_styles.scss',
'app/views/application/_custom_beta_link.slim',
'app/views/application/_custom_notebook_listing_label.slim',
'app/views/application/_custom_table_row_heading_label.slim',
'app/views/application/_custom_email_needs_to_be_simplified.slim',
]
stubs.each do |stub|
FileUtils.touch(Rails.root.join(stub).to_s) unless
File.exist?(Rails.root.join(stub).to_s)
end
# Allow tables in markdown
Rails::Html::WhiteListSanitizer.allowed_tags.merge(%w[table thead tbody tr th td])
# Set up git repository for notebooks
if defined?(Rails::Server) && GalleryConfig.storage.track_revisions && !GalleryConfig.storage.database_notebooks
begin
Git.open(GalleryConfig.directories.repo)
# success => repo already exists, nothing else to do
rescue StandardError
Rails.logger.info('Creating git repository for notebooks')
Revision.init
end
end