aboutsummaryrefslogtreecommitdiff
path: root/src/guff/views/page.cr
blob: b1019a6c7580c54fefb04670092036e432020ccb (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
class Guff::Views::PageView < Guff::Views::HTMLView
  def initialize(context : Context, @item : Hash(String, String))
    super(context)

    # FIXME: remove -1 hack
    @theme_id = -1_i32
    if tmp_theme_id = @item[%w{theme_id site_theme_id}.find { |k|
      @item[k]? && @item[k].size > 0
    }]
      @theme_id = tmp_theme_id.to_i32
    end
  end

  private def scripts
    super(theme_assets.scripts.map { |val|
      "/guff/themes/%s/%s" % [theme_slug, val]
    })
    # TODO: allow page-specific scripts
  end

  private def styles
    super(theme_assets.styles.map { |val|
      "/guff/themes/%s/%s" % [theme_slug, val]
    })
    # TODO: allow page-specific styles
  end

  private def theme_assets
    @context.models.theme.assets(@theme_id)
  end

  private def theme_slug : String
    @theme_slug ||= @context.models.theme.get(@theme_id)["theme_slug"] as String
  end

  ECR.def_to_s("src/views/page.ecr")
end