Skip to content

Commit

Permalink
Using new Tailwind-css-based Reference Generator. (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
BinarySoftware authored Apr 13, 2021
1 parent a1fd466 commit 647a09c
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 146 deletions.
26 changes: 13 additions & 13 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:

jobs:
lint:
runs-on: ubuntu-latest
runs-on: ubuntu-18.04

steps:
- uses: actions/checkout@v2
Expand All @@ -31,7 +31,7 @@ jobs:
run: poetry run pylint src

build:
runs-on: ubuntu-latest
runs-on: ubuntu-18.04
needs: lint

steps:
Expand All @@ -52,14 +52,14 @@ jobs:
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: gen
- name: Copy to website
uses: andstor/copycat-action@v3
with:
personal_token: ${{ secrets.CI_PAT }}
src_path: /.
src_branch: gh-pages
dst_path: /docs/reference/.
dst_branch: gh-pages
dst_owner: enso-org
dst_repo_name: website
clean: true
# - name: Copy to website
# uses: andstor/copycat-action@v3
# with:
# personal_token: ${{ secrets.CI_PAT }}
# src_path: /.
# src_branch: gh-pages
# dst_path: /docs/reference/.
# dst_branch: gh-pages
# dst_owner: enso-org
# dst_repo_name: website
# clean: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Thumbs.db
.vscode/
distribution/
gen/
temp/
.idea
venv
__pycache__
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ max-bool-expr=5
max-branches=12

# Maximum number of locals for function / method body.
max-locals=15
max-locals=20

# Maximum number of parents for a class (see R0901).
max-parents=7
Expand Down
4 changes: 2 additions & 2 deletions src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
DIRECTORY: str = "distribution/std-lib"

#: The commit from which scala parser will be obtained.
PARSER_COMMIT: str = "43c6fde4ef5873c645aa1ff196d7b36864831468"
PARSER_COMMIT: str = "9ea38e66db60953f9955ca9ee60c9c4478ff251f"
#: The URL used to download scala parser package.
PARSER_URL: str = "https://packages.luna-lang.org/parser-js/nightly/"
#: The method in scala parser used to generate documentation from AST.
Expand All @@ -25,7 +25,7 @@
#: The URL leading to IDE repository.
IDE_REPO_URL: str = "https://raw.githubusercontent.com/enso-org/ide/"
#: The branch in the above repository from which stylesheet will be downloaded.
IDE_BRANCH: str = "develop"
IDE_BRANCH: str = "wip/mm/doc-stylesheet"
#: The directory in the above repository from which stylesheet will be obtained.
IDE_DIRECTORY: str = "/src/rust/ide/view/src/documentation/"

Expand Down
187 changes: 92 additions & 95 deletions src/create_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,101 +6,94 @@
from airium import Airium


def create_index_page(out_dir: str, out_name: str, gen_files: List[str]) -> None:
def add_breadcrumbs_to_pages(out_dir: str, temp_dir: str, gen_files: List[str]) -> None:
"""
Generates index page.
Method used to create breadcrumbs (for now - tree) and add them to generated content.
"""
template = Airium()
logging.info("Generating: %s", out_name)
with template.html():
with template.head():
template.title(_t="Enso Reference")
template.link(href="style.css", rel="stylesheet")
template.link(href="favicon.ico", rel="icon")
template.style(_t="ul { padding-inline-start: 15px; }")
template.style(
_t="""ul, .section ul {
list-style: none;
padding: 0;
margin: 0;
word-wrap: initial;
}
ul li {
padding: 5px 10px;
}
.section ul { display: none; }
.section input:checked ~ ul { display: block; }
.section input[type=checkbox] { display: none; }
.section {
position: relative;
padding-left: 20px !important;
}
.section label:after {
content: "+";
position: absolute;
top: 0; left: 0;
padding: 0;
text-align: center;
font-size: 17px;
color: cornflowerblue;
transition: all 0.3s;
}
.section input:checked ~ label:after {
color: cadetblue;
transform: rotate(45deg);
}
@media only screen and (max-width: 1100px) {
#tree {
width: 30% !important;
}
}
"""
)
template.script(
_t="""function set_frame_content(file) {
document.getElementById("frame").src = file
}"""
)
with template.body(style="background-color: #333"):
template.h2(
style="""text-align: center;
padding: 15px;
margin: 0;
color: #fafafa""",
_t="Enso Reference",
)
with template.div(
style="background-color: #fafafa; display: flex; height: 100%"
):
with template.div(
id="tree",
style="""background-color: #efefef;
border-radius: 14px;
width: 20%;
margin: 15px;
padding-left: 20px;
overflow: scroll;
height: 90%;""",
):
grouped_file_names = group_by_prefix(gen_files)
create_html_tree(template, "", grouped_file_names, gen_files)
template.iframe(
frameborder="0",
height="100%",
id="frame",
src="Base-Main.html",
width="100%",
target="_blank",
)
logging.info("Generating breadcrumbs")
gen_files.remove("Main")
grouped_file_names = group_by_prefix(gen_files)
create_html_tree(template, "", grouped_file_names, gen_files)
breadcrumbs = str(template).replace('class="', 'className="')

html_file = open(out_dir + "/" + out_name, "w")
html_file.write(str(template))
html_file.close()
stl = """
<style jsx>{`
.section ul {
cursor: pointer;
list-style: none;
padding: 0;
margin: 0;
word-wrap: initial;
}
.section span {
cursor: pointer;
}
ul li {
padding: 5px 10px;
}
.section ul {
display: none;
}
.section input:checked ~ ul {
display: block;
}
.section input[type='checkbox'] {
display: none;
}
.section {
position: relative;
padding-left: 20px !important;
list-style-type: none;
}
.section label:after {
content: '▶';
position: absolute;
top: 7px;
left: 0;
padding: 0;
text-align: center;
font-size: 14px;
color: rgba(75, 88, 100, var(--tw-text-opacity));
transition: all 0.3s;
}
.section input:checked ~ label:after {
transform: rotate(90deg);
}
`}</style>
"""

breadcrumbs = "<div>" + stl + breadcrumbs + "</div>"

for out_name in gen_files:
temp_file = open(temp_dir + "/" + out_name + ".js", "r")
out_file = open(out_dir + "/" + out_name + ".js", "w")
temp_br = breadcrumbs
partials = out_name.split("-")
valid_ids = ["-".join(partials[:i]) for i in range(len(partials))]
for elem in valid_ids:
beg = '<input type="checkbox" id="' + elem + '" '
temp_br = temp_br.replace(beg + "/>", beg + 'checked="True" />')
beg_link = 'href="' + out_name + '"'
temp_br = temp_br.replace(beg_link, beg_link + ' className="font-bold"')
out_file.write(temp_file.read().replace("{/*BREADCRUMBS*/}", temp_br))
temp_file.close()
out_file.close()

std_main_file = open(temp_dir + "/" + "Base-Data-Maybe.js", "r")
index_file = open(out_dir + "/" + "index.js", "w")
index_file.write(
std_main_file.read().replace(
"{/*BREADCRUMBS*/}", breadcrumbs.replace('a href="', 'a href="reference/')
)
)
std_main_file.close()
index_file.close()


def create_html_tree(
Expand All @@ -112,23 +105,27 @@ def create_html_tree(
if len(ele) > 0:
with template.ul():
for key, value in ele.items():
file_name = curr_beg + "-" + key
file_name = curr_beg + "-" + key if len(curr_beg) > 0 else key
action = ""
if file_name in all_existing_files:
action = "set_frame_content('" + file_name + ".html')"
action = file_name
elif file_name + "-Main" in all_existing_files:
action = file_name + "-Main"
if len(value) > 0:
klass = "section"
with template.li(klass=klass):
template.input(type="checkbox", id=file_name)
template.label(for_=file_name, _t=key, onclick=action)
with template.label(for_=file_name):
template.a(href=action, _t=key)
beg = curr_beg
if len(curr_beg) == 0:
beg = key
else:
beg = beg + "-" + key
create_html_tree(template, beg, value, all_existing_files)
else:
template.li(onclick=action, _t=key)
with template.li():
template.a(href=action, _t=key)


def group_by_prefix(strings: List[str]) -> dict:
Expand Down
27 changes: 16 additions & 11 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,27 @@
import argparse
import logging
import constants
from downloaders import download_stdlib, download_parser, download_stylesheet
from parse import init_parser, init_gen_dir, gen_all_files
from create_static import create_index_page
from downloaders import download_stdlib, download_parser
from safe_create_directory import safe_create_directory
from parse import init_parser, gen_all_files
from create_static import add_breadcrumbs_to_pages


def main(arguments: argparse.Namespace) -> None:
"""
Program entry point.
"""
logging.basicConfig(level=arguments.log_level)
download_stdlib(
arguments.token, arguments.org, arguments.repo, arguments.br, arguments.dir
)
download_parser(arguments.parser_url, arguments.commit, arguments.parser)
download_stylesheet(arguments.ide_br, arguments.style)
if not arguments.dont_download:
download_stdlib(
arguments.token, arguments.org, arguments.repo, arguments.br, arguments.dir
)
download_parser(arguments.parser_url, arguments.commit, arguments.parser)
parser = init_parser(arguments.parser)
init_gen_dir(arguments.out, arguments.style)
gen_files = gen_all_files(parser, arguments.std, arguments.out, arguments.style)
create_index_page(arguments.out, arguments.index, gen_files)
safe_create_directory("temp")
safe_create_directory(arguments.out)
gen_files = gen_all_files(parser, arguments.std, "temp")
add_breadcrumbs_to_pages(arguments.out, "temp", gen_files)
logging.info("All done.")


Expand Down Expand Up @@ -66,5 +68,8 @@ def main(arguments: argparse.Namespace) -> None:
"--index", default=constants.INDEX_FILE, help="Index page name."
)
arg_parser.add_argument("--log_level", default=logging.INFO, help="Logging level.")
arg_parser.add_argument(
"--dont_download", default=False, help="Have local stdlib and parser."
)
args = arg_parser.parse_args()
main(args)
Loading

0 comments on commit 647a09c

Please sign in to comment.