Skip to content

Commit

Permalink
Add a table of contents to select documentation pages (sass#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
Israel-4Ever committed Nov 29, 2018
1 parent 0964c75 commit 04f0d79
Show file tree
Hide file tree
Showing 25 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,11 @@

set :relative_links, true
end

before_render do |body, _, _, template_class|
if current_page.data.table_of_contents &&
template_class == Middleman::Renderers::RedcarpetTemplate
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML_TOC.new)
markdown.render(body).sub(/<ul( |>)/, '<ul class="table-of-contents"\1') + body
end
end
7 changes: 7 additions & 0 deletions helpers/sass_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,13 @@ def fun_fact
], class: 'sl-c-callout sl-c-callout--fun-fact')
end

def table_of_contents(resource)
content = File.read(resource.source_file)
toc_renderer = Redcarpet::Render::HTML_TOC.new
markdown = Redcarpet::Markdown.new(toc_renderer)
markdown.render(content)
end

def markdown_wrap(content)
Tilt['markdown'].new { content }.render
end
Expand Down
1 change: 1 addition & 0 deletions source/documentation/at-rules/control/if.html.md.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "@if and @else"
table_of_contents: true
---

The `@if` rule is written `@if <expression> { ... }`, and it controls whether or
Expand Down
1 change: 1 addition & 0 deletions source/documentation/at-rules/css.html.md.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: CSS At-Rules
table_of_contents: true
---

<% impl_status dart: '1.15.0', libsass: false, ruby: false do %>
Expand Down
1 change: 1 addition & 0 deletions source/documentation/at-rules/extend.html.md.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "@extend"
table_of_contents: true
---

There are often cases when designing a page when one class should have all the
Expand Down
1 change: 1 addition & 0 deletions source/documentation/at-rules/function.html.md.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "@function"
table_of_contents: true
---

Functions allow you to define complex operations on [SassScript values][] that
Expand Down
1 change: 1 addition & 0 deletions source/documentation/at-rules/import.html.md.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "@import"
table_of_contents: true
---

Sass extends CSS's [`@import` rule][] with the ability to import Sass and CSS
Expand Down
1 change: 1 addition & 0 deletions source/documentation/at-rules/mixin.html.md.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "@mixin and @include"
table_of_contents: true
---

Mixins allow you to define styles that can be re-used throughout your
Expand Down
1 change: 1 addition & 0 deletions source/documentation/cli/dart-sass.html.md.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Dart Sass Command-Line Interface
table_of_contents: true
---

## Usage
Expand Down
1 change: 1 addition & 0 deletions source/documentation/cli/ruby-sass.html.md.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Ruby Sass Command-Line Interface
table_of_contents: true
---

<% heads_up do %>
Expand Down
1 change: 1 addition & 0 deletions source/documentation/interpolation.html.md.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Interpolation
table_of_contents: true
---

Interpolation can be used almost anywhere in a Sass stylesheet to embed the
Expand Down
1 change: 1 addition & 0 deletions source/documentation/js-api.html.md.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: JavaScript API
table_of_contents: true
---

Both major Sass implementations support the same JavaScript API. [Dart Sass][]
Expand Down
1 change: 1 addition & 0 deletions source/documentation/operators/numeric.html.md.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Numeric Operators
table_of_contents: true
---

Sass supports the standard set of mathematical operators for [numbers][]. They
Expand Down
1 change: 1 addition & 0 deletions source/documentation/style-rules.html.md.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Style Rules
table_of_contents: true
---

Style rules are the foundation of Sass, just like they are for CSS. And they
Expand Down
1 change: 1 addition & 0 deletions source/documentation/style-rules/declarations.html.md.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Property Declarations
table_of_contents: true
---

In Sass as in CSS, property declarations define how elements that match a
Expand Down
1 change: 1 addition & 0 deletions source/documentation/syntax/special-functions.html.md.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Special Functions
table_of_contents: true
---

CSS defines many functions, and most of them work just fine with Sass's normal
Expand Down
1 change: 1 addition & 0 deletions source/documentation/syntax/structure.html.md.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Structure of a Stylesheet
table_of_contents: true
---

Just like CSS, most Sass stylesheets are mainly made up of style rules that
Expand Down
1 change: 1 addition & 0 deletions source/documentation/values/lists.html.md.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Lists
table_of_contents: true
---

<% impl_status dart: true, libsass: '3.5.0', ruby: '3.5.0' do %>
Expand Down
1 change: 1 addition & 0 deletions source/documentation/values/maps.html.md.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Maps
table_of_contents: true
---

Maps in Sass hold pairs of keys and values, and make it easy to look up a value
Expand Down
1 change: 1 addition & 0 deletions source/documentation/values/strings.html.md.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Strings
table_of_contents: true
---

Strings are sequences of characters (specifically [Unicode code points][]). Sass
Expand Down
1 change: 1 addition & 0 deletions source/documentation/variables.html.md.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Variables
table_of_contents: true
---

Sass variables are simple: you assign a value to a name that begins with `$`,
Expand Down

0 comments on commit 04f0d79

Please sign in to comment.