Skip to content

Commit 8746f5e

Browse files
committed
fix(visuals): using visual markers now
Makes everything evaluate faster, and is good enough as well. Besides, you don't have to think about whitespace too much, keeping things simpler is usually better
1 parent e96260b commit 8746f5e

4 files changed

Lines changed: 82 additions & 65 deletions

File tree

gen/youtube3/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ let mut hub = YouTube::new(hyper::Client::new(), auth);
9393
```
9494

9595
**TODO** Example calls - there should soon be a generator able to do that with proper inputs
96+
9697
## About error handling
9798

9899
## About Customization/Callbacks

gen/youtube3/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
//! ```
9393
//!
9494
//! **TODO** Example calls - there should soon be a generator able to do that with proper inputs
95+
//!
9596
//! ## About error handling
9697
//!
9798
//! ## About Customization/Callbacks
@@ -146,8 +147,8 @@ pub use cmn::{Hub, Resource, Part, ResponseResult, RequestResult, NestedType};
146147
/// // Provide your own `AuthenticatorDelegate` to adjust the way it operates and get feedback about what's going on
147148
/// // You probably want to bring in your own `TokenStorage` to persist tokens and retrieve them from storage.
148149
/// let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
149-
/// hyper::Client::new(),
150-
/// <MemoryStorage as Default>::default(), None);
150+
/// hyper::Client::new(),
151+
/// <MemoryStorage as Default>::default(), None);
151152
/// let mut hub = YouTube::new(hyper::Client::new(), auth);
152153
/// # }
153154
/// ```

src/mako/lib/lib.mako

Lines changed: 71 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<%! from util import (activity_split, put_and, md_italic, split_camelcase_s, canonical_type_name,
22
rust_test_fn_invisible, rust_doc_test_norun, rust_doc_comment, markdown_rust_block,
3-
unindent, indent) %>\
3+
unindent_first_by) %>\
44
<%namespace name="util" file="util.mako"/>\
55
66
## If rust-doc is True, examples will be made to work for rust doc tests. Otherwise they are set
77
## for github markdown.
8-
<%def name="docs(c, rust_doc=True)" filter="unindent">\
8+
###############################################################################################
9+
###############################################################################################
10+
<%def name="docs(c, rust_doc=True)">\
911
<%
1012
# fr == fattest resource, the fatter, the more important, right ?
1113
fr = None
@@ -17,86 +19,91 @@
1719
resource, activity = activity_split(an)
1820
amap.setdefault(resource, list()).append(activity)
1921
%>\
20-
# Features
22+
# Features
2123

22-
Handle the following *Resources* with ease ...
24+
Handle the following *Resources* with ease ...
2325

24-
% for r in sorted(amap.keys()):
25-
* ${split_camelcase_s(r)} (${put_and(md_italic(sorted(amap[r])))})
26-
% endfor
26+
% for r in sorted(amap.keys()):
27+
* ${split_camelcase_s(r)} (${put_and(md_italic(sorted(amap[r])))})
28+
% endfor
2729

28-
# Structure of this Library
30+
# Structure of this Library
2931

30-
The API is structured into the following primary items:
32+
The API is structured into the following primary items:
3133

32-
* **Hub**
33-
* a central object to maintain state and allow accessing all *Activities*
34-
* **Resources**
35-
* primary types that you can apply *Activities* to
36-
* a collection of properties and *Parts*
37-
* **Parts**
38-
* a collection of properties
39-
* never directly used in *Activities*
40-
* **Activities**
41-
* operations to apply to *Resources*
34+
* **Hub**
35+
* a central object to maintain state and allow accessing all *Activities*
36+
* **Resources**
37+
* primary types that you can apply *Activities* to
38+
* a collection of properties and *Parts*
39+
* **Parts**
40+
* a collection of properties
41+
* never directly used in *Activities*
42+
* **Activities**
43+
* operations to apply to *Resources*
4244

43-
Generally speaking, you can invoke *Activities* like this:
45+
Generally speaking, you can invoke *Activities* like this:
4446

45-
```Rust,ignore
46-
let r = hub.resource().activity(...).${api.terms.action}()
47-
```
47+
```Rust,ignore
48+
let r = hub.resource().activity(...).${api.terms.action}()
49+
```
4850

49-
Or specifically ...
51+
Or specifically ...
5052

51-
```ignore
53+
```ignore
5254
% for an, a in c.sta_map[fr.id].iteritems():
5355
<% resource, activity = activity_split(an) %>\
54-
let r = hub.${resource}().${activity}(...).${api.terms.action}()
56+
let r = hub.${resource}().${activity}(...).${api.terms.action}()
5557
% endfor
56-
```
58+
```
59+
60+
The `resource()` and `activity(...)` calls create [builders][builder-pattern]. The second one dealing with `Activities`
61+
supports various methods to configure the impending operation (not shown here). It is made such that all required arguments have to be
62+
specified right away (i.e. `(...)`), whereas all optional ones can be [build up][builder-pattern] as desired.
63+
The `${api.terms.action}()` method performs the actual communication with the server and returns the respective result.
5764

58-
The `resource()` and `activity(...)` calls create [builders][builder-pattern]. The second one dealing with `Activities`
59-
supports various methods to configure the impending operation (not shown here). It is made such that all required arguments have to be
60-
specified right away (i.e. `(...)`), whereas all optional ones can be [build up][builder-pattern] as desired.
61-
The `${api.terms.action}()` method performs the actual communication with the server and returns the respective result.
65+
# Usage (*TODO*)
6266

