odania 0.0.17 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/odania/config/domain.rb +4 -0
- data/lib/odania/config/global_config.rb +12 -5
- data/lib/odania/config/internal.rb +12 -2
- data/lib/odania/config/layout.rb +7 -2
- data/lib/odania/config/page.rb +1 -0
- data/lib/odania/config/style.rb +18 -5
- data/lib/odania/config/sub_domain.rb +7 -13
- data/lib/odania/varnish/generators/generate_site_assets_vcl.rb +41 -0
- data/lib/odania/varnish/generators/generate_sites_vcl.rb +4 -0
- data/lib/odania/version.rb +1 -1
- data/lib/odania.rb +0 -1
- data/templates/varnish/general.vcl.erb +4 -0
- data/templates/varnish/general_site_assets.vcl.erb +21 -0
- data/templates/varnish/site.vcl.erb +32 -2
- data/templates/varnish/site_assets.vcl.erb +34 -0
- data/templates/varnish/sites.vcl.erb +1 -0
- metadata +5 -5
- data/lib/odania/erb.rb +0 -154
- data/spec/lib/odania/erb_spec.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8231be278b477108ee91b8b72cb153b777dea0c6
|
4
|
+
data.tar.gz: 144e705b3ef3b3eef96860a6ed3e69215afaf997
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 639da08f0dc6895d1c7627a73ae835b110797a54250a9202e6d4acd9aa403d072026b9517afa924d3a4563cc0931a0ca01019e21e3e7aca7b5ba697647258223
|
7
|
+
data.tar.gz: a993aeef804be2fc9ab2e7618eaac0f18b27cfc077310c9814cd62d9b3ac00160121d972d9e95e07fc554368639d25b9a67dc664c0ff8c9e282d3b1100bda6a9
|
data/Gemfile.lock
CHANGED
data/lib/odania/config/domain.rb
CHANGED
@@ -49,6 +49,11 @@ module Odania
|
|
49
49
|
puts 'Error start ' + '+' * 50
|
50
50
|
puts e.inspect
|
51
51
|
puts 'Error end ' + '+' * 50
|
52
|
+
puts 'Error backtrace start ' + '+' * 50
|
53
|
+
e.backtrace.each do |line|
|
54
|
+
puts line
|
55
|
+
end
|
56
|
+
puts 'Error backtrace end ' + '+' * 50
|
52
57
|
end
|
53
58
|
end
|
54
59
|
end
|
@@ -78,15 +83,17 @@ module Odania
|
|
78
83
|
@default_subdomains.deep_merge(plugin_cfg['default_subdomains']) unless plugin_cfg['default_subdomains'].nil?
|
79
84
|
|
80
85
|
# Add this service as a default backend if specified
|
81
|
-
@default_backend_groups << group_name if
|
86
|
+
@default_backend_groups << group_name if plugin_cfg['plugin-config']['default']
|
82
87
|
|
83
88
|
# Add config
|
84
|
-
config_section.
|
85
|
-
|
86
|
-
@
|
89
|
+
unless config_section.nil?
|
90
|
+
config_section.each_pair do |key, val|
|
91
|
+
unless @config[key].nil?
|
92
|
+
@duplicates.add :config, {key => 'already defined'}, group_name
|
93
|
+
end
|
87
94
|
end
|
95
|
+
@config.deep_merge! config_section
|
88
96
|
end
|
89
|
-
@config.deep_merge! config_section
|
90
97
|
|
91
98
|
# Add Domain Information
|
92
99
|
unless plugin_cfg['domains'].nil?
|
@@ -7,7 +7,17 @@ module Odania
|
|
7
7
|
reset
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
10
|
+
def assets
|
11
|
+
result = {}
|
12
|
+
self.layouts.each_pair do |name, layout|
|
13
|
+
layout.assets.each_pair do |key, val|
|
14
|
+
result[key] = val
|
15
|
+
end
|
16
|
+
end
|
17
|
+
result
|
18
|
+
end
|
19
|
+
|
20
|
+
def load(data, group_name)
|
11
21
|
reset
|
12
22
|
unless data['partials'].nil?
|
13
23
|
data['partials'].each_pair do |name, data|
|
@@ -17,7 +27,7 @@ module Odania
|
|
17
27
|
|
18
28
|
unless data['layouts'].nil?
|
19
29
|
data['layouts'].each_pair do |name, data|
|
20
|
-
self.layouts[name].load(data)
|
30
|
+
self.layouts[name].load(data, group_name)
|
21
31
|
end
|
22
32
|
end
|
23
33
|
end
|
data/lib/odania/config/layout.rb
CHANGED
@@ -7,6 +7,11 @@ module Odania
|
|
7
7
|
reset
|
8
8
|
end
|
9
9
|
|
10
|
+
def assets
|
11
|
+
return {} if self.styles['_general'].nil? or self.styles['_general'].assets.nil?
|
12
|
+
self.styles['_general'].assets
|
13
|
+
end
|
14
|
+
|
10
15
|
def dump
|
11
16
|
style_data = {}
|
12
17
|
styles.each_pair do |name, style|
|
@@ -18,11 +23,11 @@ module Odania
|
|
18
23
|
result
|
19
24
|
end
|
20
25
|
|
21
|
-
def load(data)
|
26
|
+
def load(data, group_name)
|
22
27
|
reset
|
23
28
|
unless data['styles'].nil?
|
24
29
|
data['styles'].each_pair do |key, val|
|
25
|
-
self.styles[key].load(val)
|
30
|
+
self.styles[key].load(val, group_name)
|
26
31
|
end
|
27
32
|
end
|
28
33
|
end
|
data/lib/odania/config/page.rb
CHANGED
data/lib/odania/config/style.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Odania
|
2
2
|
module Config
|
3
3
|
class Style
|
4
|
-
attr_accessor :name, :entry_point, :direct, :dynamic
|
4
|
+
attr_accessor :name, :entry_point, :direct, :dynamic, :assets
|
5
5
|
|
6
6
|
def initialize(name)
|
7
7
|
self.name = name
|
@@ -23,26 +23,38 @@ module Odania
|
|
23
23
|
dynamic_data[web_url] = page.dump
|
24
24
|
end
|
25
25
|
|
26
|
+
asset_data = {}
|
27
|
+
assets.each_pair do |asset_url, page|
|
28
|
+
asset_data[asset_url] = page.dump
|
29
|
+
end
|
30
|
+
|
26
31
|
{
|
27
32
|
'entry_point' => entry_point,
|
28
33
|
'direct' => direct_data,
|
29
|
-
'dynamic' => dynamic_data
|
34
|
+
'dynamic' => dynamic_data,
|
35
|
+
'assets' => asset_data
|
30
36
|
}
|
31
37
|
end
|
32
38
|
|
33
|
-
def load(data)
|
39
|
+
def load(data, group_name)
|
34
40
|
reset
|
35
41
|
self.entry_point = data['entry_point'] unless data['entry_point'].nil?
|
36
42
|
|
37
43
|
unless data['direct'].nil?
|
38
44
|
data['direct'].each_pair do |name, data|
|
39
|
-
self.direct[name].load(data)
|
45
|
+
self.direct[name].load(data, group_name)
|
40
46
|
end
|
41
47
|
end
|
42
48
|
|
43
49
|
unless data['dynamic'].nil?
|
44
50
|
data['dynamic'].each_pair do |name, data|
|
45
|
-
self.dynamic[name].load(data)
|
51
|
+
self.dynamic[name].load(data, group_name)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
unless data['assets'].nil?
|
56
|
+
data['assets'].each_pair do |name, data|
|
57
|
+
self.assets[name].load(data, group_name)
|
46
58
|
end
|
47
59
|
end
|
48
60
|
end
|
@@ -53,6 +65,7 @@ module Odania
|
|
53
65
|
self.entry_point = nil
|
54
66
|
self.direct = Hash.new { |hash, key| hash[key] = Page.new }
|
55
67
|
self.dynamic = Hash.new { |hash, key| hash[key] = Page.new }
|
68
|
+
self.assets = Hash.new { |hash, key| hash[key] = Page.new }
|
56
69
|
@plugins = {:direct => Hash.new { |hash, key| hash[key] = [] }, :dynamic => Hash.new { |hash, key| hash[key] = [] }}
|
57
70
|
end
|
58
71
|
end
|
@@ -31,25 +31,19 @@ module Odania
|
|
31
31
|
result
|
32
32
|
end
|
33
33
|
|
34
|
-
def add_internal(web_url, group_name, plugin_url, plugin_name)
|
35
|
-
result = true
|
36
|
-
result = false unless self.assets.key? web_url
|
37
|
-
self.assets[web_url].group_name = group_name
|
38
|
-
self.assets[web_url].plugin_url = plugin_url
|
39
|
-
@plugins[:asset][web_url] << plugin_name
|
40
|
-
result
|
41
|
-
end
|
42
|
-
|
43
34
|
def get_redirects
|
44
|
-
return {} if self.
|
45
|
-
|
46
|
-
self.config['redirects']
|
35
|
+
return {} if self.redirects.nil?
|
36
|
+
self.redirects
|
47
37
|
end
|
48
38
|
|
49
39
|
def plugins(type, key)
|
50
40
|
@plugins[type][key]
|
51
41
|
end
|
52
42
|
|
43
|
+
def assets
|
44
|
+
self.internal.assets
|
45
|
+
end
|
46
|
+
|
53
47
|
def dump
|
54
48
|
direct_data = {}
|
55
49
|
direct.each_pair do |web_url, page|
|
@@ -93,7 +87,7 @@ module Odania
|
|
93
87
|
end
|
94
88
|
end
|
95
89
|
|
96
|
-
self.internal.load(data['internal']) unless data['internal'].nil?
|
90
|
+
self.internal.load(data['internal'], group_name) unless data['internal'].nil?
|
97
91
|
unless data['redirects'].nil?
|
98
92
|
data['redirects'].each_pair do |src_url, target_url|
|
99
93
|
duplicates[:redirect] << src_url if self.redirects.key? src_url
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Odania
|
2
|
+
class GenerateSiteAssetsVcl
|
3
|
+
attr_accessor :domain, :template, :default_subdomains
|
4
|
+
|
5
|
+
def default_subdomain_for(domain)
|
6
|
+
return self.default_subdomains[domain.name] unless self.default_subdomains[domain.name].nil?
|
7
|
+
return self.default_subdomains['_general'] unless self.default_subdomains['_general'].nil?
|
8
|
+
'www'
|
9
|
+
end
|
10
|
+
|
11
|
+
def template_url_for(domain, page)
|
12
|
+
"&domain=#{domain.name}"+
|
13
|
+
"&plugin_url=#{page.plugin_url.nil? ? '/' : page.plugin_url}"+
|
14
|
+
"&group_name=#{Odania.varnish_sanitize(page.group_name)}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def prepare_url(url)
|
18
|
+
return "/#{url}" unless '/'.eql? url[0]
|
19
|
+
url
|
20
|
+
end
|
21
|
+
|
22
|
+
def general_subdomain
|
23
|
+
self.domain['_general']
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize(domain, default_subdomains)
|
27
|
+
self.domain = domain
|
28
|
+
self.default_subdomains = default_subdomains
|
29
|
+
self.template = File.new("#{BASE_DIR}/templates/varnish/site_assets.vcl.erb").read
|
30
|
+
self.template = File.new("#{BASE_DIR}/templates/varnish/general_site_assets.vcl.erb").read if '_general'.eql? domain.name
|
31
|
+
end
|
32
|
+
|
33
|
+
def render
|
34
|
+
Erubis::Eruby.new(self.template).result(binding)
|
35
|
+
end
|
36
|
+
|
37
|
+
def write(out_dir)
|
38
|
+
File.write("#{out_dir}/sites/#{self.domain.name}_assets.vcl", self.render)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative 'generate_site_vcl'
|
2
|
+
require_relative 'generate_site_assets_vcl'
|
2
3
|
|
3
4
|
module Odania
|
4
5
|
class GenerateSitesVcl
|
@@ -21,6 +22,9 @@ module Odania
|
|
21
22
|
self.domains.each_pair do |domain_name, domain|
|
22
23
|
out = GenerateSiteVcl.new(domain, default_subdomains)
|
23
24
|
out.write out_dir
|
25
|
+
|
26
|
+
out = GenerateSiteAssetsVcl.new(domain, default_subdomains)
|
27
|
+
out.write out_dir
|
24
28
|
end
|
25
29
|
end
|
26
30
|
end
|
data/lib/odania/version.rb
CHANGED
data/lib/odania.rb
CHANGED
@@ -18,6 +18,10 @@ sub vcl_recv {
|
|
18
18
|
std.log("template partial identified! Page:" + req.url);
|
19
19
|
set req.backend_hint = core_backend_director.backend();
|
20
20
|
return (hash);
|
21
|
+
} else if (req.url ~ "^/template/page") {
|
22
|
+
std.log("template page identified! Page:" + req.url);
|
23
|
+
set req.backend_hint = core_backend_director.backend();
|
24
|
+
return (hash);
|
21
25
|
}
|
22
26
|
}
|
23
27
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
vcl 4.0;
|
2
|
+
# generated varnish config: <%= ENVIRONMENT %>
|
3
|
+
# local test: <%= LOCAL_TEST_MODE ? 'ENABLED' : 'DISABLED' %>
|
4
|
+
|
5
|
+
sub vcl_recv {
|
6
|
+
std.log("pre varnish log info '<%= domain.name %>':" + req.http.host);
|
7
|
+
if (req.http.host ~ "<%= domain.name %>$") {
|
8
|
+
std.log("varnish log info '<%= domain.name %>':" + req.http.host);
|
9
|
+
|
10
|
+
<% general_subdomain.assets.each_pair do |url, page| %>
|
11
|
+
if (req.url ~ "^<%= prepare_url url %>") {
|
12
|
+
std.log("page identified '<%= subdomain.name %>.<%= domain.name %>' Page:'<%= url %>':" + req.url);
|
13
|
+
|
14
|
+
set req.backend_hint = <%= page.director %>.backend();
|
15
|
+
<% unless page.plugin_url.nil? %>set req.url = "<%= page.plugin_url %>";<% end %>
|
16
|
+
|
17
|
+
return (hash);
|
18
|
+
}
|
19
|
+
<% end %>
|
20
|
+
}
|
21
|
+
}
|
@@ -10,7 +10,8 @@ sub vcl_recv {
|
|
10
10
|
if (req.http.host ~ "<%= domain.name %>$") {
|
11
11
|
std.log("varnish log info '<%= domain.name %>':" + req.http.host);
|
12
12
|
|
13
|
-
<% domain.subdomains.each_pair do |subdomain_name, subdomain|
|
13
|
+
<% domain.subdomains.each_pair do |subdomain_name, subdomain|
|
14
|
+
next if '_general'.eql? subdomain_name %>
|
14
15
|
<%= is_first ? '' : 'else ' %>if (req.http.host ~ "^<%= subdomain.name %>.<%= domain.name %>$") {
|
15
16
|
std.log("subdomain identified '<%= subdomain.name %>.<%= domain.name %>':" + req.http.host + " url: " + req.url );
|
16
17
|
|
@@ -44,12 +45,41 @@ sub vcl_recv {
|
|
44
45
|
<% is_first = false %>
|
45
46
|
<% end %>
|
46
47
|
|
48
|
+
# Important: This needs to be directly after the subdomain config
|
47
49
|
<%= is_first ? '' : 'else' %> {
|
48
|
-
# Redirect to default
|
50
|
+
# Redirect to default subdomain
|
49
51
|
std.log("varnish log info 'redirect to default':" + req.url);
|
50
52
|
set req.http.Location = "http://<%= default_subdomain_for(domain) %>.<%= domain.name %>" + req.url;
|
51
53
|
return (synth(750, "Permanently moved"));
|
52
54
|
}
|
55
|
+
|
56
|
+
# General part
|
57
|
+
<% domain.get_redirects.each_pair do |src, target| %>
|
58
|
+
if (req.url ~ "<%= src %>") {
|
59
|
+
std.log("general redirect identified '<%= domain.name %>' src:'<%= src %>':" + req.url);
|
60
|
+
set req.http.Location = "<%= target %>";
|
61
|
+
return (synth(750, "Permanently moved"));
|
62
|
+
}
|
63
|
+
<% end %>
|
64
|
+
|
65
|
+
<% subdomain = domain.subdomains['_general'] %>
|
66
|
+
<% %w(direct dynamic).each do |type| %>
|
67
|
+
<% subdomain[type].each_pair do |url, page| %>
|
68
|
+
if (req.url ~ "^<%= prepare_url url %>") {
|
69
|
+
std.log("page identified '<%= subdomain.name %>.<%= domain.name %>' Page:'<%= url %>':" + req.url);
|
70
|
+
|
71
|
+
<% if 'direct'.eql? type %>
|
72
|
+
set req.backend_hint = <%= page.director %>.backend();
|
73
|
+
<% unless page.plugin_url.nil? %>set req.url = "<%= page.plugin_url %>";<% end %>
|
74
|
+
<% else %>
|
75
|
+
set req.backend_hint = core_backend_director.backend();
|
76
|
+
set req.url = "/template/page?req_url=" + req.url + "&req_host=" + req.http.host + "<%= template_url_for(domain, page) %>";
|
77
|
+
<% end %>
|
78
|
+
|
79
|
+
return (hash);
|
80
|
+
}
|
81
|
+
<% end %>
|
82
|
+
<% end %>
|
53
83
|
}
|
54
84
|
}
|
55
85
|
|
@@ -0,0 +1,34 @@
|
|
1
|
+
<%
|
2
|
+
is_first = true
|
3
|
+
%>
|
4
|
+
vcl 4.0;
|
5
|
+
# generated varnish config: <%= ENVIRONMENT %>
|
6
|
+
# local test: <%= LOCAL_TEST_MODE ? 'ENABLED' : 'DISABLED' %>
|
7
|
+
|
8
|
+
sub vcl_recv {
|
9
|
+
std.log("pre varnish log info '<%= domain.name %>':" + req.http.host);
|
10
|
+
if (req.http.host ~ "<%= domain.name %>$") {
|
11
|
+
std.log("varnish log info '<%= domain.name %>':" + req.http.host);
|
12
|
+
|
13
|
+
<% domain.subdomains.each_pair do |subdomain_name, subdomain| %>
|
14
|
+
<% unless '_general'.eql? subdomain_name %><%= is_first ? '' : 'else ' %>if (req.http.host ~ "^<%= subdomain.name %>.<%= domain.name %>$") {<% end %>
|
15
|
+
std.log("subdomain identified '<%= subdomain.name %>.<%= domain.name %>':" + req.http.host + " url: " + req.url );
|
16
|
+
|
17
|
+
<% subdomain.assets.each_pair do |url, page| %>
|
18
|
+
if (req.url ~ "^<%= prepare_url url %>") {
|
19
|
+
std.log("page identified '<%= subdomain.name %>.<%= domain.name %>' Page:'<%= url %>':" + req.url);
|
20
|
+
|
21
|
+
set req.backend_hint = <%= page.director %>.backend();
|
22
|
+
<% unless page.plugin_url.nil? %>set req.url = "<%= page.plugin_url %>";<% end %>
|
23
|
+
|
24
|
+
return (hash);
|
25
|
+
}
|
26
|
+
<% end %>
|
27
|
+
|
28
|
+
<% unless '_general'.eql? subdomain_name %>
|
29
|
+
}
|
30
|
+
<% is_first = false %>
|
31
|
+
<% end %>
|
32
|
+
<% end %>
|
33
|
+
}
|
34
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: odania
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Petersen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -184,7 +184,6 @@ files:
|
|
184
184
|
- lib/odania/config/style.rb
|
185
185
|
- lib/odania/config/sub_domain.rb
|
186
186
|
- lib/odania/consul.rb
|
187
|
-
- lib/odania/erb.rb
|
188
187
|
- lib/odania/plugin.rb
|
189
188
|
- lib/odania/plugin_config/base.rb
|
190
189
|
- lib/odania/varnish.rb
|
@@ -193,6 +192,7 @@ files:
|
|
193
192
|
- lib/odania/varnish/generators/generate_default_vcl.rb
|
194
193
|
- lib/odania/varnish/generators/generate_general_vcl.rb
|
195
194
|
- lib/odania/varnish/generators/generate_redirects_vcl.rb
|
195
|
+
- lib/odania/varnish/generators/generate_site_assets_vcl.rb
|
196
196
|
- lib/odania/varnish/generators/generate_site_vcl.rb
|
197
197
|
- lib/odania/varnish/generators/generate_sites_vcl.rb
|
198
198
|
- lib/odania/version.rb
|
@@ -201,7 +201,6 @@ files:
|
|
201
201
|
- spec/fixtures/plugin_config_1.json
|
202
202
|
- spec/lib/odania/config/global_config_spec.rb
|
203
203
|
- spec/lib/odania/config/plugin_config_spec.rb
|
204
|
-
- spec/lib/odania/erb_spec.rb
|
205
204
|
- spec/lib/odania/plugin_spec.rb
|
206
205
|
- spec/lib/odania/varnish_spec.rb
|
207
206
|
- spec/lib/odania_spec.rb
|
@@ -214,8 +213,10 @@ files:
|
|
214
213
|
- templates/varnish/default.vcl.erb
|
215
214
|
- templates/varnish/general.vcl.erb
|
216
215
|
- templates/varnish/general_site.vcl.erb
|
216
|
+
- templates/varnish/general_site_assets.vcl.erb
|
217
217
|
- templates/varnish/redirects.vcl.erb
|
218
218
|
- templates/varnish/site.vcl.erb
|
219
|
+
- templates/varnish/site_assets.vcl.erb
|
219
220
|
- templates/varnish/sites.vcl.erb
|
220
221
|
- templates/varnish/websocker.vcl.erb
|
221
222
|
homepage: http://www.odania.com
|
@@ -252,7 +253,6 @@ test_files:
|
|
252
253
|
- spec/fixtures/plugin_config_1.json
|
253
254
|
- spec/lib/odania/config/global_config_spec.rb
|
254
255
|
- spec/lib/odania/config/plugin_config_spec.rb
|
255
|
-
- spec/lib/odania/erb_spec.rb
|
256
256
|
- spec/lib/odania/plugin_spec.rb
|
257
257
|
- spec/lib/odania/varnish_spec.rb
|
258
258
|
- spec/lib/odania_spec.rb
|
data/lib/odania/erb.rb
DELETED
@@ -1,154 +0,0 @@
|
|
1
|
-
module Odania
|
2
|
-
class Erb
|
3
|
-
attr_accessor :variables, :config, :page, :asset
|
4
|
-
|
5
|
-
def initialize(template, domain, partials, group_name, req_host)
|
6
|
-
@template = template
|
7
|
-
|
8
|
-
self.variables = Variables.new(template, domain, partials, group_name, req_host)
|
9
|
-
self.config = Config.new self.variables
|
10
|
-
self.page = Page.new self.variables
|
11
|
-
self.asset = Asset.new self.variables
|
12
|
-
|
13
|
-
if LOCAL_TEST_MODE
|
14
|
-
data = "\n<!-- Domain: #{domain} -->"
|
15
|
-
data += "\n<!-- Group Name: #{group_name} -->"
|
16
|
-
data += "\n<!-- Request Host: #{req_host} -->"
|
17
|
-
data += "\n<!-- Base Domain: #{self.variables.base_domain} -->"
|
18
|
-
data += "\n<!-- Partials: #{JSON.pretty_generate(self.variables.partials)} -->"
|
19
|
-
data += "\n<!-- Config: #{JSON.pretty_generate(self.variables.config)} -->"
|
20
|
-
data += "\n<!-- SubDomain Config: #{JSON.pretty_generate(self.variables.subdomain_config)} -->"
|
21
|
-
#data += "\n<!-- Global Config: #{JSON.pretty_generate(self.variables.global_config)} -->"
|
22
|
-
@template += data.html_safe
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def render
|
27
|
-
ERB.new(@template).result(binding)
|
28
|
-
end
|
29
|
-
|
30
|
-
class Variables
|
31
|
-
attr_accessor :template, :config, :subdomain_config, :global_config, :domain
|
32
|
-
attr_accessor :base_domain, :partials, :group_name, :req_host
|
33
|
-
|
34
|
-
def initialize(template, domain, partials, group_name, req_host)
|
35
|
-
self.template = template
|
36
|
-
self.global_config = Odania.plugin.get_global_config
|
37
|
-
|
38
|
-
domain_info = PublicSuffix.parse(domain)
|
39
|
-
self.config, self.base_domain = Odania.plugin.get_domain_config_for domain_info.domain, self.global_config
|
40
|
-
self.subdomain_config = self.config[domain_info.trd] unless domain_info.trd.nil?
|
41
|
-
self.subdomain_config = self.config['_general'] if self.subdomain_config.nil?
|
42
|
-
self.subdomain_config = {} if self.subdomain_config.nil?
|
43
|
-
|
44
|
-
self.domain = domain
|
45
|
-
self.partials = partials
|
46
|
-
self.group_name = group_name
|
47
|
-
self.req_host = req_host
|
48
|
-
end
|
49
|
-
|
50
|
-
def get_partial(page)
|
51
|
-
get_specific %w(internal partials), page
|
52
|
-
end
|
53
|
-
|
54
|
-
def get_config_key(key)
|
55
|
-
get_specific %w(config), key
|
56
|
-
end
|
57
|
-
|
58
|
-
def notify_error_async(type, key, data)
|
59
|
-
data = {
|
60
|
-
domain: self.domain,
|
61
|
-
base_domain: self.base_domain,
|
62
|
-
group_name: self.group_name,
|
63
|
-
req_host: self.req_host,
|
64
|
-
type: type,
|
65
|
-
key: key,
|
66
|
-
data: data
|
67
|
-
}
|
68
|
-
ProcessErrorJob.perform_later data
|
69
|
-
end
|
70
|
-
|
71
|
-
private
|
72
|
-
|
73
|
-
def get_specific(part, page)
|
74
|
-
subdomain = req_host.gsub(".#{domain}", '')
|
75
|
-
|
76
|
-
# subdomain specific layouts
|
77
|
-
result = retrieve_hash_path global_config, ['domains', domain, subdomain] + part + [page]
|
78
|
-
return result unless result.nil?
|
79
|
-
|
80
|
-
# domain specific layouts
|
81
|
-
result = retrieve_hash_path global_config, ['domains', domain, '_general'] + part + [page]
|
82
|
-
return result unless result.nil?
|
83
|
-
|
84
|
-
# general layouts
|
85
|
-
result = retrieve_hash_path global_config, %w(domains _general _general) + part + [page]
|
86
|
-
return result unless result.nil?
|
87
|
-
|
88
|
-
nil
|
89
|
-
end
|
90
|
-
|
91
|
-
def retrieve_hash_path(hash, path)
|
92
|
-
key = path.shift
|
93
|
-
|
94
|
-
return nil until hash.has_key? key
|
95
|
-
return hash[key] if path.empty?
|
96
|
-
retrieve_hash_path hash[key], path
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
class Config
|
101
|
-
def initialize(variables)
|
102
|
-
@variables = variables
|
103
|
-
end
|
104
|
-
|
105
|
-
def get(key)
|
106
|
-
val = @variables.get_config_key(key)
|
107
|
-
return val unless val.nil?
|
108
|
-
"--- Config Key Not found: #{key} ---"
|
109
|
-
|
110
|
-
@variables.notify_error_async :config, 'Key not found', key
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
class Page
|
115
|
-
def initialize(variables)
|
116
|
-
@variables = variables
|
117
|
-
end
|
118
|
-
|
119
|
-
def get(page)
|
120
|
-
if not @variables.partials[page].nil?
|
121
|
-
"<!-- Page: #{page} -->\n<esi:include src=\"#{@variables.partials[page]}\"/>\n<!-- End Page: #{page} -->"
|
122
|
-
else
|
123
|
-
partial = @variables.get_partial(page)
|
124
|
-
|
125
|
-
if partial.nil?
|
126
|
-
#"<!-- Page: #{page} -->\n<esi:include src=\"http://internal.core/template/partial/#{page}?domain=#{@variables.domain}&group_name=#{@variables.group_name}\"/>\n<!-- End Page: #{page} -->"
|
127
|
-
"\n\n\n<pre>UNHANDLED PAGE: #{page} !!!!!!!!!!!!!!!!!!!!</pre>\n\n\n"
|
128
|
-
else
|
129
|
-
"<!-- Page: #{page} -->\n<esi:include src=\"http://internal.core/template/partial/#{page}?domain=#{@variables.domain}&group_name=#{@variables.group_name}&plugin_url=#{partial['plugin_url']}&req_host=#{@variables.req_host}\"/>\n<!-- End Page: #{page} -->"
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
class Asset
|
136
|
-
def initialize(variables)
|
137
|
-
@variables = variables
|
138
|
-
end
|
139
|
-
|
140
|
-
def get(asset)
|
141
|
-
asset_url = get_asset_url(@variables.domain)
|
142
|
-
asset_url = "//#{asset_url}" unless asset_url.include? '//'
|
143
|
-
"#{asset_url}/#{asset}"
|
144
|
-
end
|
145
|
-
|
146
|
-
private
|
147
|
-
|
148
|
-
def get_asset_url(domain)
|
149
|
-
return @variables.subdomain_config['asset_url'] unless @variables.subdomain_config['asset_url'].nil?
|
150
|
-
domain
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
data/spec/lib/odania/erb_spec.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
describe Odania::Erb do
|
2
|
-
context 'render simple template' do
|
3
|
-
let(:subject) {
|
4
|
-
Odania::Erb.new('This is a very simple template', 'example.com', {}, 'odania-test', 'test.odania.com')
|
5
|
-
}
|
6
|
-
|
7
|
-
let(:global_cfg) {
|
8
|
-
JSON.parse File.read("#{BASE_DIR}/spec/fixtures/global_config.json")
|
9
|
-
}
|
10
|
-
|
11
|
-
it 'renders simple template' do
|
12
|
-
$consul_mock.config.set('global_plugins_config', global_cfg)
|
13
|
-
expect(subject.render).to eq('This is a very simple template')
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|