aboutsummaryrefslogtreecommitdiff
path: root/src/guff/page-features.cr
blob: 5b0c107271a7ef7e47177252a47bce1189557a51 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
module Guff::PageFeatures
  FEATURES = {
    "jquery": {
      scripts: %w{
        /guff-stuff/jquery-2.2.1.min.js
      },
    },

    "luigi-template": {
      scripts: %w{
        /guff-stuff/luigi-template-0.4.1.min.js
      },
    },

    "font-awesome": {
      styles: %w{
        /guff-stuff/font-awesome-4.5.0/css/font-awesome.min.css
      },
    },

    "bootstrap": {
      deps: %w{jquery},

      styles: %w{
        /guff-stuff/bootstrap-3.3.6/css/bootstrap.min.css
        /guff-stuff/bootstrap-3.3.6/css/bootstrap-theme.min.css
      },

      scripts: %w{
        /guff-stuff/bootstrap-3.3.6/js/bootstrap.min.js
      },

      # TODO
      metas: [] of Hash(String, String),
    },

    "guff/util": {
      deps: %w{jquery luigi-template},

      scripts: %w{
        /guff-stuff/js/util.js
      },
    },
  }

  def self.add(key : String, page)
    raise "unknown feature: #{key}" unless FEATURES.has_key?(key)
    f = FEATURES[key]
    
    if f.has_key?(:deps)
      # add dependencies
      (f[:deps] as Array(String)).each do |dep|
        page.add_feature(dep)
      end
    end

    if f.has_key?(:scripts)
      # add scripts
      (f[:scripts] as Array(String)).each do |path|
        page.scripts << path
      end
    end

    if f.has_key?(:styles)
      # add styles
      (f[:styles] as Array(String)).each do |path|
        page.styles << path
      end
    end

    if f.has_key?(:metas)
      # add metas
      (f[:metas] as Array(Hash(String, String))).each do |meta|
        page.metas << meta
      end
    end
  end
end