rails oo views

43
Loading...

Upload: elia-schito

Post on 19-Jan-2015

3.346 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Rails OO views

Loading...

Page 2: Rails OO views

Markdown vs. MongoDBA Journey through bleeding edge

technologies for the NeXT Web

Page 3: Rails OO views

RubyMotion vs. BackboneA Journey through bleeding edge

technologies for the NeXT Web

Page 4: Rails OO views
Page 5: Rails OO views
Page 6: Rails OO views

Rails Views for the

OO-savvy Rubyist

Page 7: Rails OO views

M

V

C

Page 8: Rails OO views

M

V

C

Page 9: Rails OO views

Look at: Rails current implementation

Page 10: Rails OO views

def show @post = Post.find(params[:id]) @title = @post.titleend

Page 11: Rails OO views

<h1><%= @post.title %></h1><p><%= @post.body %></p>

Page 12: Rails OO views

<html> <head><title><%= @title %></title></head> <body><%= yield %></body></html>

Page 13: Rails OO views

My name‘s Guybrush threepwood. I‘m new in town

Matz told me their only for Object‘s internal state

Who‘s in charge here?

Nice talking to you.

And tell me boy, what‘s wrong with my @ivars

Page 14: Rails OO views

So how should I use @ivars?

Page 15: Rails OO views

When you design a class, you decide what internal state it has and also decide how that state is to appear on the outside (to users of your class).

Page 16: Rails OO views

The internal state is held in instance variables. The external state is exposed through methods we‘re call- ing attributes.

Page 17: Rails OO views

Dave Thomas,Programming Ruby

Page 18: Rails OO views

Deep in the Rails source...

Page 19: Rails OO views

# Define some internal variables that

# should not be propagated to the view.self.protected_instance_variables = [

:@_status, :@_headers, :@_params, :@_env, :@_response, :@_request, :@_view_runtime,

:@_stream, :@_url_options, :@_action_has_layout]

Page 20: Rails OO views

# Define some internal variables that

# should not be propagated to the view.self.protected_instance_variables = [

:@_status, :@_headers, :@_params, :@_env, :@_response, :@_request, :@_view_runtime,

:@_stream, :@_url_options, :@_action_has_layout]

Page 21: Rails OO views

protected instance variables

Page 22: Rails OO views

protected - instance - variables

Page 23: Rails OO views

I‘ll stick with "helper_method".

Give me some "decent_exposure"?

It‘s "obviews"!

I‘m made of rubber, you‘re made of glue.

And tell me boy, what ya doing about this?

Page 24: Rails OO views

helper_methodpros: rails standardcons: verbose, bad semantics, class level

Page 25: Rails OO views

helper_methodpros: rails standardcons: verbose, bad semantics, class level

Page 26: Rails OO views

helper_methodpros: rails standardcons: verbose, bad semantics, class level

Page 27: Rails OO views

decent_exposurepros: easy syntax, good defaultscons: class level

Page 28: Rails OO views

decent_exposurepros: easy syntax, good defaultscons: class level

Page 29: Rails OO views

decent_exposurepros: easy syntax, good defaultscons: class level

Page 30: Rails OO views

obviewspros: easy syntax, action levelcons: unpublished

Page 31: Rails OO views

obviewspros: easy syntax, action levelcons: unpublished

Page 32: Rails OO views

obviewspros: easy syntax, action levelcons: unpublished!

Page 33: Rails OO views

We want examples!

Page 34: Rails OO views

class PostsController < ApplicationController

expose :posts

def posts; Post.all; end

end

We want examples!

Page 35: Rails OO views

def show

expose post

end

def post; posts.find(params[:id]) end

We want examples!

Page 36: Rails OO views

def show

expose post: posts.find(params[:id])

end

We want examples!

Page 37: Rails OO views

<h1><%= post.title %></h1>

<p><%= post.body %></p>

We want examples!

Page 38: Rails OO views
Page 39: Rails OO views

Obviews

Page 40: Rails OO views

Obviews

on rubygems shipping today!

Page 41: Rails OO views

Thank you !1

Page 42: Rails OO views

No monkeys were harmed during the making of this keynote

twitter: @eliagithub: @eliablog: dev.mikamai.comblog: elia.schito.me

MIKAMAI

Page 43: Rails OO views

No monkeys were harmed during the making of this keynote

twitter: @eliagithub: @eliablog: dev.mikamai.comblog: elia.schito.me

MIKAMAI