class Jekyll::Site

class Site

Attributes

parsed_translations[RW]

Public Instance Methods

process() click to toggle source
process

Reads Jekyll and plugin configuration parameters set on _config.yml, sets
main parameters and processes the website for each language.
# 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
Also aliased as: process_org
process_org()
Alias for: process
read_posts(dir) click to toggle source
read_posts
# 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
Also aliased as: read_posts_org
read_posts_org(dir)
Alias for: read_posts