Skip to content

Commit

Permalink
Merge pull request #18 from elwayman02/documentation
Browse files Browse the repository at this point in the history
Documentation
  • Loading branch information
elwayman02 committed Aug 16, 2015
2 parents b760cca + 62223b9 commit dfafe6b
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 9 deletions.
43 changes: 41 additions & 2 deletions addon/adapters/tumblr-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,56 @@ import Ember from 'ember';
import DS from 'ember-data';

export default DS.RESTAdapter.extend({
/**
* Tumblr Application API Key
* @type {string}
* @default
*/
apiKey: '',

/**
* Tumblr Blog URL
* @type {string}
* @default
*/
blogUrl: '',
type: '',

/**
* Tumblr API Hostname
* @type {string}
* @default
*/
host: 'https://api.tumblr.com',

/**
* Post Type
* @type {string}
* @default
*/
type: '',

/**
* Build path from type
* @returns {string} API path with type string appended
*/
pathForType() {
const type = Ember.isPresent(this.get('type')) ? `/${this.get('type')}` : '';
return `posts${type}`;
},
namespace: Ember.computed(function () {

/**
* Build namespace from blogURL
* @returns {string} Tumblr API namespace with blogURL appended
*/
namespace: Ember.computed('blogURL', function () {
return `v2/blog/${this.get('blogUrl')}`;
}),

/**
* Build hash for AJAX call
* Appends API key and sets data type
* @returns {object} hash of AJAX options
*/
ajaxOptions() {
const hash = this._super.apply(this, arguments);
hash.data = hash.data || {};
Expand Down
49 changes: 48 additions & 1 deletion addon/components/tumblr-blog.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,59 @@
import Ember from 'ember';

export default Ember.Component.extend({
/**
* Class names for the component
* @type {Array.string}
* @default
*/
classNames: ['tumblr-blog'],
posts: Ember.A([]),

/**
* Route to link posts to
* @type {string}
* @default
*/
postsRoute: null,

/**
* Determines whether or not the blog can collapse its posts
* @type {boolean}
* @default
*/
collapsible: false,

/**
* Default all posts to collapsed
* @type {boolean}
* @default
*/
collapseByDefault: true,

/**
* Use date formatting
* @type {boolean}
* @default
*/
formatDates: true,

/**
* Configurable Sort Options
* @type {Array.string}
* @default
*/
sortBy: [],

/**
* Posts to be displayed
* @type {Array.Tumblr-Post}
* @default
*/
posts: Ember.A([]),

/**
* Sorted array of posts
* @type {Array.Tumblr-Post}
* @default
*/
sortedPosts: Ember.computed.sort('posts', 'sortBy')
});
57 changes: 57 additions & 0 deletions addon/components/tumblr-post.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,82 @@
import Ember from 'ember';

export default Ember.Component.extend({
/**
* Class names for the component
* @type {Array.string}
* @default
*/
classNames: ['tumblr-post'],

/**
* Class names bound to other properties
* @type {Array.string}
* @default
*/
classNameBindings: ['isCollapsed:tumblr-post-collapsed'],

/**
* Route to link posts to
* @type {string}
* @default
*/
postsRoute: null,

/**
* Determines whether or not the blog can collapse its posts
* @type {boolean}
* @default
*/
collapsible: false,

/**
* Post should be collapsed if possible
* @type {boolean}
* @default
*/
collapsed: true,

/**
* Use date formatting
* @type {boolean}
* @default
*/
formatDates: true,

/**
* Text to display when post is collapsed
* @type {string}
* @default
*/
collapsedText: 'View More',

/**
* Text to display when post is expanded
* @type {string}
* @default
*/
expandedText: 'Collapse Post',

/**
* Is post collapsed?
* @type {boolean}
* @default
*/
isCollapsed: Ember.computed('collapsible', 'collapsed', function () {
return this.get('collapsible') && this.get('collapsed');
}),

/**
* Choose which text to display, depending on whether the component is collapsed
* @type {string}
* @default
*/
expandButtonText: Ember.computed('isCollapsed', 'collapsedText', 'expandedText', function () {
return this.get('isCollapsed') ? this.get('collapsedText') : this.get('expandedText');
}),

actions: {
/** Expand/collapse the component */
expand() {
this.toggleProperty('collapsed');
}
Expand Down
15 changes: 15 additions & 0 deletions addon/serializers/tumblr-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@ import Ember from 'ember';
import DS from 'ember-data';

export default DS.RESTSerializer.extend({
/**
* Post Type
* @type {string}
* @default
*/
type: '',

/**
* Use Post Type to determine model name for serializing
* @param {string} payloadKey The incoming payload key
* @returns {string} The modified key
*/
modelNameFromPayloadKey(payloadKey) {
const type = this.get('type');
if (Ember.isPresent(type)) {
Expand All @@ -12,6 +22,11 @@ export default DS.RESTSerializer.extend({
return this._super(payloadKey);
},

/**
* Normalize the payload to match our models
* @param {object} payload The incoming payload
* @returns {object} The modified payload
*/
normalizePayload(payload) {
if (payload.response && payload.response.posts) {
const posts = payload.response.posts.map(function (post) {
Expand Down
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.0",
"version": "0.5.1",
"description": "Ember Addon for integrating a Tumblr blog",
"directories": {
"doc": "doc",
Expand Down
2 changes: 1 addition & 1 deletion tests/dummy/app/templates/collapsed-blog.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<h3>This is a blog with collapsed posts</h3>

{{tumblr-blog
posts=model.content
posts=model
postsRoute='post'
collapsible=true}}
2 changes: 1 addition & 1 deletion tests/dummy/app/templates/linked-blog.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
<h3>This blog contains links to individual posts in the post titles</h3>

{{tumblr-blog
posts=model.content
posts=model
postsRoute='post'}}
2 changes: 1 addition & 1 deletion tests/dummy/app/templates/no-format-blog.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<h3>This blog uses no date formatting</h3>

{{tumblr-blog
posts=model.content
posts=model
postsRoute='post'
formatDates=false}}
2 changes: 1 addition & 1 deletion tests/dummy/app/templates/sorted-blog.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

{{debugger}}
{{tumblr-blog
posts=model.content
posts=model
postsRoute='post'
sortBy=sortBy}}
2 changes: 1 addition & 1 deletion tests/dummy/app/templates/uncollapsed-blog.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<h3>This is a collapsible blog that starts uncollapsed</h3>

{{tumblr-blog
posts=model.content
posts=model
postsRoute='post'
collapsible=true
collapseByDefault=false}}

0 comments on commit dfafe6b

Please sign in to comment.