Adds support for translation of platform pages

This commit is contained in:
Igor Kuzmenko 2017-07-18 17:49:58 +02:00
parent f5a483c86b
commit 43ec650bd4
3 changed files with 43 additions and 20 deletions

View file

@ -5,4 +5,6 @@
id: wallets-hardware id: wallets-hardware
platform: platform:
name: hardware name: hardware
os:
name: hardware
--- ---

View file

@ -5,4 +5,6 @@
id: wallets-web id: wallets-web
platform: platform:
name: web name: web
os:
name: web
--- ---

View file

@ -22,6 +22,22 @@ module Jekyll
end end
end end
class PlatformPage < Page
def initialize(site, base, dir, platform, os, lang)
@site = site
@base = base
@dir = dir
@name = 'index.html'
self.process(@name)
self.read_yaml(File.join(base, '_layouts'), 'wallet-platform.html')
self.data['platform'] = platform
self.data['os'] = os
self.data['id'] = ['wallets', platform['name'], os['name']].join('-')
self.data['lang'] = lang
end
end
class WalletsPageGenerator < Generator class WalletsPageGenerator < Generator
safe true safe true
@ -29,6 +45,9 @@ module Jekyll
# Get the collection of wallets from _wallets # Get the collection of wallets from _wallets
walletsCol = site.collections['wallets']; walletsCol = site.collections['wallets'];
# Get the collection of wallets from _wallets
platformsCol = site.collections['platforms'];
# Output dir # Output dir
# TODO: Make this configurable and "translatable" # TODO: Make this configurable and "translatable"
walletsDir = 'wallets' walletsDir = 'wallets'
@ -49,38 +68,38 @@ module Jekyll
locs[lang] = YAML.load_file("_translations/"+file)[lang] locs[lang] = YAML.load_file("_translations/"+file)[lang]
end end
puts('----- Generating wallet pages -----')
# Getting information about each found wallet # Getting information about each found wallet
walletsCol.docs.each do |doc| locs.each do |lang,value|
file = doc.path platformsCol.docs.each do |doc|
wallet = YAML.load_file(file) file = doc.path
walletPlatforms = wallet['platform'] data = YAML.load_file(file)
platform = data['platform']
os = data['os']
dir = File.join(platform['name'], os['name'])
site.pages << PlatformPage.new(site, site.source, File.join(lang, walletsDir, dir), platform, os, lang)
end
puts(wallet['id'] + ' is loaded. Generating pages...') walletsCol.docs.each do |doc|
file = doc.path
wallet = YAML.load_file(file)
walletPlatforms = wallet['platform']
# Going through all available combinations of # Going through all available combinations of
# platforms and OSes # platforms and OSes
walletPlatforms.each do |platform| walletPlatforms.each do |platform|
platform['os'].each do |os| platform['os'].each do |os|
# This allows generation only of valid wallet pages # This allows generation only of valid wallet pages
if platform['name'] if platform['name']
locs.each do |lang,value|
dir = File.join(platform['name'], os['name'], wallet['id']) dir = File.join(platform['name'], os['name'], wallet['id'])
site.pages << WalletPage.new(site, site.source, File.join(lang, walletsDir, dir), wallet, platform, os, lang) site.pages << WalletPage.new(site, site.source, File.join(lang, walletsDir, dir), wallet, platform, os, lang)
end end
end
end
end end
end end
puts(wallet['id'] + ' is processed.')
end end
puts('----- Wallet pages generated -----')
end end
end end