From 5317eed25ebfb23c54fef8abb1a792bd810a7574 Mon Sep 17 00:00:00 2001 From: Fabian Rodriguez Date: Thu, 18 Jul 2024 09:28:45 +0200 Subject: [PATCH] Refactor indent filter, it now accepts a param indicating the number of spaces to indent the content. --- app/_includes/components/entity_example/format/admin-api.html | 2 +- app/_includes/components/entity_example/format/deck.html | 2 +- app/_includes/components/entity_example/format/konnect.html | 2 +- app/_plugins/filters/indent.rb | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/_includes/components/entity_example/format/admin-api.html b/app/_includes/components/entity_example/format/admin-api.html index 7eb112f0..82f9dcd0 100644 --- a/app/_includes/components/entity_example/format/admin-api.html +++ b/app/_includes/components/entity_example/format/admin-api.html @@ -3,6 +3,6 @@ --header "accept: application/json" \ --header "Content-Type: application/json" \ --data ' -{{ include.presenter.data | json_prettify | indent | indent }} +{{ include.presenter.data | json_prettify | indent: 4 }} ' {% endhighlight %} diff --git a/app/_includes/components/entity_example/format/deck.html b/app/_includes/components/entity_example/format/deck.html index e446a1d7..c346867b 100644 --- a/app/_includes/components/entity_example/format/deck.html +++ b/app/_includes/components/entity_example/format/deck.html @@ -2,5 +2,5 @@ _format_version: "3.0" {{ include.presenter.entity }}: - -{{ include.presenter.data | indent }} +{{ include.presenter.data | indent: 2 }} {% endhighlight %} diff --git a/app/_includes/components/entity_example/format/konnect.html b/app/_includes/components/entity_example/format/konnect.html index 7eb112f0..82f9dcd0 100644 --- a/app/_includes/components/entity_example/format/konnect.html +++ b/app/_includes/components/entity_example/format/konnect.html @@ -3,6 +3,6 @@ --header "accept: application/json" \ --header "Content-Type: application/json" \ --data ' -{{ include.presenter.data | json_prettify | indent | indent }} +{{ include.presenter.data | json_prettify | indent: 4 }} ' {% endhighlight %} diff --git a/app/_plugins/filters/indent.rb b/app/_plugins/filters/indent.rb index f642ae8d..6c2a02d0 100644 --- a/app/_plugins/filters/indent.rb +++ b/app/_plugins/filters/indent.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true module IndentFilter - def indent(input) + def indent(input, spaces) input .gsub("\n", '') .split("\n") - .map { |l| l.prepend(' ') } + .map { |l| l.prepend(' ' * spaces.to_i) } .join("\n") end end