forked from php-fig/www.php-fig.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_build
executable file
·65 lines (56 loc) · 1.73 KB
/
_build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env ruby
# encoding: utf-8
# A script for programmatically generating PSR and translation pages for php-fig.org
PSR_DIR = File.join(File.dirname(__FILE__), '_includes', 'fig-standards', 'accepted')
LANG_MAP = {
:es => 'Spanish',
:fr => 'French',
:it => 'Italian',
}
raise 'Run "git submodule init"' unless File.directory?(PSR_DIR)
Dir["#{PSR_DIR}/*.md"].each do |original|
next unless File.basename(original) =~ /^PSR-(\d+)\b/
num = $1
title = File.read(original).split(/[\n\r]/).first
pages = [
{
:lang => 'en',
:name => 'English (official)',
:path => "/psr/psr-#{num}",
:title => "PSR-#{num} — #{title}",
:disc => false,
:inc => original.sub(%r{.*/fig-standards/}, 'fig-standards/'),
}
]
Dir["#{PSR_DIR}/*/PSR-#{num}*.md"].sort.each do |tr|
lang = File.basename(File.dirname(tr))
title = File.read(tr).split(/[\n\r]/).first
pages << {
:lang => lang,
:name => LANG_MAP[lang.to_sym],
:path => "/psr/psr-#{num}/#{lang}",
:title => "PSR-#{num} — #{title}",
:inc => tr.sub(%r{.*/fig-standards/}, 'fig-standards/'),
}
end
pages.each do |page|
links = []
pages.each do |other|
links << " - name: #{other[:name]}"
links << " path: #{other[:path]}" unless other[:path] == page[:path]
end
File.open(".#{page[:path]}/index.md", 'w') do |f|
f << <<-EOS.gsub(/^ {8}/, '')
---
# This file is automatically generated by `_build`.
layout: psr
title: #{page[:title]}
disclaimer: #{page[:lang] == 'en' ? 'false' : 'true'}
translations:
#{links.join("\n")}
---
{% include #{page[:inc]} %}
EOS
end
end
end