[Xfce4-commits] <cafe:master> Switch to using HAML templates.
Jannis Pohlmann
noreply at xfce.org
Sun Mar 13 18:00:01 CET 2011
Updating branch refs/heads/master
to d5136c7cd81b1d5c8561711d5ad28c694574d279 (commit)
from 58f83bfabc983ff5bcbf852bc205b39fd4431ffa (commit)
commit d5136c7cd81b1d5c8561711d5ad28c694574d279
Author: Jannis Pohlmann <jannis at xfce.org>
Date: Sun Mar 13 17:58:49 2011 +0100
Switch to using HAML templates.
lib/helpers/general.rb | 49 +++++++++++++++++++++++------------
lib/views/authentication_login.erb | 9 ------
lib/views/foot.erb | 3 --
lib/views/head.erb | 15 -----------
lib/views/index.erb | 2 -
lib/views/index.haml | 1 +
lib/views/layout.haml | 14 ++++++++++
lib/views/member.erb | 40 -----------------------------
lib/views/member.haml | 31 ++++++++++++++++++++++
lib/views/members.erb | 29 ---------------------
lib/views/members.haml | 21 +++++++++++++++
lib/views/stylesheet.sass | 3 +-
12 files changed, 101 insertions(+), 116 deletions(-)
diff --git a/lib/helpers/general.rb b/lib/helpers/general.rb
index e25b5de..daf145d 100644
--- a/lib/helpers/general.rb
+++ b/lib/helpers/general.rb
@@ -1,3 +1,5 @@
+require 'haml'
+
module Cafe
module Helpers
module General
@@ -12,27 +14,22 @@ module Cafe
module Helpers
include Cafe::Models
- def header(args={})
- custom_binding = binding.clone
- eval 'params = ' + args.inspect, custom_binding
- import('head', custom_binding)
- end
-
- def footer
- import('foot')
- end
-
- def import(template, custom_binding=nil)
+ def render_layout(custom_binding, &block)
directory = File.expand_path(File.dirname(__FILE__))
- filename = File.join(directory, '..', 'views', "#{template}.erb")
- erb = open(filename) do |file|
- ERB.new(file.read)
+ filename = File.join(directory, '..', 'views', 'layout.haml')
+ engine = open(filename) do |file| Haml::Engine.new(file.read) end
+ engine.render(if custom_binding.nil? then binding else custom_binding end) do
+ block.call(self)
end
- erb.result(if custom_binding.nil? then binding else custom_binding end)
end
- def view(*args)
- import(*args)
+ def view(template, custom_binding = nil)
+ render_layout(custom_binding) do
+ directory = File.expand_path(File.dirname(__FILE__))
+ filename = File.join(directory, '..', 'views', "#{template}.haml")
+ engine = open(filename) do |file| Haml::Engine.new(file.read) end
+ engine.render(if custom_binding.nil? then binding else custom_binding end)
+ end
end
def cycle(*values)
@@ -63,6 +60,24 @@ module Cafe
env[:error].has_key?(key)
end
end
+
+ def inline_error(key)
+ if error_set?(key)
+ haml "%span{:class => 'error'} #{error(key)}"
+ else
+ ''
+ end
+ end
+
+ def block_error(key)
+ if error_set?(key)
+ haml "%p.error
+ %span.placeholder
+ #{error(key)}"
+ else
+ ''
+ end
+ end
end
end
end
diff --git a/lib/views/authentication_login.erb b/lib/views/authentication_login.erb
deleted file mode 100644
index 11c37fa..0000000
--- a/lib/views/authentication_login.erb
+++ /dev/null
@@ -1,9 +0,0 @@
-<%= header :title => 'Xfce Foundation Manager | Login' %>
-<form method="post" action="/login">
- <fieldset>
- <p><label for="email">Email address:</label> <input type="text" id="email" name="email" /></p>
- <p><label for="password">Password:</label> <input type="password" id="password" name="password"/></p>
- <p><span class="placeholder"> </span> <input type="submit" value="Log in"/></p>
- </fieldset>
-</form>
-<%= footer %>
diff --git a/lib/views/foot.erb b/lib/views/foot.erb
deleted file mode 100644
index 5b6e2d6..0000000
--- a/lib/views/foot.erb
+++ /dev/null
@@ -1,3 +0,0 @@
- </div>
- </body>
-</html>
diff --git a/lib/views/head.erb b/lib/views/head.erb
deleted file mode 100755
index 2013134..0000000
--- a/lib/views/head.erb
+++ /dev/null
@@ -1,15 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
- <title>Xfce Foundation Manager<%= if params.has_key?(:title) then " | #{params[:title]}" end %></title>
- <link rel="stylesheet" href="/stylesheet.css" media="all" type="text/css"/>
- </head>
- <body>
- <h1><%= if params.has_key?(:title) then params[:title] else 'Xfce Foundation Manager' end %></h1>
- <p id="main-toolbar">
- <% if authenticated? %>
- <a href="/members">Members</a>
- <% end %>
- </p>
- <div id="body">
diff --git a/lib/views/index.erb b/lib/views/index.erb
deleted file mode 100644
index ffce996..0000000
--- a/lib/views/index.erb
+++ /dev/null
@@ -1,2 +0,0 @@
-<%= header :title => 'Overview' %>
-<%= footer %>
diff --git a/lib/views/index.haml b/lib/views/index.haml
new file mode 100644
index 0000000..04a6767
--- /dev/null
+++ b/lib/views/index.haml
@@ -0,0 +1 @@
+%h2 Overview
diff --git a/lib/views/layout.haml b/lib/views/layout.haml
new file mode 100644
index 0000000..bec4350
--- /dev/null
+++ b/lib/views/layout.haml
@@ -0,0 +1,14 @@
+!!! Strict
+%html
+ %head
+ %meta{'http-equiv' => 'Content-Type', :content => 'text/html; charset=utf-8'}/
+ %title foo
+ %link{:rel => 'stylesheet', :href => '/stylesheet.css', :media => 'all', :type => 'text/css'}/
+ %body
+ %h1 Xfce Foundation Manager
+ %p{:id => 'main-toolbar'}
+ %a{:href => '/'} Overview
+ - if authenticated?
+ %a{:href => '/members'} Foundation Members
+ #body
+ = yield
diff --git a/lib/views/member.erb b/lib/views/member.erb
deleted file mode 100644
index 8f8fccc..0000000
--- a/lib/views/member.erb
+++ /dev/null
@@ -1,40 +0,0 @@
-<%= header :title => 'Edit Member %s' % [@member.fullname] %>
-<h2>Member Information</h2>
-<form method="post" action="/member/<%= @member.id %>/information">
- <fieldset>
- <p>
- <label for="fullname">Full name:</label>
- <input type="text" id="fullname" name="fullname" value="<%= @member.fullname %>"/>
- <% if error(:fullname) %><span class="error"><%= error(:fullname) %></span><% end %>
- </p>
- <p>
- <label for="email">Email address:</label>
- <input type="text" id="email" name="email" value="<%= @member.email %>"/>
- <% if error(:email) %><span class="error"><%= error(:email) %></span><% end %>
- </p>
- <p>
- <label for="address">Address:</label>
- <textarea id="address" name="address"><%= @member.address %></textarea>
- </p>
- <% if error(:address) %><p class="error"><span class="placeholder"> </span><%= error(:address) %></p><% end %>
- <p>
- <label for="new_password">Password:</label>
- <input type="password" id="new_password" name="new_password" value=""/>
- <% if error(:new_password) %><span class="error"><%= error(:new_password) %></span><% end %>
- </p>
- <p>
- <label for="new_password">Password (confirmation):</label>
- <input type="password" id="new_password_repeat" name="new_password_repeat" value=""/>
- <% unless params.has_key?(:new_password) %>
- <span class="info">Leave empty for no password change</span>
- <% end %>
- </p>
- <p>
- <label for="member_since">Member since:</label>
- <input type="text" id="member_since" name="member_since" value="<%= @member.member_since %>"/>
- <span class="info">Format: YYYY-MM-DD</span>
- </p>
- <p><span class="placeholder"> </span> <input type="submit" value="Save"/></p>
-</form>
-<h2>Membership Status</h2>
-<%= footer %>
diff --git a/lib/views/member.haml b/lib/views/member.haml
new file mode 100644
index 0000000..9b9522e
--- /dev/null
+++ b/lib/views/member.haml
@@ -0,0 +1,31 @@
+%h2 Member Information
+%form{:method => 'post', :action => "/member/#{@member.id}/information"}
+ %fieldset
+ %p
+ %label{:for => 'fullname'} Name:
+ %input{:type => 'text', :id => 'fullname', :name => 'fullname', :value => @member.fullname}/
+ = inline_error(:fullname)
+ %p
+ %label{:for => 'email'} Email address:
+ %input{:type => 'text', :id => 'email', :name => 'email', :value => @member.email}
+ = inline_error(:email)
+ %p
+ %label{:for => 'address'} Address:
+ %textarea{:id => 'address', :name => 'address'}= @member.address
+ = block_error(:address)
+ %p
+ %label{:for => 'member_since'} Member since:
+ %input{:type => 'text', :id => 'member_since', :name => 'member_since', :value => @member.member_since}
+ %span.info Format: YYYY-MM-DD
+ = block_error(:member_since)
+ %p
+ %label{:for => 'new_password'} Password:
+ %input{:type => 'password', :id => 'new_password', :name => 'new_password'}
+ = inline_error(:new_password)
+ %p
+ %label{:for => 'new_password_repeat'} Password confirmation:
+ %input{:type => 'password', :id => 'new_password_repeat', :name => 'new_password_repeat'}
+ %span.info Leave empty to keep the current password
+ %p
+ %span.placeholder
+ %input{:type => 'submit', :value => 'Save'}
diff --git a/lib/views/members.erb b/lib/views/members.erb
deleted file mode 100644
index 44fba06..0000000
--- a/lib/views/members.erb
+++ /dev/null
@@ -1,29 +0,0 @@
-<%= header :title => 'Members' %>
-<h2>Member List</h2>
-<% if Member.count == 0 %>
- <p>The foundation currently has no members.</p>
-<% else %>
- <table cellspacing="0" cellpadding="0">
- <tr>
- <th>Member ID</th>
- <th>Full Name</th>
- <th>Email Address</th>
- <th>Address</th>
- <th>Member Since</th>
- <th>Actions</th>
- </tr>
- <% for member in Member.all(:order => [:fullname.asc]) %>
- <tr class="<%= cycle('odd', 'even') %>">
- <td>#<%= member.id %></td>
- <td><%= member.fullname %></td>
- <td><%= member.email %></td>
- <td><%= member.address.gsub(/\n/, '<br/>') %></td>
- <td><%= member.member_since %></td>
- <td>
- <a href="/member/<%= member.id %>">Edit</a>
- </td>
- </tr>
- <% end %>
- </table>
-<% end %>
-<%= footer %>
diff --git a/lib/views/members.haml b/lib/views/members.haml
new file mode 100644
index 0000000..55e8d3e
--- /dev/null
+++ b/lib/views/members.haml
@@ -0,0 +1,21 @@
+%h2 Foundation Members
+- if Member.count == 0
+ %p The foundation currently has no members.
+- else
+ %table{:cellspacing => 0, :cellpadding => 0}
+ %tr
+ %th Member ID
+ %th Name
+ %th Email Address
+ %th Address
+ %th Member Since
+ %th Actions
+ - for member in Member.all(:order => [:fullname.asc])
+ %tr
+ %td= '#%s' % member.id
+ %td= member.fullname
+ %td= member.email
+ %td= member.address.gsub(/\n/, '<br />')
+ %td= member.member_since
+ %td
+ %a{:href => "/member/#{member.id}"} Edit
diff --git a/lib/views/stylesheet.sass b/lib/views/stylesheet.sass
index 82e3e57..47ab8fc 100755
--- a/lib/views/stylesheet.sass
+++ b/lib/views/stylesheet.sass
@@ -33,8 +33,9 @@ h1
a
color: rgb(255,255,255)
padding: 0em
+ margin-right: 0.5em
&:hover
- color: rgb(50,100,200)
+ color: rgb(102,153,255)
#body
padding:
More information about the Xfce4-commits
mailing list