Simplify #json_build

This commit is contained in:
Alex Ling
2021-09-14 02:30:57 +00:00
parent 4b464ed361
commit 4eaf271fa4
4 changed files with 55 additions and 62 deletions
+11 -9
View File
@@ -46,17 +46,19 @@ class Entry
file.close
end
def build_json(json : JSON::Builder, *, slim = false)
json.object do
{% for str in ["zip_path", "title", "size", "id"] %}
def build_json(*, slim = false)
JSON.build do |json|
json.object do
{% for str in ["zip_path", "title", "size", "id"] %}
json.field {{str}}, @{{str.id}}
{% end %}
json.field "title_id", @book.id
json.field "pages" { json.number @pages }
unless slim
json.field "display_name", @book.display_name @title
json.field "cover_url", cover_url
json.field "mtime" { json.number @mtime.to_unix }
json.field "title_id", @book.id
json.field "pages" { json.number @pages }
unless slim
json.field "display_name", @book.display_name @title
json.field "cover_url", cover_url
json.field "mtime" { json.number @mtime.to_unix }
end
end
end
end