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.



24
25
26
# File 'lib/jekyll-multiple-languages-plugin.rb', line 24

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.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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
# File 'lib/jekyll-multiple-languages-plugin.rb', line 34

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' ] # Baseurl set on _config.yml
  exclude_org                 = self.exclude             # List of excluded paths
  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
    
    # exclude folders or files from being copied to all the language folders
    exclude_from_localizations =  self.config['exclude_from_localizations']
    self.exclude               = exclude_org + exclude_from_localizations
    
    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
  self.exclude             = exclude_org  # List of excluded paths
  @dest                    = dest_org     # Destination folder where the website is generated
  
  puts 'Build complete'
end

#process_orgObject



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

alias :process_org :process

#read_posts(dir) ⇒ Object

read_posts



114
115
116
117
118
119
120
121
122
123
# File 'lib/jekyll-multiple-languages-plugin.rb', line 114

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



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

alias :read_posts_org :read_posts