litestar-vite 0.1.22__py3-none-any.whl → 0.2.0__py3-none-any.whl

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.

Potentially problematic release.


This version of litestar-vite might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
- from typing import TYPE_CHECKING, TypeVar
3
+ from typing import TYPE_CHECKING, Any, Mapping, TypeVar
4
4
 
5
5
  import markupsafe
6
6
  from litestar.contrib.jinja import JinjaTemplateEngine
@@ -12,10 +12,11 @@ if TYPE_CHECKING:
12
12
  from pathlib import Path
13
13
 
14
14
  from jinja2 import Environment
15
+ from jinja2 import Template as JinjaTemplate
15
16
 
16
17
  from litestar_vite.config import ViteConfig
17
18
 
18
- T = TypeVar("T", bound=TemplateEngineProtocol)
19
+ T = TypeVar("T", bound=TemplateEngineProtocol["JinjaTemplate", Mapping[str, Any]])
19
20
 
20
21
 
21
22
  class ViteTemplateEngine(JinjaTemplateEngine):
@@ -39,9 +40,8 @@ class ViteTemplateEngine(JinjaTemplateEngine):
39
40
  msg = "Please configure the `ViteConfig` instance."
40
41
  raise ValueError(msg)
41
42
  self.config = config
42
-
43
43
  self.asset_loader = ViteAssetLoader.initialize_loader(config=self.config)
44
- self.engine.globals.update({"vite_hmr": self.get_hmr_client, "vite": self.get_asset_tag})
44
+ self.engine.globals.update({"vite_hmr": self.get_hmr_client, "vite": self.get_asset_tag}) # pyright: ignore[reportCallIssue,reportArgumentType]
45
45
 
46
46
  def get_hmr_client(self) -> markupsafe.Markup:
47
47
  """Generate the script tag for the Vite WS client for HMR.
@@ -62,6 +62,7 @@ class ViteTemplateEngine(JinjaTemplateEngine):
62
62
  self,
63
63
  path: str | list[str],
64
64
  scripts_attrs: dict[str, str] | None = None,
65
+ **_: Any,
65
66
  ) -> markupsafe.Markup:
66
67
  """Generate all assets include tags for the file in argument.
67
68
 
@@ -75,6 +76,7 @@ class ViteTemplateEngine(JinjaTemplateEngine):
75
76
  context: The template context.
76
77
  path: Path to a Vite asset to include.
77
78
  scripts_attrs: script attributes
79
+ _: extra args to satisfy type checking
78
80
 
79
81
  Keyword Arguments:
80
82
  scripts_attrs {Optional[Dict[str, str]]}: Override attributes added to scripts tags. (default: {None})
@@ -82,4 +84,21 @@ class ViteTemplateEngine(JinjaTemplateEngine):
82
84
  Returns:
83
85
  str: All tags to import this asset in your HTML page.
