Class: OdaniaStaticPages::Config::Generator::Jekyll

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_dir, options) ⇒ Jekyll

Returns a new instance of Jekyll.



7
8
9
10
11
12
13
14
15
# File 'lib/odania_static_pages/config/generator/jekyll.rb', line 7

def initialize(project_dir, options)
	@plugins = options['plugins'] || %w(jekyll-feed octopress-image-tag octopress-gist)
	@encoding = options['encoding'] || 'utf-8'
	@common_folder = options['common_folder'] || 'common'
	@extra_options = options['extra_options'] || {}
	@gem_extra = options['gem_extra'] || ''
	@project_dir = project_dir
	@nginx_default_redirect = options['nginx_default_redirect'] || 'https://www.odania-it.com'
end

Instance Attribute Details

#common_folderObject (readonly)

Returns the value of attribute common_folder.



5
6
7
# File 'lib/odania_static_pages/config/generator/jekyll.rb', line 5

def common_folder
  @common_folder
end

#encodingObject (readonly)

Returns the value of attribute encoding.



5
6
7
# File 'lib/odania_static_pages/config/generator/jekyll.rb', line 5

def encoding
  @encoding
end

#extra_optionsObject (readonly)

Returns the value of attribute extra_options.



5
6
7
# File 'lib/odania_static_pages/config/generator/jekyll.rb', line 5

def extra_options
  @extra_options
end

#gem_extraObject (readonly)

Returns the value of attribute gem_extra.



5
6
7
# File 'lib/odania_static_pages/config/generator/jekyll.rb', line 5

def gem_extra
  @gem_extra
end

#nginx_default_redirectObject (readonly)

Returns the value of attribute nginx_default_redirect.



5
6
7
# File 'lib/odania_static_pages/config/generator/jekyll.rb', line 5

def nginx_default_redirect
  @nginx_default_redirect
end

#pluginsObject (readonly)

Returns the value of attribute plugins.



5
6
7
# File 'lib/odania_static_pages/config/generator/jekyll.rb', line 5

def plugins
  @plugins
end

Class Method Details

.from_hash(project_dir, data) ⇒ Object



27
28
29
# File 'lib/odania_static_pages/config/generator/jekyll.rb', line 27

def self.from_hash(project_dir, data)
	Jekyll.new project_dir, data
end

Instance Method Details

#full_common_folderObject



63
64
65
# File 'lib/odania_static_pages/config/generator/jekyll.rb', line 63

def full_common_folder
	File.join(@project_dir, @common_folder)
end

#jekyll_configObject



84
85
86
87
# File 'lib/odania_static_pages/config/generator/jekyll.rb', line 84

def jekyll_config
	return YAML.load_file jekyll_config_file if File.exist? jekyll_config_file
	{}
end

#jekyll_config_fileObject



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

def jekyll_config_file
	File.join(@project_dir, '_jekyll_config.yml')
end


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/odania_static_pages/config/generator/jekyll.rb', line 38

def link(base_dir, page_path, page)
	common_subfolders.each do |folder|
		create_link_if_required page_path, folder
	end

	puts ' -> Linking plugins'
	plugins_dir = File.join(page_path, '_plugins')
	FileUtils.mkdir_p plugins_dir

	Dir.glob(File.join(full_common_folder, '_plugins', '*')).each do |plugin_file|
		puts "   -> Linking plugin #{File.basename(plugin_file)}"
		FileUtils.ln_s plugin_file, plugins_dir, force: true
	end

	puts ' -> Linking Gemfile*'
	dot_bundle_folder = File.join(full_common_folder, '.bundle')
	FileUtils.ln_s(dot_bundle_folder, page_path, force: true) if File.exist? dot_bundle_folder
	FileUtils.ln_s File.join(full_common_folder, 'Gemfile'), File.join(page_path, 'Gemfile'), force: true
	FileUtils.ln_s File.join(full_common_folder, 'Gemfile.lock'), File.join(page_path, 'Gemfile.lock'), force: true

	puts ' -> Linking common pages'
	FileUtils.mkdir_p template_pages_dir
	link_common_pages template_pages_dir, page_path, template_pages_dir, page['lang']
end

#page_path(page_config) ⇒ Object



75
76
77
78
# File 'lib/odania_static_pages/config/generator/jekyll.rb', line 75

def page_path(page_config)
	uri = URI.parse(page_config['url'])
	uri.host
end

#pages_dirObject



71
72
73
# File 'lib/odania_static_pages/config/generator/jekyll.rb', line 71

def pages_dir
	File.join(@project_dir, 'pages')
end

#prepare_config(cfg) ⇒ Object



31
32
33
34
35
36
# File 'lib/odania_static_pages/config/generator/jekyll.rb', line 31

def prepare_config(cfg)
	page_config = cfg.clone
	page_config['plugins'] = @plugins
	page_config['encoding'] = @encoding
	@extra_options.merge page_config
end

#template_pages_dirObject



67
68
69
# File 'lib/odania_static_pages/config/generator/jekyll.rb', line 67

def template_pages_dir
	File.join(full_common_folder, '_pages')
end

#to_hObject



17
18
19
20
21
22
23
24
25
# File 'lib/odania_static_pages/config/generator/jekyll.rb', line 17

def to_h
	{
		plugins: @plugins,
		encoding: @encoding,
		common_folder: @common_folder,
		extra_options: @extra_options,
		gem_extra: @gem_extra
	}.stringify_keys!
end