Skip to content

Commit

Permalink
refactor!: restructured exports significantly
Browse files Browse the repository at this point in the history
This has been needed for a long time, and should make the locations
of things *much* more logical.
  • Loading branch information
arctic-hen7 committed Jul 8, 2022
1 parent 6ec4852 commit 70d425b
Show file tree
Hide file tree
Showing 73 changed files with 356 additions and 530 deletions.
27 changes: 2 additions & 25 deletions examples/core/custom_server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,15 @@ mod templates;

use perseus::{Html, PerseusApp};

// pub fn get_app<G: Html>() -> PerseusApp<G> {
// PerseusApp::new()
// .template(crate::templates::index::get_template)
// .template(crate::templates::about::get_template)
// .error_pages(crate::error_pages::get_error_pages)
// }

// #[perseus::engine_main]
// async fn main() {
// use perseus::builder::{get_op, run_dflt_engine};

// let op = get_op().unwrap();
// let exit_code = run_dflt_engine(op, get_app,
// perseus_warp::dflt_server).await; std::process::exit(exit_code);
// }

// #[perseus::browser_main]
// pub fn main() -> perseus::ClientReturn {
// use perseus::run_client;

// run_client(get_app)
// }

// Note: we use fully-qualified paths in the types to this function so we don't
// have to target-gate some more imports
#[cfg(not(target_arch = "wasm32"))] // We only have access to `warp` etc. on the engine-side, so this function
// should only exist there
pub async fn dflt_server<
M: perseus::stores::MutableStore + 'static,
T: perseus::internal::i18n::TranslationsManager + 'static,
T: perseus::i18n::TranslationsManager + 'static,
>(
props: perseus::internal::serve::ServerProps<M, T>,
props: perseus::server::ServerProps<M, T>,
(host, port): (String, u16),
) {
use perseus_warp::perseus_routes;
Expand Down
2 changes: 1 addition & 1 deletion examples/core/plugins/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod error_pages;
mod plugin;
mod templates;

use perseus::{Html, PerseusApp, Plugins};
use perseus::{plugins::Plugins, Html, PerseusApp};

#[perseus::main(perseus_integration::dflt_server)]
pub fn main<G: Html>() -> PerseusApp<G> {
Expand Down
2 changes: 1 addition & 1 deletion examples/core/router_state/src/templates/index.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use perseus::{templates::RouterLoadState, Html, Template};
use perseus::{router::RouterLoadState, Html, Template};
use sycamore::prelude::{create_memo, view, Scope, View};

#[perseus::template_rx]
Expand Down
2 changes: 1 addition & 1 deletion examples/demos/fetching/src/templates/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub async fn get_build_state(
// We'll cache the result with `try_cache_res`, which means we only make the
// request once, and future builds will use the cached result (speeds up
// development)
let body = perseus::cache_fallible_res(
let body = perseus::utils::cache_fallible_res(
"ipify",
|| async {
// This just gets the IP address of the machine that built the app
Expand Down
2 changes: 1 addition & 1 deletion packages/perseus-actix-web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ sycamore = { version = "=0.8.0-beta.7", features = ["ssr"] }

[features]
# Enables the default server configuration, which provides a convenience function if you're not adding any extra routes
dflt-server = [ "perseus/builder" ]
dflt-server = []
6 changes: 2 additions & 4 deletions packages/perseus-actix-web/src/configurer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ use crate::translations::translations;
use actix_files::{Files, NamedFile};
use actix_web::{web, HttpRequest};
use perseus::{
internal::{
i18n::TranslationsManager,
serve::{get_render_cfg, ServerOptions, ServerProps},
},
i18n::TranslationsManager,
server::{get_render_cfg, ServerOptions, ServerProps},
stores::MutableStore,
};

Expand Down
4 changes: 1 addition & 3 deletions packages/perseus-actix-web/src/dflt_server.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use crate::configurer;
use actix_web::{App, HttpServer};
use futures::executor::block_on;
use perseus::{
internal::i18n::TranslationsManager, internal::serve::ServerProps, stores::MutableStore,
};
use perseus::{i18n::TranslationsManager, server::ServerProps, stores::MutableStore};

/// Creates and starts the default Perseus server using Actix Web. This should
/// be run in a `main()` function annotated with `#[tokio::main]` (which
Expand Down
14 changes: 6 additions & 8 deletions packages/perseus-actix-web/src/initial_load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ use actix_web::{http::StatusCode, web, HttpRequest, HttpResponse};
use fmterr::fmt_err;
use perseus::{
errors::err_to_status_code,
internal::{
get_path_prefix_server,
i18n::{TranslationsManager, Translator},
router::{match_route_atomic, RouteInfoAtomic, RouteVerdictAtomic},
serve::{
build_error_page, get_page_for_template, get_path_slice, GetPageProps, HtmlShell,
ServerOptions,
},
i18n::{TranslationsManager, Translator},
router::{match_route_atomic, RouteInfoAtomic, RouteVerdictAtomic},
server::{
build_error_page, get_page_for_template, get_path_slice, GetPageProps, HtmlShell,
ServerOptions,
},
stores::{ImmutableStore, MutableStore},
utils::get_path_prefix_server,
ErrorPages, SsrNode,
};
use std::collections::HashMap;
Expand Down
2 changes: 1 addition & 1 deletion packages/perseus-actix-web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ mod translations;
pub use crate::configurer::configurer;
#[cfg(feature = "dflt-server")]
pub use dflt_server::dflt_server;
pub use perseus::internal::serve::ServerOptions;
pub use perseus::server::ServerOptions;
6 changes: 2 additions & 4 deletions packages/perseus-actix-web/src/page_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ use actix_web::{http::StatusCode, web, HttpRequest, HttpResponse};
use fmterr::fmt_err;
use perseus::{
errors::err_to_status_code,
internal::{
i18n::TranslationsManager,
serve::{get_page_for_template, GetPageProps, ServerOptions},
},
i18n::TranslationsManager,
server::{get_page_for_template, GetPageProps, ServerOptions},
stores::{ImmutableStore, MutableStore},
};
use serde::Deserialize;
Expand Down
4 changes: 2 additions & 2 deletions packages/perseus-actix-web/src/translations.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use actix_web::{web, HttpRequest, HttpResponse};
use fmterr::fmt_err;
use perseus::internal::i18n::TranslationsManager;
use perseus::internal::serve::ServerOptions;
use perseus::i18n::TranslationsManager;
use perseus::server::ServerOptions;

/// The handler for calls to `.perseus/translations/{locale}`. This will manage
/// returning errors and the like. THe JSON body returned from this does NOT
Expand Down
2 changes: 1 addition & 1 deletion packages/perseus-axum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ closure = "0.3"

[features]
# Enables the default server configuration, which provides a convenience function if you're not adding any extra routes
dflt-server = [ "perseus/builder" ]
dflt-server = []
3 changes: 1 addition & 2 deletions packages/perseus-axum/src/dflt_server.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::get_router;
use perseus::{
internal::i18n::TranslationsManager, internal::serve::ServerProps, stores::MutableStore,
PerseusAppBase, SsrNode,
i18n::TranslationsManager, server::ServerProps, stores::MutableStore, PerseusAppBase, SsrNode,
};
use std::net::SocketAddr;

Expand Down
14 changes: 6 additions & 8 deletions packages/perseus-axum/src/initial_load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ use axum::{
use fmterr::fmt_err;
use perseus::{
errors::err_to_status_code,
internal::{
get_path_prefix_server,
i18n::{TranslationsManager, Translator},
router::{match_route_atomic, RouteInfoAtomic, RouteVerdictAtomic},
serve::{
build_error_page, get_page_for_template, get_path_slice, GetPageProps, HtmlShell,
ServerOptions,
},
i18n::{TranslationsManager, Translator},
router::{match_route_atomic, RouteInfoAtomic, RouteVerdictAtomic},
server::{
build_error_page, get_page_for_template, get_path_slice, GetPageProps, HtmlShell,
ServerOptions,
},
stores::{ImmutableStore, MutableStore},
utils::get_path_prefix_server,
ErrorPages, Request, SsrNode,
};
use std::{collections::HashMap, rc::Rc, sync::Arc};
Expand Down
2 changes: 1 addition & 1 deletion packages/perseus-axum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ mod translations;
pub use crate::router::get_router;
#[cfg(feature = "dflt-server")]
pub use dflt_server::dflt_server;
pub use perseus::internal::serve::ServerOptions;
pub use perseus::server::ServerOptions;
6 changes: 2 additions & 4 deletions packages/perseus-axum/src/page_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ use axum::{
use fmterr::fmt_err;
use perseus::{
errors::err_to_status_code,
internal::{
i18n::TranslationsManager,
serve::{get_page_for_template, GetPageProps, ServerOptions},
},
i18n::TranslationsManager,
server::{get_page_for_template, GetPageProps, ServerOptions},
stores::{ImmutableStore, MutableStore},
Request,
};
Expand Down
4 changes: 2 additions & 2 deletions packages/perseus-axum/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use axum::{
Router,
};
use closure::closure;
use perseus::internal::serve::{get_render_cfg, ServerProps};
use perseus::{internal::i18n::TranslationsManager, stores::MutableStore};
use perseus::server::{get_render_cfg, ServerProps};
use perseus::{i18n::TranslationsManager, stores::MutableStore};
use std::sync::Arc;
use tower_http::services::{ServeDir, ServeFile};

Expand Down
2 changes: 1 addition & 1 deletion packages/perseus-axum/src/translations.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use axum::{extract::Path, http::StatusCode};
use fmterr::fmt_err;
use perseus::internal::{i18n::TranslationsManager, serve::ServerOptions};
use perseus::{i18n::TranslationsManager, server::ServerOptions};
use std::sync::Arc;

pub async fn translations_handler<T: TranslationsManager>(
Expand Down
8 changes: 4 additions & 4 deletions packages/perseus-cli/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ pub fn run_cmd(

let exit_code = match output.status.code() {
Some(exit_code) => exit_code, // If we have an exit code, use it
None if output.status.success() => 0, /* If we don't, but we know the command succeeded,
* return 0 (success code) */
None if output.status.success() => 0, /* If we don't, but we know the command succeeded, */
// return 0 (success code)
None => 1, /* If we don't know an exit code but we know that the command failed, return 1
* (general error code) */
};
Expand Down Expand Up @@ -141,8 +141,8 @@ pub fn run_cmd_directly(

let exit_code = match output.status.code() {
Some(exit_code) => exit_code, // If we have an exit code, use it
None if output.status.success() => 0, /* If we don't, but we know the command succeeded,
* return 0 (success code) */
None if output.status.success() => 0, /* If we don't, but we know the command succeeded, */
// return 0 (success code)
None => 1, /* If we don't know an exit code but we know that the command failed, return 1
* (general error code) */
};
Expand Down
4 changes: 2 additions & 2 deletions packages/perseus-cli/src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ fn run_server(
let output = child.wait_with_output().unwrap();
let exit_code = match output.status.code() {
Some(exit_code) => exit_code, // If we have an exit code, use it
None if output.status.success() => 0, /* If we don't, but we know the command succeeded,
* return 0 (success code) */
None if output.status.success() => 0, /* If we don't, but we know the command succeeded, */
// return 0 (success code)
None => 1, /* If we don't know an exit code but we know that the command failed, return 1
* (general error code) */
};
Expand Down
6 changes: 0 additions & 6 deletions packages/perseus-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,3 @@ regex = "1"
trybuild = { version = "1.0", features = ["diff"] }
sycamore = "=0.8.0-beta.7"
serde = { version = "1", features = [ "derive" ] }

[features]
# Enables live reloading support (which makes the macros listen for live reload events and adjust appropriately). Do NOT enable this here without also enabling it on `perseus`!
live-reload = []
# Enables support for HSR (which makes the macros respond to live reload events by freezing and thawing as appropriate). Do NOT enable this here without also enabling is on `perseus`!
hsr = [ "live-reload" ]
8 changes: 4 additions & 4 deletions packages/perseus-macro/src/entrypoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ pub fn main_impl(input: MainFn, server_fn: Path) -> TokenStream {
#[tokio::main]
async fn main() {
// Get the operation we're supposed to run (serve, build, export, etc.) from an environment variable
let op = ::perseus::builder::get_op().unwrap();
let exit_code = ::perseus::builder::run_dflt_engine(op, __perseus_simple_main, #server_fn).await;
let op = ::perseus::engine::get_op().unwrap();
let exit_code = ::perseus::engine::run_dflt_engine(op, __perseus_simple_main, #server_fn).await;
std::process::exit(exit_code);
}

Expand Down Expand Up @@ -213,8 +213,8 @@ pub fn main_export_impl(input: MainFn) -> TokenStream {
#[tokio::main]
async fn main() {
// Get the operation we're supposed to run (serve, build, export, etc.) from an environment variable
let op = ::perseus::builder::get_op().unwrap();
let exit_code = ::perseus::builder::run_dflt_engine_export_only(op, __perseus_simple_main).await;
let op = ::perseus::engine::get_op().unwrap();
let exit_code = ::perseus::engine::run_dflt_engine_export_only(op, __perseus_simple_main).await;
std::process::exit(exit_code);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/perseus-macro/src/head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pub fn head_impl(input: HeadFn) -> TokenStream {
#[cfg(target_arch = "wasm32")]
#vis fn #name() {}
#[cfg(not(target_arch = "wasm32"))]
#vis fn #name(cx: ::sycamore::prelude::Scope, props: ::perseus::templates::PageProps) -> ::sycamore::prelude::View<::sycamore::prelude::SsrNode> {
#vis fn #name(cx: ::sycamore::prelude::Scope, props: ::perseus::template::PageProps) -> ::sycamore::prelude::View<::sycamore::prelude::SsrNode> {
// The user's function, with Sycamore component annotations and the like preserved
// We know this won't be async because Sycamore doesn't allow that
#(#attrs)*
Expand All @@ -163,7 +163,7 @@ pub fn head_impl(input: HeadFn) -> TokenStream {
#[cfg(target_arch = "wasm32")]
#vis fn #name() {}
#[cfg(not(target_arch = "wasm32"))]
#vis fn #name(cx: ::sycamore::prelude::Scope, props: ::perseus::templates::PageProps) -> ::sycamore::prelude::View<::sycamore::prelude::SsrNode> {
#vis fn #name(cx: ::sycamore::prelude::Scope, props: ::perseus::template::PageProps) -> ::sycamore::prelude::View<::sycamore::prelude::SsrNode> {
// The user's function, with Sycamore component annotations and the like preserved
// We know this won't be async because Sycamore doesn't allow that
#(#attrs)*
Expand Down
4 changes: 2 additions & 2 deletions packages/perseus-macro/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub fn template_impl(input: TemplateFn) -> TokenStream {
let arg = &args[1];

quote! {
#vis fn #name<G: ::sycamore::prelude::Html>(cx: ::sycamore::prelude::Scope, props: ::perseus::templates::PageProps) -> ::sycamore::prelude::View<G> {
#vis fn #name<G: ::sycamore::prelude::Html>(cx: ::sycamore::prelude::Scope, props: ::perseus::template::PageProps) -> ::sycamore::prelude::View<G> {
// The user's function, with Sycamore component annotations and the like preserved
// We know this won't be async because Sycamore doesn't allow that
#(#attrs)*
Expand All @@ -142,7 +142,7 @@ pub fn template_impl(input: TemplateFn) -> TokenStream {
let cx_arg = &args[0];

quote! {
#vis fn #name<G: ::sycamore::prelude::Html>(cx: ::sycamore::prelude::Scope, props: ::perseus::templates::PageProps) -> ::sycamore::prelude::View<G> {
#vis fn #name<G: ::sycamore::prelude::Html>(cx: ::sycamore::prelude::Scope, props: ::perseus::template::PageProps) -> ::sycamore::prelude::View<G> {
// The user's function, with Sycamore component annotations and the like preserved
// We know this won't be async because Sycamore doesn't allow that
#(#attrs)*
Expand Down
8 changes: 4 additions & 4 deletions packages/perseus-macro/src/template_rx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ pub fn template_impl(input: TemplateFn) -> TokenStream {
match rx_props_ty {
// This template takes dummy state and global state
Type::Tuple(TypeTuple { elems, .. }) if elems.is_empty() => quote! {
#vis fn #name<G: ::sycamore::prelude::Html>(cx: ::sycamore::prelude::Scope, props: ::perseus::templates::PageProps) -> ::sycamore::prelude::View<G> {
#vis fn #name<G: ::sycamore::prelude::Html>(cx: ::sycamore::prelude::Scope, props: ::perseus::template::PageProps) -> ::sycamore::prelude::View<G> {
use ::perseus::state::MakeRx;

let render_ctx = ::perseus::get_render_ctx!(cx);
Expand Down Expand Up @@ -207,7 +207,7 @@ pub fn template_impl(input: TemplateFn) -> TokenStream {
},
// This template takes its own state and global state
_ => quote! {
#vis fn #name<G: ::sycamore::prelude::Html>(cx: ::sycamore::prelude::Scope, props: ::perseus::templates::PageProps) -> ::sycamore::prelude::View<G> {
#vis fn #name<G: ::sycamore::prelude::Html>(cx: ::sycamore::prelude::Scope, props: ::perseus::template::PageProps) -> ::sycamore::prelude::View<G> {
use ::perseus::state::MakeRx;

let render_ctx = ::perseus::get_render_ctx!(cx).clone();
Expand Down Expand Up @@ -269,7 +269,7 @@ pub fn template_impl(input: TemplateFn) -> TokenStream {
};
let name_string = name.to_string();
quote! {
#vis fn #name<G: ::sycamore::prelude::Html>(cx: ::sycamore::prelude::Scope, props: ::perseus::templates::PageProps) -> ::sycamore::prelude::View<G> {
#vis fn #name<G: ::sycamore::prelude::Html>(cx: ::sycamore::prelude::Scope, props: ::perseus::template::PageProps) -> ::sycamore::prelude::View<G> {
use ::perseus::state::MakeRx;

// The user's function, with Sycamore component annotations and the like preserved
Expand Down Expand Up @@ -305,7 +305,7 @@ pub fn template_impl(input: TemplateFn) -> TokenStream {
let cx_arg = &fn_args[0];
// There are no arguments except for the scope
quote! {
#vis fn #name<G: ::sycamore::prelude::Html>(cx: ::sycamore::prelude::Scope, props: ::perseus::templates::PageProps) -> ::sycamore::prelude::View<G> {
#vis fn #name<G: ::sycamore::prelude::Html>(cx: ::sycamore::prelude::Scope, props: ::perseus::template::PageProps) -> ::sycamore::prelude::View<G> {
use ::perseus::state::MakeRx;

// The user's function, with Sycamore component annotations and the like preserved
Expand Down
2 changes: 1 addition & 1 deletion packages/perseus-warp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ sycamore = { version = "=0.8.0-beta.7", features = ["ssr"] }

[features]
# Enables the default server configuration, which provides a convenience function if you're not adding any extra routes
dflt-server = [ "perseus/builder" ]
dflt-server = []
5 changes: 1 addition & 4 deletions packages/perseus-warp/src/dflt_server.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use crate::perseus_routes;
use perseus::{
internal::{i18n::TranslationsManager, serve::ServerProps},
stores::MutableStore,
};
use perseus::{i18n::TranslationsManager, server::ServerProps, stores::MutableStore};
use std::net::SocketAddr;

/// Creates and starts the default Perseus server with Warp. This should be run
Expand Down
14 changes: 6 additions & 8 deletions packages/perseus-warp/src/initial_load.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use fmterr::fmt_err;
use perseus::{
errors::err_to_status_code,
internal::{
get_path_prefix_server,
i18n::{TranslationsManager, Translator},
router::{match_route_atomic, RouteInfoAtomic, RouteVerdictAtomic},
serve::{
build_error_page, get_page_for_template, get_path_slice, GetPageProps, HtmlShell,
ServerOptions,
},
i18n::{TranslationsManager, Translator},
router::{match_route_atomic, RouteInfoAtomic, RouteVerdictAtomic},
server::{
build_error_page, get_page_for_template, get_path_slice, GetPageProps, HtmlShell,
ServerOptions,
},
stores::{ImmutableStore, MutableStore},
utils::get_path_prefix_server,
ErrorPages, SsrNode,
};
use std::{collections::HashMap, rc::Rc, sync::Arc};
Expand Down
Loading

0 comments on commit 70d425b

Please sign in to comment.