Skip to content

Commit 6c0722c

Browse files
author
Jeff Verkoeyen
committed
[Catalog] Add README.
Reviewers: #material_components_ios_owners, ajsecord, randallli, junius Reviewed By: #material_components_ios_owners, ajsecord, randallli, junius Projects: #material_components_ios Differential Revision: http://codereview.cc/D123
1 parent 1b61971 commit 6c0722c

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

catalog/MDCCatalog.xcworkspace/contents.xcworkspacedata

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

catalog/README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Catalog by convention
2+
3+
This app is dynamically generated by taking advantage of CocoaPods wildcards. The Podfile for the
4+
catalog adds all Material components. It also adds any example source that matches a wildcard like
5+
`components/*/examples/*.{h,m,swift}`. Check out `material-components-ios-catalog.podspec` for the
6+
most up-to-date paths.
7+
8+
At runtime, the app enumerates all instances of UIViewController that respond to the
9+
`+catalogHierarchy` class method. This method is expected to return an array of strings that define
10+
the "breadcrumbs" for the view controller in the app.
11+
12+
The app uses the aggregate of these breadcrumbs to build a navigation tree, with each node either
13+
representing a specific UIViewController (an example) or a list of other nodes.
14+
15+
## Building the app
16+
17+
We use CocoaPods to manage the dependencies of this app. To generate the dependent projects, run
18+
the following within the `catalog/` directory of this repo:
19+
20+
pod install
21+
22+
This will update the MDCCatalog.xcworkspace.
23+
24+
Open the workspace and ensure that the "MDCCatalog" target is selected.
25+
26+
Build and run the app.
27+
28+
## Adding examples
29+
30+
Let's build a hypothetical example for the "Ink" component.
31+
32+
The first step is to create a source file. This can be either a .m or a .swift; whichever you
33+
prefer. Place this source file in the component's `examples/` directory, like so:
34+
35+
> View controller names must be globally-unique across every component's example set. An easy way to
36+
> ensure this is to prefix the controller with the name of the component.
37+
38+
components/Ink/examples/InkDemoViewController.m
39+
40+
Note that, like unit tests, you likely won't need to create a .h file for your example.
41+
42+
You can now create the view controller class.
43+
44+
#import <UIKit/UIKit.h>
45+
46+
@interface InkDemoViewController : UIViewController
47+
@end
48+
49+
@implementation InkDemoViewController
50+
51+
// TODO: Support other categorizational methods.
52+
+ (NSArray *)catalogHierarchy {
53+
return @[ @"Ink", @"README demo" ];
54+
}
55+
56+
@end
57+
58+
The `catalogHierarchy` method is the mechanism by which you define *where* the example lives in the
59+
catalog app. It is easiest to think of the values as a list of breadcrumbs.
60+
61+
To add the example to the Catalog app, simply run pod install in the catalog/ directory again:
62+
63+
catalog/ $ pod install
64+
65+
Build and run and you'll see your example listed in the app's hierarchy.

0 commit comments

Comments
 (0)