Skip to content

Instantly share code, notes, and snippets.

View iHiD's full-sized avatar
💙

Jeremy Walker iHiD

💙
View GitHub Profile
@iHiD
iHiD / data_helper.rb
Created June 25, 2012 19:47
Security Article Part 3 - 13
module DataHelper
def data_to_table(data)
content_tag :table do
rows = data.map do |row|
content_tag :tr do
cells = row.map do |cell|
content_tag :td, cell
end
safe_join(cells)
end
@iHiD
iHiD / data_helper.rb
Created June 25, 2012 19:35
Security Article Part 3 - 14
module DataHelper
def data_to_table(data)
content_tag :table do
data.map do |row|
content_tag :tr do
row.map {|cell| content_tag :td, cell}.reduce(:<<)
end
end.reduce(:<<)
end
end
@iHiD
iHiD / data_helper.rb
Created June 25, 2012 19:17
Security Article Part 3 - 12
module DataHelper
...
output << "<td>#{h cell}</td>"
...
end
@iHiD
iHiD / data_helper.rb
Created June 25, 2012 19:16
Security Article Part 3 - 11
module DataHelper
# Expects a nested array such as:
# [[1,'Jez','iHiD'], [2,'Bob','<b>xyz</b>']]
#
# and outputs:
# <table>
# <tr><td>1</td><td>Jez</td><td>iHiD</td></tr>
# <tr><td>2</td><td>Bob</td><td>&lt;b&gt;xyz&lt;/b&gt;</td></tr>
# </table>
def data_to_table(data)
@iHiD
iHiD / show.html.erb
Created June 25, 2012 19:15
Security Article Part 3 - 10
<h2><%= @blog_post.title %></h2>
<div id="content"><%= sanitize(@blog_post.content, tags: tags %w(b strong i em)) %></div>
@iHiD
iHiD / show.html.haml
Created June 25, 2012 19:13
Security Article Part 3 - 9
=cache "#{current_user.is_admin?}_user_#{@user.id}_#{@user.updated_at}_#{@user.media_files_updated_at}_#{@user.wall_updated_at}" do
%h2= @user.name
=cache "#{current_user.is_admin?}_user_#{@user.id}_information_#{@user.updated_at}" do
=render "users/information"
=cache "user_#{@user.id}_media_files_#{@user.media_files_updated_at}" do
=render "users/media_files"
=cache "user_#{@user.id}_wall_#{@user.wall_updated_at}" do
@iHiD
iHiD / show.html.haml
Created June 25, 2012 19:13
Security Article Part 3 - 8
=cache "user_#{@user.id}_#{@user.updated_at}_#{@user.media_files_updated_at}_#{@user.wall_updated_at}" do
%h2= @user.name
=cache "user_#{@user.id}_information_#{@user.updated_at}" do
=render "users/information"
=cache "user_#{@user.id}_media_files_#{@user.media_files_updated_at}" do
=render "users/media_files"
=cache "user_#{@user.id}_wall_#{@user.wall_updated_at}" do
@iHiD
iHiD / _information.html.haml
Created June 25, 2012 19:12
Security Article Part 3 - 7
.bio= @user.bio
.university
.field University
.value= @user.university
.university_year
.field Year
.value= @user.university_year
@iHiD
iHiD / show.html.haml
Created June 25, 2012 19:12
Security Article Part 3 - 6
%h2= @user.name
=render "users/information"
=render "users/media_files"
=render "users/wall"
@iHiD
iHiD / show.html.erb
Created June 25, 2012 14:40
Security Article Part 3 - 5
<h2><%= @blog_post.title %></h2>
<div id="content"><%= raw @blog_post.content %></div>