front end on rails

54
Front End on Rails A series of tips, tricks and a little magic by Justin Halsall

Upload: justin-halsall

Post on 07-Nov-2014

7.762 views

Category:

Technology


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Front End on Rails

Front End on RailsA series of tips, tricks and a little magic

by Justin Halsall

Page 2: Front End on Rails

Rails is sexy!

Page 3: Front End on Rails

Rails is sexy!If you know your stuff

Page 4: Front End on Rails

HTML is sexy!

Page 5: Front End on Rails

HTML is sexy!If you know your stuff

Page 6: Front End on Rails

Sexy!

Not Sexy!

Page 7: Front End on Rails

Sexy!

Fronteersfronteers.nl

Page 8: Front End on Rails

<html><p>simple tips to minify hassle</p>

Page 9: Front End on Rails

Doctypebe strict!

Page 10: Front End on Rails

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

Page 11: Front End on Rails

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

Page 12: Front End on Rails

“near standards mode”yuck!

Page 13: Front End on Rails

different boxmodelhell in a handbasket

Page 14: Front End on Rails

inline/block level element

Page 15: Front End on Rails

Block level elements<div>Your general-purpose box<h1> ... <h6>All headings<p>Paragraph<ul>, <ol>, <dl>Lists (unordered, ordered and definition)<li>, <dt>, <dd>List items, definition list terms, and definition list definitions<table>Tables<blockquote>Like an indented paragraph, meant for quoting passages of text<pre>Indicates a block of preformatted code<form>An input form

Page 16: Front End on Rails

Inline elements<span>Your all-purpose inline element<a>Anchor, used for links (and also to mark specific targets on a page for direct linking)<strong>Used to make your content strong, displayed as bold in most browsers, replaces the narrower <b> (bold) tag<em>Adds emphasis, but less strong than <strong>. Usually displayed as italic text, and replaces the old <i> (italic) tag<img />Image<br>The line-break is an odd case, as it's an inline element that forces a new line. However, as the text carries on on the next line, it's not a block-level element.<input>Form input fields like text fields and buttons<abbr>Indicates an abbr. (hover to see how it works)<acronym>Working much like the abbreviation, but used for things like this TLA.

Page 17: Front End on Rails

<strong><div></div></strong>

block nested in inline element

Page 18: Front End on Rails

<strong><div></div></strong>

Don’t do it

block nested in inline element

Page 20: Front End on Rails

<h1>Headers</h1>

The first step towards semantic enlightenment

don’t use more that one <h1> on a page

headers should be used as a tree structure

Page 21: Front End on Rails

<h1>Ruby</h1>

<h2>Articles</h2> <h2>Documentation</h2>

<h3>RubyConf 2010</h3>

<h3>Ruby 2.0.1 relaesed</h3>

<h3>Books</h3> <h3>Online</h3>

<h4>O'Reily</h4><h4>Pragmatic

programmers</h4>

Page 22: Front End on Rails

IDs & Classes

IDs need to be unique

Class should be re-used

IDs define the elements identity

Classes define the elements type

Page 23: Front End on Rails

<h1>List of companies that use Ruby</h1><ul> <li id='company_1' class='ruby_agency'> <h2>Ye olde webshoppe</h2> <p>Hero for hire</p> </li> <li id='company_2' class='startup'> <h2>Wakoopa</h2> <p>Cool dutch startup</p> </li> <li id='company_3' class='startup'> <h2>Soocial</h2> <p>Another cool dutch startup</p> </li></ul>

Page 24: Front End on Rails

<h1>List of companies that use Ruby</h1><ul> <li id='company_1' class='ruby_agency'> <h2>Ye olde webshoppe</h2> <p>Hero for hire</p> </li> <li id='company_2' class='startup'> <h2>Wakoopa</h2> <p>Cool dutch startup</p> </li> <li id='company_3' class='startup'> <h2>Soocial</h2> <p>Another cool dutch startup</p> </li></ul>

Page 25: Front End on Rails

<h1>List of companies that use Ruby</h1><ul> <li id='company_1' class='ruby_agency'> <h2>Ye olde webshoppe</h2> <p>Hero for hire</p> </li> <li id='company_2' class='startup'> <h2>Wakoopa</h2> <p>Cool dutch startup</p> </li> <li id='company_3' class='startup'> <h2>Soocial</h2> <p>Another cool dutch startup</p> </li></ul>

Page 26: Front End on Rails

#justin { color: yellow;}.webdeveloper { color: blue;}

<p id='justin' class='webdeveloper'> Justin Halsall</p>

Specificity

Page 27: Front End on Rails

#justin { color: yellow;}.webdeveloper { color: blue;}

<p id='justin' class='webdeveloper'> Justin Halsall</p>

Specificity

Justin Halsall

Page 29: Front End on Rails

Sass (Syntactically Awesome StyleSheets)

Nicer syntax: no more {curly brackets}

Nested rules: saves lots of repetition

Variables

Automatic minifying in production

Page 30: Front End on Rails

