| Rendr / Node.js | |
|---|---|
| DRY (no duplicate views) |
✓ |
| SEO Friendly | ✓ |
| "Thick" client | ✓ |
| Mostly write one language | ✓ |
| Rails? | X |
| Rendr / Node.js | Duplicate Code | |
|---|---|---|
| DRY (no duplicate views) |
✓ | X |
| SEO Friendly | ✓ | ✓ |
| "Thick" client | ✓ | ✓ |
| Mostly write one language | ✓ | X |
| Rails? | X | ½ |
| Rendr / Node.js | Duplicate Code | Turbolinks | |
|---|---|---|---|
| DRY (no duplicate views) |
✓ | X | ✓ |
| SEO Friendly | ✓ | ✓ | ✓ |
| "Thick" client | ✓ | ✓ | X |
| Mostly write one language | ✓ | X | ✓ |
| Rails? | X | ½ | ✓ |
| Rendr / Node.js | Duplicate Code | Turbolinks | Ember / Angular / Backbone | |
|---|---|---|---|---|
| DRY (no duplicate views) |
✓ | X | ✓ | ✓ |
| SEO Friendly | ✓ | ✓ | ✓ | X |
| "Thick" client | ✓ | ✓ | X | ✓ |
| Mostly write one language | ✓ | X | ✓ | X |
| Rails? | X | ½ | ✓ | ½ |
| Perspectives | Rendr / Node.js | Duplicate Code | Turbolinks | Ember / Angular / Backbone | |
|---|---|---|---|---|---|
| DRY (no duplicate views) |
✓ | ✓ | X | ✓ | ✓ |
| SEO Friendly | ✓ | ✓ | ✓ | ✓ | X |
| "Thick" client | ✓ | ✓ | ✓ | X | ✓ |
| Mostly write one language | ✓ | ✓ | X | ✓ | X |
| Rails? | ✓ | X | ½ | ✓ | ½ |
<%= link_to user.name, user_url(user) %>
<%= link_to "Quote of the day",
ActiveRecord::Base.connection.execute(<<-SQL).first['url']
SELECT url FROM quotes_of_the_day ORDER BY Random() LIMIT 1
SQL
%>
{{referent}}
{{{body}}}
{{#edit}}
Edit
{{/edit}}
{
referent: "node.js",
body: 'node.js is a platform...',
edit: true,
edit_href: '/talks/1/annotations/3/edit'
}
{
referent: "node.js",
...
}
{{referent}}
'<blockquote>node.js</blockquote>'
{
...
body: 'node.js is a platform...',
...
}
{{{body}}}
'<a href="http://nodejs.org/">node.js</a> is a platform...'
{
...
edit: true,
edit_href: '/talks/1/annotations/3/edit'
}
{{#edit}}
Edit
{{/edit}}
'<a href="/talks/1/annotations/3/edit">Edit</a>'
{
edit: false,
...
}
{{^edit}} Can't edit! {{/edit}}
'Can't edit!'
{{referent}}
{{{body}}}
{{#edit}}
Edit
{{/edit}}
{
referent: "node.js",
body: 'node.js is a platform...',
edit: true,
edit_href: '/talks/1/annotations/3/edit'
}
class Annotations::Show < Perspectives::Base
param :annotation # param = input
property(:referent) { annotation.referent }
property(:body) { annotation.body_as_html }
# property = output
property(:edit) do
annotation.created_by == current_user || current_user.admin?
end
property(:edit_href) { edit_annotation_path(annotation) }
end
class Annotations::Show < Perspectives::Base
param :annotation
# param = input
# ...
end
class Annotations::Show < Perspectives::Base
property(:referent) { annotation.referent }
property(:body) { annotation.body_as_html }
# property = output
# ...
end
class Annotations::Show < Perspectives::Base
property(:referent) { annotation.referent }
property(:body) { annotation.body_as_html }
# ...
end
{
referent: "node.js",
body: 'node.js is a platform...',
edit: true,
edit_href: '/talks/1/annotations/3/edit'
}
# Gemfile
gem 'perspectives'
rails generate perspectives:install
class AnnotationsController < ApplicationController
def show
annotation = Annotation.find(params[:id])
respond_with(perspective('annotations/show',
annotation: annotation))
end
end
<%= @annotation.referent %>
<%= @annotation.body_as_html %>
<% if @annotation.created_by == current_user || current_user.admin? %>
<%= link_to 'Edit', edit_annotation_path(@annotation) %>
<% end %>
...
{{#edit}}
Edit
{{/edit}}
class Annotations::Show < Perspectives::Base
# ...
property(:edit) do
annotation.created_by == current_user || current_user.admin?
end
# ...
end
# spec/perspectives/annotations/show_spec.rb
require 'spec_helper'
describe Annotations::Show do
it 'should be easy to test!' do
user = double(:user)
annotation = double(:annotation, created_by: user)
annotations_show = described_class.new(
{current_user: user},
annotation: annotation)
annotations_show.edit.should be_true
end
end
class Annotations::Show < Perspectives::Base
param :annotation
cache { annotation }
end
class Annotations::Show < Perspectives::Base
param :annotation
cache { annotation }
# cache_key:
# "annotations/1-20140404025902750005000"
end
class Annotations::Show < Perspectives::Base
param :annotation
cache { annotation }
delegate :created_by, to: :annotation
nested 'users/avatar', user: :created_by
end
class Users::Avatar < Perspectives::Base
param :user
cache { user }
# cache_key:
# "users/4-20140420203350976646000"
end
class Annotations::Show < Perspectives::Base
param :annotation
cache { annotation }
delegate :created_by, to: :annotation
nested 'users/avatar', user: :created_by
end
class Annotations::Show < Perspectives::Base
cache { annotation }
nested 'users/avatar', user: :created_by
# cache_key:
# "annotations/1-20140404025902750005000"
# +
# "users/4-20140420203350976646000"
# =
end