Skip to content
Open
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
29 changes: 27 additions & 2 deletions elsa/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,43 @@ def path_option(app):
help='Input path, default _build')


def _get_item_show_func(label, width, air=8, end=''):
def item_show_func(page):
if page is None:
return end

available = click.get_terminal_size()[0] - len(label) - width - air
if len(page.url) <= available:
return page.url

use = available - 1
first = use // 2
last = use - first
return page.url[:first] + '…' + page.url[-last:]

return item_show_func


def freeze_app(app, freezer, path, base_url):
if not base_url:
raise click.UsageError('No base URL provided, use --base-url')
print('Generating HTML...')

app.config['FREEZER_DESTINATION'] = path
app.config['FREEZER_BASE_URL'] = base_url
app.config['SERVER_NAME'] = urllib.parse.urlparse(base_url).netloc

# make sure Frozen Flask warnings are treated as errors
warnings.filterwarnings('error', category=flask_frozen.FrozenFlaskWarning)

freezer.freeze()
label = 'Generating HTML...'
width = max(click.get_terminal_size()[0] // 6, 3)

with click.progressbar(freezer.freeze_yield(),
item_show_func=_get_item_show_func(label, width),
width=width,
label=label) as urls:
for url in urls:
pass # Frozen-Flask and click.progressbar doing all the hard work


def inject_cname(app):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def long_description():
url='https://github.com/pyvec/elsa',
packages=[p for p in find_packages() if p != 'tests'],
install_requires=[
'click',
'click >= 2.0',
'Flask',
'Frozen-Flask >= 0.14',
'ghp-import',
Expand Down