diff --git a/Cargo.lock b/Cargo.lock index 7f7ea00..3ad48f7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -352,25 +352,50 @@ dependencies = [ name = "alcova" version = "0.1.0" dependencies = [ - "anyhow 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", + "actix 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "actix-web 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "actix-web-actors 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "alcova_macros 0.1.0", + "futures 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonwebtoken 7.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.56 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "alcova_macros" +name = "alcova_examples" version = "0.1.0" dependencies = [ + "actix 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "actix-codec 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "actix-files 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "actix-identity 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "actix-rt 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "actix-web 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "actix-web-actors 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "alcova 0.1.0", + "alcova_macros 0.1.0", + "awc 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", + "env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "listenfd 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "alcova_macros" +version = "0.1.0" +dependencies = [ "proc-macro-error 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "syn 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "anyhow" -version = "1.0.31" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "arc-swap" version = "0.4.7" @@ -606,30 +631,6 @@ dependencies = [ "termcolor 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "example" -version = "0.1.0" -dependencies = [ - "actix 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "actix-codec 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "actix-files 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "actix-identity 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "actix-rt 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "actix-web 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "actix-web-actors 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "alcova 0.1.0", - "alcova_macros 0.1.0", - "awc 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "bytes 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", - "env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "listenfd 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "liveview 0.1.0", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "failure" version = "0.1.8" @@ -970,20 +971,6 @@ dependencies = [ "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "liveview" -version = "0.1.0" -dependencies = [ - "actix 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "actix-web 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "actix-web-actors 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonwebtoken 7.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.56 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "lock_api" version = "0.3.4" @@ -1913,7 +1900,6 @@ dependencies = [ "checksum addr2line 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1b6a2d3371669ab3ca9797670853d61402b03d0b4b9ebf33d677dfa720203072" "checksum adler 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ccc9a9dd069569f212bc4330af9f17c4afb5e8ce185e83dbb14f1349dda18b10" "checksum aho-corasick 0.7.13 (registry+https://github.com/rust-lang/crates.io-index)" = "043164d8ba5c4c3035fec9bbee8647c0261d788f3474306f93bb65901cae0e86" -"checksum anyhow 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)" = "85bb70cc08ec97ca5450e6eba421deeea5f172c0fc61f78b5357b2a8e8be195f" "checksum arc-swap 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "4d25d88fd6b8041580a654f9d0c581a047baee2b3efee13275f2fc392fc75034" "checksum async-trait 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "a265e3abeffdce30b2e26b7a11b222fe37c6067404001b434101457d0385eb92" "checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" diff --git a/Cargo.toml b/Cargo.toml index 05d8171..9b22dc8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,5 @@ members = [ "./alcova", "./alcova_macros", - "./example", - "./liveview", + "./alcova_examples", ] diff --git a/alcova/Cargo.toml b/alcova/Cargo.toml index 5ecbdbc..804938c 100644 --- a/alcova/Cargo.toml +++ b/alcova/Cargo.toml @@ -1,11 +1,19 @@ [package] name = "alcova" version = "0.1.0" -authors = ["Connor Brewster "] +authors = ["Connor Brewster "] edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -anyhow = "1.0" +actix = "0.9.0" +actix-web-actors = "2.0.0" +actix-web = "2.0.0" +alcova_macros = { path = "../alcova_macros" } +futures = "0.3.5" +jsonwebtoken = "7" +log = "0.4.8" +serde = { version = "1.0", features = [ "derive" ] } +serde_json = "1.0" diff --git a/alcova/src/lib.rs b/alcova/src/lib.rs index 137d0d3..7549a83 100644 --- a/alcova/src/lib.rs +++ b/alcova/src/lib.rs @@ -1,5 +1,13 @@ -mod ast; -mod parse; +#[macro_use] +extern crate log; -pub use ast::{BinaryOperator, CodeExpression, Expression, Pattern, Template, TypePath}; -pub use parse::{parse_template, Parser}; +mod live_socket; +mod live_template; +mod live_view; +mod registry; + +pub use live_socket::{LiveSocket, LiveSocketContext}; +pub use live_template::{Changes, LiveTemplate, RenderedTemplate, Slot}; +pub use live_view::{LiveHandler, LiveMessage, LiveView, LiveViewContext}; +pub use registry::LiveViewRegistry; +pub use alcova_macros::*; diff --git a/liveview/src/live_socket.rs b/alcova/src/live_socket.rs similarity index 100% rename from liveview/src/live_socket.rs rename to alcova/src/live_socket.rs diff --git a/liveview/src/live_template.rs b/alcova/src/live_template.rs similarity index 100% rename from liveview/src/live_template.rs rename to alcova/src/live_template.rs diff --git a/liveview/src/live_view.rs b/alcova/src/live_view.rs similarity index 100% rename from liveview/src/live_view.rs rename to alcova/src/live_view.rs diff --git a/liveview/src/registry.rs b/alcova/src/registry.rs similarity index 100% rename from liveview/src/registry.rs rename to alcova/src/registry.rs diff --git a/example/Cargo.toml b/alcova_examples/Cargo.toml similarity index 83% rename from example/Cargo.toml rename to alcova_examples/Cargo.toml index 6199781..70c3ff1 100644 --- a/example/Cargo.toml +++ b/alcova_examples/Cargo.toml @@ -1,13 +1,12 @@ [package] -name = "example" +name = "alcova_examples" version = "0.1.0" -authors = ["Connor Brewster "] +authors = ["Connor Brewster "] edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -liveview = { path = "../liveview" } alcova = { path = "../alcova" } alcova_macros = { path = "../alcova_macros" } actix = "0.9.0" diff --git a/example/fruits.txt b/alcova_examples/fruits.txt similarity index 100% rename from example/fruits.txt rename to alcova_examples/fruits.txt diff --git a/example/src/chat.rs b/alcova_examples/src/chat.rs similarity index 99% rename from example/src/chat.rs rename to alcova_examples/src/chat.rs index 36baeab..36c67d1 100644 --- a/example/src/chat.rs +++ b/alcova_examples/src/chat.rs @@ -2,8 +2,7 @@ use crate::RootTemplate; use actix::{Actor, Addr, AsyncContext, Context, Handler, Message, Recipient}; use actix_identity::Identity; use actix_web::{http, web, HttpRequest, Responder}; -use alcova_macros::LiveTemplate; -use liveview::{ +use alcova::{ LiveHandler, LiveMessage, LiveSocketContext, LiveTemplate, LiveView, LiveViewContext, }; use serde::{Deserialize, Serialize}; diff --git a/example/src/fruit.rs b/alcova_examples/src/fruit.rs similarity index 96% rename from example/src/fruit.rs rename to alcova_examples/src/fruit.rs index cb9ee29..37f6ce3 100644 --- a/example/src/fruit.rs +++ b/alcova_examples/src/fruit.rs @@ -1,7 +1,6 @@ use crate::RootTemplate; use actix_web::{web, Responder}; -use alcova_macros::LiveTemplate; -use liveview::{LiveSocketContext, LiveTemplate, LiveView, LiveViewContext}; +use alcova::{LiveSocketContext, LiveTemplate, LiveView, LiveViewContext}; fn fruits() -> Vec<&'static str> { include_str!("../fruits.txt").lines().collect() diff --git a/example/src/main.rs b/alcova_examples/src/main.rs similarity index 96% rename from example/src/main.rs rename to alcova_examples/src/main.rs index 8c23121..67bb44e 100644 --- a/example/src/main.rs +++ b/alcova_examples/src/main.rs @@ -10,11 +10,10 @@ use actix_files as fs; use actix_identity::{CookieIdentityPolicy, IdentityService}; use actix_web::{middleware, web, App, Error, HttpRequest, HttpResponse, HttpServer, Responder}; use actix_web_actors::ws; -use alcova_macros::LiveTemplate; +use alcova::{LiveSocket, LiveTemplate, LiveViewRegistry}; use chat::{ChatLive, Lobby}; use fruit::FruitLive; use listenfd::ListenFd; -use liveview::{LiveSocket, LiveTemplate, LiveViewRegistry}; use timer::TimerLive; use top::TopLive; diff --git a/example/src/timer.rs b/alcova_examples/src/timer.rs similarity index 98% rename from example/src/timer.rs rename to alcova_examples/src/timer.rs index 76b3547..37eca21 100644 --- a/example/src/timer.rs +++ b/alcova_examples/src/timer.rs @@ -1,8 +1,7 @@ use crate::RootTemplate; use actix::{AsyncContext, Message, SpawnHandle}; use actix_web::{web, Responder}; -use alcova_macros::LiveTemplate; -use liveview::{ +use alcova::{ LiveHandler, LiveMessage, LiveSocketContext, LiveTemplate, LiveView, LiveViewContext, }; use std::time::{Duration, Instant}; diff --git a/example/src/top.rs b/alcova_examples/src/top.rs similarity index 98% rename from example/src/top.rs rename to alcova_examples/src/top.rs index 55876bb..37e4036 100644 --- a/example/src/top.rs +++ b/alcova_examples/src/top.rs @@ -1,8 +1,7 @@ use crate::RootTemplate; use actix::{AsyncContext, Message}; use actix_web::{web, Responder}; -use alcova_macros::LiveTemplate; -use liveview::{ +use alcova::{ LiveHandler, LiveMessage, LiveSocketContext, LiveTemplate, LiveView, LiveViewContext, }; use std::{process::Stdio, time::Duration}; diff --git a/example/templates/chat.html.rlt b/alcova_examples/templates/chat.html.rlt similarity index 100% rename from example/templates/chat.html.rlt rename to alcova_examples/templates/chat.html.rlt diff --git a/example/templates/fruit.html.rlt b/alcova_examples/templates/fruit.html.rlt similarity index 91% rename from example/templates/fruit.html.rlt rename to alcova_examples/templates/fruit.html.rlt index 620d5d0..fe8b9ee 100644 --- a/example/templates/fruit.html.rlt +++ b/alcova_examples/templates/fruit.html.rlt @@ -1,4 +1,4 @@ -

Rust LiveView Autocomplete

+

Alcova Autocomplete

{{ if true != !(@selected.len() > 3) }} Well thats a lot of fruit! diff --git a/example/templates/index.html.rlt b/alcova_examples/templates/index.html.rlt similarity index 82% rename from example/templates/index.html.rlt rename to alcova_examples/templates/index.html.rlt index ec5280d..d87afe6 100644 --- a/example/templates/index.html.rlt +++ b/alcova_examples/templates/index.html.rlt @@ -1,4 +1,4 @@ -

Rust LiveView Demos

+

Alcova Demos

  • Fruit Autocomplete Demo
  • diff --git a/example/templates/layout.html.rlt b/alcova_examples/templates/layout.html.rlt similarity index 82% rename from example/templates/layout.html.rlt rename to alcova_examples/templates/layout.html.rlt index 6d440c0..ac07ed4 100644 --- a/example/templates/layout.html.rlt +++ b/alcova_examples/templates/layout.html.rlt @@ -4,8 +4,8 @@ - Rust LiveView Demo - + Alcova Demo + diff --git a/example/templates/login.html.rlt b/alcova_examples/templates/login.html.rlt similarity index 100% rename from example/templates/login.html.rlt rename to alcova_examples/templates/login.html.rlt diff --git a/example/templates/timer.html.rlt b/alcova_examples/templates/timer.html.rlt similarity index 100% rename from example/templates/timer.html.rlt rename to alcova_examples/templates/timer.html.rlt diff --git a/example/templates/top.html.rlt b/alcova_examples/templates/top.html.rlt similarity index 100% rename from example/templates/top.html.rlt rename to alcova_examples/templates/top.html.rlt diff --git a/alcova_macros/Cargo.toml b/alcova_macros/Cargo.toml index 0a0fe93..581722f 100644 --- a/alcova_macros/Cargo.toml +++ b/alcova_macros/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "alcova_macros" version = "0.1.0" -authors = ["Connor Brewster "] +authors = ["Connor Brewster "] edition = "2018" [lib] @@ -11,6 +11,5 @@ proc-macro = true [dependencies] syn = {version = "1.0", features = [ "full" ] } quote = "1.0" -alcova = {path = "../alcova"} proc-macro-error = "1.0" proc-macro2 = "1.0" diff --git a/alcova/src/ast.rs b/alcova_macros/src/ast.rs similarity index 100% rename from alcova/src/ast.rs rename to alcova_macros/src/ast.rs diff --git a/alcova_macros/src/lib.rs b/alcova_macros/src/lib.rs index 330aac2..c8e897a 100644 --- a/alcova_macros/src/lib.rs +++ b/alcova_macros/src/lib.rs @@ -1,8 +1,10 @@ extern crate proc_macro; -use alcova::{ - parse_template, BinaryOperator, CodeExpression, Expression, Parser, Pattern, TypePath, -}; +mod ast; +mod parse; + +use ast::{BinaryOperator, CodeExpression, Expression, Pattern, Template, TypePath}; +use parse::{parse_template, Parser}; use proc_macro::TokenStream; use proc_macro_error::{abort, proc_macro_error}; use quote::quote; @@ -95,25 +97,25 @@ fn impl_live_template(ast: &syn::DeriveInput) -> TokenStream { #[automatically_derived] #[allow(unused_qualifications)] - impl liveview::LiveTemplate for #name { - fn render(&self) -> liveview::RenderedTemplate { + impl alcova::LiveTemplate for #name { + fn render(&self) -> alcova::RenderedTemplate { use std::convert::TryInto; - liveview::RenderedTemplate { + alcova::RenderedTemplate { slots: vec![ #slots ] } } - fn changes(&self, old_template: &Self) -> liveview::Changes { + fn changes(&self, old_template: &Self) -> alcova::Changes { use std::convert::TryInto; let mut changes = vec![]; #changes - liveview::Changes { changes } + alcova::Changes { changes } } } }; @@ -370,7 +372,7 @@ fn generate_match_arm( } } -fn generate_slots(template: &alcova::Template) -> Result { +fn generate_slots(template: &Template) -> Result { let mut tokens: Vec = vec![]; for expression in &template.expressions { @@ -378,7 +380,7 @@ fn generate_slots(template: &alcova::Template) -> Result { tokens.extend(quote! { - liveview::Slot::Static(#value), + alcova::Slot::Static(#value), }); } Expression::CodeBlock(_) @@ -387,7 +389,7 @@ fn generate_slots(template: &alcova::Template) -> Result { tokens.extend(quote! { - liveview::Slot::Dynamic(#value), + alcova::Slot::Dynamic(#value), }); } } @@ -396,7 +398,7 @@ fn generate_slots(template: &alcova::Template) -> Result Result { +fn generate_changes(template: &Template) -> Result { let mut tokens: Vec = vec![]; for (i, expression) in template.expressions.iter().enumerate() { diff --git a/alcova/src/parse.rs b/alcova_macros/src/parse.rs similarity index 100% rename from alcova/src/parse.rs rename to alcova_macros/src/parse.rs diff --git a/liveview/Cargo.toml b/liveview/Cargo.toml deleted file mode 100644 index d7493e7..0000000 --- a/liveview/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "liveview" -version = "0.1.0" -authors = ["Connor Brewster "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -actix = "0.9.0" -actix-web-actors = "2.0.0" -actix-web = "2.0.0" -futures = "0.3.5" -jsonwebtoken = "7" -log = "0.4.8" -serde = { version = "1.0", features = [ "derive" ] } -serde_json = "1.0" - diff --git a/liveview/src/lib.rs b/liveview/src/lib.rs deleted file mode 100644 index 0afa498..0000000 --- a/liveview/src/lib.rs +++ /dev/null @@ -1,12 +0,0 @@ -#[macro_use] -extern crate log; - -mod live_socket; -mod live_template; -mod live_view; -mod registry; - -pub use live_socket::{LiveSocket, LiveSocketContext}; -pub use live_template::{Changes, LiveTemplate, RenderedTemplate, Slot}; -pub use live_view::{LiveHandler, LiveMessage, LiveView, LiveViewContext}; -pub use registry::LiveViewRegistry; diff --git a/notes.md b/notes.md deleted file mode 100644 index 70b4137..0000000 --- a/notes.md +++ /dev/null @@ -1,37 +0,0 @@ -# LiveView Rust - -Template ideas: - -* Static parts -* Dynamic parts - -A template is a list of static and dynamic things: - -1. Static "Hello " -2. Dynamic "{{ name }}" -3. Static "!" - -But we also need to think about constructs like for loops. - -* All the things in the list are a single dynamic slot -* You elements with the id attribute and let the client fix things up - -Will go with former for now since its much simpler. - -We may also want to nest templates, but this is something for another time. - -## Templates - -I think I will hand roll my own template parser. - -In general, I like to use plain HTML for the HTML bits, but then there will be a limited syntax for outputting content. -The syntax should be similar to Rust and should be very easy to translate over. - -To start, we will just allow inserting data. We will use the EEX/Ruby type thing where @ means the variable comes from the "assigns". -This is an important thing to have so that we know how to change track from the root assigns. - -Very basic example: -``` -

    <%= @page_title %>

    -``` - diff --git a/static/index.html b/static/index.html index 05edf6c..d14eaeb 100644 --- a/static/index.html +++ b/static/index.html @@ -1,2 +1 @@ -

    Hello LiveView Rust

    - +

    Hello Alcova!

    \ No newline at end of file