robotframework-libtoc 1.5.0__tar.gz → 1.6.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: robotframework-libtoc
3
- Version: 1.5.0
3
+ Version: 1.6.0
4
4
  Summary: Docs and TOC generator for Robot Framework resources and libs
5
5
  Home-page: https://github.com/amochin/robotframework-libtoc
6
6
  License: Apache-2.0
@@ -21,7 +21,7 @@ Description-Content-Type: text/markdown
21
21
  ## Robot Framework LibTOC
22
22
 
23
23
  ## What it does
24
- This tool generates docs using Robot Framework [Libdoc](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#libdoc) for an entire folder (or multiple folders) with Robot Framework resources/libs and creates a TOC (table of contents) file for them
24
+ This tool generates docs using Robot Framework [Libdoc](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#libdoc) for an entire folder (or multiple folders) with Robot Framework resources/libs and creates a TOC (table of contents) file for them.
25
25
 
26
26
  ## Why use it
27
27
  The Robot Framework Libdoc tool normally generates a HTML file for a single keyword library or a resource file.
@@ -84,11 +84,12 @@ pip install robotframework-libtoc
84
84
  - Create the `.libtoc` config files in the *root of the resources folder* and/or in *direct subfolders* where you need docs to be created.
85
85
  - Run `libtoc`. The last `resources_dirs` parameter is mandatory, it takes any number of paths. Other params are optional:
86
86
  - `-d, --output_dir`
87
+ - `-P, --pythonpath`
87
88
  - `--config_file`
88
89
  - `--toc_file`
89
90
  - `--toc_template`
90
91
  - `--homepage_template`
91
- - `-P, --pythonpath`
92
+ - `--no_timestamp`
92
93
 
93
94
  Examples:
94
95
  ```shell
@@ -111,4 +112,3 @@ There are two ways to extend the list of paths where the libraries are searched
111
112
  2. Set the **PYTHONPATH** environment variable
112
113
 
113
114
  See more in [Robot Framework User Guide](http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pythonpath).
114
-
@@ -1,7 +1,7 @@
1
1
  ## Robot Framework LibTOC
2
2
 
3
3
  ## What it does
4
- This tool generates docs using Robot Framework [Libdoc](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#libdoc) for an entire folder (or multiple folders) with Robot Framework resources/libs and creates a TOC (table of contents) file for them
4
+ This tool generates docs using Robot Framework [Libdoc](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#libdoc) for an entire folder (or multiple folders) with Robot Framework resources/libs and creates a TOC (table of contents) file for them.
5
5
 
6
6
  ## Why use it
7
7
  The Robot Framework Libdoc tool normally generates a HTML file for a single keyword library or a resource file.
@@ -64,11 +64,12 @@ pip install robotframework-libtoc
64
64
  - Create the `.libtoc` config files in the *root of the resources folder* and/or in *direct subfolders* where you need docs to be created.
65
65
  - Run `libtoc`. The last `resources_dirs` parameter is mandatory, it takes any number of paths. Other params are optional:
66
66
  - `-d, --output_dir`
67
+ - `-P, --pythonpath`
67
68
  - `--config_file`
68
69
  - `--toc_file`
69
70
  - `--toc_template`
70
71
  - `--homepage_template`
71
- - `-P, --pythonpath`
72
+ - `--no_timestamp`
72
73
 
73
74
  Examples:
74
75
  ```shell
@@ -90,4 +91,4 @@ There are two ways to extend the list of paths where the libraries are searched
90
91
  1. Using the `--pythonpath` option
91
92
  2. Set the **PYTHONPATH** environment variable
92
93
 
93
- See more in [Robot Framework User Guide](http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pythonpath).
94
+ See more in [Robot Framework User Guide](http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pythonpath).
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "robotframework-libtoc"
3
- version = "1.5.0"
3
+ version = "1.6.0"
4
4
  description = "Docs and TOC generator for Robot Framework resources and libs"
5
5
  authors = ["Andre Mochinin"]
6
6
  license = "Apache-2.0"
@@ -29,7 +29,10 @@ def toc(links, timestamp, home_page_path, template_file="", search_index=None):
29
29
 
30
30
  result = html_template.replace("{}", home_page_path, 1)
31
31
  result = result.replace("{}", links, 1)
32
- result = result.replace("{}", timestamp, 1)
32
+ if timestamp:
33
+ result = result.replace("{}", timestamp, 1)
34
+ else:
35
+ result = result.replace("Created: {}", "", 1)
33
36
 
34
37
  # inject search index data (done after format() to avoid brace escaping issues)
35
38
  if search_index is not None:
@@ -121,16 +124,16 @@ def extract_libdoc_data(html_file_path):
121
124
  return None
122
125
 
123
126
 
124
- def build_search_index(src_dir, base_dir):
127
+ def build_search_index(src_dir, base_dir, homepage_file):
125
128
  """
126
- Builds a search index from all libdoc HTML files in src_dir.
129
+ Builds a search index from all libdoc HTML files in src_dir (except ``homepage_file``).
127
130
  Returns a list of library/resource entries with their keywords.
128
131
  """
129
132
  index = []
130
133
  for dirpath, dirnames, filenames in os.walk(src_dir):
131
134
  dirnames.sort()
132
135
  for file_name in sorted(filenames):
133
- if file_name.endswith(".html") and file_name != "homepage.html":
136
+ if file_name.endswith(".html") and file_name != homepage_file:
134
137
  file_path = os.path.join(dirpath, file_name)
135
138
  data = extract_libdoc_data(file_path)
136
139
  if data:
@@ -170,9 +173,31 @@ def build_search_index(src_dir, base_dir):
170
173
  return index
171
174
 
172
175
 
173
- def inject_libtoc_script(src_dir):
176
+ def strip_libdoc_timestamps(src_dir, homepage_file):
177
+ """
178
+ Removes the 'generated' timestamp from the libdoc JSON data embedded in each
179
+ libdoc HTML file in src_dir (except ``homepage_file``), replacing it with an empty string.
180
+ """
181
+ for dirpath, dirnames, filenames in os.walk(src_dir):
182
+ dirnames.sort()
183
+ for file_name in sorted(filenames):
184
+ if file_name.endswith(".html") and file_name != homepage_file:
185
+ file_path = os.path.join(dirpath, file_name)
186
+ with open(file_path, "r", encoding="utf-8") as f:
187
+ content = f.read()
188
+ new_content = re.sub(
189
+ r'"generated":\s*"[^"]*"',
190
+ '"generated": ""',
191
+ content,
192
+ )
193
+ if new_content != content:
194
+ with open(file_path, "w", encoding="utf-8") as f:
195
+ f.write(new_content)
196
+
197
+
198
+ def inject_libtoc_script(src_dir, homepage_file):
174
199
  """
175
- Injects a small <script> into each libdoc HTML file in src_dir that:
200
+ Injects a small <script> into each libdoc HTML file in src_dir (except ``homepage_file``) that:
176
201
  - Reads the theme from localStorage and applies data-theme on <html> so the
177
202
  page respects the libtoc theme choice even when file:// cross-origin prevents
178
203
  parent frame DOM access.
@@ -201,7 +226,7 @@ def inject_libtoc_script(src_dir):
201
226
  for dirpath, dirnames, filenames in os.walk(src_dir):
202
227
  dirnames.sort()
203
228
  for file_name in sorted(filenames):
204
- if file_name.endswith(".html") and file_name != "homepage.html":
229
+ if file_name.endswith(".html") and file_name != homepage_file:
205
230
  file_path = os.path.join(dirpath, file_name)
206
231
  with open(file_path, "r", encoding="utf-8") as f:
207
232
  content = f.read()
@@ -353,6 +378,7 @@ def create_toc(
353
378
  homepage_file="homepage.html",
354
379
  toc_template="",
355
380
  homepage_template="",
381
+ no_timestamp=False,
356
382
  ):
357
383
  """
358
384
  Generates a `toc_file` (Table of Contents) HTML page with links to all HTML files inside the `html_docs_dir` and all it's subfolders.
@@ -376,16 +402,20 @@ def create_toc(
376
402
 
377
403
  # create homepage in "src"
378
404
  homepage_path = os.path.join(src_subdir, homepage_file)
379
- current_date_time = datetime.now().strftime("%d.%m.%Y %H:%M:%S")
405
+ current_date_time = "" if no_timestamp else datetime.now().strftime("%d.%m.%Y %H:%M:%S")
380
406
  doc_files_links = add_files_from_folder(src_subdir, os.path.abspath(html_docs_dir))
381
407
  with open(homepage_path, "w", encoding="utf8") as f:
382
408
  f.write(homepage(homepage_template))
383
409
 
384
410
  # build search index from generated docs
385
- search_index = build_search_index(src_subdir, os.path.abspath(html_docs_dir))
411
+ search_index = build_search_index(src_subdir, os.path.abspath(html_docs_dir), homepage_file)
412
+
413
+ # strip timestamps from libdoc HTML files if requested
414
+ if no_timestamp:
415
+ strip_libdoc_timestamps(src_subdir, homepage_file)
386
416
 
387
417
  # inject libtoc script into all libdoc HTML files
388
- inject_libtoc_script(src_subdir)
418
+ inject_libtoc_script(src_subdir, homepage_file)
389
419
 
390
420
  # create TOC
391
421
  toc_file_path = os.path.join(html_docs_dir, toc_file)
@@ -430,6 +460,12 @@ def main():
430
460
  default="",
431
461
  help="Custom HTML template for the homepage file",
432
462
  )
463
+ parser.add_argument(
464
+ "--no_timestamp",
465
+ action="store_true",
466
+ default=False,
467
+ help="Do not include timestamps in the generated TOC and libdoc HTML files",
468
+ )
433
469
  parser.add_argument(
434
470
  "-P",
435
471
  "--pythonpath",
@@ -513,6 +549,7 @@ def main():
513
549
  args.toc_file,
514
550
  toc_template=args.toc_template,
515
551
  homepage_template=args.homepage_template,
552
+ no_timestamp=args.no_timestamp,
516
553
  )
517
554
  else:
518
555
  print("No docs were created!")