tombloo patch

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
      });
    });
  }
});