diff --git a/lib/index.coffee b/lib/index.coffee
index 1a91b4367..f3108783a 100644
--- a/lib/index.coffee
+++ b/lib/index.coffee
@@ -20,6 +20,8 @@ taxonomiesModule = require './taxonomies/index.js'
filtersModule = require './filters/index.js'
directivesModule = require './directives/index.js'
languageModule = require './language/index.js'
+templatesModule = require './templates/index.js'
+overwriteModule = require '../config/index.js'
# Style entry point
require './scss/bootstrap'
@@ -42,7 +44,6 @@ module.exports = app = angular.module 'wordpress-hybrid-client', [
authorsModule
languageModule
require('./bookmark/bookmark.module').name
- require('./post/post.module').name
require('./menu/menu.module').name
require('./cordova/cordova.module').name
require('./params/params.module').name
@@ -52,6 +53,8 @@ module.exports = app = angular.module 'wordpress-hybrid-client', [
require('./syntaxHighlighter/syntaxHighlighter.module').name
require('./init/init.module').name
directivesModule
+ templatesModule
+ overwriteModule
]
app.config ($stateProvider, $urlRouterProvider) ->
diff --git a/lib/pages/config.js b/lib/pages/config.js
index 0636ab8f3..714473ad5 100644
--- a/lib/pages/config.js
+++ b/lib/pages/config.js
@@ -6,7 +6,7 @@ export default function($stateProvider) {
url: "/pages",
views: {
'content': {
- template: require("./pages.html"),
+ templateProvider: ($templateCache) => $templateCache.get('module/pages.html'),
controller: "WPHCPagesController as pagesCtrl"
}
}
@@ -14,7 +14,7 @@ export default function($stateProvider) {
url: "/:id",
views: {
'content@public': {
- template: require("./page.html"),
+ templateProvider: ($templateCache) => $templateCache.get('module/page.html'),
controller: "WPHCPageController as pageCtrl"
}
}
diff --git a/lib/pages/page.controller.js b/lib/pages/page.controller.js
index b1af74399..545ec41ff 100644
--- a/lib/pages/page.controller.js
+++ b/lib/pages/page.controller.js
@@ -7,7 +7,6 @@ export default class extends AbstractItem {
super($injector, $scope);
this.setType('page');
- // this.setTitle($filter('translate')('pages.title'));
this.setService($WPHCPage);
}
}
diff --git a/lib/post/post.config.coffee b/lib/post/post.config.coffee
deleted file mode 100644
index b7f25dfa5..000000000
--- a/lib/post/post.config.coffee
+++ /dev/null
@@ -1,10 +0,0 @@
-module.exports = angular.module('wordpress-hybrid-client.post').config ($stateProvider, $urlRouterProvider) ->
- $stateProvider
- .state 'public.post',
- url: "/post/:id"
- params:
- post: null
- views:
- 'content':
- template: require "./post"
- controller: "WPHCPostController as post"
diff --git a/lib/post/post.controller.coffee b/lib/post/post.controller.coffee
deleted file mode 100644
index 4d95d452d..000000000
--- a/lib/post/post.controller.coffee
+++ /dev/null
@@ -1,19 +0,0 @@
-module.exports = angular.module('wordpress-hybrid-client.post').controller 'WPHCPostController', ($log, $scope, $q, $WPHCPost, $state, $stateParams) ->
- $log.info 'WPHCPostController'
- vm = @
- vm.post = undefined
- vm.init = ->
- if $stateParams.post
- $log.info 'load post via object'
- deferred = $q.defer()
- deferred.resolve
- data: $stateParams.post
- promise = deferred.promise
- else
- $log.info 'load post via id'
- promise = $WPHCPost.get $stateParams.id
-
- promise.then (response) ->
- vm.post = response.data
-
- return vm
diff --git a/lib/post/post.html b/lib/post/post.html
deleted file mode 100644
index 0308f68b7..000000000
--- a/lib/post/post.html
+++ /dev/null
@@ -1,7 +0,0 @@
-
- {{ post.post.title.rendered | translate}}
-
-
-
-
-
diff --git a/lib/post/post.module.coffee b/lib/post/post.module.coffee
deleted file mode 100644
index d4e28720c..000000000
--- a/lib/post/post.module.coffee
+++ /dev/null
@@ -1,5 +0,0 @@
-module.exports = app = angular.module 'wordpress-hybrid-client.post', []
-
-require './post.config'
-require './post.controller'
-require './post.service'
diff --git a/lib/post/post.service.coffee b/lib/post/post.service.coffee
deleted file mode 100644
index 0bd0c83d5..000000000
--- a/lib/post/post.service.coffee
+++ /dev/null
@@ -1,59 +0,0 @@
-md5 = require 'MD5'
-
-module.exports = angular.module('wordpress-hybrid-client.post').factory '$WPHCPost', ($log, $wpApiPosts, $wpApiMedia, $wpApiComments, $q, $WPHCConfig, CacheFactory) ->
- $log.info '$WPHCPost'
-
- getCommentsCache = () ->
- if CacheFactory.get 'comments'
- return CacheFactory.get 'comments'
- CacheFactory 'comments', _.get $WPHCConfig, 'post.cache'
-
- getPostCache = () ->
- if CacheFactory.get 'post'
- return CacheFactory.get 'post'
- CacheFactory 'post', _.get $WPHCConfig, 'post.cache'
-
- getFeatureImage: (featureImageId) ->
- return $q.when(null) if !featureImageId or featureImageId is 0
- return $wpApiMedia.get featureImageId
- .then (response) ->
- response.data
-
- getComments: (id) ->
- deferred = $q.defer()
- hash = md5 $WPHCConfig.api.baseUrl + id
- itemCache = getCommentsCache().get 'item-comments-' + hash
- $log.debug 'Post cache', itemCache
- if itemCache
- deferred.resolve itemCache
- else
- $wpApiComments.getList
- post: id
- status: "approved"
- type: "comment"
- orderby: 'date'
- order: 'asc'
- per_page: _.get($WPHCConfig, 'post.comments.per_page') || 50
- .then (response) ->
- getCommentsCache().put 'item-comments-' + hash, response.data
- deferred.resolve response.data
- .catch (error) ->
- deferred.reject error
- deferred.promise
-
- get: (id) ->
- deferred = $q.defer()
- hash = md5 $WPHCConfig.api.baseUrl + id
- itemCache = getPostCache().get 'item-' + hash
- $log.debug 'Post cache', itemCache
- if itemCache
- deferred.resolve itemCache
- else
- $wpApiPosts.get id,
- "_embed": true
- .then (response) ->
- getPostCache().put 'item-' + hash, response
- deferred.resolve response
- .catch (error) ->
- deferred.reject error
- deferred.promise
diff --git a/lib/posts/config.js b/lib/posts/config.js
index 77e9cf5d9..5d9807a01 100644
--- a/lib/posts/config.js
+++ b/lib/posts/config.js
@@ -1,13 +1,22 @@
export default function($stateProvider) {
'ngInject';
- $stateProvider.state('public.posts', {
- url: "/posts",
- views: {
- 'content': {
- template: require("./index.html"),
- controller: "WPHCPostsController as postsCtrl"
+ $stateProvider
+ .state('public.posts', {
+ url: "/posts",
+ views: {
+ 'content': {
+ templateProvider: ($templateCache) => $templateCache.get('module/posts.html'),
+ controller: "WPHCPostsController as postsCtrl"
+ }
}
- }
- });
+ }).state('public.posts.id', {
+ url: "/:id",
+ views: {
+ 'content@public': {
+ templateProvider: ($templateCache) => $templateCache.get('module/post.html'),
+ controller: "WPHCPostController as postCtrl"
+ }
+ }
+ });
}
diff --git a/lib/posts/index.js b/lib/posts/index.js
index 86e9d5f27..963cfc4f5 100644
--- a/lib/posts/index.js
+++ b/lib/posts/index.js
@@ -1,11 +1,15 @@
import modConfig from './config.js';
-import modController from './controller.js';
-import modService from './service.js';
+import modPostsController from './posts.controller.js';
+import modPostsService from './posts.service.js';
+import modPostController from './post.controller.js';
+import modPostService from './post.service.js';
let mod = angular.module('wordpress-hybrid-client.posts', []);
mod.config(modConfig);
-mod.controller('WPHCPostsController', modController);
-mod.service('$WPHCPosts', modService);
+mod.controller('WPHCPostsController', modPostsController);
+mod.controller('WPHCPostController', modPostController);
+mod.service('$WPHCPosts', modPostsService);
+mod.service('$WPHCPost', modPostService);
export default mod = mod.name;
diff --git a/lib/posts/post.controller.js b/lib/posts/post.controller.js
new file mode 100644
index 000000000..1f6ceb182
--- /dev/null
+++ b/lib/posts/post.controller.js
@@ -0,0 +1,12 @@
+import AbstractItem from '../abstract/AbstractItem.js';
+
+export default class extends AbstractItem {
+
+ constructor($WPHCPost, $injector, $scope) {
+ 'ngInject';
+
+ super($injector, $scope);
+ this.setType('post');
+ this.setService($WPHCPost);
+ }
+}
diff --git a/lib/posts/post.service.js b/lib/posts/post.service.js
new file mode 100644
index 000000000..380e2a830
--- /dev/null
+++ b/lib/posts/post.service.js
@@ -0,0 +1,52 @@
+import md5 from 'MD5';
+import AbstractItemService from '../abstract/AbstractItemService.js';
+
+export default class extends AbstractItemService {
+ constructor($wpApiPosts, $injector) {
+ 'ngInject';
+
+ super($injector);
+ this.setType('post');
+ this.setService($wpApiPosts);
+ }
+
+ getFeatureImage(featureImageId) {
+ if (!featureImageId || featureImageId === 0) {
+ return this.$q.when(null);
+ }
+ return this.$injector.get('$wpApiMedia').get(featureImageId).then(function(response) {
+ return response.data;
+ });
+ }
+
+ getComments(id) {
+ var deferred, hash, itemCache;
+ deferred = this.$q.defer();
+ hash = md5(this.config.api.baseUrl + id);
+ itemCache = this.getCommentsCache().get('item-comments-' + hash);
+ this.$log.debug('Post cache', itemCache);
+ if (itemCache) {
+ deferred.resolve(itemCache);
+ } else {
+ this.$injector.get('$wpApiComments').getList({
+ post: id,
+ status: "approved",
+ type: "comment",
+ orderby: 'date',
+ order: 'asc',
+ per_page: _.get(this.config, 'post.comments.per_page') || 50
+ }).then(angular.bind(this, (response) => {
+ this.getCommentsCache().put('item-comments-' + hash, response.data);
+ return deferred.resolve(response.data);
+ }))["catch"]((error) => deferred.reject(error));
+ }
+ return deferred.promise;
+ }
+
+ getCommentsCache() {
+ if (this.CacheFactory.get('comments')) {
+ return this.CacheFactory.get('comments');
+ }
+ return this.CacheFactory('comments', _.get(this.config, 'post.cache'));
+ }
+}
diff --git a/lib/posts/controller.js b/lib/posts/posts.controller.js
similarity index 100%
rename from lib/posts/controller.js
rename to lib/posts/posts.controller.js
diff --git a/lib/posts/service.js b/lib/posts/posts.service.js
similarity index 100%
rename from lib/posts/service.js
rename to lib/posts/posts.service.js
diff --git a/lib/taxonomies/config.js b/lib/taxonomies/config.js
index e4ed21ea3..9331ec892 100644
--- a/lib/taxonomies/config.js
+++ b/lib/taxonomies/config.js
@@ -15,7 +15,7 @@ export default function($stateProvider) {
url: "/:slug",
views: {
'content@public': {
- template: require("../posts/index.html"),
+ templateProvider: ($templateCache) => $templateCache.get('module/posts.html'),
controller: "WPHCTaxonomiesPostsController as postsCtrl"
}
}
diff --git a/lib/templates/index.js b/lib/templates/index.js
new file mode 100644
index 000000000..23636c68a
--- /dev/null
+++ b/lib/templates/index.js
@@ -0,0 +1,10 @@
+let mod = angular.module('wordpress-hybrid-client.templates', []);
+
+mod.run(($templateCache) => {
+ $templateCache.put('module/post.html', require('!html!./module-post.html'));
+ $templateCache.put('module/posts.html', require('!html!./module-posts.html'));
+ $templateCache.put('module/page.html', require('!html!./module-page.html'));
+ $templateCache.put('module/pages.html', require('!html!./module-pages.html'));
+});
+
+export default mod = mod.name;
diff --git a/lib/pages/page.html b/lib/templates/module-page.html
similarity index 82%
rename from lib/pages/page.html
rename to lib/templates/module-page.html
index 5e3ea3de4..1c38e2857 100644
--- a/lib/pages/page.html
+++ b/lib/templates/module-page.html
@@ -1,5 +1,5 @@
- {{ pageCtrl.title | translate}}
+ {{ ::pageCtrl.item.title.rendered }}
diff --git a/lib/pages/pages.html b/lib/templates/module-pages.html
similarity index 100%
rename from lib/pages/pages.html
rename to lib/templates/module-pages.html
diff --git a/lib/templates/module-post.html b/lib/templates/module-post.html
new file mode 100644
index 000000000..6b0173e66
--- /dev/null
+++ b/lib/templates/module-post.html
@@ -0,0 +1,8 @@
+
+ {{ ::postCtrl.item.title.rendered }}
+
+
+
+
+
+
diff --git a/lib/posts/index.html b/lib/templates/module-posts.html
similarity index 100%
rename from lib/posts/index.html
rename to lib/templates/module-posts.html
diff --git a/package.json b/package.json
index 91af3e87c..653cdc3b7 100644
--- a/package.json
+++ b/package.json
@@ -56,6 +56,7 @@
"exports-loader": "^0.6.2",
"expose-loader": "^0.7.0",
"file-loader": "^0.8.4",
+ "fs-extra": "^0.26.3",
"gulp": "^3.9.0",
"gulp-util": "^3.0.6",
"html-loader": "^0.3.0",
diff --git a/scripts/install.js b/scripts/install.js
index 2510b9d90..8722c31f5 100644
--- a/scripts/install.js
+++ b/scripts/install.js
@@ -1,45 +1,21 @@
-var fs = require('fs'),
- npm = require("npm");
+var fs = require('fs-extra');
-copyFile('../dist/config.dev.cson', '../config/config.dev.cson', callback);
-copyFile('../dist/config.prod.cson', '../config/config.prod.cson', callback);
-copyFile('../dist/menu.dev.json', '../config/menu.dev.json', callback);
-copyFile('../dist/menu.prod.json', '../config/menu.prod.json', callback);
-copyFile('../dist/config.xml','../config.xml', callback);
-copyFile('../dist/config.scss','../config/config.scss', callback);
-copyFile('../release.sh.dist','../release.sh', callback);
-copyFile('../about.md.dist','../about.md', callback);
+copy('../dist/config.cson', '../config/config.cson');
+copy('../dist/menu.json', '../config/menu.json');
+copy('../dist/config.xml', '../config.xml');
+copy('../dist/config.scss', '../config/config.scss');
+copy('../dist/index.js', '../config/index.js', true);
+copy('../dist/templates', '../config/templates');
+copy('../release.sh.dist', '../release.sh');
+copy('../about.md.dist', '../about.md');
-function callback(error){
- if (error)
- console.log(error);
-}
-
-function copyFile(source, target, cb) {
- var cbCalled = false;
-
- if (fs.existsSync(target)){
- done('the destination already exist, will not overwrite: ' + target);
+function copy(source, target, overwrite) {
+ if (!overwrite && fs.existsSync(target)) {
+ console.log('the destination already exist, will not overwrite: ' + target);
return;
}
-
- var rd = fs.createReadStream(source);
- rd.on("error", function(err) {
- done(err);
- });
- var wr = fs.createWriteStream(target);
- wr.on("error", function(err) {
- done(err);
- });
- wr.on("close", function(ex) {
- done();
- });
- rd.pipe(wr);
-
- function done(err) {
- if (!cbCalled) {
- cb(err);
- cbCalled = true;
- }
- }
+ fs.copy(source, target, function(err) {
+ if (err) return console.error(err)
+ console.log('success: ' + target)
+ })
}