Compare commits

...

25 Commits
V1.0.3 ... main

Author SHA1 Message Date
Maximilien Rigaut 7b7d1aaa39
Merge pull request #42 from idle-org/release
Release 1.0.4
2022-06-16 04:04:38 +02:00
Maximilien Rigaut bb5f9aa4b6
Merge pull request #41 from idle-org/develop
Develop
2022-06-16 04:00:27 +02:00
Maximilien Rigaut 4036dbe05b
Merge branch 'release' into develop 2022-06-16 03:57:04 +02:00
Maximilien Rigaut a6e44b5611
Merge pull request #40 from idle-org/releases/v1.0.4
Version 1.0.4
2022-06-16 03:55:47 +02:00
Maximilien Rigaut d68b2295e8
Version 1.0.4 2022-06-16 03:54:10 +02:00
Maximilien Rigaut 6b26a5c700
Merge pull request #39 from idle-org/features/roadmap
Roadmap
2022-06-16 03:40:25 +02:00
Maximilien Rigaut 0da3828cd0
Roadmap 2022-06-16 03:39:57 +02:00
Maximilien Rigaut 4bfd730616
Merge pull request #38 from idle-org/features/context
Added a better context to error
2022-06-16 03:39:34 +02:00
Maximilien Rigaut 86891e9e86
Added a better context to error 2022-06-16 03:38:27 +02:00
Maximilien Rigaut 09c8eef46b
Merge pull request #37 from idle-org/features/aliases
Inline image & aliases (and index corrected accordingly)
2022-06-16 02:26:54 +02:00
Maximilien Rigaut c2a44f40c5
Inline image & aliases (and index corrected accordingly) 2022-06-16 02:26:13 +02:00
Maximilien Rigaut 237a417396
Merge pull request #36 from idle-org/test-new-doc
Test new doc
2022-06-16 02:04:57 +02:00
Maximilien Rigaut b47c88ffde
Quick fix 2022-06-16 01:47:08 +02:00
Maximilien Rigaut 4a1857c80f
Hacks 2022-06-16 01:34:48 +02:00
Maximilien Rigaut 3d8c1bf4b4
Indent 2022-06-16 01:02:51 +02:00
Maximilien Rigaut 22b19d4481
Indent 2022-06-16 00:50:24 +02:00
Maximilien Rigaut 62da1bacc3
Reformated doc 2022-06-16 00:42:27 +02:00
Maximilien Rigaut ee61ac9b00
test doc 2022-06-16 00:31:49 +02:00
Maximilien Rigaut af71c12b21
Merge pull request #35 from idle-org/release
Release
2022-06-15 23:57:43 +02:00
Maximilien Rigaut aad46ec9f9
Merge pull request #34 from idle-org/develop
Develop
2022-06-15 23:57:14 +02:00
Maximilien Rigaut b420c89ab8
Merge pull request #33 from idle-org/features/header-fix
fixed the header / structural elements export syntax
2022-06-15 23:55:04 +02:00
Maximilien Rigaut 001abba7bf
Merge pull request #30 from idle-org/release
Release 1.0.3
2022-06-15 22:28:44 +02:00
Maximilien Rigaut 77475d3414
fixed the header / structural elements export syntax 2022-06-15 22:25:36 +02:00
Maximilien Rigaut 8989e05af7
Merge branch 'release' 2022-06-15 21:40:06 +02:00
Maximilien Rigaut d7af2e213a
Merge pull request #21 from idle-org/release
Release
2022-06-15 20:24:14 +02:00
25 changed files with 294 additions and 164 deletions

View File

