maglevcms 2.0.0 → 2.1.0
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 +4 -4
- data/app/frontend/editor/components/dynamic-form/dynamic-input.vue +1 -0
- data/app/frontend/editor/components/kit/simple-select.vue +9 -2
- data/app/frontend/editor/components/section-pane/block-list/new-block-button.vue +8 -2
- data/app/frontend/editor/components/section-pane/block-tree/new-nested-block-button.vue +8 -2
- data/app/models/concerns/maglev/translatable.rb +24 -4
- data/app/models/maglev/application_record.rb +10 -0
- data/app/models/maglev/page/search_concern.rb +1 -3
- data/app/models/maglev/site/locales_concern.rb +2 -16
- data/app/models/maglev/site.rb +4 -0
- data/app/services/maglev/fetch_section_screenshot_url.rb +12 -1
- data/app/services/maglev/fetch_style.rb +1 -1
- data/app/services/maglev/reset_section_content.rb +64 -0
- data/app/types/maglev/locales_type.rb +9 -0
- data/config/initializers/active_record_types.rb +5 -0
- data/config/initializers/migration_patches.rb +9 -0
- data/db/migrate/20200831101942_create_maglev_section_content.rb +4 -0
- data/db/migrate/20210819092740_switch_to_localized_page_fields.rb +8 -2
- data/db/migrate/20211008064437_add_locales_to_sites.rb +2 -0
- data/db/migrate/20211013210954_translate_section_content.rb +6 -2
- data/db/migrate/20211203224112_add_open_graph_tags_to_pages.rb +4 -0
- data/db/migrate/20220612092235_add_style_to_sites.rb +2 -0
- data/lib/commands/maglev/change_site_locales_command.rb +1 -1
- data/lib/commands/maglev/create_site_command.rb +1 -1
- data/lib/commands/maglev/sections/remove_command.rb +1 -1
- data/lib/commands/maglev/sections/rename_command.rb +6 -2
- data/lib/commands/maglev/sections/reset_command.rb +56 -0
- data/lib/maglev/version.rb +1 -1
- data/lib/maglev.rb +1 -1
- data/lib/tasks/maglev/vite.rake +8 -0
- data/lib/tasks/maglev_tasks.rake +0 -11
- metadata +6 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fb191e7d79b2c6224c1c5082034d56e19a065d75a42c8a967f88de2e30d1b3ee
|
|
4
|
+
data.tar.gz: bb2b968757017e6a7eae8935e71e05afffdd453646d8c4c2dbc26d0b819e11dd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 59e86e32d8a2ad174ebf6d0448b8fe953fc5bb7ecee259743efd3f382997e4b92baffa9d0bb5557c6e2f29fbe2c72153472226bec2c63e4db51e6a228cd952ab
|
|
7
|
+
data.tar.gz: 70ac8b82452c35e9c6acaac1cdc056b0f45ae5d439f86bcfa81a711bfa11f08efd7205a24a92b317988ace188fd6ac2584a576bb57a00ac20b73cc71978b596d
|
|
@@ -33,6 +33,7 @@ export default {
|
|
|
33
33
|
return []
|
|
34
34
|
},
|
|
35
35
|
},
|
|
36
|
+
i18nScope: { type: String, default: 'support.simpleSelect' },
|
|
36
37
|
},
|
|
37
38
|
computed: {
|
|
38
39
|
selectedOption: {
|
|
@@ -46,10 +47,16 @@ export default {
|
|
|
46
47
|
},
|
|
47
48
|
methods: {
|
|
48
49
|
getOptionLabel(option) {
|
|
49
|
-
|
|
50
|
+
const value = this.getOptionValue(option)
|
|
51
|
+
const i18nKey = `${this.i18nScope}.${this.name}_options.${value}`
|
|
52
|
+
const translatedLabel = this.$st(i18nKey)
|
|
53
|
+
|
|
54
|
+
if (!this.isBlank(translatedLabel)) return translatedLabel
|
|
55
|
+
|
|
56
|
+
return typeof option === 'string' ? option : option.label
|
|
50
57
|
},
|
|
51
58
|
getOptionValue(option) {
|
|
52
|
-
return typeof option === '
|
|
59
|
+
return (typeof option === 'string') ? option : option.value
|
|
53
60
|
},
|
|
54
61
|
},
|
|
55
62
|
}
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
<button
|
|
18
18
|
v-for="blockType in blockTypes"
|
|
19
19
|
:key="blockType.type"
|
|
20
|
-
class="mb-2 text-base text-gray-900 py-2 px-14 hover:bg-gray-100 transition-colors"
|
|
20
|
+
class="mb-2 text-base text-gray-900 py-2 px-14 hover:bg-gray-100 transition-colors text-left"
|
|
21
21
|
@click="addSectionBlockAndClose(blockType.type)"
|
|
22
22
|
>
|
|
23
|
-
{{ blockType
|
|
23
|
+
{{ blockTypeLabel(blockType) }}
|
|
24
24
|
</button>
|
|
25
25
|
</div>
|
|
26
26
|
</template>
|
|
@@ -56,6 +56,9 @@ export default {
|
|
|
56
56
|
)
|
|
57
57
|
else return this.currentSectionDefinition.blocks
|
|
58
58
|
},
|
|
59
|
+
currentBlockTypesI18nScope() {
|
|
60
|
+
return `${this.currentSectionI18nScope}.blocks.types`
|
|
61
|
+
}
|
|
59
62
|
},
|
|
60
63
|
methods: {
|
|
61
64
|
...mapActions(['addSectionBlock']),
|
|
@@ -63,6 +66,9 @@ export default {
|
|
|
63
66
|
this.addSectionBlock({ blockType })
|
|
64
67
|
this.$refs.dropdown.close()
|
|
65
68
|
},
|
|
69
|
+
blockTypeLabel(blockType) {
|
|
70
|
+
return this.$st(`${this.currentBlockTypesI18nScope}.${blockType.type}`) ?? blockType.name
|
|
71
|
+
}
|
|
66
72
|
},
|
|
67
73
|
}
|
|
68
74
|
</script>
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
<button
|
|
16
16
|
v-for="blockType in blockTypes"
|
|
17
17
|
:key="blockType.type"
|
|
18
|
-
class="mb-2 text-base text-gray-900 py-2 px-4 hover:bg-gray-100 transition-colors"
|
|
18
|
+
class="mb-2 text-base text-gray-900 py-2 px-4 hover:bg-gray-100 transition-colors text-left"
|
|
19
19
|
@click="addNestedSectionBlockAndClose(blockType.type)"
|
|
20
20
|
>
|
|
21
|
-
{{ blockType
|
|
21
|
+
{{ blockTypeLabel(blockType) }}
|
|
22
22
|
</button>
|
|
23
23
|
</div>
|
|
24
24
|
</template>
|
|
@@ -49,6 +49,9 @@ export default {
|
|
|
49
49
|
(block) => this.accept.indexOf(block.type) !== -1,
|
|
50
50
|
)
|
|
51
51
|
},
|
|
52
|
+
currentBlockTypesI18nScope() {
|
|
53
|
+
return `${this.currentSectionI18nScope}.blocks.types`
|
|
54
|
+
}
|
|
52
55
|
},
|
|
53
56
|
methods: {
|
|
54
57
|
...mapActions(['addSectionBlock']),
|
|
@@ -62,6 +65,9 @@ export default {
|
|
|
62
65
|
this.addSectionBlock({ blockType, parentId: this.parentId })
|
|
63
66
|
this.$refs.dropdown.close()
|
|
64
67
|
},
|
|
68
|
+
blockTypeLabel(blockType) {
|
|
69
|
+
return this.$st(`${this.currentBlockTypesI18nScope}.${blockType.type}`) ?? blockType.name
|
|
70
|
+
},
|
|
65
71
|
},
|
|
66
72
|
}
|
|
67
73
|
</script>
|
|
@@ -8,20 +8,38 @@ module Maglev
|
|
|
8
8
|
extend ActiveSupport::Concern
|
|
9
9
|
|
|
10
10
|
def translations_for(attr)
|
|
11
|
-
|
|
11
|
+
# With MySQL, there is no default value for JSON columns, so we need to check for nil
|
|
12
|
+
public_send("#{attr}_translations").presence || {}
|
|
12
13
|
end
|
|
13
14
|
|
|
14
15
|
def translate_attr_in(attr, locale, source_locale)
|
|
15
16
|
translations_for(attr)[locale.to_s] ||= translations_for(attr)[source_locale.to_s]
|
|
16
17
|
end
|
|
17
18
|
|
|
19
|
+
# rubocop:disable Metrics/BlockLength
|
|
18
20
|
class_methods do
|
|
19
21
|
def order_by_translated(attr, direction)
|
|
20
|
-
order(
|
|
22
|
+
order(translated_arel_attribute(attr, Maglev::I18n.current_locale) => direction)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def translated_arel_attribute(attr, locale)
|
|
26
|
+
return Arel.sql("#{attr}_translations->>'#{locale}'") unless mysql?
|
|
27
|
+
|
|
28
|
+
# MySQL and MariaDB JSON support 🤬🤬🤬
|
|
29
|
+
# Note: doesn't work with Rails 7.0.x
|
|
30
|
+
json_extract = Arel::Nodes::NamedFunction.new(
|
|
31
|
+
'json_extract',
|
|
32
|
+
[Arel::Nodes::SqlLiteral.new("#{attr}_translations"), Arel::Nodes.build_quoted("$.#{locale}")]
|
|
33
|
+
)
|
|
34
|
+
Arel::Nodes::NamedFunction.new('json_unquote', [json_extract])
|
|
21
35
|
end
|
|
22
36
|
|
|
23
37
|
def translates(*attributes, presence: false)
|
|
24
|
-
attributes.each
|
|
38
|
+
attributes.each do |attr|
|
|
39
|
+
# MariaDB doesn't support native JSON columns (longtext instead), we need to force it.
|
|
40
|
+
attribute("#{attr}_translations", :json) if respond_to?(:attribute)
|
|
41
|
+
setup_accessors(attr)
|
|
42
|
+
end
|
|
25
43
|
add_presence_validator(attributes) if presence
|
|
26
44
|
end
|
|
27
45
|
|
|
@@ -37,12 +55,14 @@ module Maglev
|
|
|
37
55
|
|
|
38
56
|
def setup_accessors(attr)
|
|
39
57
|
define_method("#{attr}=") do |value|
|
|
40
|
-
public_send("#{attr}_translations=",
|
|
58
|
+
public_send("#{attr}_translations=",
|
|
59
|
+
translations_for(attr).merge(Maglev::I18n.current_locale.to_s => value))
|
|
41
60
|
end
|
|
42
61
|
|
|
43
62
|
define_method(attr) { translations_for(attr)[Maglev::I18n.current_locale.to_s] }
|
|
44
63
|
define_method("default_#{attr}") { translations_for(attr)[Maglev::I18n.default_locale.to_s] }
|
|
45
64
|
end
|
|
46
65
|
end
|
|
66
|
+
# rubocop:enable Metrics/BlockLength
|
|
47
67
|
end
|
|
48
68
|
end
|
|
@@ -32,9 +32,7 @@ module Maglev::Page::SearchConcern
|
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
def search_title_node(locale)
|
|
35
|
-
|
|
36
|
-
arel_table[:title_translations],
|
|
37
|
-
Arel::Nodes.build_quoted(locale))
|
|
35
|
+
translated_arel_attribute(:title, locale)
|
|
38
36
|
end
|
|
39
37
|
end
|
|
40
38
|
end
|
|
@@ -5,12 +5,8 @@ module Maglev::Site::LocalesConcern
|
|
|
5
5
|
extend ActiveSupport::Concern
|
|
6
6
|
|
|
7
7
|
included do
|
|
8
|
-
##
|
|
9
|
-
|
|
10
|
-
serialize :locales, coder: LocalesSerializer
|
|
11
|
-
else
|
|
12
|
-
serialize :locales, LocalesSerializer
|
|
13
|
-
end
|
|
8
|
+
## custom column type ##
|
|
9
|
+
attribute :locales, :maglev_locales
|
|
14
10
|
|
|
15
11
|
## validation ##
|
|
16
12
|
validates :locales, 'maglev/collection': true, length: { minimum: 1 }
|
|
@@ -42,15 +38,5 @@ module Maglev::Site::LocalesConcern
|
|
|
42
38
|
end
|
|
43
39
|
end
|
|
44
40
|
end
|
|
45
|
-
|
|
46
|
-
class LocalesSerializer
|
|
47
|
-
def self.dump(array)
|
|
48
|
-
(array || []).map(&:as_json)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def self.load(array)
|
|
52
|
-
(array || []).map { |attributes| Maglev::Site::Locale.new(**attributes.symbolize_keys) }
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
41
|
end
|
|
56
42
|
# rubocop:enable Style/ClassAndModuleChildren
|
data/app/models/maglev/site.rb
CHANGED
|
@@ -8,7 +8,18 @@ module Maglev
|
|
|
8
8
|
argument :section
|
|
9
9
|
|
|
10
10
|
def call
|
|
11
|
-
fetch_section_screenshot_path.call(section: section) +
|
|
11
|
+
screenshot_path = fetch_section_screenshot_path.call(section: section) + query_string
|
|
12
|
+
asset_host ? URI.join(asset_host, screenshot_path).to_s : screenshot_path
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def asset_host
|
|
18
|
+
Rails.application.config.asset_host
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def query_string
|
|
22
|
+
"?#{section.screenshot_timestamp}"
|
|
12
23
|
end
|
|
13
24
|
end
|
|
14
25
|
end
|
|
@@ -31,7 +31,7 @@ module Maglev
|
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
def custom_value(setting)
|
|
34
|
-
value = site.style.find { |local_value| local_value['id'] == setting.id }
|
|
34
|
+
value = (site.style || []).find { |local_value| local_value['id'] == setting.id }
|
|
35
35
|
value && value['type'] == setting.type ? value['value'] : setting.default
|
|
36
36
|
end
|
|
37
37
|
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Maglev
|
|
4
|
+
# Reset the content of a section type across a site and its pages
|
|
5
|
+
class ResetSectionContent
|
|
6
|
+
include Injectable
|
|
7
|
+
|
|
8
|
+
argument :site
|
|
9
|
+
argument :theme
|
|
10
|
+
argument :type
|
|
11
|
+
|
|
12
|
+
def call
|
|
13
|
+
validate_section_type!
|
|
14
|
+
|
|
15
|
+
@count = 0
|
|
16
|
+
|
|
17
|
+
reset_content
|
|
18
|
+
|
|
19
|
+
@count
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def validate_section_type!
|
|
25
|
+
return if theme.sections.find(type)
|
|
26
|
+
|
|
27
|
+
raise Maglev::Errors::UnknownSection,
|
|
28
|
+
"Section type '#{type}' doesn't exist in the theme"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def reset_content
|
|
32
|
+
ActiveRecord::Base.transaction do
|
|
33
|
+
reset_resource_content(site)
|
|
34
|
+
site_pages.find_each do |page|
|
|
35
|
+
reset_resource_content(page)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def reset_resource_content(resource)
|
|
41
|
+
site.each_locale do
|
|
42
|
+
@count += reset_sections_content_of_type(resource.find_sections_by_type(type), type)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
resource.save!
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def reset_sections_content_of_type(sections, type)
|
|
49
|
+
return 0 if sections.blank?
|
|
50
|
+
|
|
51
|
+
sections.map do |section|
|
|
52
|
+
section.replace(build_default_content(type))
|
|
53
|
+
end.size
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def build_default_content(type)
|
|
57
|
+
theme.sections.find(type).build_default_content
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def site_pages
|
|
61
|
+
Maglev::Page
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -3,6 +3,8 @@ class CreateMaglevSectionContent < ActiveRecord::Migration[6.0]
|
|
|
3
3
|
change_table :maglev_sites do |t|
|
|
4
4
|
if t.respond_to? :jsonb
|
|
5
5
|
t.jsonb :sections, default: []
|
|
6
|
+
elsif mysql?
|
|
7
|
+
t.json :sections # MySQL doesn't support default values for json columns
|
|
6
8
|
else
|
|
7
9
|
t.json :sections, default: []
|
|
8
10
|
end
|
|
@@ -11,6 +13,8 @@ class CreateMaglevSectionContent < ActiveRecord::Migration[6.0]
|
|
|
11
13
|
change_table :maglev_pages do |t|
|
|
12
14
|
if t.respond_to? :jsonb
|
|
13
15
|
t.jsonb :sections, default: []
|
|
16
|
+
elsif mysql?
|
|
17
|
+
t.json :sections # MySQL doesn't support default values for json columns
|
|
14
18
|
else
|
|
15
19
|
t.json :sections, default: []
|
|
16
20
|
end
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
class SwitchToLocalizedPageFields < ActiveRecord::Migration[6.1]
|
|
2
2
|
def up
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
remove_column :maglev_pages, :title if column_exists?(:maglev_pages, :title)
|
|
4
|
+
remove_column :maglev_pages, :seo_title if column_exists?(:maglev_pages, :seo_title)
|
|
5
|
+
remove_column :maglev_pages, :meta_description if column_exists?(:maglev_pages, :meta_description)
|
|
6
|
+
|
|
5
7
|
change_table :maglev_pages do |t|
|
|
6
8
|
if t.respond_to? :jsonb
|
|
7
9
|
t.jsonb :title_translations, default: {}
|
|
8
10
|
t.jsonb :seo_title_translations, default: {}
|
|
9
11
|
t.jsonb :meta_description_translations, default: {}
|
|
12
|
+
elsif mysql?
|
|
13
|
+
t.json :title_translations
|
|
14
|
+
t.json :seo_title_translations
|
|
15
|
+
t.json :meta_description_translations
|
|
10
16
|
else
|
|
11
17
|
t.json :title_translations, default: {}
|
|
12
18
|
t.json :seo_title_translations, default: {}
|
|
@@ -3,6 +3,8 @@ class AddLocalesToSites < ActiveRecord::Migration[6.0]
|
|
|
3
3
|
change_table :maglev_sites do |t|
|
|
4
4
|
if t.respond_to? :jsonb
|
|
5
5
|
t.jsonb :locales, default: []
|
|
6
|
+
elsif mysql?
|
|
7
|
+
t.json :locales # MySQL doesn't support default values for json columns
|
|
6
8
|
else
|
|
7
9
|
t.json :locales, default: []
|
|
8
10
|
end
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
class TranslateSectionContent < ActiveRecord::Migration[6.0]
|
|
2
2
|
def change
|
|
3
|
-
remove_column :maglev_sites, :sections, :jsonb, default: []
|
|
4
|
-
remove_column :maglev_pages, :sections, :jsonb, default: []
|
|
3
|
+
remove_column :maglev_sites, :sections, :jsonb, default: [] if column_exists?(:maglev_sites, :sections)
|
|
4
|
+
remove_column :maglev_pages, :sections, :jsonb, default: [] if column_exists?(:maglev_pages, :sections)
|
|
5
5
|
|
|
6
6
|
change_table :maglev_sites do |t|
|
|
7
7
|
if t.respond_to? :jsonb
|
|
8
8
|
t.jsonb :sections_translations, default: {}
|
|
9
|
+
elsif mysql?
|
|
10
|
+
t.json :sections_translations # MySQL doesn't support default values for json columns
|
|
9
11
|
else
|
|
10
12
|
t.json :sections_translations, default: {}
|
|
11
13
|
end
|
|
@@ -14,6 +16,8 @@ class TranslateSectionContent < ActiveRecord::Migration[6.0]
|
|
|
14
16
|
change_table :maglev_pages do |t|
|
|
15
17
|
if t.respond_to? :jsonb
|
|
16
18
|
t.jsonb :sections_translations, default: {}
|
|
19
|
+
elsif mysql?
|
|
20
|
+
t.json :sections_translations # MySQL doesn't support default values for json columns
|
|
17
21
|
else
|
|
18
22
|
t.json :sections_translations, default: {}
|
|
19
23
|
end
|
|
@@ -5,6 +5,10 @@ class AddOpenGraphTagsToPages < ActiveRecord::Migration[6.0]
|
|
|
5
5
|
t.jsonb :og_title_translations, default: {}
|
|
6
6
|
t.jsonb :og_description_translations, default: {}
|
|
7
7
|
t.jsonb :og_image_url_translations, default: {}
|
|
8
|
+
elsif mysql?
|
|
9
|
+
t.json :og_title_translations
|
|
10
|
+
t.json :og_description_translations
|
|
11
|
+
t.json :og_image_url_translations
|
|
8
12
|
else
|
|
9
13
|
t.json :og_title_translations, default: {}
|
|
10
14
|
t.json :og_description_translations, default: {}
|
|
@@ -3,6 +3,8 @@ class AddStyleToSites < ActiveRecord::Migration[6.0]
|
|
|
3
3
|
change_table :maglev_sites do |t|
|
|
4
4
|
if t.respond_to? :jsonb
|
|
5
5
|
t.jsonb :style, default: []
|
|
6
|
+
elsif mysql?
|
|
7
|
+
t.json :style # MySQL doesn't support default values for json columns
|
|
6
8
|
else
|
|
7
9
|
t.json :style, default: []
|
|
8
10
|
end
|
|
@@ -6,7 +6,7 @@ module Maglev
|
|
|
6
6
|
class ChangeSiteLocalesCommand < Rails::Command::Base
|
|
7
7
|
desc 'change_site_locales [LOCALES]', 'Change site locales (format: label:prefix)'
|
|
8
8
|
|
|
9
|
-
def self.banner
|
|
9
|
+
def self.banner(_command = nil, *)
|
|
10
10
|
'bin/rails maglev:change_site_locales [label:prefix label2:prefix2 ...]'
|
|
11
11
|
end
|
|
12
12
|
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'rails'
|
|
4
|
+
|
|
3
5
|
module Maglev
|
|
4
6
|
module Sections
|
|
5
7
|
class RenameCommand < Rails::Command::Base
|
|
6
8
|
desc 'rename OLD_TYPE NEW_TYPE', 'Rename a section type across the site and its pages'
|
|
7
9
|
|
|
8
|
-
def self.banner
|
|
10
|
+
def self.banner(_command = nil, *)
|
|
9
11
|
'bin/rails maglev:sections:rename OLD_TYPE NEW_TYPE'
|
|
10
12
|
end
|
|
11
13
|
|
|
12
|
-
def perform(
|
|
14
|
+
def perform(*args)
|
|
13
15
|
require File.expand_path('config/environment', Rails.root)
|
|
14
16
|
|
|
17
|
+
old_type, new_type = args
|
|
18
|
+
|
|
15
19
|
site = fetch_site
|
|
16
20
|
theme = fetch_theme
|
|
17
21
|
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails'
|
|
4
|
+
|
|
5
|
+
module Maglev
|
|
6
|
+
module Sections
|
|
7
|
+
class ResetCommand < Rails::Command::Base
|
|
8
|
+
desc 'reset TYPE', 'Reset the content of a section type across the site and its pages'
|
|
9
|
+
|
|
10
|
+
def self.banner(_command = nil, *)
|
|
11
|
+
'bin/rails maglev:sections:reset TYPE'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def perform(type)
|
|
15
|
+
require File.expand_path('config/environment', Rails.root)
|
|
16
|
+
|
|
17
|
+
site = fetch_site
|
|
18
|
+
theme = fetch_theme
|
|
19
|
+
|
|
20
|
+
return if site.blank? || theme.blank?
|
|
21
|
+
|
|
22
|
+
count = Maglev::ResetSectionContent.call(
|
|
23
|
+
site: site,
|
|
24
|
+
theme: theme,
|
|
25
|
+
type: type
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
display_final_message(count, type)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def fetch_site
|
|
34
|
+
Maglev::Site.first.tap do |site|
|
|
35
|
+
say("[Error] You don't seem to have an existing site. 🤔", :red) unless site
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def fetch_theme
|
|
40
|
+
Maglev.local_themes&.first.tap do |theme|
|
|
41
|
+
say('[Error] No theme found. 🤔', :red) unless theme
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def display_final_message(count, type)
|
|
46
|
+
if count.zero?
|
|
47
|
+
say "No section of type '#{type}' found 🤔", :yellow
|
|
48
|
+
return
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
say "Successfully reset content of #{count} #{'section'.pluralize(count)} of type '#{type}' 🎉",
|
|
52
|
+
:green
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
data/lib/maglev/version.rb
CHANGED
data/lib/maglev.rb
CHANGED
|
@@ -29,7 +29,7 @@ module Maglev
|
|
|
29
29
|
c.uploader = :active_storage
|
|
30
30
|
c.site_publishable = false
|
|
31
31
|
c.preview_host = nil
|
|
32
|
-
c.asset_host = Rails.application.config.
|
|
32
|
+
c.asset_host = Rails.application.config.asset_host
|
|
33
33
|
c.ui_locale = nil
|
|
34
34
|
c.back_action = nil
|
|
35
35
|
c.services = {}
|
data/lib/tasks/maglev/vite.rake
CHANGED
|
@@ -58,5 +58,13 @@ namespace :maglev do
|
|
|
58
58
|
Maglev::Engine.vite_ruby.commands.print_info
|
|
59
59
|
end
|
|
60
60
|
end
|
|
61
|
+
|
|
62
|
+
desc "Copy the ViteRuby's public directory to the app's public directory"
|
|
63
|
+
task copy_public_dir: :environment do
|
|
64
|
+
output_dir_name = Maglev::Engine.vite_ruby.config.public_output_dir
|
|
65
|
+
source_path = Maglev::Engine.root.join('public', output_dir_name)
|
|
66
|
+
target_path = Rails.root.join('public')
|
|
67
|
+
FileUtils.cp_r(source_path, target_path)
|
|
68
|
+
end
|
|
61
69
|
end
|
|
62
70
|
end
|
data/lib/tasks/maglev_tasks.rake
CHANGED
|
@@ -6,17 +6,6 @@ def within_engine_folder(&block)
|
|
|
6
6
|
Dir.chdir(File.join(__dir__, '..', '..'), &block)
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
# Load all task files only if they haven't been loaded before
|
|
10
|
-
Dir[File.join(__dir__, 'maglev', '*.rake')].each do |file|
|
|
11
|
-
# Create a unique task loaded flag
|
|
12
|
-
task_name = File.basename(file, '.rake')
|
|
13
|
-
next if Rake::Task.task_defined?("maglev:#{task_name}:loaded")
|
|
14
|
-
|
|
15
|
-
load file
|
|
16
|
-
# Create a dummy task to mark this file as loaded
|
|
17
|
-
Rake::Task.define_task("maglev:#{task_name}:loaded")
|
|
18
|
-
end
|
|
19
|
-
|
|
20
9
|
unless ENV['VITE_RUBY_SKIP_ASSETS_PRECOMPILE_EXTENSION'] == 'true'
|
|
21
10
|
if Rake::Task.task_defined?('assets:precompile')
|
|
22
11
|
Rake::Task['assets:precompile'].enhance do |_task|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: maglevcms
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Didier Lafforgue
|
|
@@ -497,8 +497,10 @@ files:
|
|
|
497
497
|
- app/services/maglev/persist_section_screenshot.rb
|
|
498
498
|
- app/services/maglev/remove_section_type.rb
|
|
499
499
|
- app/services/maglev/rename_section_type.rb
|
|
500
|
+
- app/services/maglev/reset_section_content.rb
|
|
500
501
|
- app/services/maglev/search_pages.rb
|
|
501
502
|
- app/services/maglev/setup_pages.rb
|
|
503
|
+
- app/types/maglev/locales_type.rb
|
|
502
504
|
- app/validators/maglev/collection_validator.rb
|
|
503
505
|
- app/validators/maglev/presence_validator.rb
|
|
504
506
|
- app/views/layouts/maglev/admin/_header_actions.html.erb
|
|
@@ -527,8 +529,10 @@ files:
|
|
|
527
529
|
- app/views/maglev/settings/index.html.erb
|
|
528
530
|
- app/views/maglev/sitemap/index.xml.builder
|
|
529
531
|
- bin/vite
|
|
532
|
+
- config/initializers/active_record_types.rb
|
|
530
533
|
- config/initializers/filter_parameters_logging.rb
|
|
531
534
|
- config/initializers/kaminari.rb
|
|
535
|
+
- config/initializers/migration_patches.rb
|
|
532
536
|
- config/initializers/zeitwerk.rb
|
|
533
537
|
- config/locales/activerecord.ar.yml
|
|
534
538
|
- config/locales/activerecord.en.yml
|
|
@@ -555,6 +559,7 @@ files:
|
|
|
555
559
|
- lib/commands/maglev/create_site_command.rb
|
|
556
560
|
- lib/commands/maglev/sections/remove_command.rb
|
|
557
561
|
- lib/commands/maglev/sections/rename_command.rb
|
|
562
|
+
- lib/commands/maglev/sections/reset_command.rb
|
|
558
563
|
- lib/generators/maglev/install_generator.rb
|
|
559
564
|
- lib/generators/maglev/section_generator.rb
|
|
560
565
|
- lib/generators/maglev/templates/install/config/initializers/maglev.rb
|