jekyll-polyglot 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/polyglot.rb +168 -0
- metadata +64 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 804d1b4413eead1b3cb2ba61cf7756cf1ca5b474
|
4
|
+
data.tar.gz: f128e8f07eb56bcb3efe4c4e9f2c5190d1c5b759
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9aaaf216dfc22f58e87f45ec21c8b8e7e03009374b4600ddee87b3576270f4c4c902a56ceb5a65e8c154a3ae3a8c7cffa7414c430a6801d66b2125ea07574abd
|
7
|
+
data.tar.gz: 47b49166bb5fc8a3eee76a86d6ebd9ac4ecd096028443d99fb38306ee95956e029465c10ac5d4aa5ace94b54daea072139ef5b137ff669240d86dc6e3839399c
|
data/lib/polyglot.rb
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
include Process
|
2
|
+
module Jekyll
|
3
|
+
# Alteration to Jekyll Site class
|
4
|
+
# provides aliased methods to direct site.write to output into seperate
|
5
|
+
# language folders
|
6
|
+
class Site
|
7
|
+
attr_reader :default_lang, :languages, :exclude_from_localization
|
8
|
+
attr_accessor :file_langs, :active_lang
|
9
|
+
|
10
|
+
def prepare
|
11
|
+
@start_time = time
|
12
|
+
@file_langs = {}
|
13
|
+
@default_lang = config['default_lang'] || 'en'
|
14
|
+
@languages = config['languages'] || ['en']
|
15
|
+
(@keep_files << @languages - [@default_lang]).flatten!
|
16
|
+
@exclude_from_localization = config['exclude_from_localization'] || []
|
17
|
+
@active_lang = @default_lang
|
18
|
+
end
|
19
|
+
|
20
|
+
alias_method :process_orig, :process
|
21
|
+
def process
|
22
|
+
prepare
|
23
|
+
pids = {}
|
24
|
+
languages.each do |lang|
|
25
|
+
pids[lang] = fork do
|
26
|
+
process_language lang
|
27
|
+
end
|
28
|
+
end
|
29
|
+
Signal.trap('INT') do
|
30
|
+
languages.each do |lang|
|
31
|
+
puts "Killing #{pids[lang]} : #{lang}"
|
32
|
+
kill('INT', pids[lang])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
languages.each do |lang|
|
36
|
+
waitpid pids[lang]
|
37
|
+
detach pids[lang]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
alias_method :site_payload_orig, :site_payload
|
42
|
+
def site_payload
|
43
|
+
payload = site_payload_orig
|
44
|
+
payload['site']['default_lang'] = default_lang
|
45
|
+
payload['site']['languages'] = languages
|
46
|
+
payload['site']['active_lang'] = active_lang
|
47
|
+
payload
|
48
|
+
end
|
49
|
+
|
50
|
+
def process_language(lang)
|
51
|
+
@active_lang = lang
|
52
|
+
config['active_lang'] = @active_lang
|
53
|
+
return build_language(@active_lang) if @active_lang == @default_lang
|
54
|
+
process_active_language
|
55
|
+
end
|
56
|
+
|
57
|
+
def process_active_language
|
58
|
+
dest_orig = dest
|
59
|
+
exclude_orig = exclude
|
60
|
+
@dest = @dest + '/' + @active_lang
|
61
|
+
@exclude += config['exclude_from_localization']
|
62
|
+
build_language(@active_lang)
|
63
|
+
@dest = dest_orig
|
64
|
+
@exclude = exclude_orig
|
65
|
+
end
|
66
|
+
|
67
|
+
def build_language(lang)
|
68
|
+
reset
|
69
|
+
read
|
70
|
+
filter
|
71
|
+
generate
|
72
|
+
render
|
73
|
+
cleanup
|
74
|
+
puts "Building #{lang} Site"
|
75
|
+
write
|
76
|
+
end
|
77
|
+
|
78
|
+
def filter
|
79
|
+
langs = {}
|
80
|
+
approved = {}
|
81
|
+
posts.each do |post|
|
82
|
+
language = post.data['lang'] || @default_lang
|
83
|
+
next if langs[post.url] == @active_lang
|
84
|
+
if langs[post.url] == @default_lang
|
85
|
+
next if language != @active_lang
|
86
|
+
end
|
87
|
+
approved[post.url] = post
|
88
|
+
langs[post.url] = language
|
89
|
+
end
|
90
|
+
@posts = approved.values
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# Alteration to Jekyll Convertible module
|
95
|
+
# provides aliased methods to direct Convertible to skip files for write under
|
96
|
+
# certain conditions
|
97
|
+
module Convertible
|
98
|
+
def lang
|
99
|
+
data['lang'] || site.config['default_lang']
|
100
|
+
end
|
101
|
+
|
102
|
+
def lang=(str)
|
103
|
+
data['lang'] = str
|
104
|
+
end
|
105
|
+
|
106
|
+
alias_method :write_orig, :write
|
107
|
+
def write(dest)
|
108
|
+
path = polypath(dest)
|
109
|
+
return if skip?(path)
|
110
|
+
output_orig = output.clone
|
111
|
+
relativize_urls(site.active_lang)
|
112
|
+
write_orig(dest)
|
113
|
+
self.output = output_orig
|
114
|
+
site.file_langs[path] = lang
|
115
|
+
end
|
116
|
+
|
117
|
+
def polypath(dest)
|
118
|
+
n = ''
|
119
|
+
site.languages.each do |lang|
|
120
|
+
n += "(\\\.#{lang}\\/)|"
|
121
|
+
end
|
122
|
+
n.chomp! '|'
|
123
|
+
destination(dest).gsub(%r{#{n}}, '/')
|
124
|
+
end
|
125
|
+
|
126
|
+
def skip?(path)
|
127
|
+
return false if site.file_langs[path].nil?
|
128
|
+
return false if lang == site.active_lang
|
129
|
+
if lang == site.default_lang
|
130
|
+
return site.file_langs[path] == site.active_lang
|
131
|
+
end
|
132
|
+
true
|
133
|
+
end
|
134
|
+
|
135
|
+
def relativize_urls(lang)
|
136
|
+
return if lang == site.default_lang
|
137
|
+
output.gsub!(relative_url_regex, "href=\"#{site.baseurl}/#{lang}/" + '\1"')
|
138
|
+
end
|
139
|
+
|
140
|
+
def relative_url_regex
|
141
|
+
n = ''
|
142
|
+
site.exclude.each do |x|
|
143
|
+
n += "(?!#{x}\/)"
|
144
|
+
end
|
145
|
+
# regex that looks for all relative urls except for excluded files
|
146
|
+
%r{href=\"\/#{site.baseurl.gsub(%r{\/}, '')}\/((?:#{n}[^,'\"\s\/?\.#-]+\.?)*(?:\/[^\]\[\)\(\"\'\s]*)?)\"}
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
# Alteration to Jekyll StaticFile
|
151
|
+
# provides aliased methods to direct write to skip files
|
152
|
+
# excluded from localization
|
153
|
+
class StaticFile
|
154
|
+
alias_method :write_orig, :write
|
155
|
+
def write(dest)
|
156
|
+
return false if exclude_from_localization?
|
157
|
+
write_orig(dest)
|
158
|
+
end
|
159
|
+
|
160
|
+
def exclude_from_localization?
|
161
|
+
return false if @site.active_lang == @site.default_lang
|
162
|
+
@site.exclude_from_localization.each do |e|
|
163
|
+
return true if relative_path[1..-1].start_with?(e)
|
164
|
+
end
|
165
|
+
false
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-polyglot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Samuel Volin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: listen
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.0.0
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.0.0
|
33
|
+
description: Fast open source internationalization plugin for Jekyll blogs.
|
34
|
+
email: untra.sam@gmail.com
|
35
|
+
executables: []
|
36
|
+
extensions: []
|
37
|
+
extra_rdoc_files: []
|
38
|
+
files:
|
39
|
+
- lib/polyglot.rb
|
40
|
+
homepage: http://untra.github.io/polyglot
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
metadata: {}
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 2.4.8
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: I18n plugin for Jekyll Blogs
|
64
|
+
test_files: []
|