Skip to content

Instantly share code, notes, and snippets.

@meritt
Created August 12, 2012 16:31
Show Gist options
  • Save meritt/3332718 to your computer and use it in GitHub Desktop.
Save meritt/3332718 to your computer and use it in GitHub Desktop.
Пример работы компилятора CS -> JS
options = {} unless options?
options.type = type if type?
if (typeof options === "undefined" || options === null) {
var options = {};
}
if (typeof type !== "undefined" && type !== null) {
options.type = type;
}
options = {url}
options =
url: 'link'
text: 'description'
show: false
var options = {
url: url
};
var options = {
url: 'link',
text: 'description',
show: false
};
do ->
parse = (body) -> JSON.parse body
request = (url, fn = ->) ->
xhr {url}, (error, request, body) -> fn.call @, parse body
(function() {
var parse, request;
parse = function(body) {
return JSON.parse(body);
};
request = function(url, fn) {
if (fn == null) {
fn = function() {};
}
xhr({url: url}, function(error, request, body) {
fn.call(this, parse(body));
});
};
})();
do (tumblr) ->
@debug = (text) -> console.log text
@periodical = (message) ->
setTimeout (=> @debug message), 1000
(function(tumblr) {
this.debug = function(text) {
return console.log(text);
};
this.periodical = function(message) {
var _this = this;
setTimeout(function() {
_this.debug(message);
}, 1000);
};
})(tumblr);
do (tumblr) ->
@posts = (options, fn) ->
[fn, options] = [options, null] if typeof options is 'function'
request options, fn
alias = (self, type) ->
self[type] = (options, fn) -> @posts options, fn
alias tumblr, type for type in ['text', 'quote', 'link', 'answer', 'video', 'audio', 'photo']
(function(tumblr) {
var alias, type, _i, _len, _ref;
this.posts = function(options, fn) {
var _ref;
if (typeof options === 'function') {
_ref = [options, null], fn = _ref[0], options = _ref[1];
}
request(options, fn);
};
alias = function(self, type) {
self[type] = function(options, fn) {
this.posts(options, fn);
};
};
_ref = ['text', 'quote', 'link', 'answer', 'video', 'audio', 'photo'];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
type = _ref[_i];
alias(tumblr, type);
}
})(tumblr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment