Skip to content

Commit 710f208

Browse files
authored
Merge pull request #473 from integer32llc/categorization
Add Categorization!
2 parents 25f7342 + bffd16a commit 710f208

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1393
-215
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ env_logger = "0.3"
3535
rustc-serialize = "0.3"
3636
license-exprs = "^1.3"
3737
dotenv = "0.8.0"
38+
toml = "0.2"
3839

3940
conduit = "0.8"
4041
conduit-conditional-get = "0.8"

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,21 @@ follows:
123123
```
124124
cargo test
125125
```
126+
127+
## Categories
128+
129+
The list of categories available on crates.io is stored in
130+
`src/categories.toml`. To propose adding, removing, or changing a category,
131+
send a pull request making the appropriate change to that file as noted in the
132+
comment at the top of the file. Please add a description that will help others
133+
to know what crates are in that category.
134+
135+
For new categories, it's helpful to note in your PR description examples of
136+
crates that would fit in that category, and describe what distinguishes the new
137+
category from existing categories.
138+
139+
After your PR is accepted, the next time that crates.io is deployed the
140+
categories will be synced from this file.
126141
127142
## Deploying & Using a Mirror
128143

app/adapters/category-slug.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import ApplicationAdapter from './application';
2+
import Ember from 'ember';
3+
4+
export default ApplicationAdapter.extend({
5+
pathForType(modelName) {
6+
var decamelized = Ember.String.underscore(
7+
Ember.String.decamelize(modelName)
8+
);
9+
return Ember.String.pluralize(decamelized);
10+
}
11+
});

app/controllers/categories.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import Ember from 'ember';
2+
import PaginationMixin from '../mixins/pagination';
3+
4+
const { computed } = Ember;
5+
6+
export default Ember.Controller.extend(PaginationMixin, {
7+
queryParams: ['page', 'per_page', 'sort'],
8+
page: '1',
9+
per_page: 10,
10+
sort: 'alpha',
11+
12+
totalItems: computed.readOnly('model.meta.total'),
13+
14+
currentSortBy: computed('sort', function() {
15+
return (this.get('sort') === 'crates') ? '# Crates' : 'Alphabetical';
16+
}),
17+
});

app/controllers/category/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import Ember from 'ember';
2+
import PaginationMixin from '../../mixins/pagination';
3+
4+
const { computed } = Ember;
5+
6+
export default Ember.Controller.extend(PaginationMixin, {
7+
queryParams: ['page', 'per_page', 'sort'],
8+
page: '1',
9+
per_page: 10,
10+
sort: 'downloads',
11+
12+
totalItems: computed.readOnly('model.meta.total'),
13+
14+
currentSortBy: computed('sort', function() {
15+
return (this.get('sort') === 'downloads') ? 'Downloads' : 'Alphabetical';
16+
}),
17+
});

app/controllers/crate/version.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default Ember.Controller.extend({
1919
currentVersion: computed.alias('model'),
2020
requestedVersion: null,
2121
keywords: computed.alias('crate.keywords'),
22+
categories: computed.alias('crate.categories'),
2223

2324
sortedVersions: computed.readOnly('crate.versions'),
2425

@@ -49,6 +50,7 @@ export default Ember.Controller.extend({
4950
}),
5051

5152
anyKeywords: computed.gt('keywords.length', 0),
53+
anyCategories: computed.gt('categories.length', 0),
5254

5355
currentDependencies: computed('currentVersion.dependencies', function() {
5456
var deps = this.get('currentVersion.dependencies');

app/models/category-slug.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import DS from 'ember-data';
2+
3+
export default DS.Model.extend({
4+
slug: DS.attr('string'),
5+
});

app/models/category.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import DS from 'ember-data';
2+
3+
export default DS.Model.extend({
4+
category: DS.attr('string'),
5+
slug: DS.attr('string'),
6+
description: DS.attr('string'),
7+
created_at: DS.attr('date'),
8+
crates_cnt: DS.attr('number'),
9+
10+
subcategories: DS.attr(),
11+
12+
crates: DS.hasMany('crate', { async: true })
13+
});

app/models/crate.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default DS.Model.extend({
2020
owners: DS.hasMany('users', { async: true }),
2121
version_downloads: DS.hasMany('version-download', { async: true }),
2222
keywords: DS.hasMany('keywords', { async: true }),
23+
categories: DS.hasMany('categories', { async: true }),
2324
reverse_dependencies: DS.hasMany('dependency', { async: true }),
2425

2526
follow() {

0 commit comments

Comments
 (0)