Skip to content

Instantly share code, notes, and snippets.

@basicxman
Created November 6, 2011 04:56
Show Gist options
  • Select an option

  • Save basicxman/1342492 to your computer and use it in GitHub Desktop.

Select an option

Save basicxman/1342492 to your computer and use it in GitHub Desktop.
commit 4c4385126d39404ba7174a136b9573bd8c650abc
Author: Andrew Horsman <minirobotics@gmail.com>
Date: Sat Nov 5 17:32:59 2011 -0400
Design improvements and new features.
Increased word spacing on header (readability).
Increased right side padding on sidebar.
Added sitemap.
Added printer/reader friendly view.
Added Back to Top links.
Added Twitter feed on sidebar.
---
app/assets/images/tweet_hr.png | Bin 0 -> 3682 bytes
app/assets/images/twitter_bg.png | Bin 0 -> 3815 bytes
app/assets/images/twitter_bird.png | Bin 0 -> 4992 bytes
app/assets/javascripts/application.js | 1 +
app/assets/javascripts/twitter.js | 37 ++++++++++++++
app/assets/stylesheets/application.css.scss | 41 ++++++++++++++-
app/assets/stylesheets/printer.css.scss | 12 +++++
app/assets/stylesheets/readability.css.scss | 72 +++++++++++++++++++++++++++
app/controllers/pages_controller.rb | 8 +++-
app/models/menu.rb | 1 +
app/views/albums/index.html.erb | 2 +
app/views/albums/show.html.erb | 3 +
app/views/layouts/application.html.erb | 7 ++-
app/views/layouts/print.html.erb | 32 ++++++++++++
app/views/menus/_individual.html.erb | 12 +++++
app/views/menus/_menu.html.erb | 16 +-----
app/views/menus/_twitter.html.erb | 2 +
app/views/menus/show.html.erb | 2 +
app/views/pages/_page_meta.html.erb | 4 ++
app/views/pages/_social.html.erb | 6 ++
app/views/pages/home.html.erb | 2 -
app/views/pages/index.html.erb | 13 ++++-
app/views/pages/index.xml.builder | 38 ++++++++++++++
app/views/pages/show.html.erb | 3 +
app/views/photos/show.html.erb | 2 +
config/routes.rb | 2 +
26 files changed, 296 insertions(+), 22 deletions(-)
diff --git a/app/assets/images/tweet_hr.png b/app/assets/images/tweet_hr.png
new file mode 100644
index 0000000..b3f0610
Binary files /dev/null and b/app/assets/images/tweet_hr.png differ
diff --git a/app/assets/images/twitter_bg.png b/app/assets/images/twitter_bg.png
new file mode 100644
index 0000000..5f78d29
Binary files /dev/null and b/app/assets/images/twitter_bg.png differ
diff --git a/app/assets/images/twitter_bird.png b/app/assets/images/twitter_bird.png
new file mode 100644
index 0000000..c96bd31
Binary files /dev/null and b/app/assets/images/twitter_bird.png differ
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index 360661d..e652129 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -6,6 +6,7 @@
//= require photos
//= require feedbacks
//= require maps
+//= require twitter
function incrementAd() {
$.currentAd++;
diff --git a/app/assets/javascripts/twitter.js b/app/assets/javascripts/twitter.js
new file mode 100644
index 0000000..882b2d7
--- /dev/null
+++ b/app/assets/javascripts/twitter.js
@@ -0,0 +1,37 @@
+function calculate_tweet_quantity() {
+ var total_height = $("#container").height();
+ total_height -= $("#non-twitter").outerHeight();
+ total_height -= 50;
+ return Math.ceil(Math.min(3, total_height / 200));
+}
+
+function process_tweet(data) {
+ var text = data.text;
+ if (data.in_reply_to_screen_name) {
+ var sn = data.in_reply_to_screen_name;
+ text = text.replace("@" + sn, "<a target='_blank' href='http://twitter.com/" + sn + "'>@" + sn + "</a>");
+ }
+
+ text = text.replace(/http:\/\/t\.co\/[a-zA-Z0-9]+/g, "<a target='_blank' href='$&'>$&</a>");
+ return text;
+}
+
+function tweet(data) {
+ return $('<div class="tweet">' + process_tweet(data) + '</div>');
+}
+
+function twitter_callback(data) {
+ for (var i = 0; i < data.length; ++i) {
+ $("#twitter-feed").append(tweet(data[i]));
+ $("#twitter-feed").append("<div class='tweet-hr'></div>");
+ }
+
+ $("#twitter-feed").append("<div class='tweet'>Follow us on <a href='http://twitter.com/mmrambotics' target='_blank'>Twitter</a>!</div>");
+}
+
+$(function() {
+ if ($("#twitter-feed").length == 1) {
+ var count = calculate_tweet_quantity();
+ $("<script src='http://api.twitter.com/1/statuses/user_timeline.json?screen_name=mmrambotics&count=" + count + "&callback=twitter_callback'></script>").appendTo("body");
+ }
+});
diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss
index 17e337b..280f15e 100644
--- a/app/assets/stylesheets/application.css.scss
+++ b/app/assets/stylesheets/application.css.scss
@@ -78,12 +78,12 @@ div#container {
width: $sidebar_width;
background: image-url("border-sidebar.png") no-repeat top left;
min-height: 500px;
- padding: 50px 0px 0px 20px;
+ padding: 50px 10px 0px 20px;
}
div#content {
float: left;
- width: 700px;
+ width: 900px - $sidebar_width;
min-height: 500px;
padding-bottom: 50px;
@@ -96,9 +96,11 @@ div#container {
h2 {
margin-bottom: 4px;
font-size: 60px;
+ word-spacing: 10px;
}
h3 {
font-size: 30px;
+ word-spacing: 6px;
}
}
}
@@ -244,6 +246,7 @@ ul#main-menu {
}
ul#sub-menu-page {
+ padding: 0px;
list-style: none;
font-size: 20px;
line-height: 30px;
@@ -444,3 +447,37 @@ input[type="submit"] {
height: 400px;
color: #000;
}
+
+#share-this-container {
+ margin: 10px 0px;
+ h4 {
+ margin: 8px 0px;
+ }
+ div {
+ margin-left: -5px;
+ }
+}
+
+.left-offset {
+ margin-left: 15px;
+}
+
+#twitter-feed {
+ background: image-url("twitter_bird.png") no-repeat top right;
+ .tweet {
+ margin: 10px;
+ padding: 7px 0px;
+ font-size: 15px;
+ width: $sidebar_width - 15px;
+ a:link { color: $link-colour; text-decoration: none; }
+ a:visited { color: darken($link-colour, 15%); }
+ a:active, a:hover { color: darken($link-colour, 10%); text-decoration: underline; }
+ }
+
+ .tweet-hr {
+ background: image-url("tweet_hr.png") no-repeat center center;
+ height: 18px;
+ }
+
+ padding-top: 40px;
+}
diff --git a/app/assets/stylesheets/printer.css.scss b/app/assets/stylesheets/printer.css.scss
new file mode 100644
index 0000000..c744586
--- /dev/null
+++ b/app/assets/stylesheets/printer.css.scss
@@ -0,0 +1,12 @@
+* {
+ line-height: 1.6em;
+}
+
+#controls, #share-this-container, #page-meta {
+ display: none;
+}
+
+.f1 { font-family: "Droid Sans", sans-serif; }
+.f2 { font-family: Helvetica, sans-serif; }
+.f3 { font-family: Petrona, serif; }
+.f4 { font-family: "Times New Roman", serif; }
diff --git a/app/assets/stylesheets/readability.css.scss b/app/assets/stylesheets/readability.css.scss
new file mode 100644
index 0000000..ad63d7b
--- /dev/null
+++ b/app/assets/stylesheets/readability.css.scss
@@ -0,0 +1,72 @@
+* {
+ margin: 0px;
+ padding: 0px;
+ line-height: 1.6em;
+}
+
+a {
+ color: inherit;
+ text-decoration: none;
+}
+
+body {
+ &.black {
+ background-color: #222;
+ color: #eee;
+
+ #font-themes a {
+ border: 1px solid #ccc;
+ }
+ }
+}
+
+#share-this-container, #page-meta {
+ display: none;
+}
+
+#print-container {
+ margin: 5px 20px;
+}
+
+#content {
+ margin: 0px 0px 20px 0px;
+ width: 500px;
+
+ p {
+ margin: 20px 0px;
+ }
+}
+
+.f1 { font-family: "Droid Sans", sans-serif; }
+.f2 { font-family: Helvetica, sans-serif; }
+.f3 { font-family: Petrona, serif; }
+.f4 { font-family: "Times New Roman", serif; }
+
+#controls a {
+ display: block;
+ float: left;
+ width: 15px;
+ height: 15px;
+ line-height: 15px;
+ text-align: center;
+ cursor: pointer;
+ margin: 5px 5px 15px 5px;
+}
+
+#white-theme {
+ border: 1px solid #000;
+ background-color: #fff;
+}
+
+#black-theme {
+ border: 1px solid #ccc;
+ background-color: #222;
+}
+
+#font-themes a {
+ border: 1px solid #000;
+}
+
+ul {
+ margin-left: 15px;
+}
diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb
index d77b51a..c87055d 100644
--- a/app/controllers/pages_controller.rb
+++ b/app/controllers/pages_controller.rb
@@ -1,10 +1,16 @@
class PagesController < ApplicationController
def index
- @pages = Page.all
+ respond_to do |f|
+ f.html
+ f.xml
+ end
end
def show
@page = Page.find(params[:id].to_i)
+ if params[:print].present?
+ render :layout => "print"
+ end
end
def home
diff --git a/app/models/menu.rb b/app/models/menu.rb
index cd51c30..7adc839 100644
--- a/app/models/menu.rb
+++ b/app/models/menu.rb
@@ -3,6 +3,7 @@ class Menu < ActiveRecord::Base
has_many :pages
scope :ordered, order("priority DESC, title")
+ scope :alphabetical, order("title")
def items
self.pages.reorder("title")
diff --git a/app/views/albums/index.html.erb b/app/views/albums/index.html.erb
index bea0e97..c4e4f12 100644
--- a/app/views/albums/index.html.erb
+++ b/app/views/albums/index.html.erb
@@ -41,3 +41,5 @@
</table>
</div>
</div>
+
+<div class="left-offset"><%= render :partial => "pages/social" %></div>
diff --git a/app/views/albums/show.html.erb b/app/views/albums/show.html.erb
index fad2d67..29bc1d4 100644
--- a/app/views/albums/show.html.erb
+++ b/app/views/albums/show.html.erb
@@ -48,4 +48,7 @@
</tbody>
</table>
</div>
+ <div style="clear: both;"></div>
</div>
+
+<div class="left-offset"><%= render :partial => "pages/social" %></div>
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index e0d4eab..13eefb9 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -26,8 +26,11 @@
<div id="container">
<div id="main-container">
<div id="sidebar">
- <%= render :partial => "menus/menu" %>
- <%= render :partial => "ads/rotating" %>
+ <div id="non-twitter">
+ <%= render :partial => "menus/menu" %>
+ <%= render :partial => "ads/rotating" %>
+ </div>
+ <%= render :partial => "menus/twitter" %>
</div>
<div id="content">
diff --git a/app/views/layouts/print.html.erb b/app/views/layouts/print.html.erb
new file mode 100644
index 0000000..7174dcf
--- /dev/null
+++ b/app/views/layouts/print.html.erb
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title><%= title content_for(:title) %></title>
+ <link href='http://fonts.googleapis.com/css?family=Droid+Sans|Petrona' rel='stylesheet' type='text/css'>
+ <%= stylesheet_link_tag "readability" %>
+ <%= stylesheet_link_tag "printer", :media => "print" %>
+</head>
+
+<body class="<%= params[:colour] %>">
+ <div id="print-container" class="<%= params[:font] || "f1" %>">
+ <div id="controls">
+ <div id="colour-themes">
+ <%= link_to " ", query(:colour => ""), :id => "white-theme" %>
+ <%= link_to " ", query(:colour => "black"), :id => "black-theme" %>
+ </div>
+ <div style="clear: both;"></div>
+ <div id="font-themes">
+ <%= link_to "a", query(:font => "f1"), :class => "f1" %>
+ <%= link_to "a", query(:font => "f2"), :class => "f2" %>
+ <%= link_to "a", query(:font => "f3"), :class => "f3" %>
+ <%= link_to "a", query(:font => "f4"), :class => "f4" %>
+ </div>
+ <div style="clear: both;"></div>
+ </div>
+ <div id="content">
+ <h2><%= content_for(:title) %></h2>
+ <%= yield %>
+ </div>
+ </div>
+</body>
+</html>
diff --git a/app/views/menus/_individual.html.erb b/app/views/menus/_individual.html.erb
new file mode 100644
index 0000000..e9234e5
--- /dev/null
+++ b/app/views/menus/_individual.html.erb
@@ -0,0 +1,12 @@
+<li>
+ <% if @menu.pages.length == 1 %>
+ <%= link_to @menu.title, page_path(@menu.pages.first) %>
+ <% elsif @menu.pages.length > 1 %>
+ <span><%= link_to @menu.title, menu_path(@menu) %></span>
+ <ul class="sub-menu">
+ <% @menu.items.each do |page| %>
+ <li><%= sub_menu_link(page) %></li>
+ <% end %>
+ </ul>
+ <% end %>
+</li>
diff --git a/app/views/menus/_menu.html.erb b/app/views/menus/_menu.html.erb
index 51b3b79..b2d3930 100644
--- a/app/views/menus/_menu.html.erb
+++ b/app/views/menus/_menu.html.erb
@@ -1,21 +1,11 @@
<ul id="main-menu">
<li><%= link_to "Home", Page.home %></li>
<% Menu.ordered.each do |menu| %>
- <li>
- <% if menu.pages.length == 1 %>
- <%= link_to menu.title, page_path(menu.pages.first) %>
- <% elsif menu.pages.length > 1 %>
- <span><%= link_to menu.title, menu_path(menu) %></span>
- <ul class="sub-menu">
- <% menu.items.each do |page| %>
- <li><%= sub_menu_link(page) %></li>
- <% end %>
- </ul>
- <% end %>
- </li>
+ <% @menu = menu %>
+ <%= render :partial => "menus/individual" %>
<% end %>
</ul>
<br />
-<%= link_to image_tag(Robotics::Application.config.first_logo, :width => "180"), "http://usfirst.org", :target => "_blank" %></li>
+<%= link_to image_tag(Robotics::Application.config.first_logo, :width => "180"), "http://usfirst.org", :target => "_blank", :class => "left-offset" %>
diff --git a/app/views/menus/_twitter.html.erb b/app/views/menus/_twitter.html.erb
new file mode 100644
index 0000000..3df7b49
--- /dev/null
+++ b/app/views/menus/_twitter.html.erb
@@ -0,0 +1,2 @@
+<div id="twitter-feed">
+</div>
diff --git a/app/views/menus/show.html.erb b/app/views/menus/show.html.erb
index 5324a9a..4bea024 100644
--- a/app/views/menus/show.html.erb
+++ b/app/views/menus/show.html.erb
@@ -5,3 +5,5 @@
<li><%= link_to page.title, page_path(page) %></li>
<% end %>
</ul>
+
+<%= link_to "MMRambotics Sitemap", sitemap_path %>
diff --git a/app/views/pages/_page_meta.html.erb b/app/views/pages/_page_meta.html.erb
new file mode 100644
index 0000000..ca5b45b
--- /dev/null
+++ b/app/views/pages/_page_meta.html.erb
@@ -0,0 +1,4 @@
+<div id="page-meta">
+ <%= link_to "Printer/Reader Friendly", query(:print => "friendly") %>
+ | <%= link_to "Back to Top", "#" %>
+</div>
diff --git a/app/views/pages/_social.html.erb b/app/views/pages/_social.html.erb
new file mode 100644
index 0000000..a0153b6
--- /dev/null
+++ b/app/views/pages/_social.html.erb
@@ -0,0 +1,6 @@
+<!-- ShareThis -->
+<div id="share-this-container">
+ <h4 id="share-this-header">Share This</h4>
+ <div><span class='st_sharethis_large' ></span><span class='st_email_large' ></span><span class='st_twitter_large' ></span><span class='st_facebook_large' ></span><span class='st_instapaper_large' ></span><span class='st_linkedin_large' ></span><span class='st_google_reader_large' ></span><span class='st_reddit_large' ></span><span class='st_stumbleupon_large' ></span><span class='st_tumblr_large' ></span><span class='st_plusone_large' ></span></div>
+ <script type="text/javascript">var switchTo5x=true;</script><script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script><script type="text/javascript">stLight.options({publisher:'133ec31c-b674-4f92-b834-81d9b3e66560'});</script>
+</div>
diff --git a/app/views/pages/home.html.erb b/app/views/pages/home.html.erb
deleted file mode 100644
index 3453cf2..0000000
--- a/app/views/pages/home.html.erb
+++ /dev/null
@@ -1,2 +0,0 @@
-<h1>Pages#home</h1>
-<p>Find me in app/views/pages/home.html.erb</p>
diff --git a/app/views/pages/index.html.erb b/app/views/pages/index.html.erb
index 4053c02..fd786f1 100644
--- a/app/views/pages/index.html.erb
+++ b/app/views/pages/index.html.erb
@@ -1,2 +1,11 @@
-<h1>Pages#index</h1>
-<p>Find me in app/views/pages/index.html.erb</p>
+<%= content_for :title, "Site Map" %>
+
+<%= link_to "Sitemap XML", sitemap_path(:xml) %>
+
+<ul id="site-map-menu">
+ <li><%= link_to "Home", Page.home %></li>
+ <% Menu.alphabetical.each do |menu| %>
+ <% @menu = menu %>
+ <%= render :partial => "menus/individual" %>
+ <% end %>
+</ul>
diff --git a/app/views/pages/index.xml.builder b/app/views/pages/index.xml.builder
new file mode 100644
index 0000000..a5a5d44
--- /dev/null
+++ b/app/views/pages/index.xml.builder
@@ -0,0 +1,38 @@
+xml.instruct!
+xml.urlset :xmlns => "http://www.sitemaps.org/schemas/sitemap/0.9" do
+ xml.url do
+ xml.loc "http://mmrambotics.ca"
+ xml.changefreq "daily"
+ xml.priority 1.0
+ end
+
+ Page.all.each do |page|
+ xml.url do
+ xml.loc page_url(page)
+ xml.priority 0.8
+ xml.lastmod page.updated_at.to_date.to_s
+ end
+ end
+
+ Album.all.each do |album|
+ xml.url do
+ xml.loc album_url(album)
+ xml.priority 0.5
+ end
+ end
+
+ Photo.all.each do |photo|
+ xml.url do
+ xml.loc photo_url(photo)
+ xml.priority 0.5
+ xml.lastmod photo.updated_at.to_date.to_s
+ end
+ end
+
+ Menu.all.each do |menu|
+ xml.url do
+ xml.loc menu_url(menu)
+ xml.priority 0.3
+ end
+ end
+end
diff --git a/app/views/pages/show.html.erb b/app/views/pages/show.html.erb
index 6ad445f..13f9178 100644
--- a/app/views/pages/show.html.erb
+++ b/app/views/pages/show.html.erb
@@ -1,3 +1,6 @@
<%= content_for :title, @page.title %>
<%=m @page.content %>
+
+<%= render :partial => "social" %>
+<%= render :partial => "page_meta" %>
diff --git a/app/views/photos/show.html.erb b/app/views/photos/show.html.erb
index 6f3ed89..c3c149f 100644
--- a/app/views/photos/show.html.erb
+++ b/app/views/photos/show.html.erb
@@ -31,3 +31,5 @@
<%= @photo.description %>
</div>
</div>
+
+<div class="left-offset"><%= render :partial => "pages/social" %></div>
diff --git a/config/routes.rb b/config/routes.rb
index 7bc8f0a..9afd796 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -8,6 +8,8 @@ Robotics::Application.routes.draw do
resources :photos, :only => [:show]
resources :feedbacks, :only => [:create]
+ get "sitemap" => "pages#index", :as => :sitemap
+
root :to => "pages#home"
# ActiveAdmin administration [generated].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment