diff --git a/Gemfile b/Gemfile index 15a1f2929..51e9f1491 100644 --- a/Gemfile +++ b/Gemfile @@ -8,6 +8,7 @@ group :development, :test do gem "autoprefixer-rails", "~> 8.1.0" gem "byebug", "~> 10.0.0", platforms: %i[mri mingw x64_mingw] gem "capybara", "~> 2.17.0" + gem "image_processing", ">= 1.2" gem "kaminari", "~> 1.1.1" gem "puma", "~> 3.12.2" gem "rubocop", "~> 0.55.0", require: false diff --git a/app/assets/javascripts/comfy/admin/cms/wysiwyg.js b/app/assets/javascripts/comfy/admin/cms/wysiwyg.js index 9990a6a4c..3a03d3d33 100644 --- a/app/assets/javascripts/comfy/admin/cms/wysiwyg.js +++ b/app/assets/javascripts/comfy/admin/cms/wysiwyg.js @@ -39,7 +39,14 @@ imageManagerJson, fileUpload, fileManagerJson, - definedLinks + definedLinks, + // allow unsafe tags and the like (prevent redactor stripping divs and other elements) + cleanOnEnter: false, + replaceTags: false, + removeComments: false, + removeNewLines: false, + deniedTags: [], + replaceDivs: false }; }; diff --git a/app/models/comfy/cms/file.rb b/app/models/comfy/cms/file.rb index 19b05ce45..96a9a5c28 100644 --- a/app/models/comfy/cms/file.rb +++ b/app/models/comfy/cms/file.rb @@ -30,6 +30,8 @@ class Comfy::Cms::File < ActiveRecord::Base after_save :process_attachment end + after_save :clear_page_content_cache + # -- Validations ------------------------------------------------------------- validates :label, presence: true validates :file, presence: true, on: :create @@ -41,6 +43,12 @@ class Comfy::Cms::File < ActiveRecord::Base where("active_storage_blobs.content_type LIKE 'image/%'").references(:blob) } +private + +def clear_page_content_cache + Comfy::Cms::Page.where(id: site.pages.pluck(:id)).update_all(content_cache: nil) +end + protected def assign_position @@ -56,7 +64,7 @@ def assign_label def process_attachment return if @file.blank? - attachment.attach(@file) + self.attachment = @file end end diff --git a/app/views/comfy/admin/cms/categories/_edit.html.haml b/app/views/comfy/admin/cms/categories/_edit.html.haml index 175dd9e97..04ffc7f39 100644 --- a/app/views/comfy/admin/cms/categories/_edit.html.haml +++ b/app/views/comfy/admin/cms/categories/_edit.html.haml @@ -1,5 +1,5 @@ - url = comfy_admin_cms_site_category_path(@site, category) -= form_with model: @category, scope: :category, url: url, html: {class: "edit-category", id: dom_id(category)} do |form| += form_with model: @category, scope: :category, url: url, html: {class: "edit-category", id: dom_id(category)}, local: false do |form| .input-group = form.text_field :label, class: "form-control form-control-sm", id: nil .input-group-btn diff --git a/app/views/comfy/admin/cms/categories/_index.html.haml b/app/views/comfy/admin/cms/categories/_index.html.haml index 60e9d3835..c37a5af46 100644 --- a/app/views/comfy/admin/cms/categories/_index.html.haml +++ b/app/views/comfy/admin/cms/categories/_index.html.haml @@ -16,7 +16,7 @@ = render "comfy/admin/cms/categories/show", category: category - url = comfy_admin_cms_site_categories_path(@site) - = form_with scope: :category, url: url, html: {id: "new-category"} do |form| + = form_with scope: :category, url: url, html: {id: "new-category"}, local: false do |form| = form.hidden_field :categorized_type, value: type .input-group = form.text_field :label, placeholder: t('.add_placeholder'), class: 'form-control form-control-sm', id: nil diff --git a/app/views/comfy/admin/cms/files/_file.html.haml b/app/views/comfy/admin/cms/files/_file.html.haml index 10b564ebe..785490010 100644 --- a/app/views/comfy/admin/cms/files/_file.html.haml +++ b/app/views/comfy/admin/cms/files/_file.html.haml @@ -1,7 +1,7 @@ %li{data: {id: file.id}} :ruby file_tag = cms_file_link_tag(file) - thumb_url = url_for(file.attachment.variant(combine_options: Comfy::Cms::File::VARIANT_SIZE[:thumb])) if file.attachment.variable? + thumb_url = url_for(file.attachment.variant(Comfy::Cms::File::VARIANT_SIZE[:thumb])) if file.attachment.variable? .row .col-md-5.item .item-controls.d-none.d-lg-block diff --git a/app/views/comfy/admin/cms/pages/_form.html.haml b/app/views/comfy/admin/cms/pages/_form.html.haml index 113d629ef..595e7ee96 100644 --- a/app/views/comfy/admin/cms/pages/_form.html.haml +++ b/app/views/comfy/admin/cms/pages/_form.html.haml @@ -26,6 +26,6 @@ = comfy_admin_partial "comfy/admin/cms/partials/page_form_after", form: form = form.form_actions do - = submit_tag t(".preview"), name: "preview", formtarget: "comfy-cms-preview", id: nil, class: "btn btn-secondary", data: {disable_with: false} - = submit_tag t(@page.new_record?? ".create" : ".update"), class: "btn btn-primary ml-sm-1", data: {disable_with: false} + = submit_tag t(".preview"), name: "preview", formtarget: "comfy-cms-preview", id: nil, class: "btn btn-secondary" + = submit_tag t(@page.new_record?? ".create" : ".update"), class: "btn btn-primary ml-sm-1" = link_to t(".cancel"), comfy_admin_cms_site_pages_path, class: "btn btn-link" diff --git a/comfortable_mexican_sofa.gemspec b/comfortable_mexican_sofa.gemspec index 0492d7665..f0670057e 100644 --- a/comfortable_mexican_sofa.gemspec +++ b/comfortable_mexican_sofa.gemspec @@ -22,6 +22,7 @@ Gem::Specification.new do |s| s.add_dependency "active_link_to", ">= 1.0.0" s.add_dependency "comfy_bootstrap_form", ">= 4.0.0" s.add_dependency "haml-rails", ">= 1.0.0" + s.add_dependency "image_processing", ">= 1.2" s.add_dependency "jquery-rails", ">= 4.3.1" s.add_dependency "kramdown", ">= 1.0.0" s.add_dependency "mimemagic", ">= 0.3.2" diff --git a/db/migrate/20210404223642_add_service_name_to_active_storage_blobs.active_storage.rb b/db/migrate/20210404223642_add_service_name_to_active_storage_blobs.active_storage.rb new file mode 100644 index 000000000..9967a1323 --- /dev/null +++ b/db/migrate/20210404223642_add_service_name_to_active_storage_blobs.active_storage.rb @@ -0,0 +1,18 @@ +# This migration comes from active_storage (originally 20190112182829) +class AddServiceNameToActiveStorageBlobs < ActiveRecord::Migration[6.0] + def up + unless column_exists?(:active_storage_blobs, :service_name) + add_column :active_storage_blobs, :service_name, :string + + if configured_service = ActiveStorage::Blob.service.name + ActiveStorage::Blob.unscoped.update_all(service_name: configured_service) + end + + change_column :active_storage_blobs, :service_name, :string, null: false + end + end + + def down + remove_column :active_storage_blobs, :service_name + end +end diff --git a/db/migrate/20210404223643_create_active_storage_variant_records.active_storage.rb b/db/migrate/20210404223643_create_active_storage_variant_records.active_storage.rb new file mode 100644 index 000000000..a2862695e --- /dev/null +++ b/db/migrate/20210404223643_create_active_storage_variant_records.active_storage.rb @@ -0,0 +1,12 @@ +# This migration comes from active_storage (originally 20191206030411) +class CreateActiveStorageVariantRecords < ActiveRecord::Migration[6.0] + def change + create_table :active_storage_variant_records do |t| + t.belongs_to :blob, null: false, index: false + t.string :variation_digest, null: false + + t.index %i[ blob_id variation_digest ], name: "index_active_storage_variant_records_uniqueness", unique: true + t.foreign_key :active_storage_blobs, column: :blob_id + end + end +end diff --git a/lib/comfortable_mexican_sofa/content/params_parser.rb b/lib/comfortable_mexican_sofa/content/params_parser.rb index 9caea01ec..8b47e1bb0 100644 --- a/lib/comfortable_mexican_sofa/content/params_parser.rb +++ b/lib/comfortable_mexican_sofa/content/params_parser.rb @@ -14,6 +14,7 @@ class Error < StandardError; end HASH_CLOSE = %r{\}} ARRAY_OPEN = %r{\[} ARRAY_CLOSE = %r{\]} + INTEGER = %r{\b[0-9]+\b}i # @param string def initialize(string = "") @@ -134,6 +135,7 @@ def tokenize(args_string) if (t = ss.scan(STRING_LITERAL)) then [:string, t[1...-1]] elsif (t = ss.scan(HASH_KEY)) then [:hash_key, t[0...-1]] elsif (t = ss.scan(IDENTIFIER)) then [:string, t] + elsif (t = ss.scan(INTEGER)) then [:string, t.to_i] elsif (t = ss.scan(HASH_OPEN)) then [:hash_open, t] elsif (t = ss.scan(HASH_CLOSE)) then [:hash_close, t] elsif (t = ss.scan(ARRAY_OPEN)) then [:array_open, t] diff --git a/lib/comfortable_mexican_sofa/routing.rb b/lib/comfortable_mexican_sofa/routing.rb index 56cd62466..2f700693a 100644 --- a/lib/comfortable_mexican_sofa/routing.rb +++ b/lib/comfortable_mexican_sofa/routing.rb @@ -6,7 +6,7 @@ class ActionDispatch::Routing::Mapper def comfy_route(identifier, options = {}) - send("comfy_route_#{identifier}", options) + send("comfy_route_#{identifier}", **options) end end diff --git a/test/lib/content/params_parser_test.rb b/test/lib/content/params_parser_test.rb index 0cf96b956..6eb0d693e 100644 --- a/test/lib/content/params_parser_test.rb +++ b/test/lib/content/params_parser_test.rb @@ -59,6 +59,18 @@ def test_tokenizer_with_arrays ], tokens end + def test_tokenizer_with_arrays_containing_numbers + tokens = PARSER.new.send(:tokenize, "arr: [1, 2, 3]") + assert_equal [ + [:hash_key, "arr"], + [:array_open, "["], + [:string, "1".to_i], + [:string, "2".to_i], + [:string, "3".to_i], + [:array_close, "]"] + ], tokens + end + def test_tokenizer_with_quoted_value tokens = PARSER.new.send(:tokenize, "key: ''") assert_equal [[:hash_key, "key"], [:string, ""]], tokens