Skip to content

Commit 22bc520

Browse files
authored
Merge pull request #1946 from codidact/0valt/1941/community-assets-settings
Make community assets paths configurable
2 parents 199b630 + 3f05dea commit 22bc520

31 files changed

+305
-193
lines changed

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ AllCops:
77
TargetRubyVersion: 3.1
88
Exclude:
99
- 'config/**/*'
10-
- 'db/**/*'
10+
- 'db/schema.rb'
1111
- 'scripts/**/*'
1212
- 'bin/**/*'
1313
- 'lib/namespaced_env_cache.rb'

app/assets/javascripts/site_settings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ $(() => {
55
const settingEditFields = {
66
'array': $(`<select class="form-element js-setting-edit" multiple></select>`),
77
'string': $(`<input type="text" class="form-element js-setting-edit" />`),
8+
'uri_path': $(`<input type="text" class="form-element js-setting-edit" />`),
89
'integer': $('<input type="number" class="form-element js-setting-edit" />'),
910
'float': $('<input type="number" step="0.0001" class="form-element js-setting-edit" />'),
1011
'boolean': $(`<select class="form-element js-setting-edit">

app/helpers/seeds_helper.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,24 @@ def self.prioritize(types, files)
3434
(priority.index(a.second) || 999) <=> (priority.index(b.second) || 999)
3535
end.to_h
3636
end
37+
38+
Stats = Struct.new('Stats', :created, :updated, :errored, :skipped) do |struct|
39+
struct.members.each do |member|
40+
define_method "add_#{member}" do |num|
41+
self[member] += num
42+
end
43+
end
44+
45+
def <<(other)
46+
members.each do |member|
47+
send("add_#{member}", other[member])
48+
end
49+
end
50+
51+
def print
52+
members.map { |m| self[m]&.positive? ? "#{m} #{self[m]}" : nil }
53+
.compact
54+
.join(', ')
55+
end
56+
end
3757
end

app/models/site_setting.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def global?
5151
end
5252

5353
# Defines predicates for each value type
54-
[:array, :boolean, :float, :integer, :string, :text].each do |method|
54+
[:array, :boolean, :float, :integer, :string, :text, :uri_path].each do |method|
5555
define_method "#{method}?" do
5656
value_type.downcase.to_sym == method
5757
end

app/views/layouts/_head.html.erb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
<%= page_title %>
1212
</title>
1313

14-
<% icon_path = SiteSetting['IconPath'] %>
14+
<%
15+
css_path = SiteSetting['CSSPath']
16+
icon_path = SiteSetting['IconPath']
17+
js_path = SiteSetting['JSPath']
18+
%>
19+
1520
<link rel="icon" href="<%= icon_path.present? ? icon_path : '/assets/favicon.ico' %>" />
1621
<link rel="search"
1722
type="application/opensearchdescription+xml"
@@ -23,7 +28,9 @@
2328
<%= stylesheet_link_tag "https://cdn.jsdelivr.net/npm/@fortawesome/[email protected]/css/all.min.css" %>
2429
<%= stylesheet_link_tag "https://cdn.jsdelivr.net/npm/@codidact/co-design@latest/dist/codidact.css" %>
2530
<%= stylesheet_link_tag "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css" %>
26-
<%= stylesheet_link_tag "/assets/community/#{@community.host.split('.')[0]}.css" %>
31+
<% if css_path.present? %>
32+
<%= stylesheet_link_tag css_path %>
33+
<% end %>
2734
<%= stylesheet_link_tag 'application', media: 'all' %>
2835

2936
<%= javascript_include_tag "https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js" %>
@@ -33,7 +40,9 @@
3340
<%= javascript_include_tag "https://js.stripe.com/v3/" %>
3441
<% end %>
3542
<%= javascript_include_tag "https://cdn.jsdelivr.net/npm/[email protected]/dist/purify.min.js" %>
36-
<%= javascript_include_tag "/assets/community/#{@community.host.split('.')[0]}.js" %>
43+
<% if js_path.present? %>
44+
<%= javascript_include_tag js_path %>
45+
<% end %>
3746
<%= javascript_include_tag 'application' %>
3847
<script src="https://cdn.jsdelivr.net/npm/@codidact/co-design@latest/js/co-design.js" defer></script>
3948

config/routes.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,4 @@
403403
scope 'network' do
404404
root to: 'fake_community#communities', as: :fc_communities
405405
end
406-
407-
# Communities can have custom js or css defined (placed in public/assets/community).
408-
# If these are not defined for a community, respond with 204 (ok but empty)
409-
get '/assets/community/*path', to: ->(env) { [204, {}, ['']] }
410406
end

db/migrate/20160424111225_devise_create_users.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ class DeviseCreateUsers < ActiveRecord::Migration
22
def change
33
create_table :users do |t|
44
## Database authenticatable
5-
t.string :email, null: false, default: ""
6-
t.string :encrypted_password, null: false, default: ""
5+
t.string :email, null: false, default: ''
6+
t.string :encrypted_password, null: false, default: ''
77

88
## Recoverable
99
t.string :reset_password_token
@@ -30,7 +30,6 @@ def change
3030
# t.string :unlock_token # Only if unlock strategy is :email or :both
3131
# t.datetime :locked_at
3232

33-
3433
t.timestamps null: false
3534
end
3635

db/migrate/20160501095155_create_comments.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
class CreateComments < ActiveRecord::Migration
22
def change
33
create_table :comments do |t|
4-
54
t.timestamps null: false
65
end
76
end

db/migrate/20191205135001_create_active_storage_tables.active_storage.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def change
1010
t.string :checksum, null: false
1111
t.datetime :created_at, null: false
1212

13-
t.index [ :key ], unique: true
13+
t.index [:key], unique: true
1414
end
1515

1616
create_table :active_storage_attachments do |t|
@@ -20,7 +20,9 @@ def change
2020

2121
t.datetime :created_at, null: false
2222

23-
t.index [ :record_type, :record_id, :name, :blob_id ], name: "index_active_storage_attachments_uniqueness", unique: true
23+
t.index [:record_type, :record_id, :name, :blob_id],
24+
name: 'index_active_storage_attachments_uniqueness',
25+
unique: true
2426
t.foreign_key :active_storage_blobs, column: :blob_id
2527
end
2628
end
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
class AddCategoryToSiteSettings < ActiveRecord::Migration[5.2]
2-
def change
3-
add_column :site_settings, :category, :string
4-
add_index :site_settings, :category
5-
end
6-
end
1+
class AddCategoryToSiteSettings < ActiveRecord::Migration[5.2]
2+
def change
3+
add_column :site_settings, :category, :string
4+
add_index :site_settings, :category
5+
end
6+
end

0 commit comments

Comments
 (0)