Skip to content
This repository has been archived by the owner on Mar 27, 2022. It is now read-only.

Commit

Permalink
Improved theming of page content.
Browse files Browse the repository at this point in the history
Requests for page paths from the root (that exist) are redirected to /pages/#{path}.
Added some assets from the Cedar Ridge site in prep for use.
Improved page editing index.
  • Loading branch information
seven1m committed Jul 17, 2008
1 parent 9713d60 commit c2f148b
Show file tree
Hide file tree
Showing 21 changed files with 433 additions and 27 deletions.
17 changes: 16 additions & 1 deletion app/controllers/application.rb
Expand Up @@ -28,7 +28,7 @@ def get_site
end

def update_view_paths
theme_dirs = [File.join(RAILS_ROOT, 'themes', Setting.get(:appearance, :theme))]
theme_dirs = [File.join(RAILS_ROOT, 'themes', get_theme_name)]
if defined? DEPLOY_THEME_DIR
theme_dirs = [DEPLOY_THEME_DIR] + theme_dirs
end
Expand All @@ -37,6 +37,10 @@ def update_view_paths
PLUGIN_VIEW_PATHS.each { |p| self.append_view_path(p) }
end
end

def get_theme_name
Setting.get(:appearance, :theme)
end

def authenticate_user
if id = session[:logged_in_id]
Expand Down Expand Up @@ -80,6 +84,17 @@ def render_message(message)
end
end

def rescue_action_with_page_detection(exception)
get_site
path, args = request.request_uri.downcase.split('?')
if exception.is_a?(ActionController::RoutingError) and @page = Page.find_by_path(path)
redirect_to '/pages/' + @page.path + (args ? "?#{args}" : '')
else
rescue_action_without_page_detection(exception)
end
end
alias_method_chain :rescue_action, :page_detection

def me?
@logged_in and @person and @logged_in == @person
end
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/pages_controller.rb
Expand Up @@ -94,5 +94,13 @@ def get_path
def get_page
@page = Page.find(@path)
end

def get_theme_name
if params[:action] == 'show_for_public'
Setting.get(:appearance, :public_theme)
else
super
end
end

end
9 changes: 2 additions & 7 deletions app/helpers/pages_helper.rb
@@ -1,22 +1,17 @@
module PagesHelper

def breadcrumbs_for(page)
if page.slug == 'home'
''
elsif parent = page.parent
if parent = page.parent
link_to(parent.title, page_path(parent)) + ' »'
else
link_to('Home', page_path(Page.find_by_slug('home'))) + ' »'
end
end


def page_path(page)
if @logged_in and @logged_in.admin?(:edit_pages)
super
else
path = page.path == 'home' ? '' : page.path
page_for_public_path(:path => path)
page_for_public_path(path)
end
end

Expand Down
14 changes: 9 additions & 5 deletions app/models/page.rb
Expand Up @@ -17,7 +17,7 @@

class Page < ActiveRecord::Base
belongs_to :parent, :class_name => 'Page'
has_many :children, :class_name => 'Page', :foreign_key => 'parent_id'
has_many :children, :class_name => 'Page', :foreign_key => 'parent_id', :dependent => :destroy
has_many :attachments
belongs_to :site

Expand All @@ -29,10 +29,6 @@ class Page < ActiveRecord::Base
validates_exclusion_of :slug, :in => %w(admin edit new)
validates_format_of :slug, :with => /^[a-z_]+$/

# def slug=(s)
# write_attribute :slug, s.downcase.scan(/[a-z_]/).join
# end

before_save :update_path

def update_path
Expand All @@ -43,6 +39,10 @@ def update_path
end
end

def home?
path == 'home'
end

class << self

def find(id, *args)
Expand Down Expand Up @@ -71,6 +71,10 @@ def home_if_blank(path)
def paths_and_ids
connection.select_all("select path, id from pages where path != '' order by path").map { |r| [r['path'], r['id'].to_i] }
end

def root_pages(include_home=false)
Page.find_all_by_parent_id(nil).select { |p| include_home or not p.home? }
end