84
86
  """
85
- return markupsafe.Markup(self.asset_loader.generate_asset_tags(path, scripts_attrs=scripts_attrs))
87
+ if isinstance(path, str):
88
+ path = [path]
89
+ return markupsafe.Markup(
90
+ "".join([self.asset_loader.generate_asset_tags(p, scripts_attrs=scripts_attrs) for p in path]),
91
+ )
92
+
93
+ @classmethod
94
+ def from_environment(cls, config: ViteConfig, jinja_environment: Environment) -> ViteTemplateEngine: # type: ignore[override]
95
+ """Create a JinjaTemplateEngine from an existing jinja Environment instance.
96
+
97
+ Args:
98
+ config: Vite config
99
+ jinja_environment (jinja2.environment.Environment): A jinja Environment instance.
100
+
101
+ Returns:
102
+ JinjaTemplateEngine instance
103
+ """
104
+ return cls(directory=None, config=config, engine_instance=jinja_environment)
@@ -1,18 +1,16 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <!--IE compatibility-->
6
- <meta http-equiv="X-UA-Compatible" content="IE=edge" />
7
- <meta
8
- name="viewport"
9
- content="width=device-width, initial-scale=1.0, maximum-scale=1.0"
10
- />
11
- </head>
12
3
 
13
- <body>
14
- <div id="app"></div>
15
- {{ vite_hmr() }}
16
- {{ vite('resources/main.ts') }}
17
- </body>
4
+ <head>
5
+ <meta charset="utf-8" />
6
+ <!--IE compatibility-->
7
+ <meta http-equiv="X-UA-Compatible" content="IE=edge" />
8
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
9
+ </head>
10
+
11
+ <body>
12
+ {{ vite_hmr() }}
13
+ {{ vite('resources/main.ts') }}
14
+ </body>
15
+
18
16
  </html>
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: litestar-vite
3
- Version: 0.1.22
3
+ Version: 0.2.0
4
4
  Summary: Vite plugin for Litestar
5
5
  Project-URL: Changelog, https://cofin.github.io/litestar-vite/latest/changelog
6
6
  Project-URL: Discord, https://discord.gg/X3FJqy8d2j
@@ -70,19 +70,9 @@ class WebController(Controller):
70
70
  return Template(template_name="index.html.j2")
71
71
 
72
72
 
73
- vite = VitePlugin(
74
- config=ViteConfig(
75
- bundle_dir=Path("./public"),
76
- resource_dir=Path("./resources"),
77
- template_dir=Path("./templates"),
78
- # Should be False when in production
79
- dev_mode=True,
80
- hot_reload=True, # Websocket HMR asset reloading is enabled when true.
81
- ),
82
- )
73
+ vite = VitePlugin(config=ViteConfig(template_dir='templates/'))
83
74
  app = Litestar(plugins=[vite], route_handlers=[WebController])
84
75
 
85
-
86
76
  ```
87
77
 
88
78
  Create a template to serve the application in `./templates/index.html.h2`:
@@ -0,0 +1,30 @@
1
+ litestar_vite/__init__.py,sha256=QEZzbM6LXuSm52rzpzcw3OihR7xxoPCZ6jhWtZH2dZc,402
2
+ litestar_vite/__metadata__.py,sha256=Eml1c9xezV-GSodmysksrT8jPWqE__x0ENO1wM5g6q0,319
3
+ litestar_vite/cli.py,sha256=foXJ-xW1bvUEsT7nPo1hbN0FLaDzHWPG4zpmqN__rY0,10976
4
+ litestar_vite/commands.py,sha256=sfTdFfMcDxnW3_tbmIIBjpHmNdQYKHjSguGxXNP8SVw,4440
5
+ litestar_vite/config.py,sha256=Mg86uVtqDG-uVZd2YUZoJYNRIlBBbyJLl8iI-fO1zKo,7527
6
+ litestar_vite/loader.py,sha256=USrzNDppXgXLvW5WCuIgKPuM6MlECNIssnkwb_p-E8s,8117
7
+ litestar_vite/plugin.py,sha256=2rwlumH3CFozb_7NGOFwn20BMZ_4JTNHiWh0oyaN-gc,5131
8
+ litestar_vite/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ litestar_vite/template_engine.py,sha256=ffC4KPtUUNkuC0tJ0bD1Bu7c8lE33vKP0US1fWUYnO8,3853
10
+ litestar_vite/inertia/__init__.py,sha256=PMOon8tag-20riAkHH3U4VLk7NBwt9lHsOHHSKMQHJQ,695
11
+ litestar_vite/inertia/_utils.py,sha256=IAsK4Nrjx2dr9z7rXBLHAu_FG8GvCpo_fpywY7RHwl0,1932
12
+ litestar_vite/inertia/config.py,sha256=6cYR4m5oGsJnL_rH6Dt8bQJ804Oq6knj6qDsCVUqNsI,942
13
+ litestar_vite/inertia/exception_handler.py,sha256=fXLfUtrooAORd7TWJGx8hDd6_0h_mI3w89CqJz5IMmE,4022
14
+ litestar_vite/inertia/middleware.py,sha256=9ADCoCNdQNLDYhQ6ctY4Lo92E_EtgBPqIo2SdOJz9zU,1766
15
+ litestar_vite/inertia/plugin.py,sha256=ebAG9XnDBahttuc7WIUgBd3o_Ys8MdPS273LPNs5H8A,2344
16
+ litestar_vite/inertia/request.py,sha256=UReg7_ks6MGa2HbIpDsD2DochckbLA-c-k8Er2mHkVA,3509
17
+ litestar_vite/inertia/response.py,sha256=31Hm838c7nJAkKe9joLj-c33UlZpWTFAgQefxLd5vn0,14379
18
+ litestar_vite/inertia/routes.py,sha256=QksJm2RUfL-WbuhOieYnPXXWO5GYnPtmsYEm6Ef8Yeo,1782
19
+ litestar_vite/inertia/types.py,sha256=tLp0pm1N__hcWC875khf6wH1nuFlKS9-VjDqgsRkXnw,702
20
+ litestar_vite/templates/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
+ litestar_vite/templates/index.html.j2,sha256=Xue1cTl6piEOZkW3UG68SnW80NeL9PxaOp-Xr23kpr4,322
22
+ litestar_vite/templates/main.ts.j2,sha256=Nzr5m_hXMAjeDL_4yQNP3DMCf7Blh3dwg5m-67GJVbY,22
23
+ litestar_vite/templates/package.json.j2,sha256=0JWgdTuaSZ25EmCltF_zbqDdpxfvCLeYuzBjXrziXNw,299
24
+ litestar_vite/templates/styles.css.j2,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
+ litestar_vite/templates/tsconfig.json.j2,sha256=q1REIuVyXUHCy4Zi2kgTkmrhdT98vyY89k-WTrImOj8,843
26
+ litestar_vite/templates/vite.config.ts.j2,sha256=FZ4OJaB8Kjby_nlx4_LCP8eCe1LRi8kW2GspCiVMfDY,1115
27
+ litestar_vite-0.2.0.dist-info/METADATA,sha256=DGPtfcXb9Khk4EXmvwXCJAb2T992hzHkR3CLtIHAqG8,6180
28
+ litestar_vite-0.2.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
29
+ litestar_vite-0.2.0.dist-info/licenses/LICENSE,sha256=HeTiEfEgvroUXZe_xAmYHxtTBgw--mbXyZLsWDYabHc,1069
30
+ litestar_vite-0.2.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.22.3
2
+ Generator: hatchling 1.25.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,20 +0,0 @@
1
- litestar_vite/__init__.py,sha256=9X3i67Q8DJN2lQYAMa9NSPTZGzHASGn8X8yeWJqBvWg,357
2
- litestar_vite/__metadata__.py,sha256=Eml1c9xezV-GSodmysksrT8jPWqE__x0ENO1wM5g6q0,319
3
- litestar_vite/cli.py,sha256=BsYvMPcE8rFZGO8xnEwEXtrXhILgizN3JDVO_KH_FE8,9618
4
- litestar_vite/commands.py,sha256=S2oY1z1IMFPG58qD5FzDF4hjZvoKycj3Hl9XeSw3_hM,4236
5
- litestar_vite/config.py,sha256=uBbdV0INcChMOoGzVf60baovtuwkUkqkbVhwTFFw804,6978
6
- litestar_vite/loader.py,sha256=cxDwrViZJR2F7H6OTkZLwQhG0uw9VadUh-vxc91tJZs,7481
7
- litestar_vite/plugin.py,sha256=pw9ianec85DdXWnBFvhcZp7Ag4lu-3MIVP8mFzOFOg8,4843
8
- litestar_vite/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- litestar_vite/template_engine.py,sha256=UIxphAoAKrAcpAuV_CJmZgsN9GOFfqq0azQdId6yofg,2995
10
- litestar_vite/templates/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
- litestar_vite/templates/index.html.j2,sha256=GobZbXgrlFRf3sCoS-416iWfV8lBP_v3AXPQX_QVzZA,381
12
- litestar_vite/templates/main.ts.j2,sha256=Nzr5m_hXMAjeDL_4yQNP3DMCf7Blh3dwg5m-67GJVbY,22
13
- litestar_vite/templates/package.json.j2,sha256=0JWgdTuaSZ25EmCltF_zbqDdpxfvCLeYuzBjXrziXNw,299
14
- litestar_vite/templates/styles.css.j2,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
- litestar_vite/templates/tsconfig.json.j2,sha256=q1REIuVyXUHCy4Zi2kgTkmrhdT98vyY89k-WTrImOj8,843
16
- litestar_vite/templates/vite.config.ts.j2,sha256=FZ4OJaB8Kjby_nlx4_LCP8eCe1LRi8kW2GspCiVMfDY,1115
17
- litestar_vite-0.1.22.dist-info/METADATA,sha256=aSQ7qnkNkw39YYPUf2vaNRqjowtw2ub6IzmfT_ZohNs,6437
18
- litestar_vite-0.1.22.dist-info/WHEEL,sha256=bq9SyP5NxIRA9EpQgMCd-9RmPHWvbH-4lTDGwxgIR64,87
19
- litestar_vite-0.1.22.dist-info/licenses/LICENSE,sha256=HeTiEfEgvroUXZe_xAmYHxtTBgw--mbXyZLsWDYabHc,1069
20
- litestar_vite-0.1.22.dist-info/RECORD,,