decidim-skin 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.erb_lint.yml +44 -0
- data/.gitignore +12 -0
- data/.gitlab-ci.yml +137 -0
- data/.rspec +1 -0
- data/.rubocop.yml +6 -0
- data/.ruby-version +1 -0
- data/.simplecov +24 -0
- data/Appraisals +28 -0
- data/CONTRIBUTING.md +77 -0
- data/Gemfile +46 -0
- data/Gemfile.lock +977 -0
- data/LICENSE.md +661 -0
- data/README.md +105 -0
- data/Rakefile +80 -0
- data/app/controllers/decidim/skin/homepage_controller.rb +25 -0
- data/app/overrides/add_component_dropdown_require.rb +21 -0
- data/app/overrides/admin_body_data_attributes.rb +27 -0
- data/app/overrides/admin_item_show_wrapper_data.rb +11 -0
- data/app/overrides/admin_static_page_space_help.rb +35 -0
- data/app/overrides/assemblies_form_processes_field.rb +12 -0
- data/app/overrides/breadcrumb_home_require.rb +55 -0
- data/app/overrides/conferences_form_related_spaces.rb +21 -0
- data/app/overrides/content_block_cell_space_require.rb +13 -0
- data/app/overrides/content_blocks_dropdown_space_require.rb +12 -0
- data/app/overrides/help_sections_space_require.rb +13 -0
- data/app/overrides/insert_hide_css.rb +19 -0
- data/app/overrides/public_body_data_attributes.rb +11 -0
- data/app/overrides/public_content_data.rb +11 -0
- data/app/overrides/search_filters_space_require.rb +14 -0
- data/app/overrides/search_resources_filter_block_space_require.rb +14 -0
- data/app/overrides/search_section_resource_type.rb +16 -0
- data/app/overrides/space_require_attributes.rb +106 -0
- data/app/overrides/statistic_require.rb +13 -0
- data/app/views/decidim/skin/deface_partials/_hide_css.html.erb +4 -0
- data/app/views/decidim/skin/deface_partials/_public_content.html.erb +10 -0
- data/bin/check +10 -0
- data/bin/ci-setup +65 -0
- data/bin/postversion +21 -0
- data/config/i18n-tasks.yml +17 -0
- data/config/locales/de.yml +45 -0
- data/config/locales/en.yml +45 -0
- data/config/locales/fr.yml +45 -0
- data/config/locales/it.yml +45 -0
- data/decidim-skin.gemspec +37 -0
- data/docker-compose.ci.yml +128 -0
- data/docker-compose.yml +53 -0
- data/gemfiles/.gitignore +1 -0
- data/gemfiles/decidim_0.29.gemfile +35 -0
- data/gemfiles/decidim_0.32.gemfile +35 -0
- data/lib/decidim/skin/admin/config_form.rb +135 -0
- data/lib/decidim/skin/body_data_attributes.rb +49 -0
- data/lib/decidim/skin/component_hide_css.rb +17 -0
- data/lib/decidim/skin/component_presence.rb +38 -0
- data/lib/decidim/skin/components.rb +114 -0
- data/lib/decidim/skin/disabled_state.rb +59 -0
- data/lib/decidim/skin/engine.rb +101 -0
- data/lib/decidim/skin/hide_css.rb +76 -0
- data/lib/decidim/skin/homepage_dispatcher.rb +64 -0
- data/lib/decidim/skin/homepage_options.rb +71 -0
- data/lib/decidim/skin/homepage_resolver.rb +67 -0
- data/lib/decidim/skin/layout_data_attributes.rb +48 -0
- data/lib/decidim/skin/migrate_from_space_page.rb +139 -0
- data/lib/decidim/skin/organization_extensions.rb +16 -0
- data/lib/decidim/skin/overrides/breadcrumb_helper.rb +36 -0
- data/lib/decidim/skin/overrides/layout_helper.rb +19 -0
- data/lib/decidim/skin/overrides/menu_item_presenter.rb +74 -0
- data/lib/decidim/skin/overrides/menu_presenter.rb +23 -0
- data/lib/decidim/skin/overrides/meta_tags_helper.rb +40 -0
- data/lib/decidim/skin/overrides/searches_controller.rb +36 -0
- data/lib/decidim/skin/participatory_spaces.rb +130 -0
- data/lib/decidim/skin/search_filters.rb +44 -0
- data/lib/decidim/skin/seeds.rb +363 -0
- data/lib/decidim/skin/settings_tab.rb +21 -0
- data/lib/decidim/skin/space_hide_css.rb +17 -0
- data/lib/decidim/skin/stored_config.rb +28 -0
- data/lib/decidim/skin/toggle_defaults.rb +36 -0
- data/lib/decidim/skin/ui_hides.rb +27 -0
- data/lib/decidim/skin/version.rb +14 -0
- data/lib/decidim/skin.rb +61 -0
- data/lib/tasks/decidim/skin/migrate_from_space_page.rake +14 -0
- data/package.json +23 -0
- data/requests/decidim/skin/homepage_controller_spec.rb +24 -0
- data/spec/decidim/skin/body_data_attributes_spec.rb +98 -0
- data/spec/decidim/skin/components_spec.rb +96 -0
- data/spec/decidim/skin/hide_css_spec.rb +110 -0
- data/spec/decidim/skin/homepage_dispatcher_spec.rb +34 -0
- data/spec/decidim/skin/homepage_options_spec.rb +42 -0
- data/spec/decidim/skin/homepage_resolver_spec.rb +73 -0
- data/spec/decidim/skin/layout_data_attributes_spec.rb +48 -0
- data/spec/decidim/skin/migrate_from_space_page_spec.rb +121 -0
- data/spec/decidim/skin/overrides/breadcrumb_helper_spec.rb +59 -0
- data/spec/decidim/skin/overrides/layout_helper_spec.rb +25 -0
- data/spec/decidim/skin/overrides/menu_item_presenter_spec.rb +77 -0
- data/spec/decidim/skin/overrides/menu_presenter_spec.rb +49 -0
- data/spec/decidim/skin/overrides/meta_tags_helper_spec.rb +108 -0
- data/spec/decidim/skin/participatory_spaces_spec.rb +83 -0
- data/spec/decidim/skin/search_filters_spec.rb +56 -0
- data/spec/decidim/skin/seeds_spec.rb +81 -0
- data/spec/decidim/skin/settings_tab_spec.rb +22 -0
- data/spec/decidim/skin.rb +3 -0
- data/spec/decidim_skin_overrides/space_require_spec.rb +25 -0
- data/spec/forms/decidim/skin/admin/config_form_spec.rb +160 -0
- data/spec/requests/decidim/skin/homepage_controller_spec.rb +33 -0
- data/spec/spec_helper.rb +36 -0
- data/spec/system/decidim/skin/admin_add_component_require_attributes_spec.rb +28 -0
- data/spec/system/decidim/skin/admin_assembly_form_require_attributes_spec.rb +24 -0
- data/spec/system/decidim/skin/admin_help_sections_space_require_spec.rb +27 -0
- data/spec/system/decidim/skin/admin_layout_data_attributes_spec.rb +60 -0
- data/spec/system/decidim/skin/admin_organization_homepage_menu_spec.rb +39 -0
- data/spec/system/decidim/skin/public_breadcrumb_spec.rb +82 -0
- data/spec/system/decidim/skin/public_layout_data_attributes_spec.rb +131 -0
- data/system/decidim/skin/homepage_controller_spec.rb +24 -0
- data/views/decidim/skin/system/_homepage_tab.html.erb +15 -0
- metadata +246 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Skin
|
|
5
|
+
# Builds [[label, value], ...] for the Skin homepage select.
|
|
6
|
+
# Touch when a new space type or process group should appear in that select.
|
|
7
|
+
class HomepageOptions
|
|
8
|
+
def self.for(organization)
|
|
9
|
+
new(organization).options
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def initialize(organization)
|
|
13
|
+
@organization = organization
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def options
|
|
17
|
+
[
|
|
18
|
+
[I18n.t("decidim_toggle.system.decidim_skin.homepage_organization"), ORGANIZATION_HOMEPAGE]
|
|
19
|
+
] + space_options
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
attr_reader :organization
|
|
25
|
+
|
|
26
|
+
def space_options
|
|
27
|
+
enabled_space_options + process_group_options
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def enabled_space_options
|
|
31
|
+
ParticipatorySpaces.manifests.flat_map do |manifest|
|
|
32
|
+
next [] unless ParticipatorySpaces.enabled?(organization, manifest.name)
|
|
33
|
+
|
|
34
|
+
options_for(manifest.model_class_name.constantize)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def options_for(model_class)
|
|
39
|
+
scope = model_class.where(organization:)
|
|
40
|
+
scope = scope.published if scope.respond_to?(:published)
|
|
41
|
+
|
|
42
|
+
scope.order(:id).map do |record|
|
|
43
|
+
label = "#{model_class.model_name.human} [#{record.slug}]"
|
|
44
|
+
[label, record.to_global_id.to_s]
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def process_group_options
|
|
49
|
+
return [] unless ParticipatorySpaces.enabled?(organization, "participatory_processes")
|
|
50
|
+
return [] unless Gem.loaded_specs.has_key?("decidim-participatory_processes")
|
|
51
|
+
|
|
52
|
+
grouped_process_options
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def grouped_process_options
|
|
56
|
+
Decidim::ParticipatoryProcessGroup.where(organization:).order(:id).map do |group|
|
|
57
|
+
title = translated_title(group.title)
|
|
58
|
+
label = "#{Decidim::ParticipatoryProcessGroup.model_name.human} [#{title.presence || group.id}]"
|
|
59
|
+
[label, group.to_global_id.to_s]
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def translated_title(title)
|
|
64
|
+
return title if title.is_a?(String)
|
|
65
|
+
return "" unless title.respond_to?(:[])
|
|
66
|
+
|
|
67
|
+
title[I18n.locale.to_s].presence || title["en"].presence || title.values.compact.first.to_s
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Skin
|
|
5
|
+
# Resolves the configured homepage target for an organization.
|
|
6
|
+
# Touch when a GID, unpublished record, or process group should fall back to org.
|
|
7
|
+
class HomepageResolver
|
|
8
|
+
# kind: :organization (record nil) or :space (record is the homepage target).
|
|
9
|
+
Result = Struct.new(:kind, :record, keyword_init: true) do
|
|
10
|
+
def organization?
|
|
11
|
+
kind == :organization
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def space?
|
|
15
|
+
kind == :space
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.call(organization)
|
|
20
|
+
new(organization).call
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def initialize(organization)
|
|
24
|
+
@organization = organization
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def call
|
|
28
|
+
value = Skin.homepage_value(organization)
|
|
29
|
+
return organization_result if value == ORGANIZATION_HOMEPAGE
|
|
30
|
+
|
|
31
|
+
record = find_record(value)
|
|
32
|
+
return organization_result unless record
|
|
33
|
+
return organization_result unless same_organization?(record)
|
|
34
|
+
return organization_result unless published?(record)
|
|
35
|
+
|
|
36
|
+
Result.new(kind: :space, record:)
|
|
37
|
+
rescue URI::GID::MissingModelIdError, ActiveRecord::RecordNotFound, NameError
|
|
38
|
+
organization_result
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
attr_reader :organization
|
|
44
|
+
|
|
45
|
+
def find_record(value)
|
|
46
|
+
GlobalID::Locator.locate(value)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def same_organization?(record)
|
|
50
|
+
return false unless record.respond_to?(:organization)
|
|
51
|
+
|
|
52
|
+
record.organization == organization
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def published?(record)
|
|
56
|
+
return true if record.is_a?(Decidim::ParticipatoryProcessGroup)
|
|
57
|
+
return true unless record.respond_to?(:published?)
|
|
58
|
+
|
|
59
|
+
record.published?
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def organization_result
|
|
63
|
+
Result.new(kind: :organization, record: nil)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Skin
|
|
5
|
+
# Attribute hashes for admin `.item_show__wrapper` and public `#content`.
|
|
6
|
+
# Touch when CSS authors need a new controller/action stamp on those wrappers.
|
|
7
|
+
module LayoutDataAttributes
|
|
8
|
+
module_function
|
|
9
|
+
|
|
10
|
+
# ponytail: no memo; ceiling is per-request string concat; upgrade: @memo[[controller, action]] ||= hash
|
|
11
|
+
def admin_wrapper(controller_name, action_name)
|
|
12
|
+
{ "data-content" => content_value(controller_name, action_name) }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def public_content(controller_name, action_name)
|
|
16
|
+
{ "data-controller" => controller_name.to_s }
|
|
17
|
+
.merge(action_attribute(action_name))
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def admin_deface_attributes
|
|
21
|
+
{
|
|
22
|
+
"data-content" =>
|
|
23
|
+
"<%= Decidim::Skin::LayoutDataAttributes.content_value(controller_name, action_name) %>"
|
|
24
|
+
}
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def public_deface_attributes
|
|
28
|
+
{ "data-controller" => "<%= controller_name %>" }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def content_value(controller_name, action_name)
|
|
32
|
+
return controller_name.to_s if index_action?(action_name)
|
|
33
|
+
|
|
34
|
+
"#{controller_name}_#{action_name}"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def action_attribute(action_name)
|
|
38
|
+
return {} if index_action?(action_name)
|
|
39
|
+
|
|
40
|
+
{ "data-action" => action_name.to_s }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def index_action?(action_name)
|
|
44
|
+
action_name.to_s == "index"
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Skin
|
|
5
|
+
# Copies Space Page org JSON into Toggle decidim_skin config.
|
|
6
|
+
# Touch when Space Page setting keys or Skin homepage values change.
|
|
7
|
+
class MigrateFromSpacePage
|
|
8
|
+
TABLE = "space_page_organization_settings"
|
|
9
|
+
SPACE_GEMS = {
|
|
10
|
+
"Decidim::Assembly" => "decidim-assemblies",
|
|
11
|
+
"Decidim::ParticipatoryProcess" => "decidim-participatory_processes",
|
|
12
|
+
"Decidim::Conference" => "decidim-conferences"
|
|
13
|
+
}.freeze
|
|
14
|
+
|
|
15
|
+
def self.call(**)
|
|
16
|
+
new(**).call
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def initialize(force: false, dry_run: false, rows: nil)
|
|
20
|
+
@force = force
|
|
21
|
+
@dry_run = dry_run
|
|
22
|
+
@rows = rows
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def call
|
|
26
|
+
return missing_table_result if read_from_table? && !table_exists?
|
|
27
|
+
|
|
28
|
+
counts = empty_counts
|
|
29
|
+
each_row { |organization, settings| process(organization, settings, counts) }
|
|
30
|
+
counts
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def payload_for(organization, settings)
|
|
34
|
+
{
|
|
35
|
+
"enabled" => enabled_from(settings),
|
|
36
|
+
"homepage" => homepage_for(organization, settings)
|
|
37
|
+
}
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private
|
|
41
|
+
|
|
42
|
+
attr_reader :force, :dry_run, :rows
|
|
43
|
+
|
|
44
|
+
def missing_table_result
|
|
45
|
+
empty_counts.merge(missing_table: true)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def empty_counts
|
|
49
|
+
{ migrated: 0, skipped: 0 }
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def read_from_table?
|
|
53
|
+
rows.nil?
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def table_exists?
|
|
57
|
+
ActiveRecord::Base.connection.table_exists?(TABLE)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def each_row
|
|
61
|
+
source_rows.each do |row|
|
|
62
|
+
organization = Decidim::Organization.find_by(id: row["decidim_organization_id"])
|
|
63
|
+
next unless organization
|
|
64
|
+
|
|
65
|
+
yield organization, parse_settings(row["space_page_settings"])
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def source_rows
|
|
70
|
+
return rows unless read_from_table?
|
|
71
|
+
|
|
72
|
+
ActiveRecord::Base.connection.select_all(
|
|
73
|
+
"SELECT decidim_organization_id, space_page_settings FROM #{TABLE}"
|
|
74
|
+
)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def parse_settings(raw)
|
|
78
|
+
return {} if raw.blank?
|
|
79
|
+
return raw.stringify_keys if raw.respond_to?(:stringify_keys)
|
|
80
|
+
|
|
81
|
+
JSON.parse(raw)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def process(organization, settings, counts)
|
|
85
|
+
if skip?(organization)
|
|
86
|
+
counts[:skipped] += 1
|
|
87
|
+
return
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
persist(organization, payload_for(organization, settings))
|
|
91
|
+
counts[:migrated] += 1
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def skip?(organization)
|
|
95
|
+
return false if force
|
|
96
|
+
|
|
97
|
+
StoredConfig.hash_for(organization, MODULE_NAME).present?
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def persist(organization, payload)
|
|
101
|
+
return if dry_run
|
|
102
|
+
|
|
103
|
+
Decidim::Toggle.save_config!(organization, MODULE_NAME, payload)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def enabled_from(settings)
|
|
107
|
+
flag = settings["enabled"]
|
|
108
|
+
return true if flag.nil?
|
|
109
|
+
|
|
110
|
+
ActiveModel::Type::Boolean.new.cast(flag)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def homepage_for(organization, settings)
|
|
114
|
+
skin = settings["skin"].to_s
|
|
115
|
+
return ORGANIZATION_HOMEPAGE if skin.blank? || skin == "Decidim::Organization"
|
|
116
|
+
|
|
117
|
+
space = first_space(organization, skin)
|
|
118
|
+
space&.to_global_id&.to_s.presence || ORGANIZATION_HOMEPAGE
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def first_space(organization, class_name)
|
|
122
|
+
return nil unless gem_loaded_for?(class_name)
|
|
123
|
+
|
|
124
|
+
scope = class_name.constantize.where(organization:)
|
|
125
|
+
scope = scope.published if scope.respond_to?(:published)
|
|
126
|
+
scope.order(:id).first
|
|
127
|
+
rescue NameError
|
|
128
|
+
nil
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def gem_loaded_for?(class_name)
|
|
132
|
+
gem_name = SPACE_GEMS[class_name]
|
|
133
|
+
return true if gem_name.blank?
|
|
134
|
+
|
|
135
|
+
Gem.loaded_specs.has_key?(gem_name)
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Skin
|
|
5
|
+
# Mixed into Organization: whether Skin should skip the org homepage.
|
|
6
|
+
# Touch when homepage? checks must match HomepageResolver (published GID).
|
|
7
|
+
module OrganizationExtensions
|
|
8
|
+
extend ActiveSupport::Concern
|
|
9
|
+
|
|
10
|
+
def skin_custom_homepage?
|
|
11
|
+
Decidim::Skin.custom_homepage?(self) &&
|
|
12
|
+
!Decidim::Skin::HomepageResolver.call(self).organization?
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Skin
|
|
5
|
+
module Overrides
|
|
6
|
+
# Public breadcrumb: drop the space trail on a Skin locale root.
|
|
7
|
+
# Touch when `/` or `/:locale` should not repeat the homepage space title.
|
|
8
|
+
module BreadcrumbHelper
|
|
9
|
+
def breadcrumb_items(context = :public)
|
|
10
|
+
items = super
|
|
11
|
+
return items unless hide_homepage_space_crumb?(context)
|
|
12
|
+
|
|
13
|
+
[]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def hide_homepage_space_crumb?(context)
|
|
19
|
+
return false unless context == :public
|
|
20
|
+
return false unless current_organization&.skin_custom_homepage?
|
|
21
|
+
|
|
22
|
+
skin_locale_root_path?
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def skin_locale_root_path?
|
|
26
|
+
path = request.path.to_s.chomp("/")
|
|
27
|
+
path.blank? || locale_root?(path)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def locale_root?(path)
|
|
31
|
+
I18n.available_locales.any? { |locale| path == "/#{locale}" }
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Skin
|
|
5
|
+
module Overrides
|
|
6
|
+
# View helpers that return wrapper data hashes for Deface or layout ERB.
|
|
7
|
+
# Touch when admin `.item_show__wrapper` or public `#content` stamps change.
|
|
8
|
+
module LayoutHelper
|
|
9
|
+
def skin_admin_wrapper_data
|
|
10
|
+
LayoutDataAttributes.admin_wrapper(controller_name, action_name)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def skin_public_content_data
|
|
14
|
+
LayoutDataAttributes.public_content(controller_name, action_name)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Skin
|
|
5
|
+
module Overrides
|
|
6
|
+
# Prepended onto MenuItemPresenter: stamps data-require-* and menu slugs on <li>.
|
|
7
|
+
# Touch when hide CSS misses a space nav item (do not Deface MenuPresenter).
|
|
8
|
+
module MenuItemPresenter
|
|
9
|
+
# rubocop:disable Style/OptionalBooleanParameter -- match ActionView::Helpers::TagHelper#content_tag
|
|
10
|
+
def content_tag(name, content_or_options = nil, options = nil, escape = true, &)
|
|
11
|
+
return @view.content_tag(name, li_options(content_or_options), options, escape, &) if name == :li && block_given?
|
|
12
|
+
|
|
13
|
+
@view.content_tag(name, content_or_options, options, escape, &)
|
|
14
|
+
end
|
|
15
|
+
# rubocop:enable Style/OptionalBooleanParameter
|
|
16
|
+
|
|
17
|
+
def li_options(options)
|
|
18
|
+
merged = (options || {}).merge(menu_stamp_data)
|
|
19
|
+
return merged unless skin_active?
|
|
20
|
+
|
|
21
|
+
merged.merge(require_data)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def require_data
|
|
25
|
+
ParticipatorySpaces.require_data(@menu_item.identifier).merge(homepage_require_data)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def skin_active?
|
|
29
|
+
return true if current_org.blank?
|
|
30
|
+
|
|
31
|
+
Decidim::Skin.enabled_for?(current_org)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def current_org
|
|
35
|
+
return unless @view.respond_to?(:current_organization)
|
|
36
|
+
|
|
37
|
+
@view.current_organization
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def homepage_require_data
|
|
41
|
+
return {} unless @menu_item.identifier.to_s == "edit_organization_homepage"
|
|
42
|
+
|
|
43
|
+
{ "data-require-organization-homepage" => "true" }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def menu_stamp_data
|
|
47
|
+
return {} unless stamp_admin_menu?
|
|
48
|
+
return {} if menu_item_slug.blank?
|
|
49
|
+
|
|
50
|
+
{ menu_stamp_key => menu_item_slug }
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def stamp_admin_menu?
|
|
54
|
+
@options.menu_name.to_s.include?("admin") || admin_controller?
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def admin_controller?
|
|
58
|
+
@view.controller.class.name.to_s.start_with?("Decidim::Admin")
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def menu_stamp_key
|
|
62
|
+
@options.menu_name.to_s == "admin_menu" ? "data-navbar" : "data-sidebar"
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def menu_item_slug
|
|
66
|
+
id = @menu_item.identifier.to_s
|
|
67
|
+
return id if id.present?
|
|
68
|
+
|
|
69
|
+
File.basename(@menu_item.url.to_s)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Skin
|
|
5
|
+
module Overrides
|
|
6
|
+
# Prepended onto MenuPresenter: passes menu name into each MenuItemPresenter.
|
|
7
|
+
# Touch when a new MenuPresenter subclass builds items without presented_items.
|
|
8
|
+
module MenuPresenter
|
|
9
|
+
def presented_items
|
|
10
|
+
@presented_items ||= items.map { |item| presented_item(item) }
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def presented_item(item)
|
|
14
|
+
Decidim::MenuItemPresenter.new(item, @view, item_options)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def item_options
|
|
18
|
+
@options.merge(menu_name: @name)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Skin
|
|
5
|
+
module Overrides
|
|
6
|
+
# Public <title> root: homepage space title instead of organization name.
|
|
7
|
+
# Touch when the browser title should follow a custom homepage space.
|
|
8
|
+
module MetaTagsHelper
|
|
9
|
+
def add_decidim_page_title(title)
|
|
10
|
+
return super if skip_title_root?
|
|
11
|
+
|
|
12
|
+
rooted = title_root(title)
|
|
13
|
+
return @decidim_page_title if rooted.to_s.strip == @decidim_page_title&.last.to_s.strip
|
|
14
|
+
|
|
15
|
+
super(rooted)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def skip_title_root?
|
|
21
|
+
!(respond_to?(:current_organization) && current_organization)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def title_root(title)
|
|
25
|
+
org_name = current_organization_name.to_s.strip
|
|
26
|
+
return title unless title.to_s.strip == org_name
|
|
27
|
+
|
|
28
|
+
space_title_root || title
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def space_title_root
|
|
32
|
+
result = ::Decidim::Skin::HomepageResolver.call(current_organization)
|
|
33
|
+
return unless result.space?
|
|
34
|
+
|
|
35
|
+
translated_attribute(result.record.title).to_s.strip.presence
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Skin
|
|
5
|
+
module Overrides
|
|
6
|
+
# Prepended onto SearchesController#index to drop disabled space/component hits.
|
|
7
|
+
# Touch when search still lists a hidden manifest.
|
|
8
|
+
module SearchesController
|
|
9
|
+
def index
|
|
10
|
+
return super unless Decidim::Skin.enabled_for?(current_organization)
|
|
11
|
+
|
|
12
|
+
filtered_index
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def filtered_index
|
|
16
|
+
Search.call(term, current_organization, filters, page_params) do
|
|
17
|
+
on(:ok) { |results| expose_filtered_results(results) }
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def expose_filtered_results(results)
|
|
22
|
+
results = SearchFilters.filter_results(results, current_organization)
|
|
23
|
+
results_count = results.sum { |results_by_type| results_by_type.last[:count] }
|
|
24
|
+
blocks = search_blocks(results)
|
|
25
|
+
expose(sections: results, blocks:, results_count:)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def search_blocks(results)
|
|
29
|
+
Decidim::Searchable.searchable_resources_by_type.map do |type|
|
|
30
|
+
results.select { |resource_type, _results| type.include?(resource_type) }
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|