end
end
1 change: 1 addition & 0 deletions app/views/pages/_list.erb
Expand Up @@ -7,6 +7,7 @@
<%= link_to page.title, page %>
<span class="discreet">
<%= link_to 'edit', edit_page_path(page), :class => 'discreet' %> |
<%= link_to 'delete', page, :method => 'delete', :confirm => 'Are you sure? This will be permanent and will delete all children of this page!', :class => 'discreet' %> |
<%= link_to 'new here', new_page_path(:parent_id => page), :class => 'discreet' %>
</span>
<div id="page<%= page.id %>_children"></div>
Expand Down
2 changes: 2 additions & 0 deletions app/views/pages/index.html.erb
@@ -1,3 +1,5 @@
<h1>Pages</h1>

<%= render :partial => 'list' %>

<p style="margin-left:35px;"><%= link_to 'new root page', new_page_path, :class => 'discreet' %></p>
13 changes: 13 additions & 0 deletions app/views/pages/show.html.erb
@@ -1,3 +1,16 @@
<% content_for :subnav do %>
<% unless @page.home? %>
<li><%= link_to 'Home', home_path %></li>
<% end %>
<% (@page.home? ? Page.root_pages : @page.children).each do |page| %>
<li><%= link_to page.title, page_path(page) %></li>
<% end %>
<% end %>
<% if @logged_in and @logged_in.admin?(:edit_pages) %>
<p><%= link_to 'Index', pages_path %></p>
<% end %>

<p id="breadcrumbs"><%= breadcrumbs_for @page %></p>

<h1>
Expand Down
2 changes: 1 addition & 1 deletion config/environments/development.rb
Expand Up @@ -12,7 +12,7 @@
#config.breakpoint_server = true

# Show full error reports and disable caching
config.action_controller.consider_all_requests_local = true
config.action_controller.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.action_view.debug_rjs = true

Expand Down
3 changes: 2 additions & 1 deletion config/routes.rb
Expand Up @@ -2,7 +2,7 @@

PHOTO_SIZE_METHODS = {:tn => :get, :small => :get, :medium => :get, :large => :get}

map.connect '', :controller => 'people'
map.home '', :controller => 'pages', :action => 'show_for_public'

map.resource :account, :member => {:verify_code => :any, :select => :any}

Expand Down Expand Up @@ -90,4 +90,5 @@
end

ActionController::Routing::Routes.draw_plugin_routes

end
1 change: 1 addition & 0 deletions db/migrate/20080715223033_create_pages.rb
Expand Up @@ -19,6 +19,7 @@ def self.up
t.remove :song_id
t.integer :page_id
end
Setting.update_all
end

def self.down
Expand Down
120 changes: 120 additions & 0 deletions public/javascripts/ie_fix_hover.htc
@@ -0,0 +1,120 @@
<attach event="ondocumentready" handler="parseStylesheets" />
<script>
/**
* Whatever:hover - V1.42.060206 - hover & active
* ------------------------------------------------------------
* (c) 2005 - Peter Nederlof
* Peterned - http://www.xs4all.nl/~peterned/
* License - http://creativecommons.org/licenses/LGPL/2.1/
*
* Whatever:hover is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* Whatever:hover is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* Credits and thanks to:
* Arnoud Berendsen, Martin Reurings, Robert Hanson
*
* howto: body { behavior:url("csshover.htc"); }
* ------------------------------------------------------------
*/

