diff --git a/comfortable_mexican_sofa.gemspec b/comfortable_mexican_sofa.gemspec index 0492d7665..6d6301ac7 100644 --- a/comfortable_mexican_sofa.gemspec +++ b/comfortable_mexican_sofa.gemspec @@ -26,7 +26,7 @@ Gem::Specification.new do |s| s.add_dependency "kramdown", ">= 1.0.0" s.add_dependency "mimemagic", ">= 0.3.2" s.add_dependency "mini_magick", ">= 4.8.0" - s.add_dependency "rails", ">= 5.2.0" + s.add_dependency "rails", ">= 5.2.0", "< 6.1" s.add_dependency "rails-i18n", ">= 5.0.0" s.add_dependency "sassc-rails", ">= 2.0.0" end diff --git a/lib/comfortable_mexican_sofa/content/renderer.rb b/lib/comfortable_mexican_sofa/content/renderer.rb index deb057798..e2f913cb1 100644 --- a/lib/comfortable_mexican_sofa/content/renderer.rb +++ b/lib/comfortable_mexican_sofa/content/renderer.rb @@ -42,15 +42,15 @@ def register_tag(name, klass) # @param [Comfy::Cms::WithFragments, nil] context def initialize(context) @context = context - @depth = 0 end # This is how we render content out. Takes context (cms page) and content # nodes # @param [Array] # @param [Boolean] allow_erb - def render(nodes, allow_erb = ComfortableMexicanSofa.config.allow_erb) - if (@depth += 1) > MAX_DEPTH + # @param [Integer] depth + def render(nodes, allow_erb = ComfortableMexicanSofa.config.allow_erb, depth = 0) + if depth > MAX_DEPTH raise Error, "Deep tag nesting or recursive nesting detected" end @@ -61,7 +61,7 @@ def render(nodes, allow_erb = ComfortableMexicanSofa.config.allow_erb) else tokens = tokenize(node.render) nodes = nodes(tokens) - render(nodes, allow_erb || node.allow_erb?) + render(nodes, allow_erb || node.allow_erb?, depth.next) end end.flatten.join end diff --git a/lib/comfortable_mexican_sofa/seeds/file/exporter.rb b/lib/comfortable_mexican_sofa/seeds/file/exporter.rb index 818b8440a..c0a1a4b89 100644 --- a/lib/comfortable_mexican_sofa/seeds/file/exporter.rb +++ b/lib/comfortable_mexican_sofa/seeds/file/exporter.rb @@ -15,9 +15,10 @@ def export! file_path = File.join(path, file.attachment.filename.to_s) # writing attributes - ::File.open(::File.join(path, "_#{file.attachment.filename}.yml"), "w") do |f| + ::File.open(::File.join(path, "#{'%07d' % file.id}.yml"), "w") do |f| f.write({ "label" => file.label, + "name" => file.attachment.filename.to_s, "description" => file.description, "categories" => file.categories.map(&:label) }.to_yaml) diff --git a/lib/comfortable_mexican_sofa/seeds/file/importer.rb b/lib/comfortable_mexican_sofa/seeds/file/importer.rb index 7b8aadacd..815b8d0f4 100644 --- a/lib/comfortable_mexican_sofa/seeds/file/importer.rb +++ b/lib/comfortable_mexican_sofa/seeds/file/importer.rb @@ -9,8 +9,12 @@ def initialize(from, to = from) end def import! - Dir["#{path}[^_]*"].each do |file_path| - filename = ::File.basename(file_path) + Dir["#{path}*.yml"].sort.each do |file_path| + yml_name = ::File.basename(file_path) + + attrs = YAML.safe_load(File.read(file_path)) + filename = attrs["name"] unless attrs.nil? + org_path = Pathname.new(path) + filename file = site.files.with_attached_attachment .where("active_storage_blobs.filename" => filename).references(:blob).first || @@ -19,11 +23,12 @@ def import! # We need to track actual file and its attributes fresh_file = false - if File.exist?(attrs_path = File.join(path, "_#{filename}.yml")) + if File.exist?(attrs_path = File.join(path, yml_name)) if fresh_seed?(file, attrs_path) fresh_file = true attrs = YAML.safe_load(File.read(attrs_path)) + attrs.delete("name") category_ids = category_names_to_ids(file, attrs.delete("categories")) file.attributes = attrs.merge( category_ids: category_ids @@ -31,10 +36,10 @@ def import! end end - if fresh_seed?(file, file_path) + if fresh_seed?(file, org_path) fresh_file = true - file_handler = File.open(file_path) + file_handler = File.open(org_path) file.file = { io: file_handler, filename: filename, @@ -44,7 +49,7 @@ def import! if fresh_file if file.save - message = "[CMS SEEDS] Imported File \t #{file_path}" + message = "[CMS SEEDS] Imported File \t #{org_path}" ComfortableMexicanSofa.logger.info(message) else message = "[CMS SEEDS] Failed to import File \n#{file.errors.inspect}" diff --git a/test/lib/content/renderer_test.rb b/test/lib/content/renderer_test.rb index 4b6012599..79400584e 100644 --- a/test/lib/content/renderer_test.rb +++ b/test/lib/content/renderer_test.rb @@ -276,4 +276,13 @@ def test_render_stack_overflow end end + def test_render_with_more_than_hundred_tags + test_string = + Array.new(ComfortableMexicanSofa::Content::Renderer::MAX_DEPTH) { "{{cms:text content}}" }.join(" ") + out = render_string(test_string) + expected = + Array.new(ComfortableMexicanSofa::Content::Renderer::MAX_DEPTH) { "content" }.join(" ") + assert_equal expected, out + end + end