Class: Jekyll::Site

Inherits:
Object
  • Object
show all
Defined in:
lib/polyglot.rb

Overview

Alteration to Jekyll Site class provides aliased methods to direct site.write to output into seperate language folders

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#active_langObject

Returns the value of attribute active_lang.



13
14
15
# File 'lib/polyglot.rb', line 13

def active_lang
  @active_lang
end

#default_langObject (readonly)

Returns the value of attribute default_lang.



12
13
14
# File 'lib/polyglot.rb', line 12

def default_lang
  @default_lang
end

#exclude_from_localizationObject (readonly)

Returns the value of attribute exclude_from_localization.



12
13
14
# File 'lib/polyglot.rb', line 12

def exclude_from_localization
  @exclude_from_localization
end

#file_langsObject

Returns the value of attribute file_langs.



13
14
15
# File 'lib/polyglot.rb', line 13

def file_langs
  @file_langs
end

#languagesObject (readonly)

Returns the value of attribute languages.



12
13
14
# File 'lib/polyglot.rb', line 12

def languages
  @languages
end

Instance Method Details

#prepareObject



15
16
17
18
19
20
21
22
23
# File 'lib/polyglot.rb', line 15

def prepare
  @file_langs = {}
  @default_lang = config['default_lang'] || 'en'
  @languages = config['languages'] || ['en']
  @parallel_localization = config['parallel_localization'] || true
  (@keep_files << @languages - [@default_lang]).flatten!
  @exclude_from_localization = config['exclude_from_localization'] || []
  @active_lang = @default_lang
end

#processObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/polyglot.rb', line 26

def process
  prepare
  if @parallel_localization
    pids = {}
    languages.each do |lang|
      pids[lang] = fork do
        process_language lang
      end
    end
    Signal.trap('INT') do
      languages.each do |lang|
        puts "Killing #{pids[lang]} : #{lang}"
        kill('INT', pids[lang])
      end
    end
    languages.each do |lang|
      waitpid pids[lang]
      detach pids[lang]
    end
  else
    languages.each do |lang|
      process_language lang
    end
  end
end

#process_active_languageObject



68
69
70
71
72
# File 'lib/polyglot.rb', line 68

def process_active_language
  @dest = @dest + '/' + @active_lang
  @exclude += config['exclude_from_localization']
  process_orig
end

#process_language(lang) ⇒ Object



61
62
63
64
65
66
# File 'lib/polyglot.rb', line 61

def process_language(lang)
  @active_lang = lang
  config['active_lang'] = @active_lang
  return process_orig if @active_lang == @default_lang
  process_active_language
end

#process_origObject



25
# File 'lib/polyglot.rb', line 25

alias_method :process_orig, :process

#site_payloadObject



53
54
55
56
57
58
59
# File 'lib/polyglot.rb', line 53

def site_payload
  payload = site_payload_orig
  payload['site']['default_lang'] = default_lang
  payload['site']['languages'] = languages
  payload['site']['active_lang'] = active_lang
  payload
end

#site_payload_origObject



52
# File 'lib/polyglot.rb', line 52

alias_method :site_payload_orig, :site_payload