Add mapping macro and move templated into helpers.cr

pull/3/head
Omar Roth 7 years ago
parent b388181cd4
commit 4ae88cd286

@ -1,28 +1,26 @@
class Video
module HTTPParamConverter
def self.from_rs(rs)
HTTP::Params.parse(rs.read(String))
macro add_mapping(mapping)
def initialize({{*mapping.keys.map { |id| "@#{id}".id }}})
end
def to_a
return [{{*mapping.keys.map { |id| "@#{id}".id }}}]
end
def initialize(id, info, updated, title, views, likes, dislikes, wilson_score, published, description)
@id = id
@info = info
@updated = updated
@title = title
@views = views
@likes = likes
@dislikes = dislikes
@wilson_score = wilson_score
@published = published
@description = description
DB.mapping({{mapping}})
end
def to_a
return [@id, @info, @updated, @title, @views, @likes, @dislikes, @wilson_score, @published, @description]
macro templated(filename)
render "src/views/#{{{filename}}}.ecr", "src/views/layout.ecr"
end
class Video
module HTTPParamConverter
def self.from_rs(rs)
HTTP::Params.parse(rs.read(String))
end
end
DB.mapping({
add_mapping({
id: String,
info: {
type: HTTP::Params,

@ -1,4 +1,4 @@
# "Invidious" (which indexes popular video sites)
# "Invidious" (which is what YouTube should be)
# Copyright (C) 2018 Omar Roth
#
# This program is free software: you can redistribute it and/or modify

Loading…
Cancel
Save