Add command RENDER_FOOTNOTES_JSON

This commit is contained in:
Alex Kotov 2024-09-17 11:21:59 +04:00
parent 4f5feacb12
commit 9ad17cd9e5
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
3 changed files with 56 additions and 0 deletions

View file

@ -44,6 +44,8 @@ module Referator
config.formats.render_footnotes format, notes config.formats.render_footnotes format, notes
end end
def render_footnotes_json = JSON.dump(notes).freeze
private private
def config=(config) def config=(config)

View file

@ -129,6 +129,11 @@ module Referator
String @footnotes.render_footnotes command.data String @footnotes.render_footnotes command.data
end end
def do_render_footnotes_json(_command)
@config.freeze
@footnotes.render_footnotes_json
end
######### #########
# Utils # # Utils #
######### #########

49
test.rb
View file

@ -270,6 +270,55 @@ cmd :RENDER_FOOTNOTES, :json do |result|
raise unless result == expected raise unless result == expected
end 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 # # EXIT #
######## ########