Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Adding new ui
Browse files Browse the repository at this point in the history
  • Loading branch information
tomusdrw committed Sep 21, 2016
1 parent f1f8876 commit a0b2f7e
Show file tree
Hide file tree
Showing 34 changed files with 1,033 additions and 23 deletions.
24 changes: 18 additions & 6 deletions Cargo.lock

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

31 changes: 31 additions & 0 deletions dapps/js-glue/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[package]
description = "Base Package for all Parity built-in dapps"
name = "parity-dapps-glue"
version = "1.4.0"
license = "GPL-3.0"
authors = ["Ethcore <[email protected]"]
build = "build.rs"

[build-dependencies]
quasi_codegen = { version = "0.11", optional = true }
syntex = { version = "0.33", optional = true }

[dependencies]
glob = { version = "0.2.11" }
mime_guess = { version = "1.6.1" }
aster = { version = "0.17", default-features = false }
quasi = { version = "0.11", default-features = false }
quasi_macros = { version = "0.11", optional = true }
syntex = { version = "0.33", optional = true }
syntex_syntax = { version = "0.33", optional = true }
clippy = { version = "0.0.90", optional = true }

[features]
dev = ["clippy"]
default = ["with-syntex"]
nightly = ["quasi_macros"]
nightly-testing = ["clippy"]
with-syntex = ["quasi/with-syntex", "quasi_codegen", "quasi_codegen/with-syntex", "syntex", "syntex_syntax"]
use-precompiled-js = []


65 changes: 65 additions & 0 deletions dapps/js-glue/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Parity Dapps (JS-glue)

Code generator to simplify creating a built-in Parity Dapp

# How to create new builtin Dapp.
1. Clone this repository.

```bash
$ git clone https://github.com/ethcore/parity.git
```

1. Create a new directory for your Dapp. (`./myapp`)

```bash
$ mkdir -p ./parity/dapps/myapp/src/web
```

1. Copy your frontend files to `./dapps/myapp/src/web` (bundled ones)

```bash
$ cp -r ./myapp-src/* ./parity/dapps/myapp/src/web
```

1. Instead of creating `web3` in your app. Load (as the first script tag in `head`):

```html
<script src="/parity-utils/inject.js"></script>
```

The `inject.js` script will create global `web3` instance with proper provider that should be used by your dapp.

1. Create `./parity/dapps/myapp/Cargo.toml` with you apps details. See example here: [parity-status Cargo.toml](https://github.com/ethcore/parity-ui/blob/master/status/Cargo.toml).

```bash
$ git clone https://github.com/ethcore/parity-ui.git
$ cd ./parity-ui/
$ cp ./home/Cargo.toml ../parity/dapps/myapp/Cargo.toml
$ cp ./home/build.rs ../parity/dapps/myapp/build.rs
$ cp ./home/src/lib.rs ../parity/dapps/myapp/src/lib.rs
$ cp ./home/src/lib.rs.in ../parity/dapps/myapp/src/lib.rs.in
# And edit the details of your app
$ vim ../parity/dapps/myapp/Cargo.toml # Edit the details
$ vim ./parity/dapps/myapp/src/lib.rs.in # Edit the details
```
# How to include your Dapp into `Parity`?
1. Edit `dapps/Cargo.toml` and add dependency to your application (it can be optional)

```toml
# Use git repo and version
parity-dapps-myapp = { path="./myapp" }
```

1. Edit `dapps/src/apps.rs` and add your application to `all_pages` (if it's optional you need to specify two functions - see `parity-dapps-wallet` example)

1. Compile parity.

```bash
$ cargo build --release # While inside `parity`
```

1. Commit the results.

```bash
$ git add myapp && git commit -am "My first Parity Dapp".
```
45 changes: 45 additions & 0 deletions dapps/js-glue/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.


#[cfg(feature = "with-syntex")]
mod inner {
extern crate syntex;
extern crate quasi_codegen;

use std::env;
use std::path::Path;

pub fn main() {
let out_dir = env::var_os("OUT_DIR").unwrap();
let mut registry = syntex::Registry::new();
quasi_codegen::register(&mut registry);

let src = Path::new("src/lib.rs.in");
let dst = Path::new(&out_dir).join("lib.rs");

registry.expand("", &src, &dst).unwrap();
}
}

#[cfg(not(feature = "with-syntex"))]
mod inner {
pub fn main() {}
}

fn main() {
inner::main();
}
66 changes: 66 additions & 0 deletions dapps/js-glue/src/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

#[cfg(feature = "with-syntex")]
pub mod inner {
use syntex;
use codegen;
use syntax::{ast, fold};
use std::env;
use std::path::Path;

fn strip_attributes(krate: ast::Crate) -> ast::Crate {
/// Helper folder that strips the serde attributes after the extensions have been expanded.
struct StripAttributeFolder;

impl fold::Folder for StripAttributeFolder {
fn fold_attribute(&mut self, attr: ast::Attribute) -> Option<ast::Attribute> {
match attr.node.value.node {
ast::MetaItemKind::List(ref n, _) if n == &"webapp" => { return None; }
_ => {}
}

Some(attr)
}

fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac {
fold::noop_fold_mac(mac, self)
}
}

fold::Folder::fold_crate(&mut StripAttributeFolder, krate)
}

pub fn register(reg: &mut syntex::Registry) {
reg.add_attr("feature(custom_derive)");
reg.add_attr("feature(custom_attribute)");

reg.add_decorator("derive_WebAppFiles", codegen::expand_webapp_implementation);
reg.add_post_expansion_pass(strip_attributes);
}

pub fn generate() {
let out_dir = env::var_os("OUT_DIR").unwrap();
let mut registry = syntex::Registry::new();
register(&mut registry);

let src = Path::new("src/lib.rs.in");
let dst = Path::new(&out_dir).join("lib.rs");

registry.expand("", &src, &dst).unwrap();
}
}

#[cfg(not(feature = "with-syntex"))]
pub mod inner {
use codegen;

pub fn register(reg: &mut rustc_plugin::Registry) {
reg.register_syntax_extension(
syntax::parse::token::intern("derive_WebAppFiles"),
syntax::ext::base::MultiDecorator(
Box::new(codegen::expand_webapp_implementation)));

reg.register_attribute("webapp".to_owned(), AttributeType::Normal);
}

pub fn generate() {}
}
Loading

0 comments on commit a0b2f7e

Please sign in to comment.