Skip to content

Don't allow getting component parts of templates #636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ struct UsersContext {
data: Vec<Vec<User>>,
}

static LAYOUT: &str = "components/layout";

fn get_title(page_name: &str) -> String {
let mut v: Vec<char> = page_name.replace("-", " ").chars().collect();
v[0] = v[0].to_uppercase().nth(0).unwrap();
Expand All @@ -86,14 +88,19 @@ fn index() -> Template {
let context = Context {
page: page.clone(),
title,
parent: "layout".to_string(),
parent: LAYOUT.to_string(),
is_landing: true,
rust_version: rust_version::rust_version()
.map_or(String::new(), |v| format!("Version {}", v)),
};
Template::render(page, &context)
}

#[get("/components/<_file..>", rank = 1)]
fn components(_file: PathBuf) -> Template {
not_found()
}

#[get("/logos/<file..>", rank = 1)]
fn logos(file: PathBuf) -> Option<NamedFile> {
NamedFile::open(Path::new("static/logos").join(file)).ok()
Expand All @@ -111,7 +118,7 @@ fn category(category: Category) -> Template {
let context = Context {
page: category.name().to_string(),
title,
parent: "layout".to_string(),
parent: LAYOUT.to_string(),
is_landing: false,
};
Template::render(page, &context)
Expand All @@ -124,7 +131,7 @@ fn governance() -> Template {
let context = GroupContext {
page: page.clone(),
title,
parent: "layout".to_string(),
parent: LAYOUT.to_string(),
is_landing: false,
data: load_governance_data(),
};
Expand Down Expand Up @@ -152,7 +159,7 @@ fn team(t: String, subject: String) -> Template {
let context = GroupContext {
page: page.clone(),
title,
parent: "layout".to_string(),
parent: LAYOUT.to_string(),
is_landing: false,
data: load_group_data(t, &subject),
};
Expand Down Expand Up @@ -195,7 +202,7 @@ fn production() -> Template {
let context = UsersContext {
page: page.clone(),
title,
parent: "layout".to_string(),
parent: LAYOUT.to_string(),
is_landing: false,
data: load_users_data(),
};
Expand All @@ -216,7 +223,7 @@ fn subject(category: Category, subject: String) -> Template {
let context = Context {
page: subject,
title,
parent: "layout".to_string(),
parent: LAYOUT.to_string(),
is_landing: false,
};
Template::render(page, &context)
Expand Down Expand Up @@ -245,7 +252,7 @@ fn not_found() -> Template {
let context = Context {
page: "404".to_string(),
title,
parent: "layout".to_string(),
parent: LAYOUT.to_string(),
is_landing: false,
};
Template::render(page, &context)
Expand Down Expand Up @@ -296,6 +303,7 @@ fn main() {
subject,
files,
logos,
components,
redirect,
redirect_en_us,
redirect_locale
Expand Down
2 changes: 1 addition & 1 deletion templates/footer.hbs → templates/components/footer.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<li><a href="http://ping.rust-lang.org">Check Website Status</a></li>
</ul>
<div class="languages">
{{> languages-dropdown }}
{{> components/languages-dropdown }}
</div>
</div>
<div class="four columns mt3 mt0-l">
Expand Down
4 changes: 2 additions & 2 deletions templates/layout.hbs → templates/components/layout.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@
<meta name="theme-color" content="#ffffff">
</head>
<body>
{{> nav}}
{{> components/nav}}
<div id="main-content">
{{~> page}}
</div>
{{> footer}}
{{> components/footer}}
</body>
</html>
2 changes: 1 addition & 1 deletion templates/nav.hbs → templates/components/nav.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</ul>

<div class=" w-100 w-auto-l flex-none flex justify-center pv4 pv-0-l languages">
{{> languages-dropdown}}
{{> components/languages-dropdown}}
</div>

</nav>
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
<div class="row">
<article class="six columns box">
<h3>Define your inputs</h3>
<pre><code>{{> what/cli/code-inputs }}</code></pre>
<pre><code>{{> components/what/cli/code-inputs }}</code></pre>
</article>

<article class="six columns box">
<h3>Write your tool</h3>
<pre><code>{{> what/cli/code-main }}</code></pre>
<pre><code>{{> components/what/cli/code-main }}</code></pre>
</article>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
<div class="row">
<article class="six columns box">
<h3>POST some JSON</h3>
<pre><code>{{> what/networking/post-json }}</code></pre>
<pre><code>{{> components/what/networking/post-json }}</code></pre>

<a href="https://docs.rs/reqwest/" class="button button-secondary">Learn more about reqwest</a>
</article>

<article class="six columns box">
<h3>Handle a JSON POST</h3>
<pre><code>{{> what/networking/take-json }}</code></pre>
<pre><code>{{> components/what/networking/take-json }}</code></pre>

<a href="https://rocket.rs/" class="button button-secondary">Learn more about Rocket</a>
</article>
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions templates/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
</div>
</header>

{{> edition-banner }}
{{> panels/language-values }}
{{> panels/domains }}
{{> panels/production }}
{{> panels/get-involved }}
{{> components/edition-banner }}
{{> components/panels/language-values }}
{{> components/panels/domains }}
{{> components/panels/production }}
{{> components/panels/get-involved }}

{{/inline}}
{{~> (parent)~}}
6 changes: 3 additions & 3 deletions templates/learn/get-started.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<h3>Rustup: the Rust installer and version management tool</h3>
<p>The primary way that folks install Rust is through a tool called Rustup, which is a Rust installer
and version management tool.</p>
{{> tools/rustup }}
{{> components/tools/rustup }}
<br /><br />
<a href="/tools/install" class="button button-secondary">Learn more about installation</a>
<hr />
Expand All @@ -43,7 +43,7 @@

<h3>Other tools</h3>
<p>Rust support is available in many editors:</p>
{{> tools/editors }}
{{> components/tools/editors }}
<br />
<p>You can install a code formatting tool (Rustfmt) with <code>rustup component add rustfmt</code>,
and a linting tool (Clippy) with <code>rustup component add clippy</code>.</p>
Expand Down Expand Up @@ -177,6 +177,6 @@ fn main() {
<img alt="a gif of ferris scurrying side to side" src=/static/images/ferris.gif />
</div>
</section>
{{> tools/install-script }}
{{> components/tools/install-script }}
{{/inline}}
{{~> (parent)~}}
2 changes: 1 addition & 1 deletion templates/tools/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<a href="https://github.com/rust-lang-nursery/rls" target="_blank" rel="noopener">Rust Language Server</a>.
</div>
</div>
{{> tools/editors }}
{{> components/tools/editors }}
</div>
</section>

Expand Down
4 changes: 2 additions & 2 deletions templates/tools/install.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<h2>Using rustup (Recommended)</h2>
<div class="highlight"></div>
</header>
{{> tools/rustup }}
{{> components/tools/rustup }}
</div>
</section>

Expand Down Expand Up @@ -117,7 +117,7 @@
<a href="https://forge.rust-lang.org/other-installation-methods.html" target="_blank" rel="noopener" class="button button-secondary">Learn more</a>
</div>
</section>
{{> tools/install-script }}
{{> components/tools/install-script }}

{{/inline}}
{{~> (parent)~}}
8 changes: 4 additions & 4 deletions templates/what/cli.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</div>
</header>

{{> what/cli/pitch }}
{{> what/cli/maintainable }}
{{> what/cli/example }}
{{> what/cli/production }}
{{> components/what/cli/pitch }}
{{> components/what/cli/maintainable }}
{{> components/what/cli/example }}
{{> components/what/cli/production }}

{{/inline}} {{~> (parent)~}}
8 changes: 4 additions & 4 deletions templates/what/embedded.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
</div>
</header>

{{> what/embedded/pitch }}
{{> what/embedded/showcase }}
{{> what/embedded/get-started }}
{{> what/embedded/testimonials }}
{{> components/what/embedded/pitch }}
{{> components/what/embedded/showcase }}
{{> components/what/embedded/get-started }}
{{> components/what/embedded/testimonials }}

{{/inline}}
{{~> (parent)~}}
2 changes: 1 addition & 1 deletion templates/what/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</div>
</header>

{{> panels/domains }}
{{> components/panels/domains }}

{{/inline}}
{{~> (parent)~}}
6 changes: 3 additions & 3 deletions templates/what/networking.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</div>
</header>

{{> what/networking/pitch }}
{{> what/networking/get-started }}
{{> what/networking/production }}
{{> components/what/networking/pitch }}
{{> components/what/networking/get-started }}
{{> components/what/networking/production }}

{{/inline}}
{{~> (parent)~}}
8 changes: 4 additions & 4 deletions templates/what/wasm.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
</div>
</header>

{{> what/wasm/pitch }}
{{> what/wasm/get-started }}
{{> what/wasm/js }}
{{> what/wasm/production }}
{{> components/what/wasm/pitch }}
{{> components/what/wasm/get-started }}
{{> components/what/wasm/js }}
{{> components/what/wasm/production }}

{{/inline}}
{{~> (parent)~}}