Skip to content

Instantly share code, notes, and snippets.

@azu
Created May 17, 2009 16:02
Show Gist options
  • Save azu/113041 to your computer and use it in GitHub Desktop.
Save azu/113041 to your computer and use it in GitHub Desktop.
models.register( {
name: 'HatenaDiary',
ICON: 'http://d.hatena.ne.jp/favicon.ico',
POST_URL : 'http://d.hatena.ne.jp',
check : function(ps){
return (/(regular|photo|quote|link)/).test(ps.type) && !ps.file;
},
converters: {
getTitle: function(ps){
return Hatena.reprTags(ps.tags) + (ps.page || '')
},
renderingTemplates: {
regular: '<p>{ps.description}</p>',
photo: '<p><blockquote class="tombloo_photo" cite={ps.pageUrl} title={ps.page}><img src={ps.itemUrl} /></blockquote>{ps.description}</p>',
link: '<p><div class="tombloo_link"><a href={ps.pageUrl} title={ps.page}>{ps.page}</a></div>{ps.description}</p>',
quote: '<p><div class="tombloo_link"><a href={ps.pageUrl} title={ps.page}>{ps.page}</a></div><blockquote class="tombloo_quote" cite={ps.pageUrl} title={ps.page}>{ps.body}</blockquote>{ps.description}</p>',
},
__noSuchMethod__: function(name, args){
var ps = args[0];
return {
title: (name == 'regular') ? '' : this.getTitle(ps),
body: eval( this.renderingTemplates[name] ).toString()
};
},
},
post : function(params){
var content;
var self = this;
return models.Hatena.getToken().addCallback(function(token){
content = self.converters[params.type](params);
content.rkm = token;
return models.Hatena.getCurrentUser();
}).addCallback(function(id){
var endpoint = [self.POST_URL, id, ''].join('/');
return request( endpoint, {
redirectionLimit : 0,
referrer : endpoint,
sendContent : content
});
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment