Skip to content

Commit

Permalink
Update customizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Kagemaru committed Nov 1, 2024
1 parent 98721b3 commit aeafd47
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ gem 'decidim-anonymous_codes', github: 'openpoke/decidim-module-anonymous_codes'
gem 'decidim-antivirus', github: 'mainio/decidim-module-antivirus', branch: 'release/0.27-stable'
gem 'decidim-decidim_awesome', github: 'decidim-ice/decidim-module-decidim_awesome'
gem 'decidim-jitsi_meetings', github: 'puzzle/decidim-module-jitsi-meetings', branch: DECIDIM_VERSION
gem 'decidim-participatory_documents', github: 'openpoke/decidim-module-participatory-documents', branch: 'main'
gem 'decidim-question_captcha', github: 'OpenSourcePolitics/decidim-module-question_captcha', branch: 'release/0.27-stable'
gem 'decidim-reporting_proposals', github: 'openpoke/decidim-module-reporting-proposals', branch: 'main'
gem 'decidim-participatory_documents', github: 'openpoke/decidim-module-participatory-documents', branch: 'main'
gem 'decidim-survey_multiple_answers', '~> 0.26.2'
gem 'decidim-term_customizer', github: 'mainio/decidim-module-term_customizer', branch: 'release/0.27-stable'

Expand Down
6 changes: 3 additions & 3 deletions config/initializers/clamby.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

Clamby.configure(
stream: true
)
return unless Object.const_defined?('Clamby')

Clamby.configure(stream: true)
66 changes: 55 additions & 11 deletions config/initializers/decidim_ocl_customization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,78 @@

require_relative '../../lib/customization_output'

includes = [
INCLUDES = [
[Decidim::DiffCell, DecidimOCL::DiffCell],
[Decidim::Proposals::ProposalMCell, DecidimOCL::Proposals::ProposalMCell],
[Decidim::ParticipatoryProcesses::ProcessMCell, DecidimOCL::ParticipatoryProcesses::ProcessMCell],
[Decidim::Comments::CommentActivityCell, DecidimOCL::Comments::CommentActivityCell],
[Decidim::Proposals::PublishProposalEvent, DecidimOCL::Proposals::PublishProposalEvent]
].each { |base, addition| base.include addition }
].freeze

prepends = [
PREPENDS = [
[Decidim::ApplicationMailer, DecidimOCL::ApplicationMailer],
[Decidim::Proposals::Admin::ProposalNoteCreatedEvent, DecidimOCL::Proposals::Admin::ProposalNoteCreatedEvent],
[Decidim::Forms::AnswerQuestionnaire, DecidimOCL::Forms::AnswerQuestionnaire],
[Decidim::Meetings::ContentBlocks::UpcomingMeetingsCell, DecidimOCL::Meetings::ContentBlocks::UpcomingMeetingsCell],
[Decidim::OrganizationLogoUploader, DecidimOCL::OrganizationLogoUploader],
[Decidim::ParticipatoryProcesses::ParticipatoryProcessHelper, DecidimOCL::ParticipatoryProcesses::ParticipatoryProcessHelper],
].each { |base, addition| base.prepend addition }
].freeze

override_path = Pathname.new('app/overrides')
Rails.autoloaders.main.ignore(override_path)
OVERRIDE_PATHS = ['app/overrides'].freeze

overrides = override_path.glob('**/*_override.rb')
Rails.application.config.after_initialize do
overrides.each do |override|
load override.expand_path.to_s
def load_customizations
ignored = ignore_override_paths(OVERRIDE_PATHS)

disabled = ENV.fetch('DISABLE_CUSTOMIZATION', '')
return if disabled.in? %w[true t 1]

disabled = disabled.split(',')

included = load_includes(INCLUDES, disabled)
prepended = load_prepends(PREPENDS, disabled)
overridden = load_overrides(ignored, disabled)

CustomizationOutput.puts_and_log(includes: included, prepends: prepended, overrides: overridden)
end

def load_includes(includes, disabled)
includes.each do |base, addition|
next if addition.in?(disabled)

base.include addition
end
end

CustomizationOutput.puts_and_log(includes: includes, prepends: prepends, overrides: overrides)
def load_prepends(prepends, disabled)
prepends.each do |base, addition|
next if addition.in?(disabled)

base.prepend addition
end
end

def ignore_override_paths(paths)
paths
.map { |p| Pathname.new(p) }
.each { |p| Rails.autoloaders.main.ignore(p) }
end

def load_overrides(paths, disabled)
paths =
paths
.map { |p| p.glob('**/*_override.rb') }
.flatten
.map { |p| p.expand_path.to_s }
.reject { |p| p.in? disabled }

Rails.application.config.after_initialize do
paths.each { |override| load override }
end

paths
end

load_customizations

# v Specially handled things (here be dragons) v

Expand Down
4 changes: 4 additions & 0 deletions config/initializers/decidim_questions.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# frozen_string_literal: true

return unless Object.const_defined?('Decidim::QuestionCaptcha')

Decidim::QuestionCaptcha.configure do |config|
config.questions = {
de: [
Expand Down
2 changes: 1 addition & 1 deletion lib/customization_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def self.puts_and_log(...)
end

def puts_and_log
return if ENV['CUSTOMIZATION_OUTPUT'].in? %w[false f 0]
return unless ENV['CUSTOMIZATION_OUTPUT'].in? %w[true t 1]

puts self # rubocop:disable Rails/Output
Rails.logger.info to_s
Expand Down

0 comments on commit aeafd47

Please sign in to comment.