mirror of
https://github.com/yewprint/yewprint
synced 2025-02-16 12:08:25 +00:00
Add link to the source code of each component (#117)
This commit is contained in:
parent
ec208f13e6
commit
e50b3467f7
33 changed files with 224 additions and 8 deletions
68
Cargo.lock
generated
68
Cargo.lock
generated
|
@ -1,5 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "addr2line"
|
||||
version = "0.14.1"
|
||||
|
@ -464,6 +466,17 @@ version = "2.4.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cfa8873f51c92e232f9bac4065cddef41b714152812bfc5f7672ba16d6ef8cd9"
|
||||
|
||||
[[package]]
|
||||
name = "build-data"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a94f9f7aab679acac7ce29ba5581c00d3971a861c3b501c5bb74c3ba0026d90"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"safe-lock",
|
||||
"safe-regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.6.1"
|
||||
|
@ -2302,6 +2315,59 @@ version = "1.0.5"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
|
||||
|
||||
[[package]]
|
||||
name = "safe-lock"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "077d73db7973cccf63eb4aff1e5a34dc2459baa867512088269ea5f2f4253c90"
|
||||
|
||||
[[package]]
|
||||
name = "safe-proc-macro2"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c9ca0693867c373d726819a6655d3dc4e88028905f1b1e9b9d399a57ea1d83e"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "safe-quote"
|
||||
version = "1.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "566c55c34afcf23f8ae1170373f925201163ed0a9fd315274f35eab6d660b56d"
|
||||
dependencies = [
|
||||
"safe-proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "safe-regex"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "954950893b0d83c719cb5325bf3941bae7b1c6590d923c70f78bdfed101179b5"
|
||||
dependencies = [
|
||||
"safe-regex-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "safe-regex-compiler"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77be88a67af0852122737d6944cf6cf3b493051ac063b074d11d6dc3aaa57047"
|
||||
dependencies = [
|
||||
"safe-proc-macro2",
|
||||
"safe-quote",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "safe-regex-macro"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f9276d04505a852d89fab9b9d5d72b47e84c726b121f4b8b212b44fba990485d"
|
||||
dependencies = [
|
||||
"safe-proc-macro2",
|
||||
"safe-regex-compiler",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "safemem"
|
||||
version = "0.3.3"
|
||||
|
@ -3556,7 +3622,9 @@ dependencies = [
|
|||
name = "yewprint-doc"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"build-data",
|
||||
"console_error_panic_hook",
|
||||
"reqwest",
|
||||
"syntect",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
|
|
|
@ -31,3 +31,7 @@ console_error_panic_hook = { version = "0.1.6", optional = true }
|
|||
|
||||
[build-dependencies]
|
||||
syntect = "4.4.0"
|
||||
build-data = "0.1.3"
|
||||
|
||||
[dev-dependencies]
|
||||
reqwest = { version = "0.11", features = ["blocking"] }
|
||||
|
|
|
@ -10,6 +10,8 @@ fn main() {
|
|||
let theme_set = ThemeSet::load_defaults();
|
||||
let out_dir = env::var_os("OUT_DIR").unwrap();
|
||||
|
||||
build_data::set_GIT_BRANCH();
|
||||
|
||||
fn recursive<P: AsRef<Path>>(
|
||||
base_path: P,
|
||||
syntax_set: &SyntaxSet,
|
||||
|
|
|
@ -10,7 +10,7 @@ use crate::icon::*;
|
|||
use crate::input_group::*;
|
||||
use crate::menu::*;
|
||||
use crate::panel_stack::*;
|
||||
use crate::progressbar::*;
|
||||
use crate::progress_bar::*;
|
||||
use crate::radio::*;
|
||||
use crate::slider::*;
|
||||
use crate::spinner::*;
|
||||
|
@ -18,7 +18,7 @@ use crate::switch::*;
|
|||
use crate::tabs::*;
|
||||
use crate::tag::*;
|
||||
use crate::text::*;
|
||||
use crate::textarea::*;
|
||||
use crate::text_area::*;
|
||||
use crate::tree::*;
|
||||
use std::borrow::Cow;
|
||||
use yew::prelude::*;
|
||||
|
|
|
@ -45,6 +45,7 @@ impl Component for ButtonGroupDoc {
|
|||
html! {
|
||||
<div>
|
||||
<H1 class=classes!("docs-title")>{"Button Group"}</H1>
|
||||
<SourceCodeUrl />
|
||||
<ExampleContainer
|
||||
source=source
|
||||
props=Some(html! {
|
||||
|
@ -104,3 +105,5 @@ crate::build_example_prop_component! {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
crate::build_source_code_component!();
|
||||
|
|
|
@ -49,6 +49,7 @@ impl Component for ButtonDoc {
|
|||
html! {
|
||||
<div>
|
||||
<H1 class=classes!("docs-title")>{"Button"}</H1>
|
||||
<SourceCodeUrl />
|
||||
<div>
|
||||
<ExampleContainer
|
||||
source=source
|
||||
|
@ -141,3 +142,5 @@ crate::build_example_prop_component! {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
crate::build_source_code_component!();
|
||||
|
|
|
@ -44,6 +44,7 @@ impl Component for CalloutDoc {
|
|||
html! {
|
||||
<div>
|
||||
<H1 class=classes!("docs-title")>{"Callout"}</H1>
|
||||
<SourceCodeUrl />
|
||||
<ExampleContainer
|
||||
source=source
|
||||
props=Some(html! {
|
||||
|
@ -102,3 +103,5 @@ crate::build_example_prop_component! {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
crate::build_source_code_component!();
|
||||
|
|
|
@ -43,6 +43,7 @@ impl Component for CardDoc {
|
|||
html! {
|
||||
<div>
|
||||
<H1 class=classes!("docs-title")>{"Card"}</H1>
|
||||
<SourceCodeUrl />
|
||||
<ExampleContainer
|
||||
source=source
|
||||
props=Some(html! {
|
||||
|
@ -94,3 +95,5 @@ crate::build_example_prop_component! {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
crate::build_source_code_component!();
|
||||
|
|
|
@ -32,6 +32,7 @@ impl Component for CollapseDoc {
|
|||
html! {
|
||||
<div>
|
||||
<H1 class=classes!("docs-title")>{"Collapse"}</H1>
|
||||
<SourceCodeUrl />
|
||||
<ExampleContainer source=source>
|
||||
<Example />
|
||||
</ExampleContainer>
|
||||
|
@ -39,3 +40,5 @@ impl Component for CollapseDoc {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
crate::build_source_code_component!();
|
||||
|
|
|
@ -43,6 +43,7 @@ impl Component for ControlGroupDoc {
|
|||
html! {
|
||||
<div>
|
||||
<H1 class=classes!("docs-title")>{"ControlGroup"}</H1>
|
||||
<SourceCodeUrl />
|
||||
<ExampleContainer
|
||||
source=source
|
||||
props=Some(html! {
|
||||
|
@ -86,3 +87,5 @@ crate::build_example_prop_component! {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
crate::build_source_code_component!();
|
||||
|
|
|
@ -40,6 +40,7 @@ impl Component for DividerDoc {
|
|||
html! {
|
||||
<div>
|
||||
<H1 class=classes!("docs-title")>{"Divider"}</H1>
|
||||
<SourceCodeUrl />
|
||||
<ExampleContainer
|
||||
source=source
|
||||
props=Some(html! {
|
||||
|
@ -73,3 +74,5 @@ crate::build_example_prop_component! {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
crate::build_source_code_component!();
|
||||
|
|
|
@ -45,6 +45,7 @@ impl Component for HtmlSelectDoc {
|
|||
html! {
|
||||
<div>
|
||||
<H1 class=classes!("docs-title")>{"HtmlSelect"}</H1>
|
||||
<SourceCodeUrl />
|
||||
<div>
|
||||
<ExampleContainer
|
||||
source=source
|
||||
|
@ -105,3 +106,5 @@ crate::build_example_prop_component! {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
crate::build_source_code_component!();
|
||||
|
|
|
@ -32,6 +32,7 @@ impl Component for IconDoc {
|
|||
html! {
|
||||
<div>
|
||||
<H1 class=classes!("docs-title")>{"Icon"}</H1>
|
||||
<SourceCodeUrl />
|
||||
<ExampleContainer source=source>
|
||||
<Example />
|
||||
</ExampleContainer>
|
||||
|
@ -39,3 +40,5 @@ impl Component for IconDoc {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
crate::build_source_code_component!();
|
||||
|
|
|
@ -46,6 +46,7 @@ impl Component for InputGroupDoc {
|
|||
html! {
|
||||
<div>
|
||||
<H1 class=classes!("docs-title")>{"InputGroup"}</H1>
|
||||
<SourceCodeUrl />
|
||||
<ExampleContainer
|
||||
source=source
|
||||
props=Some(html! {
|
||||
|
@ -113,3 +114,5 @@ crate::build_example_prop_component! {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
crate::build_source_code_component!();
|
||||
|
|
|
@ -15,7 +15,7 @@ mod input_group;
|
|||
mod logo;
|
||||
mod menu;
|
||||
mod panel_stack;
|
||||
mod progressbar;
|
||||
mod progress_bar;
|
||||
mod radio;
|
||||
mod slider;
|
||||
mod spinner;
|
||||
|
@ -23,7 +23,7 @@ mod switch;
|
|||
mod tabs;
|
||||
mod tag;
|
||||
mod text;
|
||||
mod textarea;
|
||||
mod text_area;
|
||||
mod tree;
|
||||
|
||||
pub use app::*;
|
||||
|
@ -54,6 +54,82 @@ macro_rules! include_raw_html {
|
|||
}};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! build_source_code_component {
|
||||
() => {
|
||||
pub struct SourceCodeUrl {
|
||||
url: String,
|
||||
}
|
||||
|
||||
impl SourceCodeUrl {
|
||||
pub fn generate_url() -> String {
|
||||
use std::path::Path;
|
||||
|
||||
let branch = env!("GIT_BRANCH");
|
||||
let component_name = Path::new(file!())
|
||||
.parent()
|
||||
.unwrap()
|
||||
.file_name()
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap();
|
||||
|
||||
format!(
|
||||
"https://github.com/yewprint/yewprint/blob/{}\
|
||||
/yewprint/src/{}.rs",
|
||||
branch, component_name,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Component for SourceCodeUrl {
|
||||
type Message = ();
|
||||
type Properties = ();
|
||||
|
||||
fn create(_: Self::Properties, _link: ComponentLink<Self>) -> Self {
|
||||
let url = SourceCodeUrl::generate_url();
|
||||
|
||||
Self { url }
|
||||
}
|
||||
|
||||
fn update(&mut self, _msg: Self::Message) -> ShouldRender {
|
||||
true
|
||||
}
|
||||
|
||||
fn change(&mut self, _props: Self::Properties) -> ShouldRender {
|
||||
true
|
||||
}
|
||||
|
||||
fn view(&self) -> Html {
|
||||
use yewprint::Text;
|
||||
|
||||
html! {
|
||||
<a
|
||||
class=classes!("bp3-text-muted")
|
||||
href=self.url.clone()
|
||||
target="_blank"
|
||||
>
|
||||
<Text>{"Go to source code"}</Text>
|
||||
</a>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod source_tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn check_url() {
|
||||
let url = SourceCodeUrl::generate_url();
|
||||
let response = reqwest::blocking::get(url).unwrap();
|
||||
|
||||
assert!(response.status().is_success())
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
|
||||
// allocator.
|
||||
#[cfg(feature = "wee_alloc")]
|
||||
|
|
|
@ -32,6 +32,7 @@ impl Component for MenuDoc {
|
|||
html! {
|
||||
<div>
|
||||
<H1 class=classes!("docs-title")>{"Menu"}</H1>
|
||||
<SourceCodeUrl />
|
||||
<ExampleContainer source=source>
|
||||
<Example />
|
||||
</ExampleContainer>
|
||||
|
@ -39,3 +40,5 @@ impl Component for MenuDoc {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
crate::build_source_code_component!();
|
||||
|
|
|
@ -43,6 +43,7 @@ impl Component for PanelStackDoc {
|
|||
html! {
|
||||
<div>
|
||||
<H1 class=classes!("docs-title")>{"PanelStack"}</H1>
|
||||
<SourceCodeUrl />
|
||||
<div>
|
||||
<ExampleContainer
|
||||
source=source
|
||||
|
@ -55,3 +56,5 @@ impl Component for PanelStackDoc {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
crate::build_source_code_component!();
|
||||
|
|
|
@ -44,6 +44,7 @@ impl Component for ProgressBarDoc {
|
|||
html! {
|
||||
<div>
|
||||
<H1 class=classes!("docs-title")>{"ProgressBar"}</H1>
|
||||
<SourceCodeUrl />
|
||||
<ExampleContainer
|
||||
source=source
|
||||
props=Some(html! {
|
||||
|
@ -102,3 +103,5 @@ crate::build_example_prop_component! {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
crate::build_source_code_component!();
|
|
@ -44,6 +44,7 @@ impl Component for RadioDoc {
|
|||
html! {
|
||||
<div>
|
||||
<H1 class=classes!("docs-title")>{"Radio"}</H1>
|
||||
<SourceCodeUrl />
|
||||
<ExampleContainer
|
||||
source=source
|
||||
props=Some(html! {
|
||||
|
@ -94,3 +95,5 @@ crate::build_example_prop_component! {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
crate::build_source_code_component!();
|
||||
|
|
|
@ -43,6 +43,7 @@ impl Component for SliderDoc {
|
|||
html! {
|
||||
<div>
|
||||
<H1 class=classes!("docs-title")>{"Slider"}</H1>
|
||||
<SourceCodeUrl />
|
||||
<ExampleContainer
|
||||
source=source
|
||||
props=Some(html! {
|
||||
|
@ -138,3 +139,5 @@ crate::build_example_prop_component! {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
crate::build_source_code_component!();
|
||||
|
|
|
@ -43,6 +43,7 @@ impl Component for SpinnerDoc {
|
|||
html! {
|
||||
<div>
|
||||
<H1 class=classes!("docs-title")>{"Spinner"}</H1>
|
||||
<SourceCodeUrl />
|
||||
<div>
|
||||
<ExampleContainer
|
||||
source=source
|
||||
|
@ -111,3 +112,5 @@ crate::build_example_prop_component! {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
crate::build_source_code_component!();
|
||||
|
|
|
@ -44,6 +44,7 @@ impl Component for SwitchDoc {
|
|||
html! {
|
||||
<div>
|
||||
<H1 class=classes!("docs-title")>{"Switch"}</H1>
|
||||
<SourceCodeUrl />
|
||||
<ExampleContainer
|
||||
source=source
|
||||
props=Some(html! {
|
||||
|
@ -95,3 +96,5 @@ crate::build_example_prop_component! {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
crate::build_source_code_component!();
|
||||
|
|
|
@ -43,6 +43,7 @@ impl Component for TabsDoc {
|
|||
html! {
|
||||
<div>
|
||||
<H1 class=classes!("docs-title")>{"Tabs"}</H1>
|
||||
<SourceCodeUrl />
|
||||
<div>
|
||||
<ExampleContainer
|
||||
source=source
|
||||
|
@ -87,3 +88,5 @@ crate::build_example_prop_component! {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
crate::build_source_code_component!();
|
||||
|
|
|
@ -68,6 +68,7 @@ impl Component for TagDoc {
|
|||
html! {
|
||||
<div>
|
||||
<H1 class=classes!("docs-title")>{"Tag"}</H1>
|
||||
<SourceCodeUrl />
|
||||
<ExampleContainer
|
||||
source=source
|
||||
props=Some(html!{
|
||||
|
@ -203,3 +204,5 @@ crate::build_example_prop_component! {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
crate::build_source_code_component!();
|
||||
|
|
|
@ -43,6 +43,7 @@ impl Component for TextDoc {
|
|||
html! {
|
||||
<div>
|
||||
<H1 class=classes!("docs-title")>{"Text"}</H1>
|
||||
<SourceCodeUrl />
|
||||
<div>
|
||||
<ExampleContainer
|
||||
source=source
|
||||
|
@ -99,3 +100,5 @@ crate::build_example_prop_component! {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
crate::build_source_code_component!();
|
||||
|
|
|
@ -45,6 +45,7 @@ impl Component for TextAreaDoc {
|
|||
html! {
|
||||
<div>
|
||||
<H1 class=classes!("docs-title")>{"Text"}</H1>
|
||||
<SourceCodeUrl />
|
||||
<div>
|
||||
<ExampleContainer
|
||||
source=source
|
||||
|
@ -110,3 +111,5 @@ crate::build_example_prop_component! {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
crate::build_source_code_component!();
|
|
@ -32,6 +32,7 @@ impl Component for TreeDoc {
|
|||
html! {
|
||||
<div>
|
||||
<H1 class=classes!("docs-title")>{"Tree"}</H1>
|
||||
<SourceCodeUrl />
|
||||
<ExampleContainer source=source>
|
||||
<Example />
|
||||
</ExampleContainer>
|
||||
|
@ -39,3 +40,5 @@ impl Component for TreeDoc {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
crate::build_source_code_component!();
|
||||
|
|
|
@ -18,7 +18,7 @@ mod icon;
|
|||
mod input_group;
|
||||
mod menu;
|
||||
mod panel_stack;
|
||||
mod progressbar;
|
||||
mod progress_bar;
|
||||
mod radio;
|
||||
mod radio_group;
|
||||
mod slider;
|
||||
|
@ -27,7 +27,7 @@ mod switch;
|
|||
mod tabs;
|
||||
mod tag;
|
||||
mod text;
|
||||
mod textarea;
|
||||
mod text_area;
|
||||
#[cfg(feature = "tree")]
|
||||
mod tree;
|
||||
|
||||
|
@ -46,7 +46,7 @@ pub use id_tree;
|
|||
pub use input_group::*;
|
||||
pub use menu::*;
|
||||
pub use panel_stack::*;
|
||||
pub use progressbar::*;
|
||||
pub use progress_bar::*;
|
||||
pub use radio::*;
|
||||
pub use radio_group::*;
|
||||
pub use slider::*;
|
||||
|
@ -55,7 +55,7 @@ pub use switch::*;
|
|||
pub use tabs::*;
|
||||
pub use tag::*;
|
||||
pub use text::*;
|
||||
pub use textarea::*;
|
||||
pub use text_area::*;
|
||||
#[cfg(feature = "tree")]
|
||||
pub use tree::*;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue