Skip to content

Commit

Permalink
Merge pull request #743 from mattico/remove-stylus-redux
Browse files Browse the repository at this point in the history
Convert Stylus to CSS
  • Loading branch information
mattico authored Jul 26, 2018
2 parents b3e0942 + 05f3c69 commit 028c8b0
Show file tree
Hide file tree
Showing 32 changed files with 896 additions and 2,546 deletions.
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
10 changes: 1 addition & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ 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/**",
]
exclude = ["book-example/*"]

[dependencies]
clap = "2.24"
Expand Down Expand Up @@ -47,9 +43,6 @@ ws = { version = "0.7", optional = true}
elasticlunr-rs = { version = "2.3", optional = true, default-features = false }
ammonia = { version = "1.1", optional = true }

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

[dev-dependencies]
select = "0.4"
pretty_assertions = "0.5"
Expand All @@ -60,7 +53,6 @@ pulldown-cmark-to-cmark = "1.1.0"
default = ["output", "watch", "serve", "search"]
debug = []
output = []
regenerate-css = []
watch = ["notify"]
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
100 changes: 0 additions & 100 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
16 changes: 14 additions & 2 deletions src/book/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,20 @@ 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 cssdir = themedir.join("css");
fs::create_dir(&cssdir)?;

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

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

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

let mut variables_css = File::create(cssdir.join("variables.css"))?;
variables_css.write_all(theme::VARIABLES_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 @@ -139,7 +139,10 @@ impl HtmlHandlebars {
)?;

write_file(destination, "book.js", &theme.js)?;
write_file(destination, "book.css", &theme.css)?;
write_file(destination, "css/general.css", &theme.general_css)?;
write_file(destination, "css/chrome.css", &theme.chrome_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

0 comments on commit 028c8b0

Please sign in to comment.