@ -29,22 +29,33 @@ You can refer to the `example_userfiles` for an idea of what the parser expects
- Fixed continuous integration - Fixed continuous integration
- Added doc generation - Added doc generation
## Roadmap
### V1.0.4 ### V1.0.4
- Make the default example site way more useful ☐ - Made the default example site more useful
- Write a documentation for the application (use specs.yaml) ☐ - Wrote a barebone documentation for the application
## Roadmap
### V1.0.5
- Add more context to the warning messages ☐
- Test configs more in-depth ☐
- Test overall site generation ☐
- Move the WARNING-level output to INFO for config overwrite ☐ - Move the WARNING-level output to INFO for config overwrite ☐
### V1.0.6
- Option to ignore br behavior ☐
- Make the default example site way more useful ☐
### V1.1 ### V1.1
- Functioning `table` Token ☐ - Functioning `table` Token ☐
- Functioning `code` Token ☐ - Functioning `code` Token ☐
- Establish a list of all configurable parameters to implement in the future, and update the roadmap with them. ☐ - Establish a list of all configurable parameters to implement in the future, and update the roadmap with them. ☐
- Decide level of logic to be implemented, and whether it should be configurable ☐ - Decide level of logic to be implemented, and whether it should be configurable ☐
- Update the uses of remaining files ☐ - Update the uses of remaining files ☐
- Add a global line count and a line tracker to the parser ☐
### V1.2 ### V1.2
- Check error messages and add a real debug level to parameters ☐ - Check error messages and add a real debug level to parameters ☐
- Thouroughly test logging, and error messages for the user ☐
- Functioning `blockquote` Token ☐ - Functioning `blockquote` Token ☐
### V1.3 ### V1.3
@ -53,6 +64,7 @@ You can refer to the `example_userfiles` for an idea of what the parser expects
### V1.4 ### V1.4
- Add html indentation for human readability of the output. ☐ - Add html indentation for human readability of the output. ☐
- Write thourough documentation for the application (use specs.yaml) ☐
### V2 ### V2
- Add a functioning post-context enhancer able to generate menus and elements from arbitrary logic. - Add a functioning post-context enhancer able to generate menus and elements from arbitrary logic.

View File

@ -10,7 +10,7 @@ shortcuts:
tab_bnw: 'tab_bnw_imported' tab_bnw: 'tab_bnw_imported'
tab_color: 'tab_colour_imported' tab_color: 'tab_colour_imported'
custom_permutation: 'custom_permutated' custom_permutation: 'custom_permutated'
empty: ''
start: | start: |
<!doctype html> <!doctype html>
<html lang="en"> <html lang="en">

View File

