Class: OdaniaStaticPages::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/odania_static_pages/config.rb,
lib/odania_static_pages/config/s3.rb,
lib/odania_static_pages/config/rsync.rb,
lib/odania_static_pages/config/docker_compose.rb,
lib/odania_static_pages/config/generator/jekyll.rb

Defined Under Namespace

Modules: Deploy, Generator Classes: Environment

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = nil) ⇒ Config

Returns a new instance of Config.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/odania_static_pages/config.rb', line 12

def initialize(path=nil)
	@base_dir = File.absolute_path(File.join(File.dirname(__FILE__), '..', '..'))
	@project_dir = path.nil? ? Dir.getwd : path
	@output_sites_path = 'sites'
	@output_nginx_path = 'nginx'
	@generator_type = 'Jekyll'
	@environments = {
		develop: Environment.new('_develop', 'DockerCompose'),
		live: Environment.new('_live', 'Rsync')
	}
	@generator = Generator::Jekyll.new(@project_dir, {})
end

Instance Attribute Details

#base_dirObject (readonly)

Returns the value of attribute base_dir.



9
10
11
# File 'lib/odania_static_pages/config.rb', line 9

def base_dir
  @base_dir
end

#environmentObject

Returns the value of attribute environment.



8
9
10
# File 'lib/odania_static_pages/config.rb', line 8

def environment
  @environment
end

#environmentsObject (readonly)

Returns the value of attribute environments.



9
10
11
# File 'lib/odania_static_pages/config.rb', line 9

def environments
  @environments
end

#generatorObject (readonly)

Returns the value of attribute generator.



9
10
11
# File 'lib/odania_static_pages/config.rb', line 9

def generator
  @generator
end

#generator_typeObject (readonly)

Returns the value of attribute generator_type.



9
10
11
# File 'lib/odania_static_pages/config.rb', line 9

def generator_type
  @generator_type
end

#output_nginx_pathObject (readonly)

Returns the value of attribute output_nginx_path.



9
10
11
# File 'lib/odania_static_pages/config.rb', line 9

def output_nginx_path
  @output_nginx_path
end

#output_sites_pathObject (readonly)

Returns the value of attribute output_sites_path.



9
10
11
# File 'lib/odania_static_pages/config.rb', line 9

def output_sites_path
  @output_sites_path
end

#project_dirObject (readonly)

Returns the value of attribute project_dir.



9
10
11
# File 'lib/odania_static_pages/config.rb', line 9

def project_dir
  @project_dir
end

Instance Method Details

#config_fileObject



50
51
52
# File 'lib/odania_static_pages/config.rb', line 50

def config_file
	File.join(@project_dir, '_config.yml')
end

#current_environmentObject



70
71
72
73
74
75
76
77
# File 'lib/odania_static_pages/config.rb', line 70

def current_environment
	if @environments[@environment].nil?
		puts "Environment #{environment} no found!"
		puts "Available Environments: #{@environments.keys}"
		exit 1
	end
	@environments[@environment]
end

#load!Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/odania_static_pages/config.rb', line 25

def load!
	if File.exist? config_file
		config = YAML.load_file(config_file).stringify_keys!
		@output_sites_path = config['output_sites_path'] unless config['output_sites_path'].nil?
		@output_nginx_path = config['output_nginx_path'] unless config['output_nginx_path'].nil?
		@generator_type = config['generator_type'] unless config['generator_type'].nil?

		unless config['environments'].nil?
			@environments = {}
			config['environments'].each_pair do |name, data|
				@environments[name] = Environment.from_hash data
			end
		end

		@deploy = Deploy.from_hash(config['deploy']) unless config['deploy'].nil?

		unless config['generator'].nil?
			generator_config_module = "OdaniaStaticPages::Config::Generator::#{@generator_type}".constantize
			@generator = generator_config_module.from_hash @project_dir, config['generator']
		end
	end

	self
end

#output_nginx_conf_d_pathObject



66
67
68
# File 'lib/odania_static_pages/config.rb', line 66

def output_nginx_conf_d_path
	File.join @output_nginx_path, 'conf.d'
end

#output_pathObject



58
59
60
# File 'lib/odania_static_pages/config.rb', line 58

def output_path
	File.join @project_dir, current_environment.output_path
end

#output_site_pathObject



54
55
56
# File 'lib/odania_static_pages/config.rb', line 54

def output_site_path
	File.join @project_dir, current_environment.output_path, @output_sites_path
end

#pages_pathObject



62
63
64
# File 'lib/odania_static_pages/config.rb', line 62

def pages_path
	File.join @project_dir, 'pages'
end

#save!Object



79
80
81
82
# File 'lib/odania_static_pages/config.rb', line 79

def save!
	puts "Writing config file #{config_file}"
	File.write config_file, YAML.dump(to_h)
end