Skip to content

Commit

Permalink
generate site with rakefile
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Jul 17, 2013
1 parent e3d2411 commit 9513fd6
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 39 deletions.
113 changes: 108 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,110 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require 'erb'
require 'account'
require 'pathname'

require File.expand_path('../config/application', __FILE__)
require 'rake'
module Rails
def self.root
Pathname.new File.dirname __FILE__
end
end

Rubycommitters::Application.load_tasks
class WEBSITE
attr_accessor :fox_count

def initialize
@fox_count = 0
@locals = {}
end

def accounts
Account.import File.open 'ruby-committers.yml'
end

def stylesheet_link_tag ogm
"<style>\n" +
File.read('public/stylesheets/site.css') +
"</style>\n"
end

def get_binding
binding
end

def link_to text, url
"<a href=\"#{url}\">#{h text}</a>".untaint
end

def h string
if string.tainted?
string = ERB::Util.h string
end

string.untaint
end

def image_tag src, attributes = {}
attrs = attributes.map { |k,v|
v = "\"#{h v}\""
[k, v].join "="
}

if attrs.any?
"<img src=\"images/#{src}\" #{attrs.join " "} />".untaint
else
"<img src=\"images/#{src}\" />".untaint
end
end

def render options
partial = options[:partial]
collection = options[:collection]

collection.map { |object|
@locals[partial.to_s] = object
filename = "app/views/accounts/_#{partial}.html.erb"
erb = ERB.new File.read(filename), 0, '<>-'
erb.filename = filename
erb.result binding
}.join
end

def link_to_service name, service
stringy = service.key.to_s

case service.name
when 'twitter'
link_to name, 'http://twitter.com/' + stringy
when 'friendfeed'
link_to name, 'http://friendfeed.com/' + stringy
when 'mixi'
link_to name, 'http://mixi.jp/show_friend.pl?id=' + stringy
when 'github'
link_to name, 'http://github.com/' + stringy
when 'facebook'
if service.key =~ /^\s*\d+$/
link_to name, 'http://www.facebook.com/profile.php?id=' + stringy
else
link_to name, 'http://www.facebook.com/' + stringy
end
when 'iddy'
link_to name, 'http://iddy.jp/profile/' + stringy
end
end

def method_missing name, *args
super unless @locals.key? name.to_s
@locals[name.to_s]
end
end

task :website do
erb = ERB.new File.read('app/views/layouts/application.html.erb')
ws = WEBSITE.new
binding = ws.get_binding do
fn = 'app/views/accounts/index.html.erb'
inner = ERB.new File.read(fn)
inner.filename = fn
inner.result(ws.get_binding)
end
puts erb.result(binding)
end
22 changes: 0 additions & 22 deletions app/helpers/accounts_helper.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,2 @@
module AccountsHelper
def link_to_service name, service
stringy = service.key.to_s

case service.name
when 'twitter'
link_to name, 'http://twitter.com/' + stringy
when 'friendfeed'
link_to name, 'http://friendfeed.com/' + stringy
when 'mixi'
link_to name, 'http://mixi.jp/show_friend.pl?id=' + stringy
when 'github'
link_to name, 'http://github.com/' + stringy
when 'facebook'
if service.key =~ /^\s*\d+$/
link_to name, 'http://www.facebook.com/profile.php?id=' + stringy
else
link_to name, 'http://www.facebook.com/' + stringy
end
when 'iddy'
link_to name, 'http://iddy.jp/profile/' + stringy
end
end
end
8 changes: 5 additions & 3 deletions app/views/accounts/_account.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<li class="account">
<div class="picture">
<div class="image-wrapper">
<% $stderr.puts Rails.root.join('public', 'images', 'people', 'lines', "#{account.username}.png").to_s %>
<% if File.exist?(Rails.root.join('public', 'images', 'people', 'lines', "#{account.username}.png").to_s) -%>
<%= image_tag "people/lines/#{account.username}.png", :onmouseover => "this.src = this.src.replace(/lines/, 'photos').replace(/png/, 'jpg');", :onmouseout => "this.src = this.src.replace(/photos/, 'lines').replace(/jpg/, 'png');" -%>
<% else -%>
<%= image_tag "people/lines/fox#{@fox_count}.png", :onmouseover => "this.src = this.src.replace(/lines/, 'photos')", :onmouseout => "this.src = this.src.replace(/photos/, 'lines')" -%>
<% @fox_count = @fox_count % 3 + 1 -%>
<%= image_tag "people/lines/fox#{fox_count}.png", :onmouseover => "this.src = this.src.replace(/lines/, 'photos')", :onmouseout => "this.src = this.src.replace(/photos/, 'lines')" -%>
<% self.fox_count = fox_count % 3 + 1 -%>
<% end -%>
</div>
</div>
Expand All @@ -27,7 +29,7 @@
<div class="sites">
<%= render :partial => 'site', :collection => account.sites -%>
<span class="books">
<% if account.books.present? -%>
<% if account.books.any? -%>
Books: &nbsp;
<% account.books.each_with_index do |book, i| %>
<a href="http://www.amazon.<%= book.isbn.match(/^4/) ? "co.jp":"com" %>/dp/<%= book.isbn %>"><%= i + 1 -%></a> &nbsp;
Expand Down
4 changes: 2 additions & 2 deletions app/views/accounts/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<%= link_to 'fork me on github',
'http://github.com/tenderlove/rubycommitters.org' %> -->

<% @fox_count = 1 -%>
<% self.fox_count = 1 %>

<ul style="list-style: none; margin: 0; padding: 0; z-index: 10; position: relative;">
<%= render :partial => 'account', :collection => @accounts %>
<%= render :partial => 'account', :collection => accounts %>
</ul>
14 changes: 7 additions & 7 deletions public/stylesheets/site.css
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
@font-face {
font-family: "MunroSmall";
src: url(/fonts/munro_small.ttf);
src: url(fonts/munro_small.ttf);
font-weight:400;
}

body {
margin: 0;
padding: 0;
background-color: #181818;
background: #FFF url(/images/header-bg.png);
background: #FFF url(images/header-bg.png);
color: #FFF;
font-family: Helvetica, Arial, sans-serif;
}
Expand All @@ -22,13 +22,13 @@ body {
}

#header {
background: #FFF url(/images/header-bg.png);
background: #FFF url(images/header-bg.png);
height: 383px;
margin-bottom: -13px;
}

#title {
background: url(/images/header2.jpg) top left no-repeat;
background: url(images/header2.jpg) top left no-repeat;
width: 957px;
height: 413px;
text-indent: -10000px;
Expand Down Expand Up @@ -89,7 +89,7 @@ body {
li.account {
max-width: 900px;
background-color: #222;
background: url(/images/foo.jpg);
background: url(images/foo.jpg);
margin: 20px;
padding: 10px;
list-style: none;
Expand All @@ -112,10 +112,10 @@ li.account div.name {
#footer {
margin-left: 20px;
height: 72px;
background: url(/images/foxes.png) bottom left no-repeat;);
background: url(images/foxes.png) bottom left no-repeat;);
padding: 65px 0 0 165px;
color: #666;
font-size: 0.55em;
font-weight: bold;
text-transform: uppercase;
}
}

0 comments on commit 9513fd6

Please sign in to comment.