Class: Jekyll::Site

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-multiple-languages-plugin.rb

Overview

class Site

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#parsed_translationsObject

Hash that stores parsed translations read from YAML files.



110
111
112
# File 'lib/jekyll-multiple-languages-plugin.rb', line 110

def parsed_translations
  @parsed_translations
end

Instance Method Details

#processObject

process

Reads Jekyll and plugin configuration parameters set on _config.yml, sets main parameters and processes the website for each language.



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/jekyll-multiple-languages-plugin.rb', line 120

def process
  # Check if plugin settings are set, if not, set a default or quit.
  #-------------------------------------------------------------------------
  self.parsed_translations ||= {}
  
  self.config['exclude_from_localizations'] ||= []

  self.config['default_locale_in_subfolder'] ||= false
  
  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 all languages
  #-------------------------------------------------------------------------
  
  # Remove .htaccess file from included files, so it wont show up on translations folders.
  self.include -= [".htaccess"]
  
  languages.each do |lang|
    
    # Language specific config/variables
    if lang != self.config['default_lang'] || self.config['default_locale_in_subfolder']
      @dest                  = dest_org    + "/" + lang
      self.config['baseurl'] = baseurl_org + "/" + lang
      self.config['lang']    =                     lang
    end
    
    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_orgObject



112
# File 'lib/jekyll-multiple-languages-plugin.rb', line 112

alias :process_org :process

#read_posts(dir) ⇒ Object

read_posts



190
191
192
193
194
195
196
197
198
199
# File 'lib/jekyll-multiple-languages-plugin.rb', line 190

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_orgObject



185
# File 'lib/jekyll-multiple-languages-plugin.rb', line 185

alias :read_posts_org :read_posts