Sass syntax

#main p :color #00ff00 :width 97%

.redbox :background-color #ff0000 :color #000000

Page 31: Front End on Rails

Sass syntax#main p :color #00ff00 :width 97%

.redbox :background-color #ff0000 :color #000000

#main p { color: #00ff00; width: 97%; } #main p .redbox { background-color: #ff0000; color: #000000; }

Page 32: Front End on Rails

Sass syntax#main p :color #00ff00 :width 97%

.redbox :background-color #ff0000 :color #000000

#main p { color: #00ff00; width: 97%; } #main p .redbox { background-color: #ff0000; color: #000000; }

Page 33: Front End on Rails

Scaffold anyone?http://flickr.com/photos/mag3737/1419671737/

Page 34: Front End on Rails

Xtreme_scaffoldhttp://github.com/Juice10/xtreme_scaffold/http://flickr.com/photos/lorna87/283420918/

Page 35: Front End on Rails

label

<%= label :post, :title %><label for="post_title">Title</label>

Page 36: Front End on Rails

Link_to :method

<%= link_to 'Destroy', post, :confirm => 'Are you sure?', :method => :delete %>

<a href="#" onclick="if (confirm('are you sure?')) { new Ajax.Request('/posts/1', {asynchronous:true, evalScripts:true, method:'delete', parameters:'authenticity_token=' + encodeURIComponent('cc2f94f376dda7d1092ad74b8ed78fc66140cc34')}); }; return false;">Destroy</a>

Page 37: Front End on Rails

Rails

HTML

Page 38: Front End on Rails

routes.rb

map.resources :posts

Page 39: Front End on Rails

routes.rb

map.resources :posts, :member => {:delete => :get}

Page 40: Front End on Rails

posts_controller.rb

# GET /posts/1/deletedef delete @post = Post.find(params[:id])end

Page 41: Front End on Rails

delete.html.erb

<h1>Destroy post</h1><p>Are you sure?</p><% form_for @post, :html => {:method => :delete} do |f| %> <%= f.submit 'Destroy' %><% end %>

Page 42: Front End on Rails

index.html.erb

<%= link_to 'Destroy', post, :confirm => 'Are you sure?', :method => :delete

Page 43: Front End on Rails

index.html.erb

<%= link_to 'Destroy', post, :confirm => 'Are you sure?', :method => :delete, :href => delete_post_path(post) %>

Page 44: Front End on Rails

index.html.erb

<%= link_to 'Destroy', post, :confirm => 'Are you sure?', :method => :delete, :href => delete_post_path(post) %>

<a href="#" onclick="if (confirm('are you sure?')) { new Ajax.Request('/posts/1', {asynchronous:true, evalScripts:true, method:'delete', parameters:'authenticity_token=' + encodeURIComponent('cc2f94f376dda7d1092ad74b8ed78fc66140cc34')}); }; return false;" href="/posts/1/delete">Destroy</a>

Page 45: Front End on Rails

index.html.erb

<%= link_to 'Destroy', post, :confirm => 'Are you sure?', :method => :delete, :href => delete_post_path(post) %>

<a href="#" onclick="if (confirm('are you sure?')) { new Ajax.Request('/posts/1', {asynchronous:true, evalScripts:true, method:'delete', parameters:'authenticity_token=' + encodeURIComponent('cc2f94f376dda7d1092ad74b8ed78fc66140cc34')}); }; return false;" href="/posts/1/delete">Destroy</a>

still u

gly

Page 46: Front End on Rails

still uglyhttp://flickr.com/photos/humandescent/318544728/

Page 47: Front End on Rails

application.jsEvent.observe(window, 'load', function(){ // all delete links $$('a.delete').each(function(link) { Event.observe(link, 'click', function(evt){ if (confirm('are you sure?')) { new Ajax.Request(link.href.gsub(/\/delete$/, ''), {asynchronous:true, evalScripts:true, method:'delete'}); }; Event.stop(evt) }) })})

Page 48: Front End on Rails

index.html.erb

<%= link_to 'Destroy', delete_post_path(post), :class => 'delete' %>

Page 49: Front End on Rails

index.html.erb

<%= link_to 'Destroy', delete_post_path(post), :class => 'delete' %>

<a href="/posts/2/delete" class="delete"> Destroy</a>

Page 50: Front End on Rails

index.html.erb

<%= link_to 'Destroy', delete_post_path(post), :class => 'delete' %>

Sexy!

<a href="/posts/2/delete" class="delete"> Destroy</a>

Page 51: Front End on Rails

Unobtrusive JavaScript RouteJSON is your friend

Page 52: Front End on Rails

The End

Twitter name: juice10

Side Project: http://tvnotify.com

Blog: http://juice10.com

Page 53: Front End on Rails

The End

Twitter name: juice10

Side Project: http://tvnotify.com

Blog: http://juice10.com

Page 54: Front End on Rails

The End

Twitter name: juice10

Side Project: http://tvnotify.com

Blog: http://juice10.com