Skip to content

Commit abdabef

Browse files
committed
Support Angular AOT, fixes #69
Add a static forRoot method to CloudinaryModule to be able to configure Cloudinary service in AOT. Add sample project to demo usage.
1 parent aa6170f commit abdabef

40 files changed

+3681
-634
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ logs
44
npm-debug.log*
55
config.ts
66

7+
# Ignore AOT compiler output
8+
/compiled
9+
*.metadata.json
10+
711
# Ignore output of typescript compilation. They WILL be included in the package since .npmignore is empty
812
index.js.map
913
index.d.ts

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
!src/**/*.js
66
!src/**/*.js.map
77
!src/**/*.d.ts
8+
!src/**/*.metadata.json
89

910
!index.js
1011
!index.js.map
1112
!index.d.ts
13+
!index.metadata.json
1214

1315
!package.json
1416

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,12 @@ Example Coudinary configuration in your application's module definition:
5959
```javascript
6060
import { NgModule } from '@angular/core';
6161
// ...
62-
import { CloudinaryModule, CloudinaryConfiguration, provideCloudinary } from '@cloudinary/angular';
62+
import { CloudinaryModule, CloudinaryConfiguration } from '@cloudinary/angular';
63+
import { Cloudinary } from 'cloudinary-core';
6364

6465
@NgModule({
6566
imports: [
66-
CloudinaryModule
67-
],
68-
providers: [
69-
provideCloudinary(require('cloudinary-core'), { cloud_name: 'your_cloud_name' } as CloudinaryConfiguration)
67+
CloudinaryModule.forRoot({Cloudinary}, { cloud_name: 'your_cloud_name' } as CloudinaryConfiguration),
7068
],
7169
bootstrap: [/* ... */]
7270
})
@@ -169,6 +167,9 @@ The samples differ by their bundling solution and upload implementation:
169167
* [Photo album sample app with jQuery](samples/photo_album_with_jquery)
170168
* Uses [Cloudinary's jQuery plugin](http://cloudinary.com/blog/direct_upload_made_easy_from_browser_or_mobile_app_to_the_cloud#direct_uploading_from_the_browser_using_jquery) for uploading files using jQuery and blueimp.
171169
* Uses [SystemJS](https://github.com/systemjs/systemjs) for bundling the application and [lite-server](https://github.com/johnpapa/lite-server) for serving the application.
170+
* [Photo Album AOT compilation](samples/photo_album_aot)
171+
* Demonstrates usage of Cloudinary SDK in an [Angular AOT](https://angular.io/docs/ts/latest/cookbook/aot-compiler.html) application
172+
* Uses [Rollup](http://rollupjs.org/) for bundling the application and [lite-server](https://github.com/johnpapa/lite-server) for serving the application.
172173

173174
Please consult with the respective README file of each sample for usage and additional information.
174175

package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
"start-sample:jquery": "npm run install-sample-from-source:jquery && cd samples/photo_album_with_jquery && npm run start:e2e",
3030
"e2e": "npm run install-sample-from-source && concurrently \"npm run start-sample\" \"protractor protractor.config.js --baseUrl='http://localhost:4000/'\" --kill-others --success first",
3131
"e2e:jquery": "npm run start-sample:jquery && protractor protractor.config.js --baseUrl='http://localhost:3000/' --kill-others --success first",
32-
"tsc": "tsc",
33-
"tsc:w": "tsc -w"
32+
"ngc": "ngc",
33+
"ngc:w": "ngc -w"
3434
},
3535
"repository": {
3636
"type": "git",
@@ -43,17 +43,19 @@
4343
},
4444
"homepage": "https://github.com/cloudinary/cloudinary_angular",
4545
"dependencies": {
46-
"@angular/common": "^2.2.4",
47-
"@angular/core": "^2.2.4",
46+
"@angular/common": "^2.4.3",
47+
"@angular/compiler-cli": "^2.2.4",
48+
"@angular/core": "^2.4.3",
49+
"@angular/platform-server": "^2.4.3",
4850
"core-js": "^2.4.1",
4951
"reflect-metadata": "^0.1.8",
5052
"rxjs": "^5.0.1",
5153
"zone.js": "^0.7.2"
5254
},
5355
"devDependencies": {
54-
"@angular/compiler": "^2.2.4",
55-
"@angular/platform-browser": "^2.2.4",
56-
"@angular/platform-browser-dynamic": "^2.2.4",
56+
"@angular/compiler": "^2.4.3",
57+
"@angular/platform-browser": "^2.4.3",
58+
"@angular/platform-browser-dynamic": "^2.4.3",
5759
"@types/jasmine": "^2.5.36",
5860
"@types/node": "^6.0.46",
5961
"@types/selenium-webdriver": "^2.53.36",

samples/photo_album/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
"description": "Sample application using Cloudinary's Angular2 SDK",
66
"license": "MIT",
77
"dependencies": {
8-
"@angular/common": "^2.3.0",
9-
"@angular/compiler": "^2.3.0",
10-
"@angular/core": "^2.3.0",
8+
"@angular/common": "^2.4.3",
9+
"@angular/compiler": "^2.4.3",
10+
"@angular/core": "^2.4.3",
1111
"@angular/forms": "^2.3.0",
1212
"@angular/http": "^2.3.0",
13-
"@angular/platform-browser": "^2.3.0",
14-
"@angular/platform-browser-dynamic": "^2.3.0",
13+
"@angular/platform-browser": "^2.4.3",
14+
"@angular/platform-browser-dynamic": "^2.4.3",
1515
"@angular/router": "^3.2.3",
1616
"@cloudinary/angular": "^2.0.0",
1717
"cloudinary-core": "^2.1.9",

samples/photo_album/yarn.lock

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
# yarn lockfile v1
33

44

5-
"@angular/common@^2.3.0":
6-
version "2.4.1"
7-
resolved "https://registry.yarnpkg.com/@angular/common/-/common-2.4.%3Cspan%20class="x x-first x-last">1.tgz#a70167430574959c3423ac96ebdec98032d3500d"
5+
"@angular/common@^2.2.4", "@angular/common@^2.4.3":
6+
version "2.4.3"
7+
resolved "https://registry.yarnpkg.com/@angular/common/-/common-2.4.%3Cspan%20class="x x-first x-last">3.tgz#78d96bd2f8a1a105f635cd25e362ba5704b47f56"
88

9-
"@angular/compiler@^2.3.0":
10-
version "2.4.1"
11-
resolved "https://registry.yarnpkg.com/@angular/compiler/-/compiler-2.4.%3Cspan%20class="x x-first x-last">1.tgz#62b4fbfc53c934bd5def78db594cbf245b3f446a"
9+
"@angular/compiler@^2.4.3":
10+
version "2.4.3"
11+
resolved "https://registry.yarnpkg.com/@angular/compiler/-/compiler-2.4.%3Cspan%20class="x x-first x-last">3.tgz#76a41916f90eda66643107740c4a9ae45cb7a6c1"
1212

13-
"@angular/core@^2.3.0":
14-
version "2.4.1"
15-
resolved "https://registry.yarnpkg.com/@angular/core/-/core-2.4.%3Cspan%20class="x x-first x-last">1.tgz#3a6d2dc7fd86fdebe4febae7eb28abad7d04c76a"
13+
"@angular/core@^2.2.4", "@angular/core@^2.4.3":
14+
version "2.4.3"
15+
resolved "https://registry.yarnpkg.com/@angular/core/-/core-2.4.%3Cspan%20class="x x-first x-last">3.tgz#a72a13bb9f01659b8388558cd6e3a570a8434b1c"
1616

1717
"@angular/forms@^2.3.0":
1818
version "2.4.1"
@@ -22,18 +22,29 @@
2222
version "2.4.1"
2323
resolved "https://registry.yarnpkg.com/@angular/http/-/http-2.4.1.tgz#f06067e370c44d025ed00a03ef704f6c46ea59ac"
2424

25-
"@angular/platform-browser-dynamic@^2.3.0":
26-
version "2.4.1"
27-
resolved "https://registry.yarnpkg.com/@angular/platform-browser-dynamic/-/platform-browser-dynamic-2.4.%3Cspan%20class="x x-first x-last">1.tgz#5fb72038f76c1e3646cea95f5b4722d67a4419dd"
25+
"@angular/platform-browser-dynamic@^2.4.3":
26+
version "2.4.3"
27+
resolved "https://registry.yarnpkg.com/@angular/platform-browser-dynamic/-/platform-browser-dynamic-2.4.%3Cspan%20class="x x-first x-last">3.tgz#d65cc9bc4487e2a86e2c6f6641c711fccfa90c5a"
2828

29-
"@angular/platform-browser@^2.3.0":
30-
version "2.4.1"
31-
resolved "https://registry.yarnpkg.com/@angular/platform-browser/-/platform-browser-2.4.%3Cspan%20class="x x-first x-last">1.tgz#4eaa829b450be34f0029796b6c3b99e27d3d5740"
29+
"@angular/platform-browser@^2.4.3":
30+
version "2.4.3"
31+
resolved "https://registry.yarnpkg.com/@angular/platform-browser/-/platform-browser-2.4.%3Cspan%20class="x x-first x-last">3.tgz#eba8588d2fffc39d0b85a9180c297d9ca2f1f3a4"
3232

3333
"@angular/router@^3.2.3":
3434
version "3.4.1"
3535
resolved "https://registry.yarnpkg.com/@angular/router/-/router-3.4.1.tgz#079c8580943547a710f292026ac86a08d336a49d"
3636

37+
"@cloudinary/angular@^2.0.0":
38+
version "2.0.0"
39+
resolved "https://registry.yarnpkg.com/@cloudinary/angular/-/angular-2.0.0.tgz#fc4906291abdca8ed1cb9e67042fdf10ce68cf28"
40+
dependencies:
41+
"@angular/common" "^2.2.4"
42+
"@angular/core" "^2.2.4"
43+
core-js "^2.4.1"
44+
reflect-metadata "^0.1.8"
45+
rxjs "^5.0.1"
46+
zone.js "^0.7.2"
47+
3748
3849
version "0.0.1"
3950
resolved "https://registry.yarnpkg.com/@types/node/-/node-0.0.1.tgz#d90a4d3bf1fe8f961edf0f76f34a7a6df79580be"

samples/photo_album_aot/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
aot/
2+
3+
*.ngsummary.json
4+
*.ngstyle.ts

samples/photo_album_aot/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
Cloudinary Angular photo Album Ahead of Time compilation Sample
2+
=======================================
3+
4+
This sample project shows:
5+
6+
1. How to use the Cloudinary Angular directives.
7+
2. How to consume Cloudinary SDK in an Angular AOT setup using rollup
8+
9+
This sample does not show how to upload images directly frmo the browser.
10+
You can see how this is implemented in other samples in this repository.
11+
12+
## Configuration ##
13+
14+
There are 2 settings you need to change for this demo to work. Copy or rename `app/js/config.ts.sample` to `app/js/config.ts` and edit the following:
15+
16+
1. **cloud_name** - Should be change to the cloud name you received when you registered for a Cloudinary account.
17+
2. **upload_preset** - You should first "Enable unsigned uploads" in the ["Upload Settings"](https://cloudinary.com/console/settings/upload) of your Cloudinary console and assign the resulting preset name to that field. Note, you may want to tweak and modify the upload preset's parameters.
18+
3. Additionally, in your Cloudinary console in the ["Security Settings"](https://cloudinary.com/console/settings/security) section you should uncheck the "list" item.
19+
20+
Learn more about [Angular AOT](https://angular.io/docs/ts/latest/cookbook/aot-compiler.html)
21+
22+
## Setup ##
23+
24+
Run `npm install` to install the required dependencies for this module.
25+
26+
Alternatively use `yarn install`
27+
28+
## Running ##
29+
30+
Run `npm run clean-aot` to delete AOT compilation artifacts
31+
Run `npm run ngc` to run Angular's AOT compiler
32+
Run `npm run rollup` to bundle the application
33+
Run `npm run lite` to start the server and automatically open a browser and navigate to the application's url.
34+
35+
## Internals ##
36+
This sample is using [Rollup](http://rollupjs.org/) for bundling the application and [lite-server](https://github.com/johnpapa/lite-server) for serving the application.
37+
38+
[index.html](index.html) loads Rollup's output, which is based on Angular's AOT compiler.
39+
40+
The sample creates a new NgModule, and depends on CloudinaryModule which is imported from the SDK module.
41+
42+
### List Resource ###
43+
44+
Cloudinary supports a JSON list resource.
45+
This list represents all resources marked with a specific tag during upload (or later through other APIs).
46+
Whenever a new resource is uploaded with a tag, or an existing resource already tagged is deleted then the list is recalculated.
47+
This enables you to group a list of resources which can be retrieved by a single query. The size of the list is currently limited to 100 entires.
48+
[Learn more](http://cloudinary.com/documentation/image_transformations#client_side_resource_lists)

samples/photo_album_aot/app/css/.gitkeep

Whitespace-only changes.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* animations css stylesheet
3+
*/
4+
5+
/* animate ngRepeat in photo listing */
6+
7+
.photo-listing.ng-enter,
8+
.photo-listing.ng-leave,
9+
.photo-listing.ng-move {
10+
-webkit-transition: 0.5s linear all;
11+
-moz-transition: 0.5s linear all;
12+
-o-transition: 0.5s linear all;
13+
transition: 0.5s linear all;
14+
}
15+
16+
.photo-listing.ng-enter,
17+
.photo-listing.ng-move {
18+
opacity: 0;
19+
height: 0;
20+
overflow: hidden;
21+
}
22+
23+
.photo-listing.ng-move.ng-move-active,
24+
.photo-listing.ng-enter.ng-enter-active {
25+
opacity: 1;
26+
height: 120px;
27+
}
28+
29+
.photo-listing.ng-leave {
30+
opacity: 1;
31+
overflow: hidden;
32+
}
33+
34+
.photo-listing.ng-leave.ng-leave-active {
35+
opacity: 0;
36+
height: 0;
37+
padding-top: 0;
38+
padding-bottom: 0;
39+
}
40+
41+
/* cross fading between routes with ngView */
42+
43+
.view-container {
44+
position: relative;
45+
}
46+
47+
.view-frame.ng-enter,
48+
.view-frame.ng-leave {
49+
background: white;
50+
position: absolute;
51+
top: 0;
52+
left: 0;
53+
right: 0;
54+
}
55+
56+
.view-frame.ng-enter {
57+
-webkit-animation: 0.5s fade-in;
58+
-moz-animation: 0.5s fade-in;
59+
-o-animation: 0.5s fade-in;
60+
animation: 0.5s fade-in;
61+
z-index: 100;
62+
}
63+
64+
.view-frame.ng-leave {
65+
-webkit-animation: 0.5s fade-out;
66+
-moz-animation: 0.5s fade-out;
67+
-o-animation: 0.5s fade-out;
68+
animation: 0.5s fade-out;
69+
z-index: 99;
70+
}
71+
72+
@keyframes fade-in {
73+
from { opacity: 0; }
74+
to { opacity: 1; }
75+
}
76+
@-moz-keyframes fade-in {
77+
from { opacity: 0; }
78+
to { opacity: 1; }
79+
}
80+
@-webkit-keyframes fade-in {
81+
from { opacity: 0; }
82+
to { opacity: 1; }
83+
}
84+
85+
@keyframes fade-out {
86+
from { opacity: 1; }
87+
to { opacity: 0; }
88+
}
89+
@-moz-keyframes fade-out {
90+
from { opacity: 1; }
91+
to { opacity: 0; }
92+
}
93+
@-webkit-keyframes fade-out {
94+
from { opacity: 1; }
95+
to { opacity: 0; }
96+
}
97+

0 commit comments

Comments
 (0)