var csshoverReg = /(^|\s)(([^a]([^ ]+)?)|(a([^#.][^ ]+)+)):(hover|active)/i,
currentSheet, doc = window.document, hoverEvents = [], activators = {
onhover:{on:'onmouseover', off:'onmouseout'},
onactive:{on:'onmousedown', off:'onmouseup'}
}

function parseStylesheets() {
if(!/MSIE (5|6)/.test(navigator.userAgent)) return;
window.attachEvent('onunload', unhookHoverEvents);
var sheets = doc.styleSheets, l = sheets.length;
for(var i=0; i<l; i++)
parseStylesheet(sheets[i]);
}
function parseStylesheet(sheet) {
if(sheet.imports) {
try {
var imports = sheet.imports, l = imports.length;
for(var i=0; i<l; i++) parseStylesheet(sheet.imports[i]);
} catch(securityException){}
}

try {
var rules = (currentSheet = sheet).rules, l = rules.length;
for(var j=0; j<l; j++) parseCSSRule(rules[j]);
} catch(securityException){}
}

function parseCSSRule(rule) {
var select = rule.selectorText, style = rule.style.cssText;
if(!csshoverReg.test(select) || !style) return;

var pseudo = select.replace(/[^:]+:([a-z-]+).*/i, 'on$1');
var newSelect = select.replace(/(\.([a-z0-9_-]+):[a-z]+)|(:[a-z]+)/gi, '.$2' + pseudo);
var className = (/\.([a-z0-9_-]*on(hover|active))/i).exec(newSelect)[1];
var affected = select.replace(/:(hover|active).*$/, '');
var elements = getElementsBySelect(affected);
if(elements.length == 0) return;

currentSheet.addRule(newSelect, style);
for(var i=0; i<elements.length; i++)
new HoverElement(elements[i], className, activators[pseudo]);
}

function HoverElement(node, className, events) {
if(!node.hovers) node.hovers = {};
if(node.hovers[className]) return;
node.hovers[className] = true;
hookHoverEvent(node, events.on, function() { node.className += ' ' + className; });
hookHoverEvent(node, events.off, function() { node.className = node.className.replace(new RegExp('\\s+'+className, 'g'),''); });
}
function hookHoverEvent(node, type, handler) {
node.attachEvent(type, handler);
hoverEvents[hoverEvents.length] = {
node:node, type:type, handler:handler
};
}

function unhookHoverEvents() {
for(var e,i=0; i<hoverEvents.length; i++) {
e = hoverEvents[i];
e.node.detachEvent(e.type, e.handler);
}
}

function getElementsBySelect(rule) {
var parts, nodes = [doc];
parts = rule.split(' ');
for(var i=0; i<parts.length; i++) {
nodes = getSelectedNodes(parts[i], nodes);
} return nodes;
}
function getSelectedNodes(select, elements) {
var result, node, nodes = [];
var identify = (/\#([a-z0-9_-]+)/i).exec(select);
if(identify) {
var element = doc.getElementById(identify[1]);
return element? [element]:nodes;
}

var classname = (/\.([a-z0-9_-]+)/i).exec(select);
var tagName = select.replace(/(\.|\#|\:)[a-z0-9_-]+/i, '');
var classReg = classname? new RegExp('\\b' + classname[1] + '\\b'):false;
for(var i=0; i<elements.length; i++) {
result = tagName? elements[i].all.tags(tagName):elements[i].all;
for(var j=0; j<result.length; j++) {
node = result[j];
if(classReg && !classReg.test(node.className)) continue;
nodes[nodes.length] = node;
}
}

return nodes;
}
</script>
44 changes: 44 additions & 0 deletions public/javascripts/ie_fix_png.js
@@ -0,0 +1,44 @@
/*
Correctly handle PNG transparency in Win IE 5.5 & 6.
http://homepage.ntlworld.com/bobosola. Updated 18-Jan-2006.
Use in <HEAD> with DEFER keyword wrapped in conditional comments:
<!--[if lt IE 7]>
<script defer type="text/javascript" src="pngfix.js"></script>
<![endif]-->
*/

function fix_ie_pngs() {

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

if ((version >= 5.5) && (document.body.filters))
{
for(var i=0; i<document.images.length; i++)
{
var img = document.images[i]
var imgName = img.src.toUpperCase()
if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
{
var imgID = (img.id) ? "id='" + img.id + "' " : ""
var imgClass = (img.className) ? "class='" + img.className + "' " : ""
var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
var imgStyle = "display:inline-block;" + img.style.cssText
if (img.align == "left") imgStyle = "float:left;" + imgStyle
if (img.align == "right") imgStyle = "float:right;" + imgStyle
if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
var strNewHTML = "<span " + imgID + imgClass + imgTitle
+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
img.outerHTML = strNewHTML
i = i-1
}
}
}
}

fix_ie_pngs();

0 comments on commit c2f148b

Please sign in to comment.