Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add pages controller and example way to render page

  • Loading branch information...
commit 124fece4b7c268102e7cd54689656dec0dbdc99f 1 parent 721b472
@mkdynamic authored
View
10 app/controllers/pages.rb
@@ -0,0 +1,10 @@
+class Pages < Application
+
+ # ...and remember, everything returned from an action
+ # goes to the client...
+ def show(path)
+ @page = (path == '/' ? Page.home : Page.find_by_path(path))
+ render
+ end
+
+end
View
5 app/helpers/global_helpers.rb
@@ -1,5 +1,10 @@
module Merb
module GlobalHelpers
+ require 'redcloth'
+
# helpers defined here available to all views.
+ def textilize(str)
+ RedCloth.new(str.to_s).to_html
+ end
end
end
View
5 app/helpers/pages_helper.rb
@@ -0,0 +1,5 @@
+module Merb
+ module PagesHelper
+
+ end
+end # Merb
View
10 app/models/attachment.rb
@@ -7,6 +7,16 @@ def filename
@filename ||= load_filename
end
+ def url(version = :original)
+ path = File.join(*("%08d" % id).scan(/..../))
+ u = Backpack.interface.username
+ "http://#{u}.backpackit.com/attachments/#{path}/#{version.to_s}#{ext}/as/#{filename}"
+ end
+
+ def ext
+ File.extname(filename)
+ end
+
private
def load_filename
View
20 app/models/page.rb
@@ -10,6 +10,16 @@ def find(id)
Page.new(id, bp_data)
end
+ def home
+ Page.find_by_trail('Home')
+ end
+
+ def find_by_path(path)
+ pages = Backpack.interface.list_pages['pages'].first['page']
+ p = pages.find { |p| ('/' + p['title'].split('>').map { |s| Page.to_slug(s) }.join('/') + Page.ext) == path }
+ return (p ? Page.find(p['id'].to_i) : nil)
+ end
+
def find_by_trail(trail)
pages = Backpack.interface.list_pages['pages'].first['page']
p = pages.find { |p| p['title'] == trail }
@@ -49,7 +59,10 @@ def widgets
end
def slug
- title.downcase.gsub(/[^A-Za-z0-9]/, ' ').strip.gsub(/\s+/, '-')
+ Page.to_slug(title)
+ end
+ def self.to_slug(str)
+ str.downcase.gsub(/[^A-Za-z0-9]/, ' ').strip.gsub(/\s+/, '-')
end
def path(rel = [])
@@ -57,7 +70,7 @@ def path(rel = [])
path = '/'
unless rel.empty?
rel = [slug] + rel
- path << rel.join('/') + ext
+ path << rel.join('/') + Page.ext
end
return path
else
@@ -65,7 +78,7 @@ def path(rel = [])
end
end
- def ext
+ def self.ext
'.html'
end
@@ -103,6 +116,7 @@ def load_widgets
widgets.first['belonging'].each do |w|
id = w['widget'].first['id'].to_i
type = w['widget'].first['type']
+ type = 'Attachment' if type == 'Asset'
unless type == 'WriteboardLink'
bp_widget = bp_data['page'].first[type.downcase.pluralize].first[type.downcase].find { |i| i['id'].to_i == id }
else
View
43 app/views/pages/show.html.erb
@@ -0,0 +1,43 @@
+<h1><%=textilize @page.title %></h1>
+
+<% @page.widgets.each do |w| %>
+ <% if w.class == Note %>
+ <% unless w.title.blank? %>
+ <h2><%=textilize w.title %></h2>
+ <% end %>
+ <%=textilize w.content %>
+ <% elsif w.class == Attachment %>
+ <a href="<%= w.url %>">
+ <%=h w.filename %>
+ </a>
+ <% elsif w.class == Gallery %>
+ <% unless w.name.blank? %>
+ <h2><%=textilize w.name %></h2>
+ <% end %>
+ <ul class="gallery">
+ <% w.images.each do |image| %>
+ <li>
+ <a href="<%= image.url %>">
+ <img src="<%= image.url(:thumbnail) %>"
+ alt="<%=h image.description %>" />
+ </a>
+ </li>
+ <% end %>
+ </ul>
+ <% elsif w.class == Separator %>
+ <h2 class="separator">
+ <%=textilize w.content %>
+ </h2>
+ <% elsif w.class == List %>
+ <% unless w.name.blank? %>
+ <h2><%=textilize w.name %></h2>
+ <% end %>
+ <ul>
+ <% w.items.each do |item| %>
+ <li><%=textilize item.content %></li>
+ <% end %>
+ </ul>
+ <% elsif w.class == WriteboardLink %>
+ <h2 class="writeboard">Writeboard Link</h2>
+ <% end %>
+<% end %>
View
5 config/router.rb
@@ -37,8 +37,9 @@
# This is fine for most cases. If you're heavily using resource-based
# routes, you may want to comment/remove this line to prevent
# clients from calling your create or destroy actions with a GET
- default_routes
+ #default_routes
# Change this for your home page to be available at /
- # match('/').to(:controller => 'whatever', :action =>'index')
+ match(/(.*)/).to(:controller => 'pages', :action =>'show', :path => "[1]")
+
end
View
142 public/stylesheets/master.css
@@ -1,119 +1,25 @@
-body {
- font-family: Arial, Verdana, sans-serif;
- font-size: 12px;
- background-color: #fff;
-}
-* {
- margin: 0px;
- padding: 0px;
- text-decoration: none;
-}
-html {
- height: 100%;
- margin-bottom: 1px;
-}
-#container {
- width: 80%;
- text-align: left;
- background-color: #fff;
- margin-right: auto;
- margin-left: auto;
-}
-#header-container {
- width: 100%;
- padding-top: 15px;
-}
-#header-container h1, #header-container h2 {
- margin-left: 6px;
- margin-bottom: 6px;
-}
-.spacer {
- width: 100%;
- height: 15px;
-}
-hr {
- border: 0px;
- color: #ccc;
- background-color: #cdcdcd;
- height: 1px;
- width: 100%;
- text-align: left;
-}
-h1 {
- font-size: 28px;
- color: #c55;
- background-color: #fff;
- font-family: Arial, Verdana, sans-serif;
- font-weight: 300;
-}
-h2 {
- font-size: 15px;
- color: #999;
- font-family: Arial, Verdana, sans-serif;
- font-weight: 300;
- background-color: #fff;
-}
-h3 {
- color: #4d9b12;
- font-size: 15px;
- text-align: left;
- font-weight: 300;
- padding: 5px;
- margin-top: 5px;
-}
-
-#left-container {
- float: left;
- width: 250px;
- background-color: #FFFFFF;
- color: black;
-}
-
-#left-container h3 {
- color: #c55;
-}
-
-#main-container {
- margin: 5px 5px 5px 260px;
- padding: 15px;
- border-left: 1px solid silver;
- min-height: 400px;
-}
-p {
- color: #000;
- background-color: #fff;
- line-height: 20px;
- padding: 5px;
-}
-a {
- color: #4d9b12;
- background-color: #fff;
- text-decoration: none;
-}
-a:hover {
- color: #4d9b12;
- background-color: #fff;
- text-decoration: underline;
-}
-#footer-container {
- clear: both;
- font-size: 12px;
- font-family: Verdana, Arial, sans-serif;
-}
-.right {
- float: right;
- font-size: 100%;
- margin-top: 5px;
- color: #999;
- background-color: #fff;
-}
-.left {
- float: left;
- font-size: 100%;
- margin-top: 5px;
- color: #999;
- background-color: #fff;
-}
-#main-container ul {
- margin-left: 3.0em;
+h2.separator {
+ border-top: 1px solid #000;
+}
+h2.writeboard {
+ color: #999;
+}
+ul.gallery {
+ list-style: none;
+ margin-left: 0;
+ padding-left: 0;
+}
+ul.gallery li {
+ margin-left: 0;
+ padding-left: 0;
+ float: left;
+ display: block;
+ padding-right: 10px;
+}
+ul.gallery:after {
+ content: ".";
+ display: block;
+ height: 0;
+ clear: both;
+ visibility: hidden;
}
View
7 spec/requests/pages_spec.rb
@@ -0,0 +1,7 @@
+require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
+
+describe "/pages" do
+ before(:each) do
+ @response = request("/pages")
+ end
+end

0 comments on commit 124fece

Please sign in to comment.
Something went wrong with that request. Please try again.