Skip to content

Commit

Permalink
git commit -m"fix conflict changelog.rst"
Browse files Browse the repository at this point in the history
  • Loading branch information
nhatnamnguyengtvthcm committed Sep 25, 2023
1 parent fd1f612 commit 6649155
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 31 deletions.
68 changes: 41 additions & 27 deletions docs/builders.rst
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ needs_lut
The **needs_lut** (Needs Lookup Table) builder exports all found needs to a single json file, which only include list of key ``id`` and value of ``docname`` or ``external_url``.
The build creates a file called **needs_lut.json** inside the given build-folder.
Usage
+++++
Expand All @@ -203,32 +204,45 @@ Format
++++++
.. code-block:: python
{
"extend_test_001": "directives/needextend",
"extend_test_002": "directives/needextend",
"req_arch_001": "directives/needarch",
"req_arch_004": "directives/needarch",
"spec_arch_001": "directives/needarch",
"test_arch_001": "directives/needarch",
"COMP_T_001": "directives/needarch",
"COMP_T_002": "directives/needarch",
"EX_REQ_1": "examples/index",
"EX_REQ_2": "examples/index",
"R_F4722": "examples/index",
"OWN_ID_123": "examples/index",
"IMPL_01": "examples/index",
"T_C3893": "examples/index",
"R_2A9D0": "filter",
"R_22EB2": "filter",
"S_D70B0": "filter",
"S_01A67": "filter",
"T_5CCAA": "filter",
"R_17EB4": "filter",
"req_flow_001": "directives/needflow",
"spec_flow_001": "directives/needflow",
{
"created": "2023-09-25T17:11:03.162346",
"current_version": "1.3",
"project": "Sphinx-Needs",
"versions": {
"1.3": {
"created": "2023-09-25T17:11:03.162329",
"filters": {},
"filters_amount": 0,
"needs": {
"extend_test_001": "directives/needextend",
"extend_test_002": "directives/needextend",
"req_arch_001": "directives/needarch",
"req_arch_004": "directives/needarch",
"spec_arch_001": "directives/needarch",
"test_arch_001": "directives/needarch",
"COMP_T_001": "directives/needarch",
"COMP_T_002": "directives/needarch",
"EX_REQ_1": "examples/index",
"EX_REQ_2": "examples/index",
"R_F4722": "examples/index",
"OWN_ID_123": "examples/index",
"IMPL_01": "examples/index",
"T_C3893": "examples/index",
"R_2A9D0": "filter",
"R_22EB2": "filter",
"S_D70B0": "filter",
"S_01A67": "filter",
"T_5CCAA": "filter",
"R_17EB4": "filter",
"req_flow_001": "directives/needflow",
"spec_flow_001": "directives/needflow",
}
}
}
}
2 changes: 1 addition & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Released: under development
-----
Released: under development
* Improvement: Added Builder :ref:`needs_lut_builder` and config option :ref:`needs_build_lut_json` in `conf.py`.

* Improvement: Added Builder :ref:`needs_id_builder` added and config option :ref:`needs_build_json_per_id` in `conf.py`.
* Improvement: Reduce document build time, by memoizing the inline parse in ``build_need``
(`#968 <https://github.com/useblocks/sphinx-needs/pull/968>`_)
Expand All @@ -25,6 +24,7 @@ Released: under development
* Improvement: Suffix all warnings with ``[needs]``, and allow them to be suppressed
(`#975 <https://github.com/useblocks/sphinx-needs/pull/975>`_)
* Improvement: :ref:`needextend` for single needs is much faster.
* Improvement: external_needs is using cached templates to save generation time.

1.3.0
-----
Expand Down
15 changes: 13 additions & 2 deletions sphinx_needs/external_needs.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import json
import os
from functools import lru_cache

import requests
from jinja2 import Environment
from jinja2 import Environment, Template
from requests_file import FileAdapter
from sphinx.application import Sphinx
from sphinx.environment import BuildEnvironment
Expand All @@ -17,6 +18,16 @@
log = get_logger(__name__)


@lru_cache(maxsize=20)
def get_target_template(target_url: str) -> Template:
"""
Provides template for target_link style
Can be cached, as the template is always the same for a given target_url
"""
mem_template = Environment().from_string(target_url)
return mem_template


def load_external_needs(app: Sphinx, env: BuildEnvironment, _docname: str) -> None:
needs_config = NeedsSphinxConfig(app.config)
for source in needs_config.external_needs:
Expand Down Expand Up @@ -95,7 +106,7 @@ def load_external_needs(app: Sphinx, env: BuildEnvironment, _docname: str) -> No

if target_url:
# render jinja content
mem_template = Environment().from_string(target_url)
mem_template = get_target_template(target_url)
cal_target_url = mem_template.render(**{"need": need})
need_params["external_url"] = f'{source["base_url"]}/{cal_target_url}'
else:
Expand Down
2 changes: 1 addition & 1 deletion sphinx_needs/templates/permalink.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
const needs_obj = version['needs'];

const id = getParameterByName('id');
var pathname = new URL(window.location.href).pathname;
var pathname = new URL(window.location.href).pathname;

pathname = pathname.substring(0, pathname.lastIndexOf('{{ permalink_file }}'));

Expand Down

0 comments on commit 6649155

Please sign in to comment.