Class: Jekyll::Site
- Inherits:
-
Object
- Object
- Jekyll::Site
- Defined in:
- lib/jekyll-multiple-languages-plugin.rb
Overview
class Site
Instance Attribute Summary collapse
-
#parsed_translations ⇒ Object
Hash that stores parsed translations read from YAML files.
Instance Method Summary collapse
-
#process ⇒ Object
process.
- #process_org ⇒ Object
-
#read_posts(dir) ⇒ Object
read_posts ======================================.
- #read_posts_org ⇒ Object
Instance Attribute Details
#parsed_translations ⇒ Object
Hash that stores parsed translations read from YAML files.
68 69 70 |
# File 'lib/jekyll-multiple-languages-plugin.rb', line 68 def parsed_translations @parsed_translations end |
Instance Method Details
#process ⇒ Object
process
Reads Jekyll and plugin configuration parameters set on _config.yml, sets main parameters and processes the website for each language.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/jekyll-multiple-languages-plugin.rb', line 78 def process # Check if plugin settings are set, if not, set a default or quit. #------------------------------------------------------------------------- self.parsed_translations ||= {} self.config['exclude_from_localizations'] ||= [] if ( !self.config['languages'] or self.config['languages'].empty? or !self.config['languages'].all? ) puts 'You must provide at least one language using the "languages" setting on your _config.yml.' exit end # Variables #------------------------------------------------------------------------- # Original Jekyll configurations baseurl_org = self.config[ 'baseurl' ].to_s # Baseurl set on _config.yml dest_org = self.dest # Destination folder where the website is generated # Site building only variables languages = self.config['languages'] # List of languages set on _config.yml # Site wide plugin configurations self.config['default_lang'] = languages.first # Default language (first language of array set on _config.yml) self.config[ 'lang'] = languages.first # Current language being processed self.config['baseurl_root'] = baseurl_org # Baseurl of website root (without the appended language code) self.config['translations'] = self.parsed_translations # Hash that stores parsed translations read from YAML files. Exposes this hash to Liquid. # Build the website for default language #------------------------------------------------------------------------- puts "Building site for default language: \"#{self.config['lang']}\" to: #{self.dest}" process_org # Build the website for the other languages #------------------------------------------------------------------------- # Remove .htaccess file from included files, so it wont show up on translations folders. self.include -= [".htaccess"] languages.drop(1).each do |lang| # Language specific config/variables @dest = dest_org + "/" + lang self.config['baseurl'] = baseurl_org + "/" + lang self.config['lang'] = lang puts "Building site for language: \"#{self.config['lang']}\" to: #{self.dest}" process_org end # Revert to initial Jekyll configurations (necessary for regeneration) self.config[ 'baseurl' ] = baseurl_org # Baseurl set on _config.yml @dest = dest_org # Destination folder where the website is generated puts 'Build complete' end |
#process_org ⇒ Object
70 |
# File 'lib/jekyll-multiple-languages-plugin.rb', line 70 alias :process_org :process |
#read_posts(dir) ⇒ Object
read_posts
152 153 154 155 156 157 158 159 160 161 |
# File 'lib/jekyll-multiple-languages-plugin.rb', line 152 def read_posts(dir) translate_posts = !self.config['exclude_from_localizations'].include?("_posts") if dir == '' && translate_posts read_posts("_i18n/#{self.config['lang']}/") else read_posts_org(dir) end end |
#read_posts_org ⇒ Object
147 |
# File 'lib/jekyll-multiple-languages-plugin.rb', line 147 alias :read_posts_org :read_posts |