Skip to content

Commit

Permalink
Update documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Błażej S committed May 16, 2022
1 parent 674c947 commit a8cabad
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ List of available config options:
The file should contain JSON in the format:
```json
{
'stable' : {
'name' : 'stable',
'latest' : false
"stable" : {
"name" : "stable",
"latest" : false
},
'0.2.0' : {
'latest' : true,
'name' : 'latest release (0.2.0)'
"0.2.0" : {
"latest" : true,
"name" : "latest release (0.2.0)"
},
'0.1.0' : {
'latest' : false,
'name' : '0.1.0'
"0.1.0" : {
"latest" : false,
"name" : "0.1.0"
}
}
```
Expand Down
39 changes: 25 additions & 14 deletions mkdocs_multiversion_plugin/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ def on_files(self, files: Files, config: Config):

def on_post_build(self, config: Config, **kwargs):
"""
Post-build scripts.
Arguments:
config (Config): global configuration object.
"""
Expand All @@ -198,38 +200,47 @@ def on_post_build(self, config: Config, **kwargs):
elif self.config[self.CONFIG_VERSIONS_PROVIDER] == 'php':
self.php_provider(self.version_file_name)

def php_provider(self, file_name):
def php_provider(self, file_name : str):
"""
Generates dynamic PHP versions provider:
Arguments:
file_name (str): name of the file to be saved.
"""
try:
path = os.path.dirname(__file__)
with open('%s/providers/php.tpl' % path) as file:
content = file.read()
tpl = Template(content)
data = tpl.render(latest_version_name_format = self.config[self.CONFIG_LATEST_VERSION_NAME_FORMAT].format(version='%s'),
version_name_format = self.config[self.CONFIG_VERSION_NAME_FORMAT].format(version='%s'))
with open(os.path.join(self.site_dir, self.version_file_name), 'w') as file:
with open(os.path.join(self.site_dir, file_name), 'w') as file:
file.write(data)

except Exception as ex:
raise PluginError('[multiversion] %s' % ex) from ex

def static_provider(self, file_name):
def static_provider(self, file_name : str):
"""
Generates static file containing versions in format:
{
'stable' : {
'name' : 'stable',
'latest' : false
"stable" : {
"name" : "stable",
"latest" : false
},
'0.2.0' : {
'latest' : true,
'name' : 'latest release (0.2.0)'
"0.2.0" : {
"latest" : true,
"name" : "latest release (0.2.0)"
},
'0.1.0' : {
'latest' : false,
'name' : '0.1.0'
"0.1.0" : {
"latest" : false,
"name" : "0.1.0"
}
}
"""
Arguments:
file_name (str): name of the file to be saved.
\ """
# get versions from git
try:
gitrefs = Git.get_refs(self.config[self.CONFIG_TAG_WHITELIST], self.config[self.CONFIG_BRANCH_WHITELIST])
Expand Down Expand Up @@ -263,7 +274,7 @@ def make_obj(text, latest):
)

y = json.dumps(versions)
f = open(os.path.join(self.site_dir, self.version_file_name), "w")
f = open(os.path.join(self.site_dir, file_name), "w")
f.write(y)
f.close()
except Exception as ex:
Expand Down

0 comments on commit a8cabad

Please sign in to comment.