From 9ad17cd9e5173fae1fce32186e1fd9ec2b5a0ddf Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Tue, 17 Sep 2024 11:21:59 +0400 Subject: [PATCH] Add command RENDER_FOOTNOTES_JSON --- lib/referator/footnotes.rb | 2 ++ lib/referator/machine.rb | 5 ++++ test.rb | 49 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/lib/referator/footnotes.rb b/lib/referator/footnotes.rb index 563bebe..f9ba220 100644 --- a/lib/referator/footnotes.rb +++ b/lib/referator/footnotes.rb @@ -44,6 +44,8 @@ module Referator config.formats.render_footnotes format, notes end + def render_footnotes_json = JSON.dump(notes).freeze + private def config=(config) diff --git a/lib/referator/machine.rb b/lib/referator/machine.rb index 885b920..9678be2 100644 --- a/lib/referator/machine.rb +++ b/lib/referator/machine.rb @@ -129,6 +129,11 @@ module Referator String @footnotes.render_footnotes command.data end + def do_render_footnotes_json(_command) + @config.freeze + @footnotes.render_footnotes_json + end + ######### # Utils # ######### diff --git a/test.rb b/test.rb index 3553a51..138823e 100755 --- a/test.rb +++ b/test.rb @@ -270,6 +270,55 @@ cmd :RENDER_FOOTNOTES, :json do |result| raise unless result == expected end +######################### +# RENDER_FOOTNOTES_JSON # +######################### + +cmd :RENDER_FOOTNOTES_JSON do |result| + expected = <<~JSON + { + "self": [ + { + "index": 1, + "category": "self", + "id": "/blog/foo", + "slug": "blog-foo", + "url": null, + "text": "Foo" + }, + { + "index": 2, + "category": "self", + "id": "/blog/bar", + "slug": "blog-bar", + "url": null, + "text": "Bar" + } + ], + "link": [ + { + "index": 3, + "category": "link", + "id": "example_com", + "slug": "example-com", + "url": "https://example.com", + "text": "Example Domain" + }, + { + "index": 4, + "category": "link", + "id": "causa_arcana_com", + "slug": "causa-arcana-com", + "url": "https://causa-arcana.com", + "text": "Causa Arcana" + } + ] + } + JSON + + raise unless JSON.parse(result) == JSON.parse(expected) +end + ######## # EXIT # ########