odania 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{LICENSE.txt → MIT-LICENSE} +1 -3
- data/README.md +3 -3
- data/Rakefile +33 -3
- data/app/assets/config/odania_manifest.js +0 -0
- data/app/assets/javascripts/application.js +13 -0
- data/app/assets/javascripts/textAngular.js +15 -0
- data/app/assets/javascripts/textAngular/textAngular-rangy.min.js +478 -0
- data/app/assets/javascripts/textAngular/textAngular-sanitize.min.js +322 -0
- data/app/assets/javascripts/textAngular/textAngular.min.js +1481 -0
- data/app/assets/stylesheets/scaffold.css +80 -0
- data/app/assets/stylesheets/textAngular/application.css +15 -0
- data/app/assets/stylesheets/textAngular/textAngular.css +204 -0
- data/app/controllers/admin/home_controller.rb +2 -0
- data/app/controllers/admin/languages_controller.rb +74 -0
- data/app/controllers/admin_controller.rb +4 -0
- data/app/controllers/application_controller.rb +3 -0
- data/app/controllers/categories_controller.rb +34 -0
- data/app/controllers/home_controller.rb +11 -0
- data/app/controllers/protected/home_controller.rb +2 -0
- data/app/controllers/protected_controller.rb +22 -0
- data/app/controllers/registration_controller.rb +12 -0
- data/app/helpers/standard_form_builder.rb +71 -0
- data/app/helpers/standard_form_helper.rb +13 -0
- data/app/models/admin.rb +37 -0
- data/app/models/language.rb +5 -0
- data/app/models/user.rb +47 -0
- data/app/views/admin/home/index.html.erb +1 -0
- data/app/views/admin/languages/_form.html.erb +16 -0
- data/app/views/admin/languages/_language.json.jbuilder +2 -0
- data/app/views/admin/languages/edit.html.erb +6 -0
- data/app/views/admin/languages/index.html.erb +27 -0
- data/app/views/admin/languages/index.json.jbuilder +1 -0
- data/app/views/admin/languages/new.html.erb +5 -0
- data/app/views/admin/languages/show.html.erb +9 -0
- data/app/views/admin/languages/show.json.jbuilder +1 -0
- data/app/views/categories/index.html.erb +9 -0
- data/app/views/categories/show.html.erb +16 -0
- data/app/views/devise/confirmations/new.html.erb +11 -0
- data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
- data/app/views/devise/mailer/email_changed.html.erb +7 -0
- data/app/views/devise/mailer/password_change.html.erb +4 -0
- data/app/views/devise/mailer/reset_password_instructions.html.erb +9 -0
- data/app/views/devise/mailer/unlock_instructions.html.erb +8 -0
- data/app/views/devise/passwords/edit.html.erb +13 -0
- data/app/views/devise/passwords/new.html.erb +11 -0
- data/app/views/devise/registrations/edit.html.erb +39 -0
- data/app/views/devise/registrations/new.html.erb +15 -0
- data/app/views/devise/sessions/new.html.erb +14 -0
- data/app/views/devise/shared/_links.html.erb +25 -0
- data/app/views/devise/unlocks/new.html.erb +11 -0
- data/app/views/home/index.html.erb +11 -0
- data/app/views/languages/_form.html.erb +20 -0
- data/app/views/languages/edit.html.erb +6 -0
- data/app/views/languages/index.html.erb +27 -0
- data/app/views/languages/new.html.erb +5 -0
- data/app/views/languages/show.html.erb +9 -0
- data/app/views/protected/home/index.html.erb +1 -0
- data/config/initializers/elasticsearch.rb +5 -0
- data/config/locales/devise.en.yml +64 -0
- data/config/routes.rb +23 -0
- data/db/seeds.rb +5 -0
- data/lib/odania.rb +7 -56
- data/lib/odania/engine.rb +14 -0
- data/lib/odania/version.rb +1 -1
- data/lib/tasks/odania_tasks.rake +4 -0
- data/lib/templates/erb/scaffold/_form.html.erb +27 -0
- data/lib/templates/erb/scaffold/edit.html.erb +6 -0
- data/lib/templates/erb/scaffold/index.html.erb +31 -0
- data/lib/templates/erb/scaffold/new.html.erb +5 -0
- data/lib/templates/erb/scaffold/show.html.erb +11 -0
- metadata +129 -84
- data/.codeclimate.yml +0 -30
- data/.gitignore +0 -17
- data/.rspec +0 -2
- data/.rubocop.yml +0 -1156
- data/.travis.yml +0 -20
- data/Gemfile +0 -4
- data/Gemfile.lock +0 -113
- data/Guardfile +0 -31
- data/features/plugin.feature +0 -35
- data/features/step_definitions/plugin_steps.rb +0 -75
- data/features/support/env.rb +0 -1
- data/lib/odania/config.rb +0 -17
- data/lib/odania/config/backend.rb +0 -31
- data/lib/odania/config/backend_group.rb +0 -43
- data/lib/odania/config/domain.rb +0 -59
- data/lib/odania/config/duplicates.rb +0 -28
- data/lib/odania/config/global_config.rb +0 -210
- data/lib/odania/config/layout.rb +0 -30
- data/lib/odania/config/page.rb +0 -29
- data/lib/odania/config/page_base.rb +0 -47
- data/lib/odania/config/plugin_config.rb +0 -58
- data/lib/odania/config/style.rb +0 -36
- data/lib/odania/config/sub_domain.rb +0 -113
- data/lib/odania/config/subdomain_config.rb +0 -124
- data/lib/odania/consul.rb +0 -138
- data/lib/odania/plugin.rb +0 -103
- data/odania.gemspec +0 -34
- data/spec/fixtures/global_config.json +0 -135
- data/spec/fixtures/plugin_config_1.json +0 -102
- data/spec/lib/odania/config/global_config_spec.rb +0 -69
- data/spec/lib/odania/config/plugin_config_spec.rb +0 -31
- data/spec/lib/odania/plugin_spec.rb +0 -25
- data/spec/lib/odania_spec.rb +0 -10
- data/spec/spec_helper.rb +0 -19
- data/spec/support/consul_mock.rb +0 -123
- data/tasks/odania.rake +0 -8
- data/tasks/rspec.rake +0 -7
@@ -1,210 +0,0 @@
|
|
1
|
-
module Odania
|
2
|
-
module Config
|
3
|
-
class GlobalConfig < PluginConfig
|
4
|
-
# Load the global configuration
|
5
|
-
def load_global_config(config)
|
6
|
-
throw 'Invalid global config!' if config.nil?
|
7
|
-
|
8
|
-
reset
|
9
|
-
@default_backend_groups = config['default_backend_groups'] unless config['default_backend_groups'].nil?
|
10
|
-
@valid_domains = config['valid_domains'] unless config['valid_domains'].nil?
|
11
|
-
@default_domains = config['default_domains'] unless config['default_domains'].nil?
|
12
|
-
@partials = config['partials'] unless config['partials'].nil?
|
13
|
-
|
14
|
-
unless config['domains'].nil?
|
15
|
-
config['domains'].each_pair do |name, data|
|
16
|
-
@domains[name].load(data)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
# load backends from consul
|
21
|
-
Odania.plugin.get_all.each_pair do |_name, instances|
|
22
|
-
instances.each do |instance|
|
23
|
-
add_backend(instance)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
#puts config.inspect
|
28
|
-
#puts @backend_groups.inspect
|
29
|
-
#puts @default_backend_groups.inspect
|
30
|
-
|
31
|
-
self
|
32
|
-
end
|
33
|
-
|
34
|
-
def load_from_consul
|
35
|
-
Odania.plugin.get_all.each_pair do |plugin_name, instances|
|
36
|
-
$logger.info "PLUGIN NAME #{plugin_name} - #{instances.count}" if $debug
|
37
|
-
instances.each do |instance|
|
38
|
-
add_backend(instance)
|
39
|
-
end
|
40
|
-
|
41
|
-
config = Odania.plugin.config_for plugin_name
|
42
|
-
next if config.nil?
|
43
|
-
|
44
|
-
begin
|
45
|
-
puts JSON.pretty_generate config if $debug
|
46
|
-
self.add_plugin_config(config)
|
47
|
-
rescue => e
|
48
|
-
$logger.error 'Error loading configuration'
|
49
|
-
$logger.error 'Config start ' + '+' * 50
|
50
|
-
puts JSON.pretty_generate config
|
51
|
-
$logger.error 'Config end ' + '+' * 50
|
52
|
-
$logger.error 'Error start ' + '+' * 50
|
53
|
-
$logger.error e.inspect
|
54
|
-
$logger.error 'Error end ' + '+' * 50
|
55
|
-
$logger.error 'Error backtrace start ' + '+' * 50
|
56
|
-
e.backtrace.each do |line|
|
57
|
-
$logger.error line
|
58
|
-
end
|
59
|
-
$logger.error 'Error backtrace end ' + '+' * 50
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def generate_global_config
|
65
|
-
$logger.info 'Loading plugin configs from consul'
|
66
|
-
load_from_consul
|
67
|
-
|
68
|
-
$logger.info 'Generating global config'
|
69
|
-
config = self.dump
|
70
|
-
puts JSON.pretty_generate config if $debug
|
71
|
-
Odania.plugin.set_global_config config
|
72
|
-
|
73
|
-
generate_subdomain_configs config
|
74
|
-
write_valid_domain_config
|
75
|
-
|
76
|
-
config
|
77
|
-
end
|
78
|
-
|
79
|
-
# Generate a config per subdomain
|
80
|
-
def generate_subdomain_configs(config)
|
81
|
-
$logger.info 'Generating subdomain configs'
|
82
|
-
@valid_domains.each do |domain, subdomains|
|
83
|
-
subdomains.each do |subdomain|
|
84
|
-
$logger.info "Generating Subdomain Config for Domain: #{domain} Subdomain: #{subdomain}"
|
85
|
-
|
86
|
-
begin
|
87
|
-
subdomain_config = SubdomainConfig.new(config, domain, subdomain).generate
|
88
|
-
Odania.plugin.set_subdomain_config "#{subdomain}.#{domain}", subdomain_config
|
89
|
-
rescue => e
|
90
|
-
$logger.error "Error generating subdomain config: #{e}"
|
91
|
-
$logger.error e.backtrace.join("\n")
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def write_valid_domain_config
|
98
|
-
$logger.info 'Writing valid domain config'
|
99
|
-
config = {
|
100
|
-
valid_domains: @valid_domains,
|
101
|
-
default_domains: @default_domains
|
102
|
-
}
|
103
|
-
Odania.plugin.set_valid_domain_config config
|
104
|
-
end
|
105
|
-
|
106
|
-
# Add the configuration from the plugin
|
107
|
-
def add_plugin_config(plugin_cfg)
|
108
|
-
config_section = plugin_cfg['config']
|
109
|
-
group_name = plugin_cfg['plugin-config']['name']
|
110
|
-
|
111
|
-
if $debug
|
112
|
-
$logger.info 'Loading configuration'
|
113
|
-
puts JSON.pretty_generate plugin_cfg
|
114
|
-
end
|
115
|
-
|
116
|
-
@plugin_config[group_name] = plugin_cfg['plugin-config']
|
117
|
-
@valid_domains.deep_merge!(plugin_cfg['valid_domains']) unless plugin_cfg['valid_domains'].nil?
|
118
|
-
@default_domains.deep_merge!(plugin_cfg['default_domains']) unless plugin_cfg['default_domains'].nil?
|
119
|
-
@partials.deep_merge!(plugin_cfg['partials']) unless plugin_cfg['partials'].nil?
|
120
|
-
|
121
|
-
# Add this service as a default backend if specified
|
122
|
-
@default_backend_groups << group_name if plugin_cfg['plugin-config']['default']
|
123
|
-
|
124
|
-
# Add config
|
125
|
-
unless config_section.nil?
|
126
|
-
config_section.each_pair do |key, _val|
|
127
|
-
unless @config[key].nil?
|
128
|
-
@duplicates.add :config, {key => 'already defined'}, group_name
|
129
|
-
end
|
130
|
-
end
|
131
|
-
@config.deep_merge! config_section
|
132
|
-
end
|
133
|
-
|
134
|
-
# Add Domain Information
|
135
|
-
unless plugin_cfg['domains'].nil?
|
136
|
-
plugin_cfg['domains'].each_pair do |name, data|
|
137
|
-
@domains[name].add(data, group_name).each do |duplicate_key, duplicate_data|
|
138
|
-
@duplicates.add duplicate_key, duplicate_data, group_name
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
true
|
144
|
-
end
|
145
|
-
|
146
|
-
def add_backend(backend_config)
|
147
|
-
return if backend_config.ServiceAddress.nil? or backend_config.ServiceAddress.empty?
|
148
|
-
|
149
|
-
backend = Backend.new(backend_config.ServiceName, backend_config.ServiceID, backend_config.ServiceAddress, backend_config.ServicePort)
|
150
|
-
@backend_groups[backend_config.ServiceName].add_backend backend
|
151
|
-
@backend_groups[backend_config.ServiceName].check_core_backend backend_config.ServiceTags
|
152
|
-
end
|
153
|
-
|
154
|
-
def reset
|
155
|
-
super
|
156
|
-
|
157
|
-
@default_backend_groups = []
|
158
|
-
@duplicates = Duplicates.new
|
159
|
-
@backend_groups = Hash.new { |hash, key| hash[key] = BackendGroup.new(key) }
|
160
|
-
@valid_domains = {}
|
161
|
-
@default_domains = {}
|
162
|
-
@partials = {}
|
163
|
-
|
164
|
-
@domains['_general'].add_subdomain('_general')
|
165
|
-
end
|
166
|
-
|
167
|
-
def duplicates
|
168
|
-
@duplicates.duplicates
|
169
|
-
end
|
170
|
-
|
171
|
-
def backend_groups
|
172
|
-
@backend_groups
|
173
|
-
end
|
174
|
-
|
175
|
-
def default_backend
|
176
|
-
group_name = @default_backend_groups.first
|
177
|
-
group_name = @backend_groups.keys.first if group_name.nil?
|
178
|
-
raise 'No backend found' if @backend_groups.empty?
|
179
|
-
@backend_groups[group_name].backends.first
|
180
|
-
end
|
181
|
-
|
182
|
-
def valid_domains
|
183
|
-
@valid_domains
|
184
|
-
end
|
185
|
-
|
186
|
-
def default_domains
|
187
|
-
@default_domains
|
188
|
-
end
|
189
|
-
|
190
|
-
def partials
|
191
|
-
@partials
|
192
|
-
end
|
193
|
-
|
194
|
-
def default_redirects
|
195
|
-
general = @domains['_general'].subdomain('_general')
|
196
|
-
return {} if general.nil?
|
197
|
-
general.redirects
|
198
|
-
end
|
199
|
-
|
200
|
-
def dump
|
201
|
-
cfg = super
|
202
|
-
cfg['default_backend_groups'] = @default_backend_groups
|
203
|
-
cfg['default_domains'] = @default_domains
|
204
|
-
cfg['valid_domains'] = @valid_domains
|
205
|
-
cfg['partials'] = @partials
|
206
|
-
cfg
|
207
|
-
end
|
208
|
-
end
|
209
|
-
end
|
210
|
-
end
|
data/lib/odania/config/layout.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
module Odania
|
2
|
-
module Config
|
3
|
-
class Layout < PageBase
|
4
|
-
attr_accessor :config
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
reset
|
8
|
-
end
|
9
|
-
|
10
|
-
def dump
|
11
|
-
result = super
|
12
|
-
result['config'] = config unless config.nil?
|
13
|
-
result
|
14
|
-
end
|
15
|
-
|
16
|
-
def load(data, group_name)
|
17
|
-
reset
|
18
|
-
super(data, group_name)
|
19
|
-
unless data['config'].nil?
|
20
|
-
self.config = data['config']
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def reset
|
25
|
-
super
|
26
|
-
self.config = {}
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
data/lib/odania/config/page.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
module Odania
|
2
|
-
module Config
|
3
|
-
class Page
|
4
|
-
attr_accessor :group_name, :plugin_url, :cacheable, :expires
|
5
|
-
|
6
|
-
def dump
|
7
|
-
result = {}
|
8
|
-
result['group_name'] = self.group_name unless self.group_name.nil?
|
9
|
-
result['plugin_url'] = self.plugin_url unless self.plugin_url.nil?
|
10
|
-
result['cacheable'] = self.cacheable unless self.cacheable.nil?
|
11
|
-
result['expires'] = self.expires unless self.expires.nil?
|
12
|
-
result
|
13
|
-
end
|
14
|
-
|
15
|
-
def load(data, group_name=nil)
|
16
|
-
self.group_name = data['group_name'] unless data['group_name'].nil?
|
17
|
-
self.group_name = group_name unless group_name.nil?
|
18
|
-
self.plugin_url = data['plugin_url']
|
19
|
-
self.cacheable = data['cacheable'] unless data['cacheable'].nil?
|
20
|
-
self.expires = data['expires'] unless data['expires'].nil?
|
21
|
-
end
|
22
|
-
|
23
|
-
def director
|
24
|
-
$logger.info self.inspect if self.group_name.nil?
|
25
|
-
"#{Odania.varnish_sanitize(self.group_name)}_director"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
module Odania
|
2
|
-
module Config
|
3
|
-
class PageBase
|
4
|
-
attr_accessor :assets
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
reset
|
8
|
-
end
|
9
|
-
|
10
|
-
def add(data, group_name=nil)
|
11
|
-
duplicates = Hash.new { |hash, key| hash[key] = [] }
|
12
|
-
unless data['assets'].nil?
|
13
|
-
data['assets'].each_pair do |name, asset_data|
|
14
|
-
duplicates[:assets] << name if self.assets.key? name
|
15
|
-
self.assets[name].load(asset_data, group_name)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
duplicates
|
19
|
-
end
|
20
|
-
|
21
|
-
def load(data, group_name)
|
22
|
-
self.add(data, group_name)
|
23
|
-
end
|
24
|
-
|
25
|
-
def reset
|
26
|
-
self.assets = Hash.new { |hash, key| hash[key] = Page.new }
|
27
|
-
|
28
|
-
@plugins = {:assets => Hash.new { |hash, key| hash[key] = [] }}
|
29
|
-
end
|
30
|
-
|
31
|
-
def [](type)
|
32
|
-
self.assets
|
33
|
-
end
|
34
|
-
|
35
|
-
def dump
|
36
|
-
asset_data = {}
|
37
|
-
assets.each_pair do |web_url, page|
|
38
|
-
asset_data[web_url] = page.dump
|
39
|
-
end
|
40
|
-
|
41
|
-
{
|
42
|
-
'assets' => asset_data
|
43
|
-
}
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
module Odania
|
2
|
-
module Config
|
3
|
-
class PluginConfig
|
4
|
-
attr_accessor :domains, :config, :valid_domains, :default_domains, :plugin_config, :partials
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
reset
|
8
|
-
end
|
9
|
-
|
10
|
-
# Load the global configuration
|
11
|
-
def load(data)
|
12
|
-
reset
|
13
|
-
@config = data['config'] unless data['config'].nil?
|
14
|
-
@plugin_config = data['plugin-config'] unless data['plugin-config'].nil?
|
15
|
-
@valid_domains = data['valid_domains'] unless data['valid_domains'].nil?
|
16
|
-
@default_domains = data['default_domains'] unless data['default_domains'].nil?
|
17
|
-
@partials = data['partials'] unless data['partials'].nil?
|
18
|
-
unless data['domains'].nil?
|
19
|
-
data['domains'].each_pair do |name, domain_data|
|
20
|
-
@domains[name].load(domain_data)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
true
|
25
|
-
end
|
26
|
-
|
27
|
-
def [](key)
|
28
|
-
@domains[key]
|
29
|
-
end
|
30
|
-
|
31
|
-
# Reset configuration
|
32
|
-
def reset
|
33
|
-
@config = {}
|
34
|
-
@plugin_config = {}
|
35
|
-
@default_domains = {}
|
36
|
-
@valid_domains = {}
|
37
|
-
@partials = {}
|
38
|
-
@domains = Hash.new { |hash, key| hash[key] = Domain.new(key) }
|
39
|
-
end
|
40
|
-
|
41
|
-
def dump
|
42
|
-
domain_data = {}
|
43
|
-
@domains.each_pair do |name, domain|
|
44
|
-
domain_data[name] = domain.dump
|
45
|
-
end
|
46
|
-
|
47
|
-
{
|
48
|
-
'plugin-config' => plugin_config,
|
49
|
-
'config' => config,
|
50
|
-
'default_domains' => @default_domains,
|
51
|
-
'valid_domains' => @valid_domains,
|
52
|
-
'partials' => @partials,
|
53
|
-
'domains' => domain_data
|
54
|
-
}
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
data/lib/odania/config/style.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
module Odania
|
2
|
-
module Config
|
3
|
-
class Style
|
4
|
-
attr_accessor :name, :entry_point
|
5
|
-
|
6
|
-
def initialize(name)
|
7
|
-
self.name = name
|
8
|
-
reset
|
9
|
-
end
|
10
|
-
|
11
|
-
def plugins(type, key)
|
12
|
-
@plugins[type][key]
|
13
|
-
end
|
14
|
-
|
15
|
-
def dump
|
16
|
-
result = super
|
17
|
-
|
18
|
-
result['entry_point'] = entry_point
|
19
|
-
result
|
20
|
-
end
|
21
|
-
|
22
|
-
def load(data, group_name)
|
23
|
-
reset
|
24
|
-
super(data, group_name)
|
25
|
-
self.entry_point = data['entry_point'] unless data['entry_point'].nil?
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def reset
|
31
|
-
super
|
32
|
-
self.entry_point = nil
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,113 +0,0 @@
|
|
1
|
-
module Odania
|
2
|
-
module Config
|
3
|
-
class SubDomain < PageBase
|
4
|
-
attr_accessor :name, :config, :web, :layouts, :from_plugin, :redirects
|
5
|
-
|
6
|
-
def initialize(name)
|
7
|
-
self.name = name
|
8
|
-
reset
|
9
|
-
end
|
10
|
-
|
11
|
-
def set_config(config_data, group_name)
|
12
|
-
errors = []
|
13
|
-
return errors if config_data.nil?
|
14
|
-
|
15
|
-
config_data.each_pair do |key, val|
|
16
|
-
from_plugin[:config][key] << group_name
|
17
|
-
errors << {:type => :config, :plugins => from_plugin[:config][key], :key => key} unless config[key].nil?
|
18
|
-
config[key] = val
|
19
|
-
end
|
20
|
-
errors
|
21
|
-
end
|
22
|
-
|
23
|
-
def get_redirects
|
24
|
-
return {} if self.redirects.nil?
|
25
|
-
self.redirects
|
26
|
-
end
|
27
|
-
|
28
|
-
def plugins(type, key)
|
29
|
-
@plugins[type][key]
|
30
|
-
end
|
31
|
-
|
32
|
-
def dump
|
33
|
-
result = super
|
34
|
-
|
35
|
-
layout_data = {}
|
36
|
-
layouts.each_pair do |layout_name, layout|
|
37
|
-
layout_data[layout_name] = layout.dump
|
38
|
-
end
|
39
|
-
|
40
|
-
web_data = {}
|
41
|
-
web.each_pair do |url, page|
|
42
|
-
web_data[url] = page.dump
|
43
|
-
end
|
44
|
-
|
45
|
-
result['redirects'] = self.redirects
|
46
|
-
result['config'] = self.config
|
47
|
-
result['web'] = web_data
|
48
|
-
result['layouts'] = layout_data
|
49
|
-
result
|
50
|
-
end
|
51
|
-
|
52
|
-
def load(data)
|
53
|
-
reset
|
54
|
-
super(data, nil)
|
55
|
-
self.add(data)
|
56
|
-
end
|
57
|
-
|
58
|
-
def add(data, group_name=nil)
|
59
|
-
duplicates = super(data, group_name)
|
60
|
-
|
61
|
-
self.config = data['config'] unless data['config'].nil?
|
62
|
-
|
63
|
-
unless data['web'].nil?
|
64
|
-
data['web'].each_pair do |name, partial_data|
|
65
|
-
self.web[name].load(partial_data, group_name)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
unless data['layouts'].nil?
|
70
|
-
data['layouts'].each_pair do |name, layout_data|
|
71
|
-
self.layouts[name].load(layout_data, group_name)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
unless data['redirects'].nil?
|
76
|
-
data['redirects'].each_pair do |src_url, target_url|
|
77
|
-
duplicates[:redirect] << src_url if self.redirects.key? src_url
|
78
|
-
self.redirects[src_url] = target_url
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
duplicates
|
83
|
-
end
|
84
|
-
|
85
|
-
def layout_assets
|
86
|
-
layout_assets = {}
|
87
|
-
self.layouts.each_pair do |_name, layout|
|
88
|
-
layout_assets.merge! layout.assets
|
89
|
-
end
|
90
|
-
layout_assets
|
91
|
-
end
|
92
|
-
|
93
|
-
def [](type)
|
94
|
-
type = type.to_sym
|
95
|
-
return self.web if :web.eql? type
|
96
|
-
return self.layouts if :layouts.eql? type
|
97
|
-
return self.layout_assets if :layout_assets.eql? type
|
98
|
-
super(type)
|
99
|
-
end
|
100
|
-
|
101
|
-
private
|
102
|
-
|
103
|
-
def reset
|
104
|
-
super
|
105
|
-
self.config = {}
|
106
|
-
self.from_plugin = {:config => Hash.new { |hash, key| hash[key] = [] }}
|
107
|
-
self.redirects = {}
|
108
|
-
self.layouts = Hash.new { |hash, key| hash[key] = Layout.new }
|
109
|
-
self.web = Hash.new { |hash, key| hash[key] = Page.new }
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|