Skip to content

Commit

Permalink
feat(mako): now sets up entire project structure
Browse files Browse the repository at this point in the history
That way, we have a common library to pull in from the main repository,
and a space for testing new code (in a partial implementation).

Next there will be generated object structures.
  • Loading branch information
Byron committed Mar 2, 2015
1 parent 317554a commit 475163e
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 14 deletions.
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@
# This library is just to try out the code that should ultimately go into the code generator !
[package]

name = "youtube3-dev"
name = "cmn"
version = "0.0.1"
authors = ["Sebastian Thiel <[email protected]>"]
description = "A library to facilitate interacting with your youtube account"
repository = "https://github.com/Byron/google-apis-rs"
license = "MIT"
keywords = ["youtube", "google", "protocol", "not-for-use"]

[lib]
# The common code, used by all generated implementations
name = "cmn"
path = "src/rust/lib.rs"

[dependencies]
# Just to get hyper to work !
openssl = "= 0.4.3"
Expand Down
7 changes: 4 additions & 3 deletions etc/api/shared.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Contains values shared among all API implementations
directories:
# directory under which all generated sources should reside
output: lib
output: gen
# how to get from `output` back to common library
common: ../
common: ..
# where are all the API meta files
api_base: etc/api
# all mako source files
Expand All @@ -18,7 +18,8 @@ api:
- source: README.md
- source: LICENSE.md
- source: cargo.toml
# output_dir: optional - not there if unset
- source: lib.rs
output_dir: src
cargo:
build_version: "0.0.1"
repo_base_url: https://github.com/Byron/google-apis-rs
Expand Down
3 changes: 3 additions & 0 deletions src/mako/cargo.toml.mako
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@ hyper = "*"
rustc-serialize = "*"
yup-oauth2 = "*"
[dependencies.cmn]
path = "${directories.common}/.."
[dev-dependencies]
yup-hyper-mock = "*"
2 changes: 1 addition & 1 deletion src/mako/deps.mako
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
api_name = util.library_name(a.name, a.version)
api_clean = api_name + '-clean'
# source, destination of individual output files
sds = [(directories.mako_src + '/' + i.source + '.mako', gen_root + i.get('output_dir', '') + '/' + i.source)
sds = [(directories.mako_src + '/' + i.source + '.mako', gen_root + '/' + i.get('output_dir', '') + '/' + i.source)
for i in api.templates]
api_json = directories.api_base + '/' + a.name + '/' + a.version + '/' + a.name + '-api.json'
api_json_inputs = api_json + " $(API_SHARED_INFO)"
Expand Down
9 changes: 9 additions & 0 deletions src/mako/lib.rs.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<% import util %>\
<%namespace name="lib" file="lib/lib.mako"/>\
<%namespace name="mutil" file="lib/util.mako"/>\
<%block filter="util.rust_module_doc_comment">\
<%lib:docs />\
</%block>
extern crate cmn;
extern crate "rustc-serialize" as rustc_serialize;
extern crate "yup-oauth2" as oauth2;
3 changes: 3 additions & 0 deletions src/mako/lib/lib.mako
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<%! import util %>\
<%namespace name="util" file="lib/util.mako"/>\
<%def name="docs()">\
TODO: Library level fully fledged documentation, incuding **summary** and **usage**.
And another line, for testing
</%def>
<%def name="license()">\
Expand Down
12 changes: 7 additions & 5 deletions src/mako/lib/util.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import re
re_linestart = re.compile('^', flags=re.MULTILINE)

# rust module doc comment filter
def rmdc(s):
return '//! ' + s
def rust_module_doc_comment(s):
return re_linestart.sub('//! ', s)

# rust doc comment filter
def rdc(s):
return '/// ' + s
def rust_doc_comment(s):
return re_linestart.sub('/// ', s)

# Expects v to be 'v\d+', throws otherwise
def to_api_version(v):
Expand All @@ -22,7 +24,7 @@ def put_and(l):

# escape each string in l with "s" and return the new list
def estr(l):
return ["%s" % i for i in l]
return ['"%s"' % i for i in l]

# build a full library name (non-canonical)
def library_name(name, version):
Expand Down
File renamed without changes.
7 changes: 3 additions & 4 deletions src/lib.rs → src/rust/dev/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
//! # // TODO - generate !
//! # }
//! ```
extern crate hyper;
extern crate "rustc-serialize" as rustc_serialize;
extern crate "yup-oauth2" as oauth2;

use std::marker::PhantomData;
use std::borrow::BorrowMut;
use std::cell::RefCell;

use hyper;
use oauth2;

mod common;
pub mod videos;

Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions src/rust/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//! library with code shared by all generated implementations
extern crate hyper;
extern crate "rustc-serialize" as rustc_serialize;
extern crate "yup-oauth2" as oauth2;

/// This module is for testing only, its code is used in mako templates
#[cfg(test)]
mod dev;

0 comments on commit 475163e

Please sign in to comment.