Skip to content

Schematic fixes #10388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 14, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class="sidenav"
fixedInViewport="true"
[attr.role]="isHandset ? 'dialog' : 'navigation'"
[mode]="isHandset ? 'over' : 'side'"
[mode]="(isHandset | async)!.matches ? 'over' : 'side'"
[opened]="!(isHandset | async)!.matches">
<mat-toolbar color="primary">Menu</mat-toolbar>
<mat-nav-list>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Observable } from 'rxjs/Observable';
class="sidenav"
fixedInViewport="true"
[attr.role]="isHandset ? 'dialog' : 'navigation'"
[mode]="isHandset ? 'over' : 'side'"
[mode]="(isHandset | async)!.matches ? 'over' : 'side'"
[opened]="!(isHandset | async)!.matches">
<mat-toolbar color="primary">Menu</mat-toolbar>
<mat-nav-list>
Expand Down
35 changes: 29 additions & 6 deletions schematics/shell/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import {Schema} from './schema';
import {materialVersion, cdkVersion, angularVersion} from '../utils/lib-versions';
import {getConfig, getAppFromConfig, AppConfig, CliConfig} from '../utils/devkit-utils/config';
import {addModuleImportToRootModule} from '../utils/ast';
import {addModuleImportToRootModule, getStylesPath} from '../utils/ast';
import {addHeadLink} from '../utils/html';
import {addPackageToPackageJson} from '../utils/package';
import {createCustomTheme} from './custom-theme';
Expand All @@ -27,7 +27,8 @@ export default function(options: Schema): Rule {
options && options.skipPackageJson ? noop() : addMaterialToPackageJson(options),
addThemeToAppStyles(options),
addAnimationRootConfig(),
addFontsToIndex()
addFontsToIndex(),
addBodyMarginToStyles()
]);
}

Expand Down Expand Up @@ -115,10 +116,32 @@ function addAnimationRootConfig() {
*/
function addFontsToIndex() {
return (host: Tree) => {
addHeadLink(host,
`<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">`);
addHeadLink(host,
`<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">`);
addHeadLink(host, `
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally prefer to not rely on newlines in template strings since it's not immediately obvious that they're intentional and someone might remove it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya, I agree. Got a better alternative? Just /n?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, just \n is obvious that it's intentional

<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">`);
addHeadLink(host, `
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">`);
return host;
};
}

/**
* Add 0 margin to body in styles.ext
*/
function addBodyMarginToStyles() {
return (host: Tree) => {
const stylesPath = getStylesPath(host);

const buffer = host.read(stylesPath);
if (!buffer) {
throw new SchematicsException(`Could not find file for path: ${stylesPath}`);
}

const src = buffer.toString();
const insertion = new InsertChange(stylesPath, src.length, `
body { margin: 0; }
`);
const recorder = host.beginUpdate(stylesPath);
recorder.insertLeft(insertion.pos, insertion.toAdd);
host.commitUpdate(recorder);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ export class <%= classify(name) %>DataSource extends DataSource<<%= classify(nam
this.sort.sortChange
];

// Set the paginators length
this.paginator.length = this.data.length;

return merge(...dataMutations).pipe(map(() => {
return this.getPagedData(this.getSortedData(this.data));
return this.getPagedData(this.getSortedData([...this.data]));
}));
}

Expand Down Expand Up @@ -91,7 +94,7 @@ export class <%= classify(name) %>DataSource extends DataSource<<%= classify(nam
}

return data.sort((a, b) => {
const isAsc = this.sort.direction == 'asc';
const isAsc = this.sort.direction === 'asc';
switch (this.sort.active) {
case 'name': return compare(a.name, b.name, isAsc);
case 'id': return compare(+a.id, +b.id, isAsc);
Expand Down
20 changes: 20 additions & 0 deletions schematics/utils/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,23 @@ export function getIndexHtmlPath(host: Tree) {
const app = getAppFromConfig(config, '0');
return normalize(`/${app.root}/${app.index}`);
}

/**
* Get the root stylesheet file.
*/
export function getStylesPath(host: Tree) {
const config = getConfig(host);
const app = getAppFromConfig(config, '0');
const styles = app.styles.find(style => {
const str = style.toString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const styles = app.styles.find(s => /styles\.(c|le|sc)ss/.test(s));

Copy link
Contributor Author

@amcdnl amcdnl Mar 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fancy ;P

return str === 'styles.css' ||
str === 'styles.less' ||
str === 'styles.scss';
});

if (!styles) {
throw new SchematicsException(`Could not find global styles.ext file.`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it valid to call your root style file something else entirely? Can we read the first stylesheet from the config? Would it be better to just no-op if we can't find it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well there is just a styles array where this lives which could include other stuff too. They could change it but I find it HIGHLY unlikely. I'll noop more gracefully.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I know if I was making a large app, I wouldn't want to have a file called styles.css because it's too vague, so I'd rename it to something like global-styles.css or browser-reset.css

}

return normalize(`/${app.root}/${styles}`);
}