Class: OdaniaStaticPages::Config::Generator::Jekyll
- Inherits:
-
Object
- Object
- OdaniaStaticPages::Config::Generator::Jekyll
- Defined in:
- lib/odania_static_pages/config/generator/jekyll.rb
Instance Attribute Summary collapse
-
#common_folder ⇒ Object
readonly
Returns the value of attribute common_folder.
-
#encoding ⇒ Object
readonly
Returns the value of attribute encoding.
-
#extra_options ⇒ Object
readonly
Returns the value of attribute extra_options.
-
#gem_extra ⇒ Object
readonly
Returns the value of attribute gem_extra.
-
#nginx_default_redirect ⇒ Object
readonly
Returns the value of attribute nginx_default_redirect.
-
#plugins ⇒ Object
readonly
Returns the value of attribute plugins.
Class Method Summary collapse
Instance Method Summary collapse
- #full_common_folder ⇒ Object
-
#initialize(project_dir, options) ⇒ Jekyll
constructor
A new instance of Jekyll.
- #jekyll_config ⇒ Object
- #jekyll_config_file ⇒ Object
- #link(base_dir, page_path, page) ⇒ Object
- #page_path(page_config) ⇒ Object
- #pages_dir ⇒ Object
- #prepare_config(cfg) ⇒ Object
- #template_pages_dir ⇒ Object
- #to_h ⇒ Object
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, ) @plugins = ['plugins'] || %w(jekyll-feed octopress-image-tag octopress-gist) @encoding = ['encoding'] || 'utf-8' @common_folder = ['common_folder'] || 'common' @extra_options = ['extra_options'] || {} @gem_extra = ['gem_extra'] || '' @project_dir = project_dir @nginx_default_redirect = ['nginx_default_redirect'] || 'https://www.odania-it.com' end |
Instance Attribute Details
#common_folder ⇒ Object (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 |
#encoding ⇒ Object (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_options ⇒ Object (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 end |
#gem_extra ⇒ Object (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_redirect ⇒ Object (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 |
#plugins ⇒ Object (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
Instance Method Details
#full_common_folder ⇒ Object
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_config ⇒ Object
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_file ⇒ Object
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 |
#link(base_dir, page_path, page) ⇒ Object
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_dir ⇒ Object
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_dir ⇒ Object
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_h ⇒ Object
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 |