63-
# Usage (*TODO*)
67+
${'##'} Instantiating the Hub
6468

65-
${'##'} Instantiating the Hub
69+
${self.hub_usage_example(rust_doc)}\
6670

67-
${self.hub_usage_example(rust_doc) | indent}\
71+
**TODO** Example calls - there should soon be a generator able to do that with proper inputs
6872

69-
**TODO** Example calls - there should soon be a generator able to do that with proper inputs
70-
${'##'} About error handling
73+
${'##'} About error handling
7174

72-
${'##'} About Customization/Callbacks
75+
${'##'} About Customization/Callbacks
7376

74-
[builder-pattern]: http://en.wikipedia.org/wiki/Builder_pattern
75-
[google-go-api]: https://github.com/google/google-api-go-client
77+
[builder-pattern]: http://en.wikipedia.org/wiki/Builder_pattern
78+
[google-go-api]: https://github.com/google/google-api-go-client
7679
</%def>
7780

7881
## Sets up a hub ready for use. You must wrap it into a test function for it to work
7982
## Needs test_prelude.
80-
<%def name="test_hub(hub_type)" filter="unindent">\
81-
use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
82-
use std::default::Default;
83-
84-
use ${util.library_name()}::${hub_type};
85-
86-
// Get an ApplicationSecret instance by some means. It contains the `client_id` and `client_secret`,
87-
// among other things.
88-
let secret: ApplicationSecret = Default::default();
89-
// Instantiate the authenticator. It will choose a suitable authentication flow for you,
90-
// unless you replace `None` with the desired Flow
91-
// Provide your own `AuthenticatorDelegate` to adjust the way it operates and get feedback about what's going on
92-
// You probably want to bring in your own `TokenStorage` to persist tokens and retrieve them from storage.
93-
let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
94-
hyper::Client::new(),
95-
<MemoryStorage as Default>::default(), None);
96-
let mut hub = ${hub_type}::new(hyper::Client::new(), auth);\
83+
###############################################################################################
84+
###############################################################################################
85+
<%def name="test_hub(hub_type)">\
86+
use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
87+
use std::default::Default;
88+
89+
use ${util.library_name()}::${hub_type};
90+
91+
// Get an ApplicationSecret instance by some means. It contains the `client_id` and `client_secret`,
92+
// among other things.
93+
let secret: ApplicationSecret = Default::default();
94+
// Instantiate the authenticator. It will choose a suitable authentication flow for you,
95+
// unless you replace `None` with the desired Flow
96+
// Provide your own `AuthenticatorDelegate` to adjust the way it operates and get feedback about what's going on
97+
// You probably want to bring in your own `TokenStorage` to persist tokens and retrieve them from storage.
98+
let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
99+
hyper::Client::new(),
100+
<MemoryStorage as Default>::default(), None);
101+
let mut hub = ${hub_type}::new(hyper::Client::new(), auth);\
97102
</%def>
98103

99104
## You will still have to set the filter for your comment type - either nothing, or rust_doc_comment !
105+
###############################################################################################
106+
###############################################################################################
100107
<%def name="hub_usage_example(rust_doc=True)">\
101108
<%
102109
test_filter = rust_test_fn_invisible
@@ -114,11 +121,13 @@ ${self.test_hub(canonical_type_name(canonicalName))}\
114121
</%block>
115122
</%def>
116123

117-
<%def name="license()" filter="unindent">\
118-
# License
119-
The **${util.library_name()}** library was generated by ${put_and(copyright.authors)}, and is placed
120-
under the *${copyright.license_abbrev}* license.
121-
You can read the full text at the repository's [license file][repo-license].
124+
###############################################################################################
125+
###############################################################################################
126+
<%def name="license()">\
127+
# License
128+
The **${util.library_name()}** library was generated by ${put_and(copyright.authors)}, and is placed
129+
under the *${copyright.license_abbrev}* license.
130+
You can read the full text at the repository's [license file][repo-license].
122131
123-
[repo-license]: ${cargo.repo_base_url + 'LICENSE.md'}
132+
[repo-license]: ${cargo.repo_base_url + 'LICENSE.md'}
124133
</%def>

src/mako/lib/util.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import collections
33

44
re_linestart = re.compile('^', flags=re.MULTILINE)
5-
re_first_4_spaces = re.compile('^ ', flags=re.MULTILINE)
5+
re_first_4_spaces = re.compile('^ {1,4}', flags=re.MULTILINE)
66

77
USE_FORMAT = 'use_format_field'
88
TYPE_MAP = {'boolean' : 'bool',
@@ -48,6 +48,12 @@ def hash_comment(s):
4848
def unindent(s):
4949
return re_first_4_spaces.sub('', s)
5050

51+
# tabs: 1 tabs is 4 spaces
52+
def unindent_first_by(tabs):
53+
def unindent_inner(s):
54+
return re.sub("^ {1,%i}" % (tabs*4), '', s)
55+
return unindent_inner
56+
5157
# add 4 spaces to the beginning of a line.
5258
# useful if you have defs embedded in an unindent block - they need to counteract.
5359
# It's a bit itchy, but logical

0 commit comments

Comments
 (0)