@ -0,0 +1,48 @@
Structural Elements:
<<div
This is a div
div>>{class='blue', 123}{{cinsertion}}[var='test', number=11]
<<article
This is an article
article>>{class='blue', 123}{{cinsertion}}[var='test', number=11]
<<aside
This is an aside
aside>>{class='blue', 123}{{cinsertion}}[var='test', number=11]
<<section
This is a section
section>>{class='blue', 123}{{cinsertion}}[var='test', number=11]
<<div
<<article
<<aside
<<section
Text
section>>{class='blue', 123}{{cinsertion}}[var='test', number=11]
aside>>{class='blue', 123}{{cinsertion}}[var='test', number=11]
article>>{class='blue', 123}{{cinsertion}}[var='test', number=11]
div>>{class='blue', 123}{{cinsertion}}[var='test', number=11]
# Header 1 #{class='blue', 123}{{cinsertion}}[var='test', number=11]
! Display 1 !{class='blue', 123}{{cinsertion}}[var='test', number=11]
Inline Element:
[Link text]('http://this.is.a.link')
*This is in italic*
**This is strong**
~~This is stricken through~~
__This is underlined__
(#1)This is a custom span(#1)
Oneline elements:
- This is an unordered list item
- This is an unordered list item
- This is an unordered list item{class='blue', 123}{{cinsertion}}[var='test', number=11]
#. This is an ordered list item
#. This is an ordered list item
#. This is an ordered list item{class='blue', 123}{{cinsertion}}[var='test', number=11]
This is a long text segment. This is a long text segment. This is a long text segment. This is a long text segment. This is a long text segment.
This is still the same long text segment. This is still the same long text segment. This is still the same long text segment.
Use a double linebreak to force linebreaks.

View File

@ -1,51 +1,28 @@
@[start]['bootstrap'] @[start]['Bootstraparse']
Structural Elements:
<<div <<div
This is a div <<header
div>>{class='blue', 123}{{cinsertion}}[var='test', number=11]
<<article
This is an article
article>>{class='blue', 123}{{cinsertion}}[var='test', number=11]
<<aside
This is an aside
aside>>{class='blue', 123}{{cinsertion}}[var='test', number=11]
<<section
This is a section
section>>{class='blue', 123}{{cinsertion}}[var='test', number=11]
<<div <<div
<<article <<div
<<aside Bootstraparse
<<section div>>{{blog-header-logo text-dark text-center border-bottom}}
Text div>>{{row flex-nowrap justify-content-between align-items-center}}
section>>{class='blue', 123}{{cinsertion}}[var='test', number=11] header>>{{blog-header py-3}}
aside>>{class='blue', 123}{{cinsertion}}[var='test', number=11] <<div
article>>{class='blue', 123}{{cinsertion}}[var='test', number=11] # What is bootstraparse ? #
div>>{class='blue', 123}{{cinsertion}}[var='test', number=11]
# Header 1 #{class='blue', 123}{{cinsertion}}[var='test', number=11] bootstraparse is a tool that allows you to bootstrap your own project.
! Display 1 !{class='blue', 123}{{cinsertion}}[var='test', number=11] In a very small number of steps, you can create a new project with the
following features:
- Imports, with the <code> ::&lt; filename > </code>syntax you can import another file and have it's contents dumped into your file.
- Markup, a subset of markdown is already supported and the rest is incomming !
- Aliases : With the <code> @&#91;alias_name&#93; </code> syntax you can create an alias for a string of text, with replacement capabilities.
- Images: With the <code> @&#123;imagename&#125; </code> syntax you can specify an image template to import, with replacement capabilities.
And much much more !
Inline Element: We encourage you to read the [documentation]("apidoc/index.html") to learn more about bootstraparse
[Link text]('http://this.is.a.link') or explore the [source code]("https://github.com/idle-org/bootstraparse")
*This is in italic* div>>{{nav-scroller py-1 mb-2}}
**This is strong** div>>{{container}}
~~This is stricken through~~
__This is underlined__
(#1)This is a custom span(#1)
Oneline elements:
- This is an unordered list item
- This is an unordered list item
- This is an unordered list item{class='blue', 123}{{cinsertion}}[var='test', number=11]
#. This is an ordered list item
#. This is an ordered list item
#. This is an ordered list item{class='blue', 123}{{cinsertion}}[var='test', number=11]
This is a long text segment. This is a long text segment. This is a long text segment. This is a long text segment. This is a long text segment.
This is still the same long text segment. This is still the same long text segment. This is still the same long text segment.
Use a double linebreak to force linebreaks.
@[end] @[end]

View File

@ -2,15 +2,14 @@
name = bootstraparse name = bootstraparse
description = A custom markdown parser for Bootstrap & Python description = A custom markdown parser for Bootstrap & Python
author = Vkyfox author = Vkyfox
version = 1.0.3 version = 1.0.4
license = Mozilla Public License Version 2.0 license = Mozilla Public License Version 2.0
license_file = LICENSE license_file = LICENSE
platforms = unix, linux, osx, cygwin, win32 platforms = unix, linux, osx, cygwin, win32
classifiers = classifiers =
Programming Language :: Python :: 3 Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.9
[options] [options]
@ -19,7 +18,7 @@ packages =
bootstraparse.modules bootstraparse.modules
install_requires = install_requires =
pyyaml>=6.0 pyyaml>=6.0
python_requires = >=3.6 python_requires = >=3.9
package_dir = package_dir =
=src =src

View File

@ -0,0 +1,5 @@
"""
Bootstraparse is a tool to parse a folder and create a website from it.
After installing it with pip, you can use it by running the following command:
- bootstraparse <origin> <destination>
"""

View File

@ -1,6 +1,6 @@
#!/usr/bin/python3 #!/usr/bin/python3
# Main program, use this to start parsing """ Main program, use this to start parsing"""
from bootstraparse.modules import sitecreator, error_mngr from bootstraparse.modules import sitecreator, error_mngr
import argparse import argparse

View File

@ -2,7 +2,7 @@ global:
template: "bootstrap.yml" template: "bootstrap.yml"
output: "example_site/" output: "example_site/"
bootstrap_version: "3.3.7" bootstrap_version: "3.3.7"
version: "1.0.3" version: "1.0.4"
bootstrap_location: "" bootstrap_location: ""
logging: logging:

View File

@ -0,0 +1,3 @@
"""
The modules in this folder are used to parse the website.
"""

View File

@ -1,11 +1,11 @@
# Interprets config files """Interprets config files
# The Config will be loaded by the environment at runtime and should be accessed that way The Config will be loaded by the environment at runtime and should be accessed that way
# Usage: Usage:
# from bootstraparse.modules.config import ConfigLoader - from bootstraparse.modules.config import ConfigLoader
# config = ConfigLoader([list of config files], extensions=[list of extensions]) - config = ConfigLoader([list of config files], extensions=[list of extensions])
# config['file']['key'] - config['file']['key']
# The ConfigLoader class has load_from_file and load_from_folder methods and __getitem__ for accessing loaded elements The ConfigLoader class has load_from_file and load_from_folder methods and __getitem__ for accessing loaded elements
"""
import os import os
import rich import rich

View File

@ -1,16 +1,16 @@
# Interprets where the parser is located and resolves errors """Interprets where the parser is located and resolves errors
# You're probably here for the ContextManager class. You're probably here for the ContextManager class.
# Containers have class_name, debug_map and validate methods for debug, Containers have class_name, debug_map and validate methods for debug,
# self.content: accessible via __getitem__, __setitem__, add, __len__, __iter__ and __getslice__. - self.content: accessible via __getitem__, __setitem__, add, __len__, __iter__ and __getslice__.
# self.optionals: accessible via __rshift__ (remapped to return self.map[other]()) - self.optionals: accessible via __rshift__ (remapped to return self.map[other]())
# and self.map: accessible via __invert__ (remapped to return self.optionals) - and self.map: accessible via __invert__ (remapped to return self.optionals)
# Usage: Usage:
# from bootstraparse.modules.context_mngr import ContextManager - from bootstraparse.modules.context_mngr import ContextManager
# ctx = ContextManager() - ctx = ContextManager()
# container = BaseContainer() - container = BaseContainer()
# container[number] -> The number element in the content - container[number] -> The number element in the content
# "class_insert" >> container[number] -> Get an element from one of the mapped methods - "class_insert" >> container[number] -> Get an element from one of the mapped methods
"""
from bootstraparse.modules import syntax, error_mngr, export from bootstraparse.modules import syntax, error_mngr, export
from bootstraparse.modules.error_mngr import MismatchedContainerError, log_exception, log_message, LonelyOptionalError # noqa from bootstraparse.modules.error_mngr import MismatchedContainerError, log_exception, log_message, LonelyOptionalError # noqa
@ -208,7 +208,7 @@ class BaseContainer:
:rtype : str :rtype : str
""" """
return '{} ({})'.format(", ".join(map(str, self.content)), return '{} ({})'.format(", ".join(map(str, self.content)),
", ".join(map(str, self.get_optionals())) if self.get_optionals() else "") ", ".join(map(str, self.get_optionals().content)) if self.get_optionals() else "")
def __repr__(self): def __repr__(self):
""" """
@ -335,7 +335,7 @@ class SeContainer(BaseContainer):
type = "structural_elements" type = "structural_elements"
def export(self, exm): def export(self, exm):
self.subtype = self[0].content[0] self.subtype = "se_"+self[0].content[0]
return super().export(exm) return super().export(exm)
@ -551,6 +551,7 @@ class ContextManager:
while index < len(self.parsed_list): while index < len(self.parsed_list):
token = self.parsed_list[index] token = self.parsed_list[index]
token.line_number = line_number token.line_number = line_number
token.index = index
token.file_name = self.name token.file_name = self.name
token.ident = self.ident token.ident = self.ident
self.pile.append(token) self.pile.append(token)
@ -583,16 +584,17 @@ class ContextManager:
# Error if closing token does not have a start # Error if closing token does not have a start
elif isinstance(token, syntax.ClosedSemanticType): elif isinstance(token, syntax.ClosedSemanticType):
raise MismatchedContainerError(token) raise MismatchedContainerError(token, self.parsed_list)
# Starting token by default (can cause unintended behaviours on bad implementations) # Starting token by default (can cause unintended behaviours on bad implementations)
elif isinstance(token, syntax.TokensToMatch): elif isinstance(token, syntax.TokensToMatch):
self._add_matched(token.label, index) self._add_matched(token.label, index)
else: else:
raise MismatchedContainerError(token) raise MismatchedContainerError(token, self.parsed_list)
except MismatchedContainerError as e: except MismatchedContainerError as e:
error_mngr.log_message(f"In context: {e.get_context()}", level="CRITICAL")
error_mngr.log_exception(e, level="CRITICAL") # FUTURE: Try to guess some hints. error_mngr.log_exception(e, level="CRITICAL") # FUTURE: Try to guess some hints.
index += 1 index += 1

View File

@ -1,19 +1,20 @@
# Module for containing super important variables """Module for containing super important variables
# Environment has self._mParams for mandatory parameters, self._sParams for secondary parameters and Environment has self._mParams for mandatory parameters, self._sParams for secondary parameters and
# self.wasInitialised and integrity_check for debug. - self.wasInitialised and integrity_check for debug.
# __getattr__ and __setattr__ check for existing super, s or m parameters, returns error if not found. - __getattr__ and __setattr__ check for existing super, s or m parameters, returns error if not found.
# Usage: Usage:
# from bootstraparse.modules.environment import Environment - from bootstraparse.modules.environment import Environment
# env = Environment() - env = Environment()
# env.integrity_check() -> Checks if all mandatory parameters are set. - env.integrity_check() -> Checks if all mandatory parameters are set.
# env["config"] -> returns config object - env["config"] -> returns config object
# env["template"] -> returns template object - env["template"] -> returns template object
# env["export_mngr"] -> returns export manager object - env["export_mngr"] -> returns export manager object
# env["global_path"] -> returns global path ??? - env["global_path"] -> returns global path ???
# env["user_path"] -> returns user path ??? - env["user_path"] -> returns user path ???
# env["site_path"] -> returns site path - env["site_path"] -> returns site path
# env["export"] -> returns export object ??? - env["export"] -> returns export object ???
# env["site_crawler"] -> returns site crawler object - env["site_crawler"] -> returns site crawler object
"""
from bootstraparse.modules import error_mngr from bootstraparse.modules import error_mngr

View File

@ -1,12 +1,14 @@
# Dedicated module for defining and interpreting errors as well as generating error messages """
# You're probably here for log_message or log_exception. Dedicated module for defining and interpreting errors as well as generating error messages
# They take: message, level=("ERROR, "INFO", "WARNING", "DEBUG", "CRITICAL") You're probably here for log_message or log_exception.
# There's also a dict_check(dic, *args) that returns true if all args are keys in the dict. - They take: message, level=("ERROR, "INFO", "WARNING", "DEBUG", "CRITICAL")
# Usage: There's also a dict_check(dic, *args) that returns true if all args are keys in the dict.
# from bootstraparse.modules.error_mngr import log_message, log_exception Usage:
# log_message("This is a message", level="INFO") level=("ERROR, "INFO", "WARNING", "DEBUG", "CRITICAL") - from bootstraparse.modules.error_mngr import log_message, log_exception
# log_exception(Exception("This is an exception"), level="ERROR") - log_message("This is a message", level="INFO") level=("ERROR, "INFO", "WARNING", "DEBUG", "CRITICAL")
# dict_check({"a": 1, "b": 2}, "a", "b") # returns [True, True] - log_exception(Exception("This is an exception"), level="ERROR")
- dict_check({"a": 1, "b": 2}, "a", "b") # returns [True, True]
"""
import logging import logging
import traceback import traceback
@ -93,6 +95,54 @@ class BootstraparseError(Exception):
pass pass
class BootstraparseTokenError(BootstraparseError):
"""
Error on a token, provides if possible the line and column number of the error,
the file name and the message of the error
and if possible a context for the error
"""
def __init__(self, token, pile, message):
self.token = token
self.pile = pile
if token is not None:
self.line = token.line_number
self.index = token.index
self.label = token.label
self.name = token.file_name
else:
self.line = None
self.index = None
self.label = None
self.name = None
self.context = self.get_context()
super().__init__(message+"\n"+self.context_multiline())
def get_context(self, context_size=5):
"""
Returns the context of the error
:return: The context of the error
:rtype: str
"""
if self.pile:
st = max(0, self.index - context_size)
en = min(len(self.pile), self.index + context_size)
return self.pile[st:en]
return []
def context_multiline(self, context_size=10):
"""
Returns the context of the error as a multiline string
:return: The context of the error
:rtype: str
"""
if self.pile:
return "\n".join([
f"{' ' if i!=context_size else '> '}{i-context_size:2d}: {j}"
for i, j in enumerate(self.get_context(context_size)) if j.label != "linebreak"
])
return ""
class ParsingError(Exception): class ParsingError(Exception):
""" """
Exception class for parsing errors Exception class for parsing errors
@ -131,17 +181,18 @@ class ParsingError(Exception):
return str(self.message) return str(self.message)
class MismatchedContainerError(BootstraparseError): class MismatchedContainerError(BootstraparseTokenError):
""" """
The token is not final and cannot be contained. Indicative of a mismatched token. The token is not final and cannot be contained. Indicative of a mismatched token.
""" """
def __init__(self, token): def __init__(self, token, pile=None):
""" """
Initializes the MismatchedContainerError class with the token that was not final Initializes the MismatchedContainerError class with the token that was not final
:param token: The token that is not final :param token: The token that is not final
:type token: syntax.SemanticType :type token: syntax.SemanticType
""" """
self.token = token self.token = token
self.pile = pile
if token: if token:
self.line = token.line_number self.line = token.line_number
self.label = token.label self.label = token.label
@ -150,7 +201,7 @@ class MismatchedContainerError(BootstraparseError):
self.line = None self.line = None
self.label = None self.label = None
self.name = None self.name = None
super().__init__(f"Could not process {self.label} at line {self.line} in file {self.name}.") super().__init__(token, pile, f"Could not process {self.label} at line {self.line} in file {self.name}.")
class LonelyOptionalError(BootstraparseError): class LonelyOptionalError(BootstraparseError):

View File

@ -1,10 +1,12 @@
# Module for final generation of the translated website """
# Usage: Module for final generation of the translated website
# from bootstraparse.modules.export import ExportManager, ExportRequest, ExportResponse Usage:
# rqs = ExportRequest("strucural_elements", "div", "optionals", {"id": "my_id", "class": "my_class"}) - from bootstraparse.modules.export import ExportManager, ExportRequest, ExportResponse
# rsp = ExportResponse("start_string", "end_string") - rqs = ExportRequest("strucural_elements", "div", "optionals", {"id": "my_id", "class": "my_class"})
# em = ExportManager(config_file, template_file) - rsp = ExportResponse("start_string", "end_string")
# em(ExportRequest()) -> ExportResponse() - em = ExportManager(config_file, template_file)
- em(ExportRequest()) -> ExportResponse()
"""
from io import StringIO from io import StringIO
from bootstraparse.modules import config, pathresolver, error_mngr, context_mngr from bootstraparse.modules import config, pathresolver, error_mngr, context_mngr

View File

@ -1,9 +1,10 @@
# Main parser, gets config files and parses them for the context manager. """
# parse_line takes a io and outputs it all as a list of parsed elements Main parser, gets config files and parses them for the context manager.
# Usage: parse_line takes a io and outputs it all as a list of parsed elements
# from bootstraparse.modules.parser import parse_line Usage:
# parse_line(io) -> [element, element, element] - from bootstraparse.modules.parser import parse_line
- parse_line(io) -> [element, element, element]
"""
from io import StringIO from io import StringIO
import bootstraparse.modules.syntax as syntax import bootstraparse.modules.syntax as syntax

View File

@ -1,11 +1,12 @@
# Module for resolving relative path problems """
# PathResolver takes a relative path in the module and outputs the absolute path, Module for resolving relative path problems
# BoostraPath can deal with relative paths in the installation folder. PathResolver takes a relative path in the module and outputs the absolute path,
# Usage: BoostraPath can deal with relative paths in the installation folder.
# from bootstraparse.modules.pathresolver import PathResolver, b_path Usage:
# b_path("../relative/path/to/file") # returns absolute path to file from the bootstraparse folder - from bootstraparse.modules.pathresolver import PathResolver, b_path
# path= PathResolver("../relative/path/to/file") # Make a PathResolver object pointing at the first path given - b_path("../relative/path/to/file") # returns absolute path to file from the bootstraparse folder
- path= PathResolver("../relative/path/to/file") # Make a PathResolver object pointing at the first path given
"""
import os import os

View File

@ -1,11 +1,12 @@
# Module for pre-parsing user files in preparation for the parser """Module for pre-parsing user files in preparation for the parser
# Usage: Usage:
# from bootstraparse.modules.preparser import preparser - from bootstraparse.modules.preparser import preparser
# pp = preparser(file, enviroment) - pp = preparser(file, enviroment)
# pp.do_import() # imports all the modules and adds them to the file, do the same for all the files that are to be imported # noqa - pp.do_import() # imports all the modules and adds them to the file, do the same for all the files that are to be imported - # noqa
# pp.do_replacements() # replaces all images and shortcuts in the file - pp.do_replacements() # replaces all images and shortcuts in the file
# pp.readlines() # returns the lines of ORIGINAL file - pp.readlines() # returns the lines of ORIGINAL file
# pp.get_all_lines() # returns the lines of the file after replacements and imports - pp.get_all_lines() # returns the lines of the file after replacements and imports
"""
import os import os

View File

@ -1,4 +1,14 @@
# Module for file and directories repartition """
Module for file and directories repartition
Usage:
- from bootstraparse.modules import SiteCrawler
- crawler = SiteCrawler(origin_path, dest_path, _env)
- crawler.set_all_preparsers()
- crawler.copy_unparsable_files()
- for element, destination in crawler:
- - save(preparse_parse(element), destination, _env)
"""
import os import os
import shutil import shutil
from bootstraparse.modules import pathresolver, preparser, error_mngr, environment, export from bootstraparse.modules import pathresolver, preparser, error_mngr, environment, export

View File

@ -1,4 +1,9 @@
# Module sequencing the successive actions necessary for website building """
Module sequencing the successive actions necessary for website building
Usage:
- create_website(origin, destination)
"""
import os import os
from bootstraparse.modules import pathresolver, sitecrawler, environment, config, export, parser, context_mngr from bootstraparse.modules import pathresolver, sitecrawler, environment, config, export, parser, context_mngr

View File

@ -1,3 +1,4 @@
"""
# Dedicated module for the syntax of all the parsing # Dedicated module for the syntax of all the parsing
# All tokens inherit a SemanticType among SemanticType, ExplicitSemanticType and EmptySemanticType # All tokens inherit a SemanticType among SemanticType, ExplicitSemanticType and EmptySemanticType
# All tokens have a label, and __eq__ and __ne__ methods. # All tokens have a label, and __eq__ and __ne__ methods.
@ -8,6 +9,7 @@
# line_to_replace.parse_line('string') # returns a List of tokens parsed for replacements # line_to_replace.parse_line('string') # returns a List of tokens parsed for replacements
# imports.parse_line('string', True) # returns a List of tokens parsed for imports # imports.parse_line('string', True) # returns a List of tokens parsed for imports
# any_token.create_diagram("filename") # Debugging # any_token.create_diagram("filename") # Debugging
"""
import os import os
from itertools import zip_longest from itertools import zip_longest
@ -555,10 +557,9 @@ alias = alias_element + pp.Opt(optional)
# Syntax elements # Syntax elements
line_to_replace = pp.OneOrMore( line_to_replace = pp.OneOrMore(
pp.SkipTo(image ^ alias)('text').add_parse_action(of_type(TextToken)) pp.SkipTo(image)('text').add_parse_action(of_type(TextToken)) + image.add_parse_action(of_type(ImageToken)) |
^ image.add_parse_action(of_type(ImageToken)) pp.SkipTo(alias)('text').add_parse_action(of_type(TextToken)) + alias.add_parse_action(of_type(AliasToken))
^ alias.add_parse_action(of_type(AliasToken)) ) | pp.rest_of_line('text').add_parse_action(of_type(TextToken))
) ^ pp.rest_of_line('text').add_parse_action(of_type(TextToken))
############################################################################## ##############################################################################

View File

@ -1 +1,3 @@
# Module for interpreting default or custom templates. """
Module for interpreting default or custom templates.
"""

View File

@ -1,11 +1,13 @@
############################################################################### """
# List of tools for testing List of tools for testing
############################################################################### =========================
# Usage:
# from bootstraparse.modules.tools import __GLk, __GL, find_*_in_file Usage:
# __GLk(n) # Returns a file link n traceback objects back - from bootstraparse.modules.tools import __GLk, __GL, find_*_in_file
# __GL() # Returns a line number at current position - __GLk(n) # Returns a file link n traceback objects back
# find_*_in_file(file) # Try to find (class, function or variable) in file and return its line number - __GL() # Returns a line number at current position
- find_*_in_file(file) # Try to find (class, function or variable) in file and return its line number
"""
import inspect import inspect
import os import os

View File

@ -1,8 +1,11 @@
structural_elements: structural_elements:
div: ["<div{optionals}>", "</div>"] se_div: ["<div{optionals}>", "</div>"]
article: ["<article{optionals}>", "</article>"] se_article: ["<article{optionals}>", "</article>"]
aside: ["<aside{optionals}>", "</aside>"] se_aside: ["<aside{optionals}>", "</aside>"]
section: ["<section{optionals}>", "</section>"] se_section: ["<section{optionals}>", "</section>"]
se_nav: ["<nav{optionals}>", "</nav>"]
se_header: ["<header{optionals}>", "</header>"]
se_body: ["<body{optionals}>", "</body>"]
header: ["<h{header_level}{optionals}>", "</h{header_level}>"] header: ["<h{header_level}{optionals}>", "</h{header_level}>"]
display: ["<p class=\"display-{display_level}\"{optionals}>", "</p>"] display: ["<p class=\"display-{display_level}\"{optionals}>", "</p>"]

View File

@ -12,12 +12,14 @@ __templates = config.ConfigLoader(pathresolver.b_path("templates/"))
__XF = pytest.mark.xfail __XF = pytest.mark.xfail
_all_templates = { _all_templates = {
"structural_elements": [ "structural_elements": [
["div", __GLk(1)], ["se_div", __GLk(1)],
["article", __GLk(1)], ["se_article", __GLk(1)],
["aside", __GLk(1)], ["se_aside", __GLk(1)],
["section", __GLk(1)], ["se_section", __GLk(1)],
["header", __GLk(1)], ["header", __GLk(1)],
["display", __GLk(1)], ["display", __GLk(1)],
["se_body", __GLk(1)],
["se_nav", __GLk(1)],
], ],
"inline_elements": [ "inline_elements": [
["link", __GLk(1)], ["link", __GLk(1)],
@ -86,7 +88,7 @@ def test_export_response():
("table", "t_head"), ("table", "t_head"),
("table", "t_row"), ("table", "t_row"),
("table", "t_cell"), ("table", "t_cell"),
("structural_elements", "div"), ("structural_elements", "se_div"),
]) ])
def test_transform(export_type, export_subtype): def test_transform(export_type, export_subtype):
""" """
@ -118,7 +120,7 @@ def test_get_template_error():
def test_with_optionnals(): def test_with_optionnals():
em = export.ExportManager(__config, __templates) em = export.ExportManager(__config, __templates)
em(export.ExportRequest("structural_elements", "div", _opts)) # noqa E741 em(export.ExportRequest("structural_elements", "se_div", _opts)) # noqa E741
def test_format_optionnals(): def test_format_optionnals():
@ -147,6 +149,7 @@ def test_bad_header():
@pytest.mark.parametrize("export_type, export_subtype, line", zipped_templates) @pytest.mark.parametrize("export_type, export_subtype, line", zipped_templates)
def test_get_templates(export_type, export_subtype, line): def test_get_templates(export_type, export_subtype, line):
print(line)
em = export.ExportManager(__config, __templates) em = export.ExportManager(__config, __templates)
# assert type(em.get_templates()) is dict # assert type(em.get_templates()) is dict
print(export_type, export_subtype) print(export_type, export_subtype)

View File

@ -47,6 +47,7 @@ def test_counterpart_container(type_n, expected_counterpart, expected_container,
try: try:
token = type_n(["test"]) # noqa token = type_n(["test"]) # noqa
token.line_number = 1 token.line_number = 1
token.index = 1
assert token.counterpart() == expected_counterpart assert token.counterpart() == expected_counterpart
if expected_container == "error": if expected_container == "error":
with pytest.raises(error_mngr.MismatchedContainerError): with pytest.raises(error_mngr.MismatchedContainerError):