Class: Odania::Config::SubDomain

Inherits:
PageBase
  • Object
show all
Defined in:
lib/odania/config/sub_domain.rb

Instance Attribute Summary collapse

Attributes inherited from PageBase

#assets

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ SubDomain

Returns a new instance of SubDomain.



6
7
8
9
# File 'lib/odania/config/sub_domain.rb', line 6

def initialize(name)
	self.name = name
	reset
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



4
5
6
# File 'lib/odania/config/sub_domain.rb', line 4

def config
  @config
end

#from_pluginObject

Returns the value of attribute from_plugin.



4
5
6
# File 'lib/odania/config/sub_domain.rb', line 4

def from_plugin
  @from_plugin
end

#layoutsObject

Returns the value of attribute layouts.



4
5
6
# File 'lib/odania/config/sub_domain.rb', line 4

def layouts
  @layouts
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/odania/config/sub_domain.rb', line 4

def name
  @name
end

#redirectsObject

Returns the value of attribute redirects.



4
5
6
# File 'lib/odania/config/sub_domain.rb', line 4

def redirects
  @redirects
end

#webObject

Returns the value of attribute web.



4
5
6
# File 'lib/odania/config/sub_domain.rb', line 4

def web
  @web
end

Instance Method Details

#[](type) ⇒ Object



93
94
95
96
97
98
99
# File 'lib/odania/config/sub_domain.rb', line 93

def [](type)
	type = type.to_sym
	return self.web if :web.eql? type
	return self.layouts if :layouts.eql? type
	return self.layout_assets if :layout_assets.eql? type
	super(type)
end

#add(data, group_name = nil) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/odania/config/sub_domain.rb', line 58

def add(data, group_name=nil)
	duplicates = super(data, group_name)

	self.config = data['config'] unless data['config'].nil?

	unless data['web'].nil?
		data['web'].each_pair do |name, partial_data|
			self.web[name].load(partial_data, group_name)
		end
	end

	unless data['layouts'].nil?
		data['layouts'].each_pair do |name, layout_data|
			self.layouts[name].load(layout_data, group_name)
		end
	end

	unless data['redirects'].nil?
		data['redirects'].each_pair do |src_url, target_url|
			duplicates[:redirect] << src_url if self.redirects.key? src_url
			self.redirects[src_url] = target_url
		end
	end

	duplicates
end

#dumpObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/odania/config/sub_domain.rb', line 32

def dump
	result = super

	layout_data = {}
	layouts.each_pair do |layout_name, layout|
		layout_data[layout_name] = layout.dump
	end

	web_data = {}
	web.each_pair do |url, page|
		web_data[url] = page.dump
	end

	result['redirects'] = self.redirects
	result['config'] = self.config
	result['web'] = web_data
	result['layouts'] = layout_data
	result
end

#get_redirectsObject



23
24
25
26
# File 'lib/odania/config/sub_domain.rb', line 23

def get_redirects
	return {} if self.redirects.nil?
	self.redirects
end

#layout_assetsObject



85
86
87
88
89
90
91
# File 'lib/odania/config/sub_domain.rb', line 85

def layout_assets
	layout_assets = {}
	self.layouts.each_pair do |_name, layout|
		layout_assets.merge! layout.assets
	end
	layout_assets
end

#load(data) ⇒ Object



52
53
54
55
56
# File 'lib/odania/config/sub_domain.rb', line 52

def load(data)
	reset
	super(data, nil)
	self.add(data)
end

#plugins(type, key) ⇒ Object



28
29
30
# File 'lib/odania/config/sub_domain.rb', line 28

def plugins(type, key)
	@plugins[type][key]
end

#set_config(config_data, group_name) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/odania/config/sub_domain.rb', line 11

def set_config(config_data, group_name)
	errors = []
	return errors if config_data.nil?

	config_data.each_pair do |key, val|
		from_plugin[:config][key] << group_name
		errors << {:type => :config, :plugins => from_plugin[:config][key], :key => key} unless config[key].nil?
		config[key] = val
	end
	errors
end