├── .editorconfig
├── .gitignore
├── .travis.yml
├── LICENSE.txt
├── README.md
├── bower.json
├── build
├── wp-angular.js
└── wp-angular.min.js
├── demo
├── index.html
└── style.css
├── gulpfile.js
├── jsdoc2md
└── README.hbs
├── package.json
├── src
├── wp-services.js
└── wp.js
└── tests
├── karma.conf.js
└── spec
├── have-posts-single.js
├── have-posts.js
├── the-content.js
├── the-date.js
├── the-excerpt.js
├── the-id.js
├── the-post-thumbnail.js
├── the-title.js
└── wp-services.js
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | end_of_line = lf
6 | insert_final_newline = true
7 | trim_trailing_whitespace = true
8 | indent_style = tab
9 | indent_size = 4
10 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .bundle
2 | node_modules
3 | npm-debug.log
4 | vendor
5 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - '6'
4 | - '5'
5 | - '4'
6 | - '0.11'
7 | - '0.10'
8 | before_script:
9 | - npm install
10 | script:
11 | - npm test
12 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Takayuki Miyauchi
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # wp-angularjs
2 |
3 | [](https://travis-ci.org/miya0001/wp-angularjs)
4 |
5 | A WP-API Client for [AngularJS](https://angularjs.org/).
6 |
7 | ## Getting Started
8 |
9 | ```
10 | $ npm install wp-angularjs --save
11 | ```
12 |
13 | Or
14 |
15 | ```
16 | $ bower install wp-angularjs --save
17 | ```
18 |
19 | ```html
20 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | ```
29 |
30 | Demo: http://miya0001.github.io/wp-angularjs/demo/
31 |
32 | ## Requires
33 |
34 | * [AngularJS](https://angularjs.org/)
35 | * [ngResource](https://github.com/angular/angular.js/tree/master/src/ngResource)
36 | * [ngSanitize](https://github.com/angular/angular.js/tree/master/src/ngSanitize)
37 |
38 | Recommended:
39 |
40 | * [ngInfiniteScroll](https://sroze.github.io/ngInfiniteScroll/)
41 | * [jQuery](https://jquery.com/)
42 |
43 | ## API Reference
44 |
45 | * [<have-posts>](#have-posts)
46 | * [<the-title>](#the-title)
47 | * [<the-content>](#the-content)
48 | * [<the-post-thumbnail>](#the-post-thumbnail)
49 | * [<the-id>](#the-id)
50 | * [<the-excerpt>](#the-excerpt)
51 | * [<the-date>](#the-date)
52 |
53 | ---
54 |
55 | ### <have-posts>
56 | The `havePosts` directive is a WordPress loop.
57 |
58 | **Attributes**
59 |
60 | | Attribute | Type | Details |
61 | |-----------|--------|----------------------------------------------------------------|
62 | | api-root | string | Root url of the API. e.g. http://example.com/wp-json/wp/v2 |
63 | | post-type | string | `posts` or `pages` or `media` or custom post type. |
64 | | per-page | number | The number of posts per page. Default is 10. |
65 | | offset | number | The number of post to displace or pass over. Default is 0. |
66 | | post-id | number | The ID of the post. |
67 | | filter | object | The object of the filter. |
68 |
69 | **Example**
70 | ```html
71 |
72 |
73 |
74 |
75 | ```
76 |
77 | If you want to get single post, you can use `post-id`.
78 |
79 | ```html
80 |
81 |
82 |
83 |
84 | ```
85 |
86 | You can pass filters to
87 | [WP_Query](https://codex.wordpress.org/Class_Reference/WP_Query)
88 | through via the `filter` argument.
89 |
90 | ```html
91 |
93 |
94 |
95 |
96 | ```
97 | ---
98 | ### <the-title>
99 | Displays the post title of the current post.
100 | This tag must be used within The ``.
101 |
102 | **Attributes**
103 |
104 | | Attribute | Type | Details |
105 | |-----------|--------|----------------------------------------------------------------|
106 | | href | string | Specify a link URL like `#/app/posts/:id`. |
107 |
108 | **Example**
109 | ```html
110 |
111 | ```
112 | Then:
113 | ```html
114 |
Hello World
115 | ```
116 | If you need a link to the post on your app. Please add `href` as attribute.
117 | ```html
118 |
119 | ```
120 | Then:
121 | ```html
122 |
123 | ```
124 | `:id` is a placeholder of the post's id. You can use `:slug` as post's slug too.
125 | ```html
126 |
127 | ```
128 | Then:
129 | ```html
130 |
131 | ```
132 | ---
133 | ### <the-content>
134 | Displays the post content of the current post.
135 | This tag must be used within The ``.
136 |
137 | **Example**
138 | ```html
139 |
140 | ```
141 | Then:
142 | ```html
143 |
Hello World
144 | ```
145 | ---
146 | ### <the-post-thumbnail>
147 | Displays the post thumbnail of the current post.
148 | This tag must be used within The ``.
149 |
150 | **Attributes**
151 |
152 | | Attribute | Type | Details |
153 | |-----------|--------|----------------------------------------------------------------|
154 | | size | string | Size of the post thumbnail. Default is `full`. |
155 | | href | string | Specify a link URL like `#/app/posts/:id`. |
156 |
157 | **Example**
158 | ```html
159 |
160 | ```
161 | Then:
162 | ```
163 |
172 | ```
173 | If you need a link to the post on your app. Please add `href` as attribute.
174 | ```html
175 |
176 | ```
177 | Then:
178 | ```html
179 |
180 |
181 |
182 | ```
183 | `:id` is a placeholder of the post's id. You can use `:slug` as post's slug too.
184 |
185 | ```html
186 |
187 | ```
188 | Then:
189 | ```html
190 |
191 |
192 |
193 | ```
194 | ---
195 | ### <the-id>
196 | Displays the ID of the current post.
197 | This tag must be used within The ``.
198 |
199 | **Example**
200 | ```
201 |
202 | ```
203 | Then:
204 | ```
205 |
123
206 | ```
207 | ---
208 | ### <the-excerpt>
209 | Displays the excerpt of the current post.
210 | This tag must be used within The ``.
211 |
212 | **Example**
213 | Place the code like following into your HTML.
214 | ```
215 |
216 | ```
217 | Then you will get like following.
218 | ```
219 |
Hello World.
220 | ```
221 | ---
222 | ### <the-date>
223 | Displays the date of the current post.
224 | This tag must be used within The ``.
225 |
226 | **Attributes**
227 |
228 | | Attribute | Type | Details |
229 | |-----------|--------|----------------------------------------------------------------|
230 | | format | string | See https://docs.angularjs.org/api/ng/filter/date |
231 |
232 | **Example**
233 | Place the code like following into your HTML.
234 | ```
235 |
236 | ```
237 | Then you will get like following.
238 | ```
239 |
2016-02-16 13:54:13
240 | ```
241 |
242 | You can set format string like following.
243 | See https://docs.angularjs.org/api/ng/filter/date.
244 | ```
245 |
246 | ```
247 | Then you will get like following.
248 | ```
249 |
2016-02-16
250 | ```
251 | ---
252 |
253 | ## Creates your custom template tag
254 |
255 | ```js
256 | // Registers your module, you should import `wp`.
257 | var myapp = angular.module( "myapp", [ "wp" ] );
258 |
259 | // Creates a `` as custom template tag.
260 | // If you place it in your HTML,
261 | // then you can get `Hello`.
262 | myapp.directive( "myPermalink", [ '$sce', function( $sce ) {
263 | return{
264 | restrict:'E',
265 | replace: true,
266 | require : '^havePosts',
267 | compile: function( tElement, tAttrs, transclude ) {
268 | return {
269 | post: function postLink( scope, element, attrs, controller ) {
270 | var post = scope.$parent.post; // post object
271 | scope.post_id = post.id;
272 | scope.title = post.title.rendered;
273 | }
274 | }
275 | },
276 | template: "{{ title }}"
277 | }
278 | } ] );
279 | ```
280 |
281 | ## Enables Infinite Scroll
282 |
283 | Please load [ngInfiniteScroll](https://sroze.github.io/ngInfiniteScroll/) like following.
284 |
285 | ```html
286 |
287 |
288 |
289 |
290 |
291 | ```
292 |
293 | Add `infinite-scroll` as a dependency.
294 |
295 | ```js
296 | angular.module( "app", [ "wp", "infinite-scroll" ] );
297 | ```
298 |
299 | That's it.
300 |
301 | ## How to contribute
302 |
303 | ```
304 | $ npm install
305 | ```
306 |
307 | Run testing.
308 |
309 | ```
310 | $ npm test
311 | ```
312 |
313 | Build `js/wp-angular.min.js`.
314 |
315 | ```
316 | $ npm run build
317 | ```
318 |
319 | Build documentation.
320 |
321 | ```
322 | $ npm run docs
323 | ```
324 |
--------------------------------------------------------------------------------
/bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "wp-angularjs",
3 | "description": "WP-API client for AngularJS",
4 | "main": "build/wp-angular.min.js",
5 | "authors": [
6 | "Takayuki Miyauchi"
7 | ],
8 | "license": "MIT",
9 | "homepage": "https://github.com/miya0001/wp-angularjs",
10 | "ignore": [
11 | "**/.*",
12 | "node_modules",
13 | "bower_components",
14 | "test",
15 | "tests"
16 | ]
17 | }
18 |
--------------------------------------------------------------------------------
/build/wp-angular.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @module wp
3 | */
4 | angular.module( "wp", [
5 | "wp.services",
6 | "ngResource",
7 | "ngSanitize"
8 | ] )
9 |
10 | /**
11 | * @name have-posts
12 | *
13 | * @description
14 | *
15 | * The `havePosts` directive is a WordPress loop.
16 | *
17 | * **Attributes**
18 | *
19 | * | Attribute | Type | Details |
20 | * |-----------|--------|----------------------------------------------------------------|
21 | * | api-root | string | Root url of the API. e.g. http://example.com/wp-json/wp/v2 |
22 | * | post-type | string | `posts` or `pages` or `media` or custom post type. |
23 | * | per-page | number | The number of posts per page. Default is 10. |
24 | * | offset | number | The number of post to displace or pass over. Default is 0. |
25 | * | post-id | number | The ID of the post. |
26 | * | filter | object | The object of the filter. |
27 | *
28 | * @example
29 | *
30 | * ```html
31 | *
32 | *
33 | *
34 | *
35 | * ```
36 | *
37 | * If you want to get single post, you can use `post-id`.
38 | *
39 | * ```html
40 | *
41 | *
42 | *
43 | *
44 | * ```
45 | *
46 | * You can pass filters to
47 | * [WP_Query](https://codex.wordpress.org/Class_Reference/WP_Query)
48 | * through via the `filter` argument.
49 | *
50 | * ```html
51 | *
53 | *
";
188 | }
189 | }
190 | }
191 | }
192 | } ] )
193 |
194 | /**
195 | * @name the-title
196 | *
197 | * @description
198 | *
199 | * Displays the post title of the current post.
200 | * This tag must be used within The ``.
201 | *
202 | * **Attributes**
203 | *
204 | * | Attribute | Type | Details |
205 | * |-----------|--------|----------------------------------------------------------------|
206 | * | href | string | Specify a link URL like `#/app/posts/:id`. |
207 | *
208 | * @example
209 | *
210 | * ```html
211 | *
212 | * ```
213 | * Then:
214 | * ```html
215 | *
Hello World
216 | * ```
217 | * If you need a link to the post on your app. Please add `href` as attribute.
218 | * ```html
219 | *
220 | * ```
221 | * Then:
222 | * ```html
223 | *
335 | * ```
336 | * If you need a link to the post on your app. Please add `href` as attribute.
337 | * ```html
338 | *
339 | * ```
340 | * Then:
341 | * ```html
342 | *
343 | *
344 | *
345 | * ```
346 | * `:id` is a placeholder of the post's id. You can use `:slug` as post's slug too.
347 | *
348 | * ```html
349 | *
350 | * ```
351 | * Then:
352 | * ```html
353 | *
"
440 | }
441 | } ] )
442 |
443 | /**
444 | * @name the-excerpt
445 | *
446 | * @description
447 | *
448 | * Displays the excerpt of the current post.
449 | * This tag must be used within The ``.
450 | *
451 | * @example
452 | *
453 | * Place the code like following into your HTML.
454 | * ```
455 | *
456 | * ```
457 | * Then you will get like following.
458 | * ```
459 | *
"
477 | }
478 | } ] )
479 |
480 | /**
481 | * @name the-date
482 | *
483 | * @description
484 | *
485 | * Displays the date of the current post.
486 | * This tag must be used within The ``.
487 | *
488 | * **Attributes**
489 | *
490 | * | Attribute | Type | Details |
491 | * |-----------|--------|----------------------------------------------------------------|
492 | * | format | string | See https://docs.angularjs.org/api/ng/filter/date |
493 | *
494 | * @example
495 | *
496 | * Place the code like following into your HTML.
497 | * ```
498 | *
499 | * ```
500 | * Then you will get like following.
501 | * ```
502 | *
2016-02-16 13:54:13
503 | * ```
504 | *
505 | * You can set format string like following.
506 | * See https://docs.angularjs.org/api/ng/filter/date.
507 | * ```
508 | *
509 | * ```
510 | * Then you will get like following.
511 | * ```
512 | *
";
188 | }
189 | }
190 | }
191 | }
192 | } ] )
193 |
194 | /**
195 | * @name the-title
196 | *
197 | * @description
198 | *
199 | * Displays the post title of the current post.
200 | * This tag must be used within The ``.
201 | *
202 | * **Attributes**
203 | *
204 | * | Attribute | Type | Details |
205 | * |-----------|--------|----------------------------------------------------------------|
206 | * | href | string | Specify a link URL like `#/app/posts/:id`. |
207 | *
208 | * @example
209 | *
210 | * ```html
211 | *
212 | * ```
213 | * Then:
214 | * ```html
215 | *
Hello World
216 | * ```
217 | * If you need a link to the post on your app. Please add `href` as attribute.
218 | * ```html
219 | *
220 | * ```
221 | * Then:
222 | * ```html
223 | *
335 | * ```
336 | * If you need a link to the post on your app. Please add `href` as attribute.
337 | * ```html
338 | *
339 | * ```
340 | * Then:
341 | * ```html
342 | *
343 | *
344 | *
345 | * ```
346 | * `:id` is a placeholder of the post's id. You can use `:slug` as post's slug too.
347 | *
348 | * ```html
349 | *
350 | * ```
351 | * Then:
352 | * ```html
353 | *
"
440 | }
441 | } ] )
442 |
443 | /**
444 | * @name the-excerpt
445 | *
446 | * @description
447 | *
448 | * Displays the excerpt of the current post.
449 | * This tag must be used within The ``.
450 | *
451 | * @example
452 | *
453 | * Place the code like following into your HTML.
454 | * ```
455 | *
456 | * ```
457 | * Then you will get like following.
458 | * ```
459 | *
"
477 | }
478 | } ] )
479 |
480 | /**
481 | * @name the-date
482 | *
483 | * @description
484 | *
485 | * Displays the date of the current post.
486 | * This tag must be used within The ``.
487 | *
488 | * **Attributes**
489 | *
490 | * | Attribute | Type | Details |
491 | * |-----------|--------|----------------------------------------------------------------|
492 | * | format | string | See https://docs.angularjs.org/api/ng/filter/date |
493 | *
494 | * @example
495 | *
496 | * Place the code like following into your HTML.
497 | * ```
498 | *
499 | * ```
500 | * Then you will get like following.
501 | * ```
502 | *
2016-02-16 13:54:13
503 | * ```
504 | *
505 | * You can set format string like following.
506 | * See https://docs.angularjs.org/api/ng/filter/date.
507 | * ```
508 | *
509 | * ```
510 | * Then you will get like following.
511 | * ```
512 | *