Class: OdaniaStaticPages::Generator::Jekyll

Inherits:
Object
  • Object
show all
Includes:
NginxHelper
Defined in:
lib/odania_static_pages/generator/jekyll.rb

Instance Method Summary collapse

Methods included from NginxHelper

#generate_nginx_config

Instance Method Details

#build(env) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/odania_static_pages/generator/jekyll.rb', line 61

def build(env)
	puts 'Building all jekyll websites'
	setup_generator

	generate_nginx_config(false)
	jekyll_env = 'live'.eql?(env) ? 'production' : env

	grouped_domains.each_pair do |site_name, page_config|
		build_for_configs(page_config, site_name, @config.output_site_path, jekyll_env)
	end
end

#initObject



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
# File 'lib/odania_static_pages/generator/jekyll.rb', line 6

def init
	puts 'Initliazing jekyll pages'
	puts
	setup_generator

	FileUtils.mkdir_p @pages_path unless File.exist? @pages_path

	unless File.exist? @jekyll_config_file
		FileUtils.cp File.join(@config.base_dir, 'templates', 'jekyll', 'example_config.yml'), @jekyll_config_file
		setup_generator
	end

	FileUtils.mkdir_p @generator_config.full_common_folder unless File.exist? @generator_config.full_common_folder

	puts 'Initialize Gemfile'
	gemfile_template = File.join(@config.base_dir, 'templates', 'jekyll', 'Gemfile.erb')
	gem_extra = @generator_config.gem_extra
	File.write File.join(@generator_config.full_common_folder, 'Gemfile'), ERB.new(File.read(gemfile_template)).result(binding)

	puts 'Copying Dockerfile'
	FileUtils.cp File.join(@config.base_dir, 'templates', 'live', 'Dockerfile'), File.join(@config.output_path, 'Dockerfile')

	puts 'Install gems'
	puts `cd #{@generator_config.full_common_folder} && bundle check`
	puts `cd #{@generator_config.full_common_folder} && bundle install --path ~/.gems` unless $?.success?

	@jekyll_config['pages'].each do |page|
		relative_page_path = @generator_config.page_path page
		relative_page_path += page['baseurl'] unless page['baseurl'].empty?
		page_path = File.join @pages_path, relative_page_path

		puts '*' * 100
		puts "Processing #{relative_page_path} => #{page_path}"

		unless File.directory? page_path
			puts "Creating page #{page['name']}"
			`cd #{@pages_path} && octopress new #{relative_page_path}`
		end

		page_config = @generator_config.prepare_config page
		current_config_file = File.join page_path, '_config.yml'
		current_config = YAML.load_file current_config_file

		unless current_config.eql? page_config
			puts ' -> Updating config'
			File.write current_config_file, YAML.dump(page_config)
		end

		@generator_config.link @config.base_dir, page_path, page

		puts
	end

end