Skip to content

Switch from Stylus to CSS #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

Closed
wants to merge 7 commits into from
Closed
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
24 changes: 0 additions & 24 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,6 @@ mdBook builds on stable Rust, if you want to build mdBook from source, here are

The resulting binary can be found in `mdBook/target/debug/` under the name `mdBook` or `mdBook.exe`.


### Making changes to the style

mdBook doesn't use CSS directly but uses [Stylus](http://stylus-lang.com/), a CSS-preprocessor which compiles to CSS.

When you want to change the style, it is important to not change the CSS directly because any manual modification to
the CSS files will be overwritten when compiling the stylus files. Instead, you should make your changes directly in the
[stylus files](https://github.com/rust-lang-nursery/mdBook/tree/master/src/theme/stylus) and regenerate the CSS.

For this to work, you first need [Node and NPM](https://nodejs.org/en/) installed on your machine.
Then run the following command to install both [stylus](http://stylus-lang.com/) and [nib](https://tj.github.io/nib/), you might need `sudo` to install successfully.

```
npm install -g stylus nib
```

When that finished, you can simply regenerate the CSS files by building mdBook with the following command:

```
cargo build --features=regenerate-css
```

This should automatically call the appropriate stylus command to recompile the files to CSS and include them in the project.

### Making a pull-request

When you feel comfortable that your changes could be integrated into mdBook, you can create a pull-request on GitHub.
Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 1 addition & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ repository = "https://github.com/rust-lang-nursery/mdBook"
keywords = ["book", "gitbook", "rustbook", "markdown"]
license = "MPL-2.0"
readme = "README.md"
build = "build.rs"
exclude = [
"book-example/*",
"src/theme/stylus/**",
]

[package.metadata.release]
Expand Down Expand Up @@ -51,12 +49,9 @@ staticfile = { version = "0.4", optional = true }
ws = { version = "0.7", optional = true}

# Search feature
elasticlunr-rs = { version = "0.2", optional = true }
elasticlunr-rs = { version = "1", optional = true }
ammonia = { version = "1.1", optional = true }

[build-dependencies]
error-chain = "0.11"

[dev-dependencies]
select = "0.4"
pretty_assertions = "0.4"
Expand All @@ -67,7 +62,6 @@ pulldown-cmark-to-cmark = "1.1.0"
default = ["output", "watch", "serve", "search"]
debug = []
output = []
regenerate-css = []
watch = ["notify", "time", "crossbeam"]
serve = ["iron", "staticfile", "ws"]
search = ["elasticlunr-rs", "ammonia"]
Expand Down
6 changes: 0 additions & 6 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
environment:
global:
PROJECT_NAME: mdBook
nodejs_version: "6"
matrix:
# Stable channel
- TARGET: i686-pc-windows-msvc
Expand Down Expand Up @@ -32,17 +31,12 @@ install:
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
- rustc -Vv
- cargo -V
- ps: Install-Product node $env:nodejs_version
- node --version
- npm --version
- npm install -g stylus nib

build: false

# Equivalent to Travis' `script` phase
test_script:
- cargo build --verbose
- cargo build --verbose --features=regenerate-css
- cargo test --verbose

before_deploy:
Expand Down
98 changes: 0 additions & 98 deletions build.rs

This file was deleted.

5 changes: 1 addition & 4 deletions ci/github_pages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@ if [ "$TRAVIS_PULL_REQUEST" != "false" ] ||
exit 0
fi

# Make sure we have the css dependencies
npm install -g stylus nib

NC='\033[39m'
CYAN='\033[36m'
GREEN='\033[32m'

rev=$(git rev-parse --short HEAD)

echo -e "${CYAN}Running cargo doc${NC}"
cargo doc --features regenerate-css > /dev/null
cargo doc > /dev/null

echo -e "${CYAN}Running mdbook build${NC}"
cargo run -- build book-example/
Expand Down
13 changes: 11 additions & 2 deletions src/book/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,17 @@ impl BookBuilder {
let mut index = File::create(themedir.join("index.hbs"))?;
index.write_all(theme::INDEX)?;

let mut css = File::create(themedir.join("book.css"))?;
css.write_all(theme::CSS)?;
let mut chrome_css = File::create(themedir.join("chrome.css"))?;
chrome_css.write_all(theme::CHROME_CSS)?;

let mut general_css = File::create(themedir.join("general.css"))?;
general_css.write_all(theme::GENERAL_CSS)?;

let mut variables_css = File::create(themedir.join("variables.css"))?;
variables_css.write_all(theme::VARIABLES_CSS)?;

let mut print_css = File::create(themedir.join("print.css"))?;
print_css.write_all(theme::PRINT_CSS)?;

let mut favicon = File::create(themedir.join("favicon.png"))?;
favicon.write_all(theme::FAVICON)?;
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/html_handlebars/hbs_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ impl HtmlHandlebars {
use utils::fs::write_file;

write_file(destination, "book.js", &theme.js)?;
write_file(destination, "book.css", &theme.css)?;
write_file(destination, "css/chrome.css", &theme.chrome_css)?;
write_file(destination, "css/general.css", &theme.general_css)?;
write_file(destination, "css/print.css", &theme.print_css)?;
write_file(destination, "css/variables.css", &theme.variables_css)?;
write_file(destination, "favicon.png", &theme.favicon)?;
write_file(destination, "highlight.css", &theme.highlight_css)?;
write_file(destination, "tomorrow-night.css", &theme.tomorrow_night_css)?;
Expand Down
Loading