work on create post

This commit is contained in:
AJ ONeal 2015-01-11 20:59:14 -07:00
부모 970bc1e33d
커밋 e9caff8e86
8개의 변경된 파일275개의 추가작업 그리고 50개의 파일을 삭제

2
app.js
파일 보기

@ -8,7 +8,7 @@ angular.module('myApp', [
'myApp.site',
'myApp.build',
'myApp.configure',
'myApp.create',
'myApp.post',
'myApp.version',
'myApp.services'
]).

파일 보기

@ -40,8 +40,8 @@
<ul style="padding-top: 9px;" class="nav navbar-nav">
<li><a href="#/authors">Authors</a></li>
<li><a href="#/site">Site</a></li>
<li><a href="#/post">Post</a></li>
<li><a href="#/build">Build</a></li>
<li><a href="#/create">Create Post</a></li>
</ul>
</div>
</div>
@ -111,7 +111,7 @@
<script src="./views/site/site.js"></script>
<script src="./views/configure/configure.js"></script>
<script src="./views/build/build.js"></script>
<script src="./views/create/create.js"></script>
<script src="./views/post/post.js"></script>
<script src="components/desirae/desirae.js"></script>
<script src="components/version/version.js"></script>
<script src="components/version/version-directive.js"></script>

파일 보기

@ -368,7 +368,21 @@
};
fsapi.putFiles = function (files) {
var body = { files: files };
var body = { files: files }
;
files.forEach(function (file) {
if (!file.contents || 'string' === typeof file.contents) {
return;
}
if (/\.json$/i.test(file.path)) {
file.contents = JSON.stringify(file.contents);
}
else if (/\.ya?ml$/i.test(file.path)) {
file.contents = exports.jsyaml.dump(file.contents);
}
});
body = JSON.stringify(body); // this is more or less instant for a few MiB of posts
return request.post('/api/fs/files', body).then(function (resp) {
var response = JSON.parse(resp)

파일 보기

@ -1,29 +0,0 @@
'use strict';
angular.module('myApp.create', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/create', {
templateUrl: 'views/create/create.html',
controller: 'CreateCtrl as Create'
});
}])
.controller('CreateCtrl', [function() {
var Desi = window.Desi || require('./deardesi').Desi
, scope = this
, desi = {}
;
Desi.init(desi).then(function () {
scope.run = function () {
return Desi.runDesi(desi).then(function () { Desi.otherStuff(); })
.catch(function (e) {
console.error('A great and uncatchable error has befallen the land. Read ye here for das detalles..');
console.error(e.message);
console.error(e);
throw e;
});
};
});
}]);

145
views/post/post.html Normal file
파일 보기

