This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Statuses = function() { | |
| }; | |
| Statuses.prototype.add = function(options) { | |
| $.ajax({ | |
| url: '/status', | |
| type: 'POST', | |
| dataType: 'json', | |
| data: { text: options.text }, | |
| success: options.success | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -function addStatus(options) { | |
| +var Statuses = function() { | |
| +}; | |
| +Statuses.prototype.add = function(options) { | |
| $.ajax({ | |
| url: '/status', | |
| type: 'POST', | |
| dataType: 'json', | |
| data: { text: options.text }, | |
| success: options.success |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function addStatus(options) { | |
| $.ajax({ | |
| url: '/status', | |
| type: 'POST', | |
| dataType: 'json', | |
| - data: { text: $('#new-status textarea').val() }, | |
| - success: function(data) { | |
| - $('#statuses ul').append('<li>' + data.text + '</li>'); | |
| - $('#new-status textarea').val(''); | |
| - } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| +function addStatus(options) { | |
| + $.ajax({ | |
| + url: '/status', | |
| + type: 'POST', | |
| + dataType: 'json', | |
| + data: { text: $('#new-status textarea').val() }, | |
| + success: function(data) { | |
| + $('#statuses ul').append('<li>' + data.text + '</li>'); | |
| + $('#new-status textarea').val(''); | |
| + } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require './xmldsl' | |
| Twitter = Struct.new :name, :avatar, :text | |
| twitters = [] | |
| 5.times { twitters << Twitter.new("Jonas", "/profile.png", "Hello World!") } | |
| xml = XML.generate do | |
| html do | |
| body do | |
| twitters.each do |tw| |
Implemented as an exercise to learn about metaprogramming in Ruby. The DSL is implemented using instance_eval and method_missing.
require 'xmldsl'
Twitter = Struct.new :name, :avatar, :text
twitters = []
5.times { twitters << Twitter.new("Jonas", "/profile.png", "Hello World!") }
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var events = new EventEmitter(); | |
| var UserView = function(el, user) { | |
| this.el = el; | |
| this.user = user; | |
| // Let's listen for someone emitting the event 'user:showImage', which | |
| // we listen for and then show the user's image. | |
| // The first parameter is the event name, the second is the function | |
| // to call when the event is triggered, and the third is the context |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| UserView.prototype.$ = function(selector) { | |
| return this.el.find(selector); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| describe('user view', function() { | |
| it('should be able to show image', function() { | |
| var user = { | |
| image: "user.png" | |
| }; | |
| var view = new UserView($('<div></div>'), user); | |
| view.showImage(); | |
| // remember that `view.el` is a jQuery object. So now we can call |