Skip to content
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

yeoman generators #647

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions yeoman/generator-horizon-angular2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
How to run:

1. enter: npm install -g yo generator-horizon-angular2
2. run: yo horizon-angular2 from desired directory
19 changes: 19 additions & 0 deletions yeoman/generator-horizon-angular2/app/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

const chalk = require('chalk');
const yeoman = require('yeoman-generator');
const yosay = require('yosay');
module.exports = yeoman.generators.Base.extend({
prompting: function() {
// yeoman greeting
this.log(yosay(
`Yo! I\'m here to help build your
${chalk.bold.yellow('Horizon Angular2')} application.`
));
},
writing: {
app: function() {
this.directory('', '');
},
},
});
10 changes: 10 additions & 0 deletions yeoman/generator-horizon-angular2/app/templates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Horizon Chat example using Angular2

Running this example

1. Install Horizon: "npm install -g horizon"
2. Install RethinkDB: https://rethinkdb.com/docs/install
3. Prep the project "cd dist && npm i && cd .."
4. Run "horizon init" in this directory
5. Run "horizon serve --dev"
6. Open http://127.0.0.1:8181
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
///<reference path="./horizon.d.ts" />

import {Component} from '@angular/core';
import {ChatComponent} from './components/chat/chat.component'

@Component({
selector: 'my-app',
template: '<chat></chat>',
directives: [ChatComponent],
styles:[` chat{
margin: auto;
max-width: 800px;
width:100%;
display:block;

}
`]
})
export class AppComponent { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import {Component, OnInit} from '@angular/core';
import {ChatService} from './chat.service'

@Component({
selector: '<chat></chat>',
styles: [`
ul {
list-style-type: none;
padding:0;
}

.message {
height: 50px;
padding:5px;
}

.message img {
vertical-align:middle;
}
.message .text {
vertical-align:middle;
margin-left:5px;
font-size:20px;
}
.message .datetime {
color:darkgrey;
float:right;
}
form{

}
input {
width: 90%;
height: 50px;
font-size: 20px;
float: left;
padding: 10px;
}
button{
width:10%;
height: 50px;
}
`],
template: `<h1>Messages</h1>
<form>
<input [(ngModel)]="newMessage">
<button type="submit" (click)="addMessage(newMessage)">Send</button>
</form>
<ul>
<li *ngFor="let message of messages; let i = index" class="message">
<img height="50px" width="50px" src="{{message.url}}" />
<span> {{message.text}} </span>
<span class="datetime u-pull-right">
{{message.datetime}}
</span>
</li>
</ul>`,
providers:[ChatService]
})
export class ChatComponent implements OnInit {
newMessage = '';
messages = [];

constructor(private _chatService: ChatService) {

}
ngOnInit() {
this.getChats()
}

getChats = function () {
this._chatService
.getChats()
.subscribe((newMessages) => {
this.messages = [...newMessages];
});
}

addMessage = function (text) {
if (text) {
this._chatService
.sendChat(text)
.subscribe();
this.newMessage = '';
}
}




}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {Component, OnInit} from '@angular/core';
import {Observable} from 'rxjs'


export class ChatService {
horizon = Horizon();
chat = this.horizon('chat');
avatar_url = `http://api.adorable.io/avatars/50/${new Date().getMilliseconds()}.png`;


constructor() { }
getChats = function (): Observable<[any]> {
return this.chat
.order('datetime', 'descending')
.limit(8)
.watch()
}

sendChat = function (text: string): Observable<[any]> {
return this.chat.store({
text: text,
datetime: new Date(),
url: this.avatar_url,
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare var Horizon: any
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { bootstrap } from '@angular/platform-browser-dynamic';
import { AppComponent } from './app.component';

bootstrap(AppComponent);
31 changes: 31 additions & 0 deletions yeoman/generator-horizon-angular2/app/templates/dist/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!doctype html>
<html>

<head>
<title>Horizon Angular 2 chat example</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="//localhost:8181/horizon/horizon.js"></script>
<script type="text/javascript" src="/horizon/horizon.js"></script>

<!-- 1. Load libraries -->
<!-- IE required polyfills, in this exact order -->
<script src="node_modules/typescript/lib/typescript.js"></script>
<script src="node_modules/es6-shim/es6-shim.min.js"></script>

<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/reflect-metadata/Reflect.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>

<!-- 2. Configure SystemJS -->
<script src="systemjs.config.js"></script>
<script>
System.import('app').catch(function(err){ console.error(err); });
</script>
</head>
<!-- 3. Display the application -->

<body>
<my-app>Loading...</my-app>
</body>

</html>
26 changes: 26 additions & 0 deletions yeoman/generator-horizon-angular2/app/templates/dist/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "angular2-chat-app",
"version": "1.0.0",
"scripts": {
"postinstall": "typings install",
"typings": "typings"
},
"license": "ISC",
"dependencies": {
"@angular/common": "2.0.0-rc.1",
"@angular/compiler": "2.0.0-rc.1",
"@angular/core": "2.0.0-rc.1",
"@angular/http": "2.0.0-rc.1",
"@angular/platform-browser": "2.0.0-rc.1",
"@angular/platform-browser-dynamic": "2.0.0-rc.1",
"systemjs": "0.19.27",
"es6-shim": "^0.35.0",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.6",
"zone.js": "^0.6.12",
"typescript": "^1.8.9"
},
"devDependencies": {
"typings":"^0.8.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
(function(global) {

// map tells the System loader where to look for things
var map = {
'app': 'app', // 'dist',
'rxjs': 'node_modules/rxjs',
'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
'@angular': 'node_modules/@angular'
};
// packages tells the System loader how to load when no filename and/or no extension
var packages = {
'app': { main: 'main.ts', defaultExtension: 'ts' },
'rxjs': { defaultExtension: 'js' },
'angular2-in-memory-web-api': { defaultExtension: 'js' },
};
var packageNames = [
'@angular/common',
'@angular/compiler',
'@angular/core',
'@angular/http',
'@angular/platform-browser',
'@angular/platform-browser-dynamic',
'@angular/testing',
];
// add package entries for angular packages in the form '@angular/common': { main: 'index.js', defaultExtension: 'js' }
packageNames.forEach(function(pkgName) {
packages[pkgName] = { main: 'index.js', defaultExtension: 'js' };
});
var config = {
transpiler: 'typescript',
typescriptOptions: {
emitDecoratorMetadata: true
},
map: map,
packages: packages
}
System.config(config);
})(this);
17 changes: 17 additions & 0 deletions yeoman/generator-horizon-angular2/app/templates/dist/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules",
"typings/main",
"typings/main.d.ts"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ambientDependencies": {
"es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#7de6c3dd94feaeb21f20054b9f30d5dabc5efabd",
"jasmine": "github:DefinitelyTyped/DefinitelyTyped/jasmine/jasmine.d.ts#7de6c3dd94feaeb21f20054b9f30d5dabc5efabd"
}
}
5 changes: 5 additions & 0 deletions yeoman/generator-horizon-angular2/app/templates/schema.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[collections]

#
[rules]

27 changes: 27 additions & 0 deletions yeoman/generator-horizon-angular2/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "generator-horizon-angular2",
"version": "0.1.0",
"description": "Horizon angular2 chat app generator",
"main": "app/index.js",
"engines": {
"node": ">=0.10.0"
},
"keywords": [
"yeoman-generator",
"angular yeoman",
"angular2 yeoman",
"angularjs",
"angular",
"angularjs2",
"angular2",
"es6"
],
"preferGlobal": true,
"dependencies": {
"lodash": "^3.7.0",
"chalk": "^1.0.0",
"npm-check": "^3.2.10",
"yeoman-generator": "^0.19.2",
"yosay": "^1.0.2"
}
}
26 changes: 26 additions & 0 deletions yeoman/generator-horizon-schema/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
how to run:

1. run npm install -g yo generator-horizon-rulecreator form any directory
2. in the desired directory run : yo horizon-rulecreator

This generator helps users create schema files that the user can then implement.

Horizon’s permission system is based on a query whitelist. Any operation on a Horizon collection is disallowed
by default, unless there is a rule that allows the operation.

A whitelist rule has three properties that define which operations it covers:

1. A user group
2. A query template describing the type of operation
3. An optional validator function written in JavaScript that can be used to check the contents of the
accessed documents, or to implement more complex permission checks

You can use the special "default" group to create rules that apply to all users, authenticated or not. Or use
the "authenticated" group to cover authenticated users only.

```
[groups.GROUP_NAME.rules.RULE_NAME]
template = "QUERY_TEMPLATE"
# Optional:
validator = "VALIDATOR_FUNCTION"
```
Loading