@ -0,0 +1,145 @@
<div class="container">
<div class="row">
<div class="page-header">
<h1>Write a Post</h1>
</div>
</div>
<form ng-submit="Post.upsert()" class="form-horizontal">
<div class="row">
<div class="col-lg-12">
<div class="well bs-component">
<fieldset>
<div class="form-group">
<label for="inputPostTitle" class="col-lg-2 control-label">Title</label>
<div class="col-lg-10">
<input
required
ng-model="Post.selected.title"
ng-change="Post.onChange()"
type="text"
class="form-control"
id="inputPostTitle"
placeholder="i.e. My First Post"
>
</div>
</div>
<!--
<div class="form-group">
<label for="inputPostUuid" class="col-lg-2 control-label">UUID</label>
<div class="col-lg-10">
<input
disabled
type="text"
class="form-control"
id="inputPostUuid"
placeholder="ERROR"
>
</div>
</div>
-->
<div class="form-group">
<label for="textAreaPost" class="col-lg-2 control-label">Post</label>
<div class="col-lg-10">
<textarea
ng-model="Post.selected.post.body"
ng-change="Post.onChange()"
class="form-control"
rows="20"
id="textAreaPost"
placeholder="i.e. I Don't Know Anything About the Gold Standard... But I Do Love Little Kittens!"
></textarea>
<span class="help-block">Put your lovely post here, in github-flavored markdown!</span>
</div>
</div>
<div class="form-group">
<label for="textAreaYaml" class="col-lg-2 control-label">Frontmatter</label>
<div class="col-lg-10">
<textarea
ng-change="Post.onFrontmatterChange()"
ng-model="Post.selected.post.frontmatter"
class="form-control"
rows="5"
id="textAreaYaml"></textarea>
</div>
</div>
<!--
<div class="form-group">
<label for="select" class="col-lg-2 control-label">Selects</label>
<div class="col-lg-10">
<select class="form-control" id="select">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</div>
TODO theme -->
<!-- TODO layout -->
<!-- TODO swatch -->
<!--
<div class="form-group">
<label for="inputPostDate" class="col-lg-2 control-label">Date</label>
<div class="col-lg-10">
<input
disabled
type="text"
class="form-control"
id="inputPostDate"
ng-placeholder="i.e. {{Post.year}}-{{Post.month}}-{{Post.day}} {{Post.hour}}:{{Post.minute}}"
>
</div>
</div>
-->
<!--
<div class="form-group">
<label for="inputPostPermalink" class="col-lg-2 control-label">Permalink</label>
<div class="col-lg-10">
<input
required
type="text"
class="form-control"
id="inputPostPermalink"
placeholder="i.e. /articles/my-first-post.html"
>
</div>
</div>
-->
<div class="form-group">
<label for="select" class="col-lg-2 control-label">Format</label>
<div class="col-lg-10">
<select
ng-model="Post.selected.format"
ng-change="Post.onChange()"
class="form-control"
id="select">
<option value="html">HTML</option>
<option selected="selected" value="md">Markdown</option>
<option disabled="disabled" value="jade">Jade (Not Implemented)</option>
</select>
<!--div class="checkbox">
<label>
<input type="checkbox"> Draft
</label>
</div-->
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<!--button class="btn btn-default">Save Draft</button-->
<button
type="submit"
class="btn btn-primary pull-right"
>Publish</button>
</div>
</div>
</fieldset>
<div id="source-button" class="btn btn-primary btn-xs" style="display: none;">&lt; &gt;</div></div>
</div>

98
views/post/post.js Normal file
파일 보기

@ -0,0 +1,98 @@
'use strict';
angular.module('myApp.post', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/post', {
templateUrl: 'views/post/post.html',
controller: 'PostCtrl as Post'
});
}])
.controller('PostCtrl'
, ['$scope', '$location', '$timeout', 'Desirae'
, function ($scope, $location, $timeout, Desirae) {
var scope = this
;
function init() {
console.log('desi loading');
Desirae.meta().then(function (desi) {
scope.blogdir = desi.blogdir.path.replace(/^\/(Users|home)\/[^\/]+\//, '~/');
scope.site = desi.site;
}).catch(function (e) {
window.alert("An Error Occured. Most errors that occur in the init phase are parse errors in the config files or permissions errors on files or directories, but check the error console for details.");
console.error(e);
throw e;
});
}
scope.selected = {
title: ""
, format: 'md'
, description: ""
, permalink: "/article/new.md"
, post: {
yml: {
title: ""
, description: ""
, uuid: window.uuid.v4()
, date: "YYYY-MM-DD HH:MM pm" // TODO desirae
, permalink: "/article/new.md"
, categories: []
, tags: []
, theme: null
, layout: null
, swatch: null
}
}
};
scope.selected.post.frontmatter = window.jsyaml.dump(scope.selected.post.yml);
scope.onChange = function () {
scope.selected.post.yml.title = scope.selected.title;
scope.selected.post.yml.description = scope.selected.description;
if (scope.selected.permalink === scope.selected.post.yml.permalink) {
scope.selected.permalink = '/articles/' + scope.selected.title.toLowerCase()
.replace(/["']/g, '')
.replace(/\W/g, '-')
+ '.' + scope.selected.format
;
scope.selected.post.yml.permalink = scope.selected.permalink;
}
scope.selected.post.frontmatter = window.jsyaml.dump(scope.selected.post.yml);
};
scope.onFrontmatterChange = function () {
scope.selected.post.yml = window.jsyaml.load(scope.selected.post.frontmatter);
scope.selected.title = scope.selected.post.yml.title;
scope.selected.description = scope.selected.post.yml.description;
};
$timeout(function () {
if (scope.selected && scope.selected.date === scope.selected.post.yml.date) {
scope.selected.date = scope.selected.post.yml.date = new Date().toISOString();
}
scope.onChange();
}, 60 * 1000);
scope.upsert = function () {
console.log(scope.selected.format)
var files = []
;
files.push({ path: 'site.yml', contents: scope.site });
console.log(files);
Desirae.putFiles(files).then(function (results) {
console.log('TODO check for error');
console.log(results);
$location.path('/post');
}).catch(function (e) {
console.error(scope.site);
console.error(e);
window.alert("Error Nation! :/");
throw e;
});
};
init();
}]);

파일 보기

@ -19,6 +19,7 @@
<div class="col-lg-9">
<input
ng-model="Site.site.title"
required
type="text" class="form-control" id="inputBlogTitle" placeholder="My Awesome Blog">
</div>
</div>
@ -39,7 +40,9 @@
<label for="inputSiteDesc" class="col-lg-3 control-label">Description
<small>(<span ng-bind="Site.site.description.length || 0"></span>/140)</small></label>
<div class="col-lg-9">
<textarea ng-model="Site.site.description"
<textarea
ng-model="Site.site.description"
required
class="form-control" id="inputSiteDesc" placeholder="i.e. For tips and tricks for try-hard ethical master cleanses, 3 wolf moons on Tumblr, disruptive lo-fi, preserving narwhals and eating kale chips, etc. YOLO."></textarea>
</div>
</div>
@ -69,6 +72,7 @@
<label for="inputProdHost" class="col-lg-3 control-label">Base URL</label>
<div class="col-lg-9">
<input ng-model="Site.site.base_url"
required
placeholder="i.e. https://example.com in https://example.com/myblog"
type="url"
class="form-control"
@ -81,7 +85,8 @@
<label for="inputProdBase" class="col-lg-3 control-label">Base Path</label>
<div class="col-lg-9">
<input ng-model="Site.site.base_path"
placeholder="i.e. /blog in https://example.com/blog"
required
placeholder="i.e. / for blog.test.com or /blog for test.com/blog"
type="text"
class="form-control"
id="inputProdBase">
@ -92,7 +97,7 @@
<label for="inputProdOutput" class="col-lg-3 control-label">Output Path</label>
<div class="col-lg-9">
<input
ng-value="Site.blogdir + '/compiled'"
ng-value="Site.blogdir + '/compiled'"
type="text" class="form-control" id="inputProdOutput" disabled>
</div>
</div>

파일 보기

@ -9,7 +9,7 @@ angular.module('myApp.site', ['ngRoute'])
});
}])
.controller('SiteCtrl', ['$scope', 'Desirae', function($scope, Desirae) {
.controller('SiteCtrl', ['$scope', '$location', 'Desirae', function ($scope, $location, Desirae) {
var scope = this
;
@ -27,26 +27,18 @@ angular.module('myApp.site', ['ngRoute'])
}
scope.upsert = function () {
console.log('yolo!');
return;
var author = scope.selectedAuthor
, files = []
, filename = author.filename
var files = []
;
delete author.filename;
if ('new' !== filename && filename !== author.handle) {
files.push({ path: 'authors/' + filename + '.yml', contents: '', delete: true });
}
files.push({ path: 'authors/' + author.handle + '.yml', contents: window.jsyaml.dump(author) });
files.push({ path: 'site.yml', contents: scope.site });
console.log(files);
Desirae.putFiles(files).then(function (results) {
console.log('updated author', results);
console.log('TODO check for error');
console.log(results);
$location.path('/post');
}).catch(function (e) {
author.filename = filename;
console.error(scope.site);
console.error(e);
window.alert("Error Nation! :/");
throw e;