aboutsummaryrefslogtreecommitdiff
path: root/src/guff/post.cr
blob: 5aa71706e204425dd75a6268d7c54e7e5c9ba717 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require "html"
require "ecr/macros"

class Guff::Post
  getter :row

  def initialize(@row : Hash(String, ::SQLite3::Value))
  end

  def to_json(io)
    @row.reduce({} of String => String | Array(String)) do |r, k, v|
      r[k] = v.to_s
      r
    end.merge({
      "tags": tags
    }).to_json(io)
  end

  def name : String
    @row["name"] as String
  end

  private def tags : Array(String)
    @tags ||= if @row.has_key?("tags") && (@row["tags"] as String).size > 0
      (@row["tags"] as String).split('|')
    else
      [] of String
    end
  end

  private def h(s) : String
    HTML.escape(s)
  end

  # FIXME: does this belong elsewhere?
  ECR.def_to_s("./src/guff/views/ecrs/post.ecr")
end