https://wiki.diasporafoundation.org/api.php?action=feedcontributions&user=TheEditor&feedformat=atomdiaspora* project wiki - User contributions [en]2024-03-28T21:10:44ZUser contributionsMediaWiki 1.39.3https://wiki.diasporafoundation.org/wiki/index.php?title=An_introduction_to_the_Diaspora_source&diff=88An introduction to the Diaspora source2012-10-10T16:28:55Z<p>TheEditor: /* The Models: */</p>
<hr />
<div>== Framework and Tools: ==<br />
<br />
Diaspora is written in '''[http://rubyonrails.org/ Ruby on Rails]''', a web framework for the [http://www.ruby-lang.org Ruby programming language].<br /><br />
If you’ve never looked at a Rails project, you may want to check out a [http://guides.rubyonrails.org/getting_started.html Rails guide like this one].<br />
<br />
There are a few tools we’re using that aren’t in every rails project:<br />
<br />
* '''Haml'''<br /><br />
Our view templates are written in HAML (a templating language) instead of the default ERB (HTML with inline Ruby code).<br /><br />
The HAML docs can be found [http://haml-lang.com/docs.html here]. The corresponding files under <tt>app/views</tt>.<br />
* '''Sass'''<br /><br />
Our CSS is written in [http://sass-lang.com/docs.html SASS] (specifically, the ‘scss’ dialect), which generates the actual CSS via the [http://guides.rubyonrails.org/asset_pipeline.html Rails asset pipeline]. The syntax is inspired by CSS, and quite similar, but it offers some additional features like nesting and variables. If you want to edit the stylesheets, have a look in <tt>app/assets/stylesheets/</tt>.<br /><br />
'''''Note:''''' Both HAML and SASS are whitespace sensitive.<br />
* '''Backbone.js &amp; Handlebars.js'''<br /><br />
The client-side functionality and rendering is mostly coordinated with [http://documentcloud.github.com/backbone/ Backbone.js], which communicates [https://en.wikipedia.org/wiki/Representational_state_transfer REST]-fully with the server with JSON and triggers the rendering of the [http://handlebarsjs.com/ Handlebars.js] templates. The logic is found in <tt>app/assets/javascripts/app</tt> and the Handlebars templates are located in <tt>app/assets/templates</tt><br />
<br />
== Testing: ==<br />
<br />
Our goal is to test ''everything''. If you find a bug, you first expose it by writing a tests that fails because of the bug. Only then you start fixing the actual code. This is called [https://en.wikipedia.org/wiki/Test-driven_development Test Driven Delopment] (TDD).<br /><br />
We write our unit tests for ruby code in [http://blog.davidchelimsky.net/2007/05/14/an-introduction-to-rspec-part-i/ Rspec], the JavaScript test are in [http://pivotal.github.com/jasmine/ Jasmine] and integration tests in [http://rubylearning.com/blog/2010/10/05/outside-in-development/ Cucumber]. Specs are in <tt>spec</tt>, and Cucumber features are in <tt>features</tt>. For more details see our page on [[Testing workflow]].<br />
<br />
== The Models: ==<br />
<br />
Our Models can be found in the <tt>app/models</tt> folder:<br />
<br />
[[User]] – Users, of course, come first. A User object represents the private information and capabilities of a user on that server. The user object is able to friend people, post updates, and update his profile. A User has a Person.<br />
<br />
[[Contact]] – Is a “proxy” object for every person a User is friends with.<br />
<br />
[[Person]] – A Person is a User viewed from the outside. When a user friends another user, they friend that user’s Person object. Person objects are replicated across servers, and they are where a User’s public key lives. A Person has many Posts. A Person has a Profile.<br />
<br />
[[Profile]] – This contains information about the person. Currently, a profile looks the same to anyone looking at it.<br />
<br />
[[Request]] – This is a friend request object that gets sent to another person.<br />
<br />
[[Aspect]] – This contains a list of people, and posts which are for that aspect. Aspects are private to Users, and we might embed the Aspect documents in the User document.<br />
<br />
[[Post]] – A Post belongs to a Person. This is a parent class for different types of posts, it contains comment ids and a few other attributes common to all Posts.<br />
<br />
* Status Message inherits from Post<br />
* Album inherits from Post<br />
* Photo inherits from Post<br />
<br />
Comment – a comment belongs to a Post<br />
<br />
Retraction – this is an object that gets sent out when a post creator deletes a post. It is not a model, but it serializes for dispatch to other Diaspora servers the same way our models do.<br />
<br />
==== Posting something (app/models/user): ====<br />
<br />
# When a user posts anything, he/she posts it to an aspect or all aspects<br />
# Assuming the post is valid, the post created and its id is stored in raw_visible_posts for that user<br />
# The html for that post is rendered on the server and is pushed to the user through the websocket<br />
# The post is then serialized to xml, wrapped in an encrypted and signed salmon envelope and POSTed to the receive urls(“http://pod.location/receive/users/:id[person_id]”) for the recipient people.<br />
<br />
==== Receiving a post (app/controllers/publics_controller.rb &amp; lib/diaspora/user/receiving.rb ): ====<br />
<br />
# The user receives the salmon, decrypts the headers.<br />
# If the signature on the salmon data is from the person who claims to have sent the post is marshaled into an object and saved into the database.<br />
# That post id is stored in the visible posts for the receiving user as well as posts for the aspect the sender is in.<br />
<br />
Here’s the autogenerated documentation http://rubydoc.info/github/diaspora/diaspora/master<br />
<br />
[[Category:Developers]]<br />
[[Category:Technical]]</div>TheEditor