-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert / to boilerplate template (#317)
- Loading branch information
Showing
8 changed files
with
196 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,58 @@ | ||
use {super::*, boilerplate::Display}; | ||
|
||
pub(crate) mod ordinal; | ||
pub(crate) mod root; | ||
|
||
#[derive(Display)] | ||
pub(crate) struct OrdinalHtml { | ||
pub(crate) ordinal: Ordinal, | ||
pub(crate) blocktime: Blocktime, | ||
pub(crate) struct PageHtml { | ||
content: Box<dyn Content>, | ||
} | ||
|
||
pub(crate) trait Content: Display { | ||
fn title(&self) -> String; | ||
|
||
fn page(self) -> PageHtml; | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use {super::*, pretty_assertions::assert_eq, unindent::Unindent}; | ||
use super::*; | ||
|
||
#[test] | ||
fn ordinal_html() { | ||
assert_eq!( | ||
OrdinalHtml { | ||
ordinal: Ordinal(0), | ||
blocktime: Blocktime::Confirmed(0), | ||
fn page() { | ||
struct Foo; | ||
|
||
impl Display for Foo { | ||
fn fmt(&self, f: &mut Formatter) -> fmt::Result { | ||
write!(f, "<h1>Foo</h1>") | ||
} | ||
.to_string(), | ||
" | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset=utf-8> | ||
<title>0°0′0″0‴</title> | ||
</head> | ||
<body> | ||
<dl><dt>number</dt><dd>0</dd></dl> | ||
<dl><dt>decimal</dt><dd>0.0</dd></dl> | ||
<dl><dt>degree</dt><dd>0°0′0″0‴</dd></dl> | ||
<dl><dt>name</dt><dd>nvtdijuwxlp</dd></dl> | ||
<dl><dt>height</dt><dd>0</dd></dl> | ||
<dl><dt>cycle</dt><dd>0</dd></dl> | ||
<dl><dt>epoch</dt><dd>0</dd></dl> | ||
<dl><dt>period</dt><dd>0</dd></dl> | ||
<dl><dt>offset</dt><dd>0</dd></dl> | ||
<dl><dt>rarity</dt><dd>mythic</dd></dl> | ||
<dl><dt>block time</dt><dd>1970-01-01 00:00:00</dd></dl> | ||
</body> | ||
</html> | ||
" | ||
.unindent() | ||
} | ||
|
||
impl Content for Foo { | ||
fn title(&self) -> String { | ||
"Foo".to_string() | ||
} | ||
|
||
fn page(self) -> PageHtml { | ||
PageHtml { | ||
content: Box::new(self), | ||
} | ||
} | ||
} | ||
|
||
assert_eq!( | ||
Foo.page().to_string(), | ||
"<!doctype html> | ||
<html lang=en> | ||
<head> | ||
<meta charset=utf-8> | ||
<title>Foo</title> | ||
</head> | ||
<body> | ||
<h1>Foo</h1> | ||
</body> | ||
</html> | ||
" | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use super::*; | ||
|
||
#[derive(Display)] | ||
pub(crate) struct OrdinalHtml { | ||
pub(crate) ordinal: Ordinal, | ||
pub(crate) blocktime: Blocktime, | ||
} | ||
|
||
impl Content for OrdinalHtml { | ||
fn title(&self) -> String { | ||
self.ordinal.degree().to_string() | ||
} | ||
|
||
fn page(self) -> PageHtml { | ||
PageHtml { | ||
content: Box::new(self), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use {super::*, pretty_assertions::assert_eq, unindent::Unindent}; | ||
|
||
#[test] | ||
fn ordinal_html() { | ||
assert_eq!( | ||
OrdinalHtml { | ||
ordinal: Ordinal(0), | ||
blocktime: Blocktime::Confirmed(0), | ||
} | ||
.to_string(), | ||
" | ||
<h1>Ordinal 0</h1> | ||
<dl> | ||
<dt>decimal</dt><dd>0.0</dd> | ||
<dt>degree</dt><dd>0°0′0″0‴</dd> | ||
<dt>name</dt><dd>nvtdijuwxlp</dd> | ||
<dt>height</dt><dd>0</dd> | ||
<dt>cycle</dt><dd>0</dd> | ||
<dt>epoch</dt><dd>0</dd> | ||
<dt>period</dt><dd>0</dd> | ||
<dt>offset</dt><dd>0</dd> | ||
<dt>rarity</dt><dd>mythic</dd> | ||
<dt>block time</dt><dd>1970-01-01 00:00:00</dd> | ||
</dl> | ||
" | ||
.unindent() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use super::*; | ||
|
||
#[derive(Display)] | ||
pub(crate) struct RootHtml { | ||
pub(crate) blocks: Vec<(u64, BlockHash)>, | ||
} | ||
|
||
impl Content for RootHtml { | ||
fn title(&self) -> String { | ||
"Ordinal Block Explorer".to_string() | ||
} | ||
|
||
fn page(self) -> PageHtml { | ||
PageHtml { | ||
content: Box::new(self), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use {super::*, pretty_assertions::assert_eq, unindent::Unindent}; | ||
|
||
#[test] | ||
fn root_html() { | ||
assert_eq!( | ||
RootHtml { | ||
blocks: vec![ | ||
( | ||
1, | ||
"1111111111111111111111111111111111111111111111111111111111111111".parse().unwrap() | ||
), | ||
( | ||
0, | ||
"0000000000000000000000000000000000000000000000000000000000000000".parse().unwrap() | ||
) | ||
], | ||
} | ||
.to_string(), | ||
" | ||
<h1>Recent Blocks</h1> | ||
<ul> | ||
<li>1 - <a href=/block/1111111111111111111111111111111111111111111111111111111111111111>1111111111111111111111111111111111111111111111111111111111111111</a></li> | ||
<li>0 - <a href=/block/0000000000000000000000000000000000000000000000000000000000000000>0000000000000000000000000000000000000000000000000000000000000000</a></li> | ||
</ul> | ||
" | ||
.unindent() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,13 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset=utf-8> | ||
<title>{{ self.ordinal.degree() }}</title> | ||
</head> | ||
<body> | ||
<dl><dt>number</dt><dd>{{ self.ordinal.n() }}</dd></dl> | ||
<dl><dt>decimal</dt><dd>{{ self.ordinal.decimal() }}</dd></dl> | ||
<dl><dt>degree</dt><dd>{{ self.ordinal.degree() }}</dd></dl> | ||
<dl><dt>name</dt><dd>{{ self.ordinal.name() }}</dd></dl> | ||
<dl><dt>height</dt><dd>{{ self.ordinal.height() }}</dd></dl> | ||
<dl><dt>cycle</dt><dd>{{ self.ordinal.cycle() }}</dd></dl> | ||
<dl><dt>epoch</dt><dd>{{ self.ordinal.epoch() }}</dd></dl> | ||
<dl><dt>period</dt><dd>{{ self.ordinal.period() }}</dd></dl> | ||
<dl><dt>offset</dt><dd>{{ self.ordinal.third() }}</dd></dl> | ||
<dl><dt>rarity</dt><dd>{{ self.ordinal.rarity() }}</dd></dl> | ||
<dl><dt>block time</dt><dd>{{ self.blocktime }}</dd></dl> | ||
</body> | ||
</html> | ||
<h1>Ordinal {{ self.ordinal.n() }}</h1> | ||
<dl> | ||
<dt>decimal</dt><dd>{{ self.ordinal.decimal() }}</dd> | ||
<dt>degree</dt><dd>{{ self.ordinal.degree() }}</dd> | ||
<dt>name</dt><dd>{{ self.ordinal.name() }}</dd> | ||
<dt>height</dt><dd>{{ self.ordinal.height() }}</dd> | ||
<dt>cycle</dt><dd>{{ self.ordinal.cycle() }}</dd> | ||
<dt>epoch</dt><dd>{{ self.ordinal.epoch() }}</dd> | ||
<dt>period</dt><dd>{{ self.ordinal.period() }}</dd> | ||
<dt>offset</dt><dd>{{ self.ordinal.third() }}</dd> | ||
<dt>rarity</dt><dd>{{ self.ordinal.rarity() }}</dd> | ||
<dt>block time</dt><dd>{{ self.blocktime }}</dd> | ||
</dl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!doctype html> | ||
<html lang=en> | ||
<head> | ||
<meta charset=utf-8> | ||
<title>{{ self.content.title() }}</title> | ||
</head> | ||
<body> | ||
$$ self.content | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h1>Recent Blocks</h1> | ||
<ul> | ||
%% for block in &self.blocks { | ||
<li>{{block.0}} - <a href=/block/{{block.1}}>{{block.1}}</a></li> | ||
%% } | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters