From dd1fea65d7630734f417ac1da1838c780cd17b09 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 5 Jun 2014 22:58:15 -0500 Subject: [PATCH 1/7] Embed the rust-www live code editor in (almost) all the examples --- Makefile | 3 +- book.json | 6 + examples/array/input.md | 4 - examples/attribute/input.md | 2 - examples/borrow/input.md | 12 - examples/bounds/input.md | 4 - examples/box/input.md | 4 - examples/channels/input.md | 4 - examples/clone/input.md | 4 - examples/closures/input.md | 4 - examples/constants/input.md | 4 - examples/enum/input.md | 6 - examples/expression/input.md | 4 - examples/for/input.md | 2 - examples/functions/input.md | 2 - examples/generics/input.md | 2 - examples/hello/input.md | 2 - examples/hof/input.md | 4 - examples/if-else/input.md | 6 - examples/iter/input.md | 4 - examples/lifetime/input.md | 6 - examples/literals/input.md | 4 - examples/loops/input.md | 8 - examples/match/input.md | 4 - examples/methods/input.md | 4 - examples/mod/input.md | 12 - examples/move/input.md | 8 - examples/operator/input.md | 4 - examples/option/input.md | 4 - examples/print/input.md | 4 - examples/process/input.md | 6 - examples/raii/input.md | 2 - examples/str/input.md | 4 - examples/structs/input.md | 4 - examples/tasks/input.md | 4 - examples/trait/input.md | 6 - examples/tuples/input.md | 4 - examples/type/input.md | 6 - examples/variables/input.md | 6 - examples/vec/input.md | 4 - .../book/editor.css | 83 +++++++ .../book/editor.js | 232 ++++++++++++++++++ .../gitbook-plugin-rust-playpen/index.js | 11 + .../gitbook-plugin-rust-playpen/package.json | 8 + setup-stage.sh | 3 + src/markdown.rs | 11 +- src/playpen.rs | 30 ++- 47 files changed, 369 insertions(+), 196 deletions(-) create mode 100644 book.json create mode 100644 node_modules/gitbook-plugin-rust-playpen/book/editor.css create mode 100644 node_modules/gitbook-plugin-rust-playpen/book/editor.js create mode 100644 node_modules/gitbook-plugin-rust-playpen/index.js create mode 100644 node_modules/gitbook-plugin-rust-playpen/package.json create mode 100755 setup-stage.sh diff --git a/Makefile b/Makefile index 6591f787db..55accc58dc 100644 --- a/Makefile +++ b/Makefile @@ -17,8 +17,7 @@ srcs = $(filter-out $(WHITELIST),$(shell find examples -name '*.rs')) .PHONY: all book clean test serve all: - mkdir -p stage - ln -sf ../examples/README.md stage/README.md + ./setup-stage.sh $(RUSTC) src/update.rs ./update rm update diff --git a/book.json b/book.json new file mode 100644 index 0000000000..365974f0d1 --- /dev/null +++ b/book.json @@ -0,0 +1,6 @@ +{ + "plugins": ["rust-playpen"], + "pluginsConfig": { + "rust-playpen": {} + } +} diff --git a/examples/array/input.md b/examples/array/input.md index 466264a0fd..e60e8e5fc5 100644 --- a/examples/array/input.md +++ b/examples/array/input.md @@ -7,8 +7,4 @@ Instead, a slice is two-word object, the first word is a pointer to the data, and the second word is the length of the slice. Slices can be used to borrow a section of an array, and have `&[T]` as type signature. -{array.rs} - {array.play} - -{array.out} diff --git a/examples/attribute/input.md b/examples/attribute/input.md index cd809bbd86..dc1443b221 100644 --- a/examples/attribute/input.md +++ b/examples/attribute/input.md @@ -31,8 +31,6 @@ Here's an example of conditional compilation. {conditional.rs} -{conditional.play} - {conditional.out} Some conditionals like `target_os` are implicitly provided by `rustc`, but diff --git a/examples/borrow/input.md b/examples/borrow/input.md index 37b6d2c4b9..5a6cc67178 100644 --- a/examples/borrow/input.md +++ b/examples/borrow/input.md @@ -4,12 +4,8 @@ passing objects by-value (`T`), objects can be passed by reference (`&T`). The compiler statically guarantees that references *always* point to valid objects, via its borrow checker. -{borrow.rs} - {borrow.play} -{borrow.out} - `&T` borrows the data via an immutable reference, and the borrower can read the data but not modify it. Mutable data can be immutably borrowed, but can also be mutably borrowed via a mutable reference `&mut T`, giving read/write access to @@ -17,8 +13,6 @@ the borrower. {mut.rs} -{mut.play} - {mut.out} When data is borrowed, it also *freezes*. "Frozen" data can't be modified via @@ -26,8 +20,6 @@ the original object, until all the references to it go out of scope. {freeze.rs} -{freeze.play} - {freeze.out} Data can be immutably borrowed any number of times, but once immutably @@ -37,8 +29,6 @@ scope, the original data can't be borrowed again. {re-borrow.rs} -{re-borrow.play} - {re-borrow.out} When doing pattern matching or destructuring via the `let` binding, the `ref` @@ -46,6 +36,4 @@ keyword can be used to take references to the fields of a struct. {ref.rs} -{ref.play} - {ref.out} diff --git a/examples/bounds/input.md b/examples/bounds/input.md index 472ffbb735..b5e8ea6b90 100644 --- a/examples/bounds/input.md +++ b/examples/bounds/input.md @@ -2,8 +2,4 @@ When writing generic code, it's important to *bound* the generic data to conform to some traits. This allows using the trait methods in these bounded implementations. -{bounds.rs} - {bounds.play} - -{bounds.out} diff --git a/examples/box/input.md b/examples/box/input.md index 324dcf58c6..1300221fc6 100644 --- a/examples/box/input.md +++ b/examples/box/input.md @@ -8,8 +8,4 @@ Boxed values can be dereferenced (unboxed) using the `*` operator, this removes one layer of indirection. Alternatively, `let box x = y` can be used to unbox `y` into `x`. -{box.rs} - {box.play} - -{box.out} diff --git a/examples/channels/input.md b/examples/channels/input.md index 73e9a6679c..a3c9b721b9 100644 --- a/examples/channels/input.md +++ b/examples/channels/input.md @@ -23,10 +23,6 @@ task number 4 reported Albeit non obvious from the output above, channels are actually FIFO. -{fifo.rs} - {fifo.play} The order is maintained, after removing the scheduler non-determinism. - -{fifo.out} diff --git a/examples/clone/input.md b/examples/clone/input.md index 0d955d0f04..734061106f 100644 --- a/examples/clone/input.md +++ b/examples/clone/input.md @@ -3,8 +3,4 @@ assignments or function calls. Sometimes the intention is to make a copy of the resource, this can be accomplish by calling the `clone()` method, defined in the `Clone` trait. -{clone.rs} - {clone.play} - -{clone.out} diff --git a/examples/closures/input.md b/examples/closures/input.md index 7f5a2a772e..c09714304c 100644 --- a/examples/closures/input.md +++ b/examples/closures/input.md @@ -7,8 +7,4 @@ surrounding scope. Closures consist of three parts: inferred * a block, the last expression is the return value -{closures.rs} - {closures.play} - -{closures.out} diff --git a/examples/constants/input.md b/examples/constants/input.md index 5010396c3c..00a833a8ef 100644 --- a/examples/constants/input.md +++ b/examples/constants/input.md @@ -9,8 +9,4 @@ allocated in read-only memory. `'static` is an special lifetime that outlives all the other lifetimes, and indicates that the referenced data is available in all the scopes. -{constants.rs} - {constants.play} - -{constants.out} diff --git a/examples/enum/input.md b/examples/enum/input.md index 29ac152fb8..ec922916f4 100644 --- a/examples/enum/input.md +++ b/examples/enum/input.md @@ -1,16 +1,10 @@ The `enum` keyword allows the creation of tagged unions, which can be used as algebraic data types. -{enum.rs} - {enum.play} -{enum.out} - `enum` can also be used to represent C-like enums. {c-like.rs} -{c-like.play} - {c-like.out} diff --git a/examples/expression/input.md b/examples/expression/input.md index a2a71810c9..62cefd8d0e 100644 --- a/examples/expression/input.md +++ b/examples/expression/input.md @@ -7,8 +7,4 @@ Block are expressions too, so they can be used as rvalues in assignments. The last expression in the block will be assigned to the lvalue. If the last expression of the block ends with a semicolon, the return value will be `()`. -{expression.rs} - {expression.play} - -{expression.out} diff --git a/examples/for/input.md b/examples/for/input.md index eba7d12cf4..57d2272309 100644 --- a/examples/for/input.md +++ b/examples/for/input.md @@ -5,6 +5,4 @@ function. `range(a, b)` will yield values from `a` (inclusive) to `b` Let's write fizzbuzz using `for` instead of `while`. -{for.rs} - {for.play} diff --git a/examples/functions/input.md b/examples/functions/input.md index fb022c04c5..ce2e1d64b1 100644 --- a/examples/functions/input.md +++ b/examples/functions/input.md @@ -8,6 +8,4 @@ return a value earlier from the function, even from inside loops or ifs. Let's rewrite fizzbuzz using functions! -{functions.rs} - {functions.play} diff --git a/examples/generics/input.md b/examples/generics/input.md index 82f74540a3..d284c10878 100644 --- a/examples/generics/input.md +++ b/examples/generics/input.md @@ -6,6 +6,4 @@ annotation is usually not required. When that's not the case, structs can be specialized via type annotation, and functions can be specialized passing the generic arguments using this syntax `::`. -{generics.rs} - {generics.play} diff --git a/examples/hello/input.md b/examples/hello/input.md index 0e6217da36..493223f8ab 100644 --- a/examples/hello/input.md +++ b/examples/hello/input.md @@ -1,7 +1,5 @@ This is the source code of the traditional Hello World program. -{hello.rs} - {hello.play} `println!` is a *macro* (we'll cover them later) that prints text to the diff --git a/examples/hof/input.md b/examples/hof/input.md index e5fabe003b..0cf7f411e9 100644 --- a/examples/hof/input.md +++ b/examples/hof/input.md @@ -2,12 +2,8 @@ Rust provides Higher Order Functions (HOF), these are functions that take a closure as argument to produce a more useful function. HOFs and lazy iterators give Rust its functional flavor. -{hof.rs} - {hof.play} -{hof.out} - [Option](http://static.rust-lang.org/doc/master/core/option/type.Option.html) and [Iterator](http://static.rust-lang.org/doc/master/core/iter/trait.Iterator.html) diff --git a/examples/if-else/input.md b/examples/if-else/input.md index c0ce073ae5..7ad570d747 100644 --- a/examples/if-else/input.md +++ b/examples/if-else/input.md @@ -1,17 +1,11 @@ Branching with if-else is similar to C. Unlike C, the boolean condition doesn't need to be surrounded by parentheses. Each condition is followed by a block. -{if-else.rs} - {if-else.play} -{if-else.out} - If-else conditionals are expressions too. Because of Rust type safety, all the branches must return the same type. {if-else-expr.rs} -{if-else-expr.play} - {if-else-expr.out} diff --git a/examples/iter/input.md b/examples/iter/input.md index 265c4016c8..5009f45e30 100644 --- a/examples/iter/input.md +++ b/examples/iter/input.md @@ -1,11 +1,7 @@ The `Iterator` trait is used to implement iterators over collections (like arrays) and lazy value generators. -{iter.rs} - {iter.play} -{iter.out} - The `Iterator` trait gives access to [several methods](http://static.rust-lang.org/doc/master/core/iter/trait.Iterator.html). diff --git a/examples/lifetime/input.md b/examples/lifetime/input.md index b2fac93460..45f97aec1e 100644 --- a/examples/lifetime/input.md +++ b/examples/lifetime/input.md @@ -47,12 +47,8 @@ Let's illustrate with an example: we want a function that returns a reference to the title field of a Book struct. The most generic function that we could write would look like this: -{reference-bad.rs} - {reference-bad.play} -{reference-bad.out} - The compiler can't tell how `'a` and `'b` are related, so we must supply this information. The answer here is that `'a = 'b`, the reason is that the title field will be destroyed when the book gets destroyed (same way with the @@ -60,6 +56,4 @@ creation time), therefore the title field has the same lifetime as the book. {reference-good.rs} -{reference-good.play} - {reference-good.out} diff --git a/examples/literals/input.md b/examples/literals/input.md index 5a2df1da17..d92b233b45 100644 --- a/examples/literals/input.md +++ b/examples/literals/input.md @@ -21,8 +21,4 @@ The operators available and operator precedence are similar to other [C-like languages ](https://en.wikipedia.org/wiki/Operator_precedence#Programming_languages) -{literals.rs} - {literals.play} - -{literals.out} diff --git a/examples/loops/input.md b/examples/loops/input.md index cd1fa01f49..fb5b461f45 100644 --- a/examples/loops/input.md +++ b/examples/loops/input.md @@ -3,20 +3,14 @@ Rust provides a `loop` keyword to indicate an infinite loop. The `break` keyword can be used to exit a loop at anytime, whereas the `continue` can be used to skip the rest of the iteration and start a new one. -{loop.rs} - {loop.play} -{loop.out} - It's possible to `break` or `continue` outer loops when dealing with nested loops. In these cases, the loops must be annotated with some `'label` and the label must be passed to the `break`/`continue` statement. {nested.rs} -{nested.play} - {nested.out} The `while` keyword can be used for looping until a condition is met. @@ -24,5 +18,3 @@ The `while` keyword can be used for looping until a condition is met. Let's write the infamous fizzbuzz using a `while` loop. {while.rs} - -{while.play} diff --git a/examples/match/input.md b/examples/match/input.md index 4b8bd0019e..1dcef3884e 100644 --- a/examples/match/input.md +++ b/examples/match/input.md @@ -1,8 +1,4 @@ Rust provides pattern matching via the `match` keyword, the syntax will be covered in the code below. -{match.rs} - {match.play} - -{match.out} diff --git a/examples/methods/input.md b/examples/methods/input.md index d8c7169d86..6bb3dae716 100644 --- a/examples/methods/input.md +++ b/examples/methods/input.md @@ -2,8 +2,4 @@ Methods are functions attached to objects, these methods have access to the data of the object and its other methods via the `self` keyword. These methods are grouped under a `impl` block. -{methods.rs} - {methods.play} - -{methods.out} diff --git a/examples/mod/input.md b/examples/mod/input.md index ed0297a9a3..ba8916c416 100644 --- a/examples/mod/input.md +++ b/examples/mod/input.md @@ -5,20 +5,14 @@ between them. A module is collection of items like: functions, structs, traits, impl blocks, and even other modules. -{nested.rs} - {nested.play} -{nested.out} - By default, the items in a module have private visibility, but this can be overridden using the `pub` modifier. Only the public items of a module can be accessed from outside the module scope. {visibility.rs} -{visibility.play} - {visibility.out} The `use` declaration can be used to bind a full path to a new name, for easier @@ -26,8 +20,6 @@ access. {use.rs} -{use.play} - {use.out} The `super` and `self` keywords can be used in the path, to remove ambiguity @@ -35,8 +27,6 @@ when accessing items. {super.rs} -{super.play} - {super.out} Structs have an extra level of visibility, their fields can be public or @@ -44,8 +34,6 @@ private. This allows encapsulation. {structs.rs} -{structs.play} - {structs.out} Modules can be mapped to a file/directory hierarchy. Let's break down the diff --git a/examples/move/input.md b/examples/move/input.md index 477190aeb1..50338ad0dd 100644 --- a/examples/move/input.md +++ b/examples/move/input.md @@ -5,19 +5,13 @@ When doing assignments, `let x = y`, or passing function arguments by value `foo(x)`, the data is copied, but the *ownership* of the resources is transferred, this is know as *moving* in Rust-speak. -{assignment.rs} - {assignment.play} -{assignment.out} - After moving resources, the previous owner loses access to the resource. This avoids *dereferencing freed memory*. {pass-by-value.rs} -{pass-by-value.play} - {pass-by-value.out} Mutability of data depends on its owner. Mutability of data can change when @@ -25,6 +19,4 @@ ownership is transferred. {mut.rs} -{mut.play} - {mut.out} diff --git a/examples/operator/input.md b/examples/operator/input.md index 24afd90359..fc11a19863 100644 --- a/examples/operator/input.md +++ b/examples/operator/input.md @@ -3,11 +3,7 @@ because operators are just sugar for method calls. For example, `a + b` desugars to `a.add(&b)`. This `add()` method is part of the `Add` trait, hence any implementor of the `Add` trait will be able to use the `+` operator. -{operator.rs} - {operator.play} -{operator.out} - Here is a [list](http://static.rust-lang.org/doc/master/core/ops/index.html) of the traits that overload operators. diff --git a/examples/option/input.md b/examples/option/input.md index 4b08e280e8..7309dfdb47 100644 --- a/examples/option/input.md +++ b/examples/option/input.md @@ -10,8 +10,4 @@ instead of unwinding the whole program, this can be accomplished using the `Some`, a tuple struct that wraps a value. The type `T` of the wrapped value is part of the type signature of option `Option`. -{option.rs} - {option.play} - -{option.out} diff --git a/examples/print/input.md b/examples/print/input.md index 6438256b66..2466173aa9 100644 --- a/examples/print/input.md +++ b/examples/print/input.md @@ -2,11 +2,7 @@ The `println!` macro not only prints to the console, but also is capable of formatting text and stringifying values. Plus, the formatting correctness will be checked at compile time. -{print.rs} - {print.play} -{print.out} - For more information about formatting, take a look at [std::fmt](http://static.rust-lang.org/doc/master/std/fmt/index.html). diff --git a/examples/process/input.md b/examples/process/input.md index 79ee362089..bed1fd3a01 100644 --- a/examples/process/input.md +++ b/examples/process/input.md @@ -1,12 +1,8 @@ The `Process` struct represents a running or finished child process. And the `Command` struct is a process builder. -{process.rs} - {process.play} -{process.out} - (You are encouraged to try the previous example with an incorrect flag) `Process` exposes the `stdin`, `stdout` and `stderr` handles for interaction @@ -14,8 +10,6 @@ with the child process via pipes. {pipe.rs} -{pipe.play} - {pipe.out} When a `Process` that owns a resource (a *runnig* child process) goes out of diff --git a/examples/raii/input.md b/examples/raii/input.md index 1f0589cfda..ba2ab3234f 100644 --- a/examples/raii/input.md +++ b/examples/raii/input.md @@ -6,8 +6,6 @@ and the resources *owned* by it are freed. This behavior shields against Don't take my word for it, let's check using `valgrind` -{raii.rs} - {raii.play} ``` diff --git a/examples/str/input.md b/examples/str/input.md index 07d75d956e..7a4ca00102 100644 --- a/examples/str/input.md +++ b/examples/str/input.md @@ -7,12 +7,8 @@ null terminated. `&str` is a slice (`&[u8]`) that always points to a valid UTF-8 sequence, and can be used to view into a `String`, just like `&[T]` is a view into `Vec`. -{str.rs} - {str.play} -{str.out} - More `str`/`String` methods can be found under the [std::str](http://static.rust-lang.org/doc/master/std/str/index.html) and [std::string](http://static.rust-lang.org/doc/master/std/string/index.html) diff --git a/examples/structs/input.md b/examples/structs/input.md index 2cccedaaf9..8586c53f5b 100644 --- a/examples/structs/input.md +++ b/examples/structs/input.md @@ -8,8 +8,4 @@ keyword: The syntax is shown below. -{structs.rs} - {structs.play} - -{structs.out} diff --git a/examples/tasks/input.md b/examples/tasks/input.md index e679151fa0..a75514bf7a 100644 --- a/examples/tasks/input.md +++ b/examples/tasks/input.md @@ -1,15 +1,11 @@ Rust provides a mechanism for spawning lightweight tasks via the `spawn` function, the argument of this function is a owned closure named `proc`. -{tasks.rs} - {tasks.play} These tasks will be scheduled by the Rust runtime and the order of execution of these tasks will be non-deterministic. -{tasks.out} - (By default, Rust uses its *native* runtime, which maps each Rust task to a native thread. Rust also provides a *green* runtime that provides green threads and maps M Rust tasks to N native threads.) diff --git a/examples/trait/input.md b/examples/trait/input.md index cb0d708bf4..29aec594e6 100644 --- a/examples/trait/input.md +++ b/examples/trait/input.md @@ -2,20 +2,14 @@ A `trait` is a collection of methods defined for an unknown type. A trait can be implemented for any data type. When some instances implement the same trait, they can be grouped in an array since they provide the same interface. -{trait.rs} - {trait.play} -{trait.out} - The compiler is capable of providing basic implementations for some traits via the `#[deriving]` attribute. These traits can still be manually implemented if a more complex behavior is required. {deriving.rs} -{deriving.play} - {deriving.out} This is a list of the "derivable" traits: diff --git a/examples/tuples/input.md b/examples/tuples/input.md index 50bc15a31f..a541373979 100644 --- a/examples/tuples/input.md +++ b/examples/tuples/input.md @@ -3,8 +3,4 @@ using parentheses `()`, and each tuple itself is a value with type signature `(T1, T2, ...)`, where `T1`, `T2` are the types of its members. Functions can use tuples to return multiple values, as tuples can hold any number of values. -{tuples.rs} - {tuples.play} - -{tuples.out} diff --git a/examples/type/input.md b/examples/type/input.md index 4c5011e543..86ebe6f132 100644 --- a/examples/type/input.md +++ b/examples/type/input.md @@ -6,20 +6,14 @@ variable from the context, heavily reducing the annotation burden. Type conversion (a.k.a. casting) must be explicitly stated using the `as` keyword. -{type.rs} - {type.play} -{type.out} - The type inference engine is pretty smart, it does more than looking at the type of the rvalue of an initialization; it also looks how the variable is used afterwards to infer its type. Here's an advanced example of type inference: {inference.rs} -{inference.play} - (You are encouraged to try the previous code with the `v.push` line commented out) diff --git a/examples/variables/input.md b/examples/variables/input.md index 2cf5b33be7..0c63b62f4d 100644 --- a/examples/variables/input.md +++ b/examples/variables/input.md @@ -1,20 +1,14 @@ Variables in Rust are declared using the `let` keyword. Variables are immutable by default, but this can be overridden using the `mut` qualifier. -{variables.rs} - {variables.play} The compiler will throw a detailed diagnostic about mutability errors. -{variables.out} - It's possible to declare variables first, and initialize them later, but this form is seldom used. Also, the compiler forbids usage of uninitialized variables, as this would lead to undefined behavior. {declare.rs} -{declare.play} - {declare.out} diff --git a/examples/vec/input.md b/examples/vec/input.md index 2a0f396e52..0846fbe7a5 100644 --- a/examples/vec/input.md +++ b/examples/vec/input.md @@ -5,11 +5,7 @@ indicates how much memory is reserved for the vector, the vector can grow as long as the length is smaller than the capacity, when this threshold needs to be surpassed, the vector gets reallocated with a bigger capacity. -{vec.rs} - {vec.play} -{vec.out} - More `Vec` methods can be found under the [std::vec](http://static.rust-lang.org/doc/master/std/vec/index.html) module diff --git a/node_modules/gitbook-plugin-rust-playpen/book/editor.css b/node_modules/gitbook-plugin-rust-playpen/book/editor.css new file mode 100644 index 0000000000..a6e072b515 --- /dev/null +++ b/node_modules/gitbook-plugin-rust-playpen/book/editor.css @@ -0,0 +1,83 @@ +// the style here follows graydon/rust-www + +#active-code { + position: relative; + display: none; + padding: 10px; + border-radius: 4px; + background-color: #FDFDFD; + border: 1px solid #CCC; +} + +#editor { + padding: none; + margin: none; + width: 100%; + min-height: 340px; + font-size: 13px; + font-family: Menlo, Monaco, Consolas, "Courier New", monospace; +} + +#result { + color: #333; + background-color: #E2EEF6; + margin-top: 10px; + padding: 10px; + display: none; + border-radius: 4px; +} + +#reset-code { + position: absolute; + z-index: 10; + float: right; + right: 8px; + top: 50px; + outline: none; +} + +#run-code { + position: absolute; + z-index: 10; + float: right; + right: 8px; + top: 8px; + outline: none; +} + +.ace-error-text, .ace-error-line, .ace-warning-text, .ace-warning-line { + position: absolute; +} + +.ace-error-text { + background-color: #e9abab; +} + +.ace-error-line { + background-color: #F6E2E2; +} + +.ace-warning-text { + background-color: #FFEF00; +} + +.ace-warning-line { + background-color: #FFFBCB; +} + +.btn-primary { + color: #fff; + background-color: #428bca; + border-color: #357ebd; + border-radius: 4px; +} +.btn-primary:hover, +.btn-primary:focus, +.btn-primary:active { + color: #fff; + background-color: #3276b1; + border-color: #285e8e; +} +.btn-primary:active { + background-image: none; +} diff --git a/node_modules/gitbook-plugin-rust-playpen/book/editor.js b/node_modules/gitbook-plugin-rust-playpen/book/editor.js new file mode 100644 index 0000000000..b4be8db8e7 --- /dev/null +++ b/node_modules/gitbook-plugin-rust-playpen/book/editor.js @@ -0,0 +1,232 @@ +// this is mostly the editor implemented by @SergioBenitez for graydon/rust-www +// plus small modifications to accommodate a "Reset" button + +// ECMAScript 6 Backwards compatability +if (typeof String.prototype.startsWith != 'function') { + String.prototype.startsWith = function(str) { + return this.slice(0, str.length) == str; + }; +} + +// Regex for finding new lines +var newLineRegex = /(?:\r\n|\r|\n)/g; + +// Fetching DOM items +var activeCode = document.getElementById("active-code"); +var editorDiv = document.getElementById("editor"); +var resetButton = document.getElementById("reset-code"); +var runButton = document.getElementById("run-code"); +var resultDiv = document.getElementById("result"); + +// Background colors for program result on success/error +var successColor = "#E2EEF6"; +var errorColor = "#F6E2E2"; +var warningColor = "#FFFBCB"; + +// Error message to return when there's a server failure +var errMsg = "The server encountered an error while running the program."; + +// Stores ACE editor markers (highights) for errors +var markers = []; + +// Status codes, because there are no enums in Javascript +var SUCCESS = 0; +var ERROR = 1; +var WARNING = 2; + +// JS exists, display ACE editor +activeCode.style.display = "block"; + +// Setting up ace editor +var editor = ace.edit("editor"); +var Range = ace.require('ace/range').Range; +editor.setTheme("ace/theme/chrome"); +editor.getSession().setMode("ace/mode/rust"); +editor.setShowPrintMargin(false); +editor.renderer.setShowGutter(false); +editor.setHighlightActiveLine(false); + +// Store original source code +var originalCode = editor.getSession().getValue(); + +// Changes the height of the editor to match its contents +function updateEditorHeight() { + // http://stackoverflow.com/questions/11584061/ + var newHeight = editor.getSession().getScreenLength() + * editor.renderer.lineHeight + + editor.renderer.scrollBar.getWidth(); + + editorDiv.style.height = Math.ceil(newHeight).toString() + "px"; + editor.resize(); +}; + +// Set initial size to match initial content +updateEditorHeight(); + +function escapeHTML(unsafe) { + return unsafe + .replace(/&/g, "&") + .replace(//g, ">") + .replace(/"/g, """) + .replace(/'/g, "'") + .replace(newLineRegex, '
'); +} + +// Dispatches a XMLHttpRequest to the Rust playpen, running the program, and +// issues a callback to `callback` with the result (or null on error) +function runProgram(program, callback) { + var req = new XMLHttpRequest(); + var data = JSON.stringify({ + version: "master", + optimize: "2", + code: program + }); + + // console.log("Sending", data); + req.open('POST', "http://play.rust-lang.org/evaluate.json", true); + req.onload = function(e) { + if (req.readyState === 4 && req.status === 200) { + var result = JSON.parse(req.response).result; + + // Need server support to get an accurate version of this. + var statusCode = SUCCESS; + if (result.indexOf("error:") !== -1) { + statusCode = ERROR; + } else if (result.indexOf("warning:") !== -1) { + statusCode = WARNING; + } + + callback(statusCode, result); + } else { + callback(false, null); + } + }; + + req.onerror = function(e) { + callback(false, null); + } + + req.setRequestHeader("Content-Type", "application/json"); + req.send(data); +} + +// The callback to runProgram +function handleResult(statusCode, message) { + // Dispatch depending on result type + if (result == null) { + resultDiv.style.backgroundColor = errorColor; + resultDiv.innerHTML = errMsg; + } else if (statusCode == SUCCESS) { + handleSuccess(message); + } else if (statusCode == WARNING) { + handleWarning(message); + } else { + handleError(message); + } +} + +// Called on successful program run +function handleSuccess(message) { + resultDiv.style.backgroundColor = successColor; + resultDiv.innerHTML = escapeHTML(message); +} + +// Called when program run results in warning(s) +function handleWarning(message) { + resultDiv.style.backgroundColor = warningColor; + handleProblem(message, "warning"); +} + +// Called when program run results in error(s) +function handleError(message) { + resultDiv.style.backgroundColor = errorColor; + handleProblem(message, "error"); +} + +// Called on unsuccessful program run. Detects and prints problems (either +// warnings or errors) in program output and highlights relevant lines and text +// in the code. +function handleProblem(message, problem) { + // Getting list of ranges with problems + var lines = message.split(newLineRegex); + + // Cleaning up the message: keeps only relevant problem output + var cleanMessage = lines.map(function(line) { + if (line.startsWith("") || line.indexOf("^") !== -1) { + var errIndex = line.indexOf(problem + ": "); + if (errIndex !== -1) return line.slice(errIndex); + return ""; + } + + // Discard playpen messages, keep the rest + if (line.startsWith("playpen:")) return ""; + return line; + }).filter(function(line) { + return line !== ""; + }).map(function(line) { + return escapeHTML(line); + }).join("
"); + + // Setting message + resultDiv.innerHTML = cleanMessage; + + // Highlighting the lines + var ranges = parseProblems(lines); + markers = ranges.map(function(range) { + return editor.getSession().addMarker(range, "ace-" + problem + "-line", + "fullLine", false); + }); + + // Highlighting the specific text + markers = markers.concat(ranges.map(function(range) { + return editor.getSession().addMarker(range, "ace-" + problem + "-text", + "text", false); + })); +} + +// Parses a problem message returning a list of ranges (row:col, row:col) where +// problems in the code have occured. +function parseProblems(lines) { + var ranges = []; + for (var i in lines) { + var line = lines[i]; + if (line.startsWith(":") && line.indexOf(": ") !== -1) { + var parts = line.split(/:\s?|\s+/, 5).slice(1, 5); + var ip = parts.map(function(p) { return parseInt(p, 10) - 1; }); + // console.log("line:", line, parts, ip); + ranges.push(new Range(ip[0], ip[1], ip[2], ip[3])); + } + } + + return ranges; +} + +// Registering handler for run button click +runButton.addEventListener("click", function(ev) { + resultDiv.style.display = "block"; + resultDiv.innerHTML = "Running..."; + + // clear previous markers, if any + markers.map(function(id) { editor.getSession().removeMarker(id); }); + + // Get the code, run the program + var program = editor.getValue(); + runProgram(program, handleResult); +}); + +// Registering handler for reset button click +resetButton.addEventListener("click", function(ev) { + editor.getSession().setValue(originalCode); + resultDiv.style.display = "none"; +}); + +// Highlight active line when focused +editor.on('focus', function() { + editor.setHighlightActiveLine(true); +}); + +// Don't when not +editor.on('blur', function() { + editor.setHighlightActiveLine(false); +}); diff --git a/node_modules/gitbook-plugin-rust-playpen/index.js b/node_modules/gitbook-plugin-rust-playpen/index.js new file mode 100644 index 0000000000..08399a481e --- /dev/null +++ b/node_modules/gitbook-plugin-rust-playpen/index.js @@ -0,0 +1,11 @@ +module.exports = { + book: { + assets: "./book", + css: [ + "editor.css" + ], + js: [ + "editor.js" + ] + } +}; diff --git a/node_modules/gitbook-plugin-rust-playpen/package.json b/node_modules/gitbook-plugin-rust-playpen/package.json new file mode 100644 index 0000000000..34040733f9 --- /dev/null +++ b/node_modules/gitbook-plugin-rust-playpen/package.json @@ -0,0 +1,8 @@ +{ + "description": "Integrate Rust playpen with gitbook", + "engines": { + "gitbook": "*" + }, + "main": "index.js", + "name": "gitbook-plugin-rust-playpen" +} diff --git a/setup-stage.sh b/setup-stage.sh new file mode 100755 index 0000000000..ff8be9339b --- /dev/null +++ b/setup-stage.sh @@ -0,0 +1,3 @@ +mkdir -p stage/node_modules +ln -sf ../book.json stage +ln -sf ../examples/README.md stage/README.md diff --git a/src/markdown.rs b/src/markdown.rs index 69c3e9f7f2..5699d11182 100644 --- a/src/markdown.rs +++ b/src/markdown.rs @@ -103,11 +103,18 @@ impl<'a> Markdown<'a> { fn insert_playpen_links(&mut self) -> Result<(), String> { let re = regex!(r"\{(.*)\.play\}"); + let mut once_ = false; let mut table = Vec::new(); for line in self.content.as_slice().lines() { match re.captures(line) { None => {}, Some(captures) => { + if once_ { + return Err(format!("more than one editor!")) + } else { + once_ = true; + } + let input = format!("\\{{}.play\\}", captures.at(1)); let src = format!("{}.rs", captures.at(1)); let p = format!("examples/{}/{}", self.id, src); @@ -116,9 +123,7 @@ impl<'a> Markdown<'a> { return Err(format!("{} not found", p)); }, Ok(source) => { - format!("([Try `{}` in the playpen!]({}))", - src, - playpen::link(source.as_slice())) + playpen::editor(source.as_slice()) } }; diff --git a/src/playpen.rs b/src/playpen.rs index 1f245408ca..a3721f3fae 100644 --- a/src/playpen.rs +++ b/src/playpen.rs @@ -1,20 +1,24 @@ -pub fn escape(code: &str) -> String { +pub fn editor(source: &str) -> String { + format!("
+ + +
{}
+
+
", escape(source)) +} + +fn escape(source: &str) -> String { let mut s = String::new(); - for c in code.chars() { - match c { - c@'!' => s.push_char(c), - c@'.' => s.push_char(c), - c@'0'..'9' => s.push_char(c), - c@'A'..'Z' => s.push_char(c), - c@'a'..'z' => s.push_char(c), - c => s.push_str(format!("%{:02X}", c as u32).as_slice()), + for chr in source.trim().chars() { + match chr { + '*' => s.push_str("*"), + '<' => s.push_str("<"), + '>' => s.push_str(">"), + '_' => s.push_str("_"), + chr => s.push_char(chr), } } s } - -pub fn link(source: &str) -> String { - format!("http://play.rust-lang.org/?code={}&run=1", escape(source)) -} From 49e04f7a1d5f2b6ff80ab4b5ceef437e6d1e3849 Mon Sep 17 00:00:00 2001 From: Vojtech Kral Date: Fri, 6 Jun 2014 23:29:46 +0200 Subject: [PATCH 2/7] Fix: editor reinitialization upon navigation --- .../book/editor.js | 128 +++++++++++------- 1 file changed, 78 insertions(+), 50 deletions(-) diff --git a/node_modules/gitbook-plugin-rust-playpen/book/editor.js b/node_modules/gitbook-plugin-rust-playpen/book/editor.js index b4be8db8e7..0ef51c335c 100644 --- a/node_modules/gitbook-plugin-rust-playpen/book/editor.js +++ b/node_modules/gitbook-plugin-rust-playpen/book/editor.js @@ -11,12 +11,12 @@ if (typeof String.prototype.startsWith != 'function') { // Regex for finding new lines var newLineRegex = /(?:\r\n|\r|\n)/g; -// Fetching DOM items -var activeCode = document.getElementById("active-code"); -var editorDiv = document.getElementById("editor"); -var resetButton = document.getElementById("reset-code"); -var runButton = document.getElementById("run-code"); -var resultDiv = document.getElementById("result"); +// DOM items +var activeCode; +var editorDiv; +var resetButton; +var runButton; +var resultDiv; // Background colors for program result on success/error var successColor = "#E2EEF6"; @@ -34,20 +34,80 @@ var SUCCESS = 0; var ERROR = 1; var WARNING = 2; -// JS exists, display ACE editor -activeCode.style.display = "block"; +// Ace editor +var editor; +var Range; -// Setting up ace editor -var editor = ace.edit("editor"); -var Range = ace.require('ace/range').Range; -editor.setTheme("ace/theme/chrome"); -editor.getSession().setMode("ace/mode/rust"); -editor.setShowPrintMargin(false); -editor.renderer.setShowGutter(false); -editor.setHighlightActiveLine(false); +// Original source code +var originalCode; -// Store original source code -var originalCode = editor.getSession().getValue(); +function initEditor() +{ + // Fetching DOM items + activeCode = document.getElementById("active-code"); + editorDiv = document.getElementById("editor"); + resetButton = document.getElementById("reset-code"); + runButton = document.getElementById("run-code"); + resultDiv = document.getElementById("result"); + + if (editorDiv === null) + return; // No editor on this page + + // Setup ace editor + editor = ace.edit("editor"); + Range = ace.require('ace/range').Range; + + // JS exists, display ACE editor + activeCode.style.display = "block"; + + editor.setTheme("ace/theme/chrome"); + editor.getSession().setMode("ace/mode/rust"); + editor.setShowPrintMargin(false); + editor.renderer.setShowGutter(false); + editor.setHighlightActiveLine(false); + + originalCode = editor.getSession().getValue(); + + // Set initial size to match initial content + updateEditorHeight(); + + // Registering handler for run button click + runButton.addEventListener("click", function(ev) { + resultDiv.style.display = "block"; + resultDiv.innerHTML = "Running..."; + + // clear previous markers, if any + markers.map(function(id) { editor.getSession().removeMarker(id); }); + + // Get the code, run the program + var program = editor.getValue(); + runProgram(program, handleResult); + }); + + // Registering handler for reset button click + resetButton.addEventListener("click", function(ev) { + editor.getSession().setValue(originalCode); + resultDiv.style.display = "none"; + }); + + // Highlight active line when focused + editor.on('focus', function() { + editor.setHighlightActiveLine(true); + }); + + // Don't when not + editor.on('blur', function() { + editor.setHighlightActiveLine(false); + }); +} + +initEditor(); + +require(["gitbook"], function(gitbook) { + gitbook.events.bind("page.change", function() { + initEditor(); + }) +}); // Changes the height of the editor to match its contents function updateEditorHeight() { @@ -60,9 +120,6 @@ function updateEditorHeight() { editor.resize(); }; -// Set initial size to match initial content -updateEditorHeight(); - function escapeHTML(unsafe) { return unsafe .replace(/&/g, "&") @@ -201,32 +258,3 @@ function parseProblems(lines) { return ranges; } - -// Registering handler for run button click -runButton.addEventListener("click", function(ev) { - resultDiv.style.display = "block"; - resultDiv.innerHTML = "Running..."; - - // clear previous markers, if any - markers.map(function(id) { editor.getSession().removeMarker(id); }); - - // Get the code, run the program - var program = editor.getValue(); - runProgram(program, handleResult); -}); - -// Registering handler for reset button click -resetButton.addEventListener("click", function(ev) { - editor.getSession().setValue(originalCode); - resultDiv.style.display = "none"; -}); - -// Highlight active line when focused -editor.on('focus', function() { - editor.setHighlightActiveLine(true); -}); - -// Don't when not -editor.on('blur', function() { - editor.setHighlightActiveLine(false); -}); From cf1cf8053c1f86a87913d8f55e67dee3d9f2b0b0 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Fri, 6 Jun 2014 16:42:34 -0500 Subject: [PATCH 3/7] Highlight code in the editor using the same colors used for static code --- node_modules/gitbook-plugin-rust-playpen/book/editor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node_modules/gitbook-plugin-rust-playpen/book/editor.js b/node_modules/gitbook-plugin-rust-playpen/book/editor.js index 0ef51c335c..6b6ff6ec28 100644 --- a/node_modules/gitbook-plugin-rust-playpen/book/editor.js +++ b/node_modules/gitbook-plugin-rust-playpen/book/editor.js @@ -60,7 +60,7 @@ function initEditor() // JS exists, display ACE editor activeCode.style.display = "block"; - editor.setTheme("ace/theme/chrome"); + editor.setTheme("ace/theme/tomorrow"); editor.getSession().setMode("ace/mode/rust"); editor.setShowPrintMargin(false); editor.renderer.setShowGutter(false); From 1f82acdcb9a584d509e089c665217a0924ef1e3d Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Fri, 6 Jun 2014 16:46:28 -0500 Subject: [PATCH 4/7] Change the editor height to always fit the contained code --- node_modules/gitbook-plugin-rust-playpen/book/editor.css | 2 +- node_modules/gitbook-plugin-rust-playpen/book/editor.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/node_modules/gitbook-plugin-rust-playpen/book/editor.css b/node_modules/gitbook-plugin-rust-playpen/book/editor.css index a6e072b515..348c6c44c7 100644 --- a/node_modules/gitbook-plugin-rust-playpen/book/editor.css +++ b/node_modules/gitbook-plugin-rust-playpen/book/editor.css @@ -13,7 +13,7 @@ padding: none; margin: none; width: 100%; - min-height: 340px; + min-height: 72px; font-size: 13px; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; } diff --git a/node_modules/gitbook-plugin-rust-playpen/book/editor.js b/node_modules/gitbook-plugin-rust-playpen/book/editor.js index 6b6ff6ec28..307f958b06 100644 --- a/node_modules/gitbook-plugin-rust-playpen/book/editor.js +++ b/node_modules/gitbook-plugin-rust-playpen/book/editor.js @@ -90,6 +90,8 @@ function initEditor() resultDiv.style.display = "none"; }); + editor.on('change', updateEditorHeight); + // Highlight active line when focused editor.on('focus', function() { editor.setHighlightActiveLine(true); From cece52e3439c314547d1878fafbfcf796053e800 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Fri, 6 Jun 2014 18:46:01 -0500 Subject: [PATCH 5/7] Fix buttons position --- node_modules/gitbook-plugin-rust-playpen/book/editor.css | 4 ++-- node_modules/gitbook-plugin-rust-playpen/book/editor.js | 8 +------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/node_modules/gitbook-plugin-rust-playpen/book/editor.css b/node_modules/gitbook-plugin-rust-playpen/book/editor.css index 348c6c44c7..2b6e16e5e8 100644 --- a/node_modules/gitbook-plugin-rust-playpen/book/editor.css +++ b/node_modules/gitbook-plugin-rust-playpen/book/editor.css @@ -1,8 +1,8 @@ -// the style here follows graydon/rust-www +/* the style here follows graydon/rust-www */ #active-code { position: relative; - display: none; + display: block; padding: 10px; border-radius: 4px; background-color: #FDFDFD; diff --git a/node_modules/gitbook-plugin-rust-playpen/book/editor.js b/node_modules/gitbook-plugin-rust-playpen/book/editor.js index 307f958b06..d62c231521 100644 --- a/node_modules/gitbook-plugin-rust-playpen/book/editor.js +++ b/node_modules/gitbook-plugin-rust-playpen/book/editor.js @@ -12,7 +12,6 @@ if (typeof String.prototype.startsWith != 'function') { var newLineRegex = /(?:\r\n|\r|\n)/g; // DOM items -var activeCode; var editorDiv; var resetButton; var runButton; @@ -41,10 +40,8 @@ var Range; // Original source code var originalCode; -function initEditor() -{ +function initEditor() { // Fetching DOM items - activeCode = document.getElementById("active-code"); editorDiv = document.getElementById("editor"); resetButton = document.getElementById("reset-code"); runButton = document.getElementById("run-code"); @@ -57,9 +54,6 @@ function initEditor() editor = ace.edit("editor"); Range = ace.require('ace/range').Range; - // JS exists, display ACE editor - activeCode.style.display = "block"; - editor.setTheme("ace/theme/tomorrow"); editor.getSession().setMode("ace/mode/rust"); editor.setShowPrintMargin(false); From db1741d9acd05ba90db23015a11869c0a32af3ab Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 7 Jun 2014 09:29:37 -0500 Subject: [PATCH 6/7] remove escaping test --- Makefile | 1 - check-line-length.sh | 1 - src/test.rs | 47 -------------------------------------------- src/update.rs | 3 --- 4 files changed, 52 deletions(-) delete mode 100644 src/test.rs diff --git a/Makefile b/Makefile index 55accc58dc..bdd60e3b0d 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,6 @@ clean: rm -rf stage test: - $(RUSTC) --test src/update.rs $(foreach src,$(srcs),$(RUSTC_NT) $(src) || exit;) ./check-line-length.sh diff --git a/check-line-length.sh b/check-line-length.sh index d61f226084..45c2c2b4c4 100755 --- a/check-line-length.sh +++ b/check-line-length.sh @@ -2,7 +2,6 @@ WHITELIST=( ./examples/lifetime/lifetime.rs - ./src/test.rs ) echo "Checking if any rust file has a line longer than 79 characters" diff --git a/src/test.rs b/src/test.rs deleted file mode 100644 index 0b2bc6f40b..0000000000 --- a/src/test.rs +++ /dev/null @@ -1,47 +0,0 @@ -mod escape { - use playpen; - - #[test] - fn hello() { - let inp = playpen::escape("// the main function -fn main() { - // print to the console - println!(\"Hello World!\"); -}"); - - let out = "%2F%2F%20the%20main%20function%0Afn%20main()%20%7B%0A%20%20%20%20%2F%2F%20print%20to%20the%20console%0A%20%20%20%20println!(%22Hello%20World!%22)%3B%0A%7D"; - - assert_eq!(format!("\n{}\n", inp), format!("\n{}\n", out)); - } - - #[test] - fn print() { - let inp = playpen::escape("fn main() { - // print! is like println! but without adding a newline at the end - print!(\"January has \"); - - // {} are placeholders for arguments that will be stringified - println!(\"{} days\", 31); - - // the positional arguments can be reused along the template - println!(\"{0}, this is {1}. {1}, this is {0}\", \"Alice\", \"Bob\"); - - // named arguments can also be used - println!(\"{subject} {verb} {predicate}\", - predicate=\"over the lazy dog\", - subject=\"the quick brown fox\", - verb=\"jumps\"); - - // special formatting can be specified in the placeholder after a `:` - println!(\"{} of {:t} people know binary, the other half don't\", 1, 2); - - // Error: you are missing an argument - //println!(\"My name is {0}, {1} {0}\", \"Bond\"); -}"); - - let out = "fn%20main()%20%7B%0A%20%20%20%20%2F%2F%20print!%20is%20like%20println!%20but%20without%20adding%20a%20newline%20at%20the%20end%0A%20%20%20%20print!(%22January%20has%20%22)%3B%0A%0A%20%20%20%20%2F%2F%20%7B%7D%20are%20placeholders%20for%20arguments%20that%20will%20be%20stringified%0A%20%20%20%20println!(%22%7B%7D%20days%22%2C%2031)%3B%0A%0A%20%20%20%20%2F%2F%20the%20positional%20arguments%20can%20be%20reused%20along%20the%20template%0A%20%20%20%20println!(%22%7B0%7D%2C%20this%20is%20%7B1%7D.%20%7B1%7D%2C%20this%20is%20%7B0%7D%22%2C%20%22Alice%22%2C%20%22Bob%22)%3B%0A%0A%20%20%20%20%2F%2F%20named%20arguments%20can%20also%20be%20used%0A%20%20%20%20println!(%22%7Bsubject%7D%20%7Bverb%7D%20%7Bpredicate%7D%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20predicate%3D%22over%20the%20lazy%20dog%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20subject%3D%22the%20quick%20brown%20fox%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20verb%3D%22jumps%22)%3B%0A%0A%20%20%20%20%2F%2F%20special%20formatting%20can%20be%20specified%20in%20the%20placeholder%20after%20a%20%60%3A%60%0A%20%20%20%20println!(%22%7B%7D%20of%20%7B%3At%7D%20people%20know%20binary%2C%20the%20other%20half%20don%27t%22%2C%201%2C%202)%3B%0A%0A%20%20%20%20%2F%2F%20Error%3A%20you%20are%20missing%20an%20argument%0A%20%20%20%20%2F%2Fprintln!(%22My%20name%20is%20%7B0%7D%2C%20%7B1%7D%20%7B0%7D%22%2C%20%22Bond%22)%3B%0A%7D"; - - assert_eq!(format!("\n{}\n", inp), format!("\n{}\n", out)); - } -} - diff --git a/src/update.rs b/src/update.rs index c7324c19e9..d6bedfbeae 100644 --- a/src/update.rs +++ b/src/update.rs @@ -12,9 +12,6 @@ mod file; mod markdown; mod playpen; -#[cfg(test)] -mod test; - fn main() { let examples = Example::get_list(); let (tx, rx) = channel(); From 262edf85f7e2f32558c6462737806f206e7265c9 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 7 Jun 2014 09:31:02 -0500 Subject: [PATCH 7/7] Whitelist line length of src/playpen.rs --- check-line-length.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/check-line-length.sh b/check-line-length.sh index 45c2c2b4c4..64b4bc5760 100755 --- a/check-line-length.sh +++ b/check-line-length.sh @@ -2,6 +2,7 @@ WHITELIST=( ./examples/lifetime/lifetime.rs + ./src/playpen.rs ) echo "Checking if any rust file has a line longer than 79 characters"