Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 8 #9

Merged
merged 3 commits into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ HTML website from raw data and files.
- [x] title of .html file
- [x] customized output destination
- [x] CSS stylesheet
- [x] customized option from config file

## Dependencies
This tool is written by `Python 3.9`, with `pip 21.1.2`.
Expand Down Expand Up @@ -42,7 +43,8 @@ python __main__.py -i ./tests/Silver\ Blaze.txt
python __main__.py -i ./tests/
# use multiple options
python __main__.py -i ./tests/Silver\ Blaze.txt -s https://cdn.jsdelivr.net/npm/water.css@2/out/water.css

# use config file
python __main__.py -c ./tests
# specify the lang attribute in root element of HTML, default en-CA
python __main__.py -i ./tests/ -l fr

Expand Down
43 changes: 39 additions & 4 deletions __main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from generator import Generator
# fix issue 7
import sys
#issue 8
import json;

DEFAULT_FILE = '.txt'
# fix issue 6
Expand All @@ -19,7 +21,7 @@
@click.command()
@click.help_option('-h', '--help')
@click.version_option('0.1', '-v', '--version')
@click.option('-i', '--input', 'inp', required=True, type=click.Path(exists=True, file_okay=True, dir_okay=True,
@click.option('-i', '--input', 'inp', required=False, type=click.Path(exists=True, file_okay=True, dir_okay=True,
readable=True, resolve_path=True,
path_type=Path),
help='Path to an input file/folder')
Expand All @@ -32,15 +34,48 @@
@click.option('-s', '--stylesheet', required=False, default='', help='URL of a CSS stylesheet')
# fix issue 6
@click.option('-l', '--lang', required=False, default=DEFAULT_LANG, help='Indicates the lang attribute on root html')
def main(inp: Path, output: Path, stylesheet: str, lang: str) -> None:
if inp.exists():
@click.option('-c', '--config', 'config_' , required= False, type=click.Path(exists=True, file_okay=True, dir_okay=True,
readable=True, resolve_path=True,
path_type=Path),
help='Path to a config file/folder')
def main(inp: Path, output: Path, stylesheet: str, lang: str , config_:Path) -> None:
if config_!=None and config_.exists():
# work with json file
try:
with open(config_, "r") as read_file:
data = json.load(read_file)
except:
click.echo("The config file has error")
sys.exit(1)
if('input' in data ):
input= Path(data['input'])
if 'output' in data:
output= Path(data['output'])
else:
output= DEFAULT_OUTPUT
if 'stylesheet' in data:
stylesheet= data['stylesheet']
else:
stylesheet= ''
if 'lang' in data:
lang= data['lang']
else:
lang= DEFAULT_LANG
#create an instance of Generator
g= Generator(input, output, stylesheet, lang)
g.generator_wrapper()
else:
click.echo(f"The input file/folder {inp} or config file does not exist.")
sys.exit(1)
elif inp !=None and inp.exists():
# create an instance of the Generator
g = Generator(inp, output, stylesheet, lang)
# TODO: or make generator_wrapper() a function, not a method
g.generator_wrapper()
else:
# f string, format string python3
click.echo(f"The input file/folder {inp} does not exist.")
click.echo(f"The input file/folder {inp} or config file does not exist.")

# fix issue 7
sys.exit(1)

Expand Down