Add shallow option to library API endpoints

This commit is contained in:
Alex Ling
2021-09-13 10:18:07 +00:00
parent d5847bb105
commit a9520d6f26
4 changed files with 50 additions and 78 deletions
+9 -17
View File
@@ -65,26 +65,18 @@ class Library
titles.flat_map &.deep_entries
end
def to_slim_json : String
JSON.build do |json|
json.object do
json.field "dir", @dir
json.field "titles" do
json.array do
self.titles.each do |title|
json.raw title.to_slim_json
end
end
end
end
end
end
def to_json(json : JSON::Builder)
def build_json(json : JSON::Builder, *, slim = false, shallow = false)
json.object do
json.field "dir", @dir
json.field "titles" do
json.raw self.titles.to_json
json.array do
self.titles.each do |title|
raw = JSON.build do |j|
title.build_json j, slim: slim, shallow: shallow
end
json.raw raw
end
end
end
end
end