Skip to content

Commit

Permalink
Merge pull request #19 from elwayman02/errors
Browse files Browse the repository at this point in the history
Display errors when posts are not found
  • Loading branch information
elwayman02 committed Aug 16, 2015
2 parents ef407e6 + 8273b8d commit 8214430
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 18 deletions.
12 changes: 12 additions & 0 deletions addon/components/tumblr-blog.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ export default Ember.Component.extend({
*/
formatDates: true,

/**
* Display an error message instead of attempting to render posts when none are returned
* @type {boolean}
* @default
*/
showErrors: true,

/**
* Error message to display when no posts were found
*/
errorMessage: "We're sorry, we were unable to retrieve any posts. Please check back later!",

/**
* Configurable Sort Options
* @type {Array.string}
Expand Down
40 changes: 23 additions & 17 deletions app/templates/components/tumblr-blog.hbs
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
{{#each sortedPosts as |post|}}
{{#if collapsible}}
{{#if collapseByDefault}}
{{tumblr-post
post=post
postsRoute=postsRoute
collapsible=true
collapsed=true
formatDates=formatDates}}
{{#if sortedPosts.length}}
{{#each sortedPosts as |post|}}
{{#if collapsible}}
{{#if collapseByDefault}}
{{tumblr-post
post=post
postsRoute=postsRoute
collapsible=true
collapsed=true
formatDates=formatDates}}
{{else}}
{{tumblr-post
post=post
postsRoute=postsRoute
collapsible=true
collapsed=false
formatDates=formatDates}}
{{/if}}
{{else}}
{{tumblr-post
post=post
postsRoute=postsRoute
collapsible=true
collapsed=false
formatDates=formatDates}}
{{/if}}
{{else}}
{{tumblr-post
post=post
postsRoute=postsRoute
formatDates=formatDates}}
{{/each}}
{{else}}
{{#if showErrors}}
<span class="tumblr-error">{{errorMessage}}</span>
{{/if}}
{{/each}}
{{/if}}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-tumblr",
"version": "0.5.1",
"version": "0.6.0",
"description": "Ember Addon for integrating a Tumblr blog",
"directories": {
"doc": "doc",
Expand Down
1 change: 1 addition & 0 deletions tests/dummy/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Router.map(function() {
this.route('uncollapsed-blog');
this.route('sorted-blog');
this.route('no-format-blog');
this.route('error-blog');
this.route('post', { path: '/posts/:post_id' });
});

Expand Down
7 changes: 7 additions & 0 deletions tests/dummy/app/routes/error-blog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Ember from 'ember';

export default Ember.Route.extend({
model() {
return Ember.A([]);
}
});
5 changes: 5 additions & 0 deletions tests/dummy/app/templates/error-blog.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>Welcome to my blog!</h1>

<h3>This blog demonstrates the error message when no posts are found</h3>

{{tumblr-blog posts=model}}
1 change: 1 addition & 0 deletions tests/dummy/app/templates/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
{{#link-to 'uncollapsed-blog'}}<button>View Blog With Collapsible Posts (Uncollapsed by Default)</button>{{/link-to}}
{{#link-to 'sorted-blog'}}<button>View Blog With Sorted Posts</button>{{/link-to}}
{{#link-to 'no-format-blog'}}<button>View Blog With Unformatted Dates</button>{{/link-to}}
{{#link-to 'error-blog'}}<button>View Blog With No Posts Error</button>{{/link-to}}
</div>
2 changes: 2 additions & 0 deletions tests/unit/components/tumblr-blog-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ test('defaults', function (assert) {
assert.equal(sortBy.length, 0, 'sortBy has no elements');

assert.ok(component.get('formatDates'), 'date formatting enabled by default');
assert.ok(component.get('showErrors'), 'error is displayed by default if no posts are found');
assert.ok(Ember.isPresent(component.get('errorMessage')), 'default error message is supplied');
});
2 changes: 2 additions & 0 deletions tests/unit/components/tumblr-post-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ test('defaults', function (assert) {
assert.ok(component.get('collapsed'), 'post is set to collapse by default if collapsible');
assert.ok(!component.get('isCollapsed'), 'post will not collapse by default, because it is not collapsible');
assert.ok(component.get('formatDates'), 'date formatting enabled by default');
assert.ok(Ember.isPresent(component.get('collapsedText')), 'default collapsedText is supplied');
assert.ok(Ember.isPresent(component.get('expandedText')), 'default expandedText is supplied');
});

test('isCollapsed', function (assert) {
Expand Down

0 comments on commit 8214430

Please sign in to comment.