Skip to content

Commit

Permalink
Adding Img cache module and dependencies #3
Browse files Browse the repository at this point in the history
  • Loading branch information
shprink committed May 26, 2015
1 parent 2826975 commit 0a44bda
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 106 deletions.
9 changes: 9 additions & 0 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ Social buttons on the left side menu. You can add any social network account the
"cacheFlushInterval": null,
"storageMode": "localStorage",
"verifyIntegrity": true
},
"img" :{
"localCacheFolder": "imgcache", /* name of the cache folder */
"useDataURI": false, /* use src="data:.."? otherwise will use src="filesystem:.." */
"chromeQuota": 10 * 1024 * 1024, /* allocated cache space : here 10MB */
"usePersistentCache": true, /* false = use temporary cache storage */
"cacheClearSize": 0, /* size in MB that triggers cache clear on init, 0 to disable */
"headers": {}, /* HTTP headers for the download requests -- e.g: headers: { 'Accept': 'application/jpg' } */
"skipURIencoding": false /* enable if URIs are already encoded (skips call to sanitizeURI) */
}
```

Expand Down
11 changes: 11 additions & 0 deletions lib/cacheImg/cacheImg.directive.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = angular.module 'wordpress-hybrid-client.cacheImg'
.directive 'wphcImgCache', ->
restrict: 'A'
link: (scope, el, attrs) ->
attrs.$observe 'ngSrc', (src) ->
ImgCache.isCached src, (path, success) ->
if success
ImgCache.useCachedFile el
else
ImgCache.cacheFile src, ->
ImgCache.useCachedFile el
7 changes: 7 additions & 0 deletions lib/cacheImg/cacheImg.module.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'imgcache.js'

module.exports = angular.module 'wordpress-hybrid-client.cacheImg', []

require "./cacheImg.directive.coffee"
require "./cacheImg.service.coffee"
require "./cacheImg.run.coffee"
16 changes: 16 additions & 0 deletions lib/cacheImg/cacheImg.run.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = angular.module 'wordpress-hybrid-client.cacheImg'
.run ($ionicPlatform, $log, $WPHCConfig) ->
ImgCache.options.debug = $WPHCConfig.debugEnabled
ImgCache.options.chromeQuota = $WPHCConfig.cache.img.chromeQuota;
ImgCache.options.localCacheFolder = $WPHCConfig.cache.img.localCacheFolder;
ImgCache.options.useDataURI = $WPHCConfig.cache.img.useDataURI;
ImgCache.options.usePersistentCache = $WPHCConfig.cache.img.usePersistentCache;
ImgCache.options.cacheClearSize = $WPHCConfig.cache.img.cacheClearSize;
ImgCache.options.headers = $WPHCConfig.cache.img.headers;
ImgCache.options.skipURIencoding = $WPHCConfig.cache.img.skipURIencoding;

$ionicPlatform.ready ->
ImgCache.init ->
$log.debug 'ImgCache init: success!'
, ->
$log.error 'ImgCache init: error! Check the log for errors'
18 changes: 18 additions & 0 deletions lib/cacheImg/cacheImg.service.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = angular.module 'wordpress-hybrid-client.cacheImg'
.service 'CacheImages', ($q) ->
checkCacheStatus: (src) ->
deferred = $q.defer()
ImgCache.isCached src, (path, success) ->
if success
deferred.resolve path
else
ImgCache.cacheFile src, ->
ImgCache.isCached src, (path, success) ->
deferred.resolve path
return
, deferred.reject
return
, deferred.reject
return
, deferred.reject
deferred.promise
2 changes: 1 addition & 1 deletion lib/directives/post/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h1 class="item-title" ng-bind-html="::post.title"></h1>
</button>
</div>
<div class="item item-author" ng-class="::{'item-avatar' : post.author.avatar}">
<img src="{{::post.author.avatar}}" ng-if="::post.author.avatar">
<img wphc-img-cache ng-src="{{::post.author.avatar}}" ng-if="::post.author.avatar">
<h2>{{post.author.name}}</h2>
{{post.date | date : format : timezone}}
</div>
Expand Down
2 changes: 1 addition & 1 deletion lib/directives/posts/posts.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h1 class="item-title" ng-bind-html="::post.title"></h1>
<h1 class="item-title" ng-bind-html="::post.title"></h1>
</div>
<div class="item item-author" ng-class="::{'item-avatar' : post.author.avatar}">
<img src="{{::post.author.avatar}}" ng-if="::post.author.avatar">
<img wphc-img-cache ng-src="{{::post.author.avatar}}" ng-if="::post.author.avatar">
<h2>{{post.author.name}}</h2>
{{post.date | date : format : timezone}}
</div>
Expand Down
1 change: 1 addition & 0 deletions lib/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module.exports = app = angular.module 'wordpress-hybrid-client', [
require('./about/about.module').name
require('./language/language.module').name
require('./accessibility/accessibility.module').name
require('./cacheImg/cacheImg.module').name
]

app.config ($stateProvider) ->
Expand Down
212 changes: 108 additions & 104 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,106 +1,110 @@
{
"name": "wordpress-hybrid-client",
"version": "1.0.0",
"title": "wordpress-hybrid-client",
"description": "AngularJS client using Ionic Framework and based on the json-rest-api plugin: https://wordpress.org/plugins/json-rest-api/ with CORS enabled.",
"main": "index.js",
"scripts": {
"install": "bower install",
"update": "bower update",
"build": "sh ./release.sh",
"devserver": "webpack-dev-server --port 9100 --progress",
"dumpdev": "gulp build",
"dumpprod": "gulp build:prod"
},
"keywords": [
"wp-api",
"angular",
"angularjs",
"rest",
"restfull",
"hybrid",
"material design",
"client"
],
"author": "Julien Renaux <[email protected]>",
"repository": {
"type": "git",
"url": "https://github.com/shprink/wordpress-hybrid-client"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/shprink/wordpress-hybrid-client/issues"
},
"homepage": "https://github.com/shprink/wordpress-hybrid-client",
"devDependencies": {
"autoprefixer-loader": "^1.1.0",
"clone": "^0.2.0",
"coffee-loader": "^0.7.2",
"coffee-script": "^1.8.0",
"css-loader": "^0.9.1",
"exports-loader": "^0.6.2",
"expose-loader": "^0.6.0",
"file-loader": "^0.8.1",
"gulp": "^3.8.10",
"gulp-bump": "^0.3.0",
"gulp-cordova-bump": "^1.2.2",
"gulp-filter": "^2.0.2",
"gulp-git": "^1.2.3",
"gulp-header": "^1.2.2",
"gulp-minify-css": "^0.4.4",
"gulp-rimraf": "^0.1.1",
"gulp-tag-version": "^1.2.1",
"gulp-util": "^3.0.1",
"gulp-webpack": "^1.1.2",
"gulp-xml-editor": "^2.2.1",
"html-loader": "^0.2.3",
"html-webpack-plugin": "^1.1.0",
"json-loader": "^0.5.1",
"markdown-loader": "^0.1.2",
"ng-annotate": "^0.15.2",
"ng-annotate-webpack-plugin": "^0.1.2",
"path": "^0.4.9",
"sass-loader": "^0.3.1",
"semver": "^4.3.4",
"style-loader": "^0.8.3",
"util": "^0.10.3",
"webpack": "^1.4.13",
"xml2js": "^0.4.8"
},
"dependencies": {
"MD5": "^1.2.1",
"angular": "^1.3.0",
"angular-animate": "^1.3.0",
"angular-aria": "^1.3.0",
"angular-cache": "^4.0.0",
"angular-filter": "^0.5.4",
"angular-memory-stats": "^1.0.0-rc4",
"angular-moment": "^0.9.0",
"angular-sanitize": "^1.3.0",
"angular-translate": "^2.5.2",
"angular-ui-router": "^0.2.13",
"imagesloaded": "^3.1.8",
"moment": "^2.9.0",
"ng-cordova": "^0.1.12-alpha",
"wp-api-angularjs": "^1.0.0-beta1"
},
"cordovaPlugins": [
"https://github.com/danwilson/google-analytics-plugin.git",
"com.google.playservices",
"./engine/cordova-crosswalk-engine-c0.6.1",
"org.apache.cordova.network-information",
"org.apache.cordova.splashscreen",
"com.ionic.keyboard",
"https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin.git",
"https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git",
"https://github.com/apache/cordova-plugin-statusbar.git",
"org.apache.cordova.globalization",
"org.apache.cordova.inappbrowser"
],
"cordovaPlatforms": [
{
"platform": "android",
"locator": "./engine/cordova-android-c0.6.1/"
}
]
"name": "wordpress-hybrid-client",
"version": "1.0.0",
"title": "wordpress-hybrid-client",
"description": "AngularJS client using Ionic Framework and based on the json-rest-api plugin: https://wordpress.org/plugins/json-rest-api/ with CORS enabled.",
"main": "index.js",
"scripts": {
"install": "bower install",
"update": "bower update",
"build": "sh ./release.sh",
"devserver": "webpack-dev-server --port 9100 --progress",
"dumpdev": "gulp build",
"dumpprod": "gulp build:prod"
},
"keywords": [
"wp-api",
"angular",
"angularjs",
"rest",
"restfull",
"hybrid",
"material design",
"client"
],
"author": "Julien Renaux <[email protected]>",
"repository": {
"type": "git",
"url": "https://github.com/shprink/wordpress-hybrid-client"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/shprink/wordpress-hybrid-client/issues"
},
"homepage": "https://github.com/shprink/wordpress-hybrid-client",
"devDependencies": {
"autoprefixer-loader": "^1.1.0",
"clone": "^0.2.0",
"coffee-loader": "^0.7.2",
"coffee-script": "^1.8.0",
"css-loader": "^0.9.1",
"exports-loader": "^0.6.2",
"expose-loader": "^0.6.0",
"file-loader": "^0.8.1",
"gulp": "^3.8.10",
"gulp-bump": "^0.3.0",
"gulp-cordova-bump": "^1.2.2",
"gulp-filter": "^2.0.2",
"gulp-git": "^1.2.3",
"gulp-header": "^1.2.2",
"gulp-minify-css": "^0.4.4",
"gulp-rimraf": "^0.1.1",
"gulp-tag-version": "^1.2.1",
"gulp-util": "^3.0.1",
"gulp-webpack": "^1.1.2",
"gulp-xml-editor": "^2.2.1",
"html-loader": "^0.2.3",
"html-webpack-plugin": "^1.1.0",
"json-loader": "^0.5.1",
"markdown-loader": "^0.1.2",
"ng-annotate": "^0.15.2",
"ng-annotate-webpack-plugin": "^0.1.2",
"path": "^0.4.9",
"sass-loader": "^0.3.1",
"semver": "^4.3.4",
"style-loader": "^0.8.3",
"util": "^0.10.3",
"webpack": "^1.4.13",
"xml2js": "^0.4.8"
},
"dependencies": {
"MD5": "^1.2.1",
"angular": "^1.3.0",
"angular-animate": "^1.3.0",
"angular-aria": "^1.3.0",
"angular-cache": "^4.0.0",
"angular-filter": "^0.5.4",
"angular-memory-stats": "^1.0.0-rc4",
"angular-moment": "^0.9.0",
"angular-sanitize": "^1.3.0",
"angular-translate": "^2.5.2",
"angular-ui-router": "^0.2.13",
"imagesloaded": "^3.1.8",
"imgcache.js": "^1.0.0",
"moment": "^2.9.0",
"ng-cordova": "^0.1.12-alpha",
"wp-api-angularjs": "^1.0.0-beta1"
},
"cordovaPlugins": [
"https://github.com/danwilson/google-analytics-plugin.git",
"com.google.playservices",
"./engine/cordova-crosswalk-engine-c0.6.1",
"org.apache.cordova.network-information",
"org.apache.cordova.splashscreen",
"com.ionic.keyboard",
"https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin.git",
"https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git",
"https://github.com/apache/cordova-plugin-statusbar.git",
"org.apache.cordova.globalization",
"org.apache.cordova.inappbrowser",
"org.apache.cordova.file-transfer",
"org.apache.cordova.file",
"org.apache.cordova.device"
],
"cordovaPlatforms": [
{
"platform": "android",
"locator": "./engine/cordova-android-c0.6.1/"
}
]
}
3 changes: 3 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ module.exports = {
loaders: [{
test: /[\/]angular\.js$/,
loader: 'expose?angular!exports?window.angular'
}, {
test: /[\/]imgcache\.js$/,
loader: 'expose?ImgCache'
}, {
test: /[\/]ionic\.js$/,
loader: 'exports?ionic' // For non commonJs
Expand Down

0 comments on commit 0a44bda

Please sign in to comment.