Copy doc comments from Rust to JS (#265)

* backend comments complete

* better matching

* gen comments

* Add example

* Move test bindings gen to own fn

* move build step into build fn

* add fn to read js, refactor gen_bindings/test to allow for this

* Add comments test

* Update readmes

* add comments to travis

* fix broken tests

* +x on build.sh

* fix wbg cmd in build.sh

* Address fitzgen's comments
This commit is contained in:
Robert Masen
2018-06-15 11:20:56 -05:00
committed by Nick Fitzgerald
parent 3ad9bac599
commit 19d6cf1488
16 changed files with 555 additions and 59 deletions

View File

@ -0,0 +1,60 @@
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
extern crate wasm_bindgen;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
/// A user defined comment
pub struct Comment {
name: String,
comment: String,
/// The position this comment
/// should exist at
pub count: u32,
color: Color,
}
#[wasm_bindgen]
impl Comment {
#[wasm_bindgen(method)]
/// The name of the user who
/// posted this comment
pub fn name(&self) -> String {
self.name.clone()
}
#[wasm_bindgen(method)]
/// The content of this comment
pub fn comment(&self) -> String {
self.comment.clone()
}
#[wasm_bindgen(constructor)]
pub fn new(name: String, comment: String, count: u32) -> Comment {
let color = if count % 2 == 0 {
Color::Blue
} else {
Color::Pink
};
Comment {
name,
comment,
count,
color,
}
}
#[wasm_bindgen(method)]
/// What color should this comment be
pub fn color(&self) -> Color {
self.color.clone()
}
}
/// The border of a comment
#[wasm_bindgen]
#[derive(Clone)]
pub enum Color {
Blue,
Pink,
}