Permalink
Browse files

Added blog posts to the front end

  • Loading branch information...
1 parent 33993be commit a39467b129349984359b30b048a00664fadcaa24 @rapind committed Mar 30, 2012
@@ -9,7 +9,9 @@ body
.page-header
padding-bottom: 10px !important
-
+ .subtitle
+ margin: 10px 0 0 0
+
.masthead
margin-bottom: 40px
@@ -46,7 +48,7 @@ body
.marketing-link
color: #333
-.page-image
+.page-image, .post-image
margin: 0 0 20px 20px
float: right
@@ -1,7 +1,7 @@
class ApplicationController < ActionController::Base
protect_from_forgery
- helper_method :photographer, :galleries, :pages
+ helper_method :photographer, :galleries, :pages, :recent_posts
before_filter :set_timezone
protected #----
@@ -21,6 +21,11 @@ def pages
@pages = Page.cached
end
+ def recent_posts
+ return @recent_posts if defined?(@recent_posts)
+ @recent_posts = Post.recent
+ end
+
def set_timezone
Time.zone = photographer.time_zone
end
@@ -0,0 +1,5 @@
+class PostsController < ApplicationController
+ inherit_resources
+ respond_to :html
+ actions :index, :show
+end
View
@@ -10,7 +10,7 @@ class Gallery < ActiveRecord::Base
# ****
# Validations
- validates :name, :presence => true, :length => { :within => 2..100 }, :uniqueness => { :case_sensitive => false }
+ validates :name, :presence => true, :length => { :within => 2..20 }, :uniqueness => { :case_sensitive => false }
validates :keywords, :length => { :within => 2..255, :allow_blank => true }
validates :description, :length => { :within => 10..8000, :allow_blank => true }
validates :cover, :presence => true
View
@@ -2,7 +2,7 @@ class Page < ActiveRecord::Base
# ****
# Validations
- validates :name, :presence => true, :length => { :within => 2..32 }
+ validates :name, :presence => true, :length => { :within => 2..20 }
validates :keywords, :length => { :within => 2..255, :allow_blank => true }
validates :body, :presence => true, :length => { :minimum => 10 }
@@ -21,6 +21,10 @@ def to_param
"#{id}-#{name}".parameterize
end
+ # ****
+ # Default ordering
+ default_scope :order => 'name'
+
# Caching
# -------
CACHED = 'pages'
View
@@ -2,7 +2,7 @@ class Post < ActiveRecord::Base
# ****
# Validations
- validates :title, :presence => true, :length => { :within => 2..128 }
+ validates :title, :presence => true, :length => { :within => 2..64 }
validates :keywords, :length => { :within => 2..255, :allow_blank => true }
validates :body, :presence => true, :length => { :minimum => 10 }
@@ -21,15 +21,19 @@ def to_param
"#{id}-#{title}".parameterize
end
+ # ****
+ # Default ordering
+ default_scope :order => 'created_at DESC'
+
# Caching
# -------
CACHED = 'recent_posts'
after_save :clear_cache
- def self.recents
+ def self.recent
Rails.cache.fetch(CACHED, :expires_in => 1.day) do
- self.order(:created_at).limit(4).all
+ self.order(:created_at).limit(3).all
end
end
@@ -3,4 +3,4 @@
%ul.thumbnails
- @gallery.photos.each do |photo|
%li.span3
- = link_to(image_tag(photo.photo.thumb('260x180!').url, :size => '260x180'), photo.photo.url, :class => "thumbnail", :rel => 'lightbox')
+ = link_to(image_tag(photo.photo.thumb('260x173!').url, :size => '260x173'), photo.photo.url, :class => "thumbnail", :rel => 'lightbox')
@@ -14,8 +14,7 @@
%li{ :class => (defined?(@gallery) and @gallery.id == gallery.id ? 'active' : '') }= link_to(gallery.name, gallery_path(gallery))
- pages.each do |page|
%li{ :class => (defined?(@page) and @page.id == page.id ? 'active' : '') }= link_to(page.name, page_path(page))
- - if photographer.blog_url
- %li= link_to('Blog', photographer.blog_url)
+ %li= link_to('Blog', posts_path)
%li.divider-vertical
%li{ :class => controller.controller_name == 'contact_requests' ? 'active' : '' }= link_to('Contact', new_contact_request_path)
.pull-right= link_to(photographer.name, root_path, :class => 'brand')
@@ -27,6 +26,8 @@
- if content_for?(:title)
.page-header
%h1= yield(:title)
+ - if content_for?(:subtitle)
+ %p.subtitle= yield(:subtitle)
.row.content
- if content_for?(:sidebar)
.span3
No changes.
@@ -0,0 +1,8 @@
+- content_for :title, @post.title
+- unless @post.keywords.blank?
+ - content_for :subtitle do
+ - @post.keywords.split(', ').each do |keyword|
+ %span.label= keyword
+
+= image_tag(@post.image.url, :class => 'post-image') if @post.image_uid
+= @post.body.to_html.html_safe
@@ -7,16 +7,18 @@
%h4 Photo Galleries
%ul.unstyled
- galleries.each do |gallery|
- %li= link_to(gallery.name, gallery_path(gallery))
+ %li= link_to(truncate(gallery.name, :length => 32), gallery_path(gallery))
.span2
%h4 Company Info
%ul.unstyled
- pages.each do |page|
- %li= link_to(page.name, page_path(page))
+ %li= link_to(truncate(page.name, :length => 32), page_path(page))
%li= link_to('Contact', new_contact_request_path)
.span3
%h4 Recent Posts
%ul.unstyled
+ - recent_posts.each do |post|
+ %li= link_to(truncate(post.title, :length => 32), post_path(post))
.span5
%p= photographer.description
View
@@ -55,7 +55,6 @@ class Application < Rails::Application
:entitystore => URI.encode("file:#{Rails.root}/tmp/dragonfly/cache/body")
} unless Rails.env.production? ## uncomment this 'unless' in Rails 3.1,
## because it already inserts Rack::Cache in production
-
config.middleware.insert_after 'Rack::Cache', 'Dragonfly::Middleware', :images
end
end
@@ -6,6 +6,8 @@
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
+ config.cache_store = :memory_store
+
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
@@ -26,5 +28,4 @@
config.assets.compress = false
config.action_mailer.default_url_options = { :host => 'localhost:3000' } # TODO - change this to whatever you run development on. I.e. :host => 'localhost:3000'
-
end
@@ -29,6 +29,7 @@
# Use a different cache store in production
# config.cache_store = :mem_cache_store
+ config.cache_store = :dalli_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
@@ -7,6 +7,8 @@
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = false
+ config.cache_store = :memory_store
+
# Configure static asset server for tests with Cache-Control for performance
config.serve_static_assets = true
config.static_cache_control = "public, max-age=3600"
View
@@ -6,6 +6,7 @@
resources :private_galleries, :only => :show
resources :galleries, :only => :show
resources :pages, :only => :show
+ resources :posts, :only => [:index, :show]
resources :contact_requests, :only => [:new, :create] do
get :thanks, :on => :collection
end
@@ -1,7 +1,7 @@
class CreatePages < ActiveRecord::Migration
def change
create_table :pages do |t|
- t.string :name, :null => false, :limit => 32
+ t.string :name, :null => false, :limit => 20
t.string :keywords, :limit => 255
t.text :body, :null => false
t.string :image_uid
@@ -2,7 +2,7 @@ class CreateGalleries < ActiveRecord::Migration
def change
create_table :galleries do |t|
t.integer :position
- t.string :name, :null => false, :limit => 100
+ t.string :name, :null => false, :limit => 20
t.string :keywords, :limit => 255
t.text :description
t.string :cover_uid
@@ -1,7 +1,7 @@
class CreatePosts < ActiveRecord::Migration
def change
create_table :posts do |t|
- t.string :title, :null => false, :limit => 128
+ t.string :title, :null => false, :limit => 64
t.string :keywords, :limit => 255
t.text :body, :null => false
t.string :image_uid
View
@@ -56,5 +56,6 @@
Page.create(:name => "Pricing", :image => File.new(Rails.root.join('creatives', 'pages', 'about.png')), :body => "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\n\nDuis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
# Creating posts
-Post.create(:title => "Baby Stuey at 1 week", :image => File.new(Rails.root.join('creatives', 'pages', 'about.png')), :body => "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\n\nDuis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
-Post.create(:title => "The Jones Family Portraits", :image => File.new(Rails.root.join('creatives', 'pages', 'about.png')), :body => "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\n\nDuis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
+Post.create(:title => "Baby Stuey at 1 week", :keywords => 'baby, photography, newborns', :image => File.new(Rails.root.join('creatives', 'pages', 'about.png')), :body => "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\n\nDuis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
+Post.create(:title => "The Jones Family Portraits", :keywords => 'family, photography, portrait, lifestyle', :image => File.new(Rails.root.join('creatives', 'pages', 'about.png')), :body => "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\n\nDuis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
+Post.create(:title => "This is how we handle titles that are extraordinarily long.", :image => File.new(Rails.root.join('creatives', 'pages', 'about.png')), :body => "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\n\nDuis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
@@ -8,7 +8,7 @@
context "validations" do
it { should validate_presence_of(:name) }
- it { should ensure_length_of(:name).is_at_least(2).is_at_most(100) }
+ it { should ensure_length_of(:name).is_at_least(2).is_at_most(20) }
it { should validate_uniqueness_of(:name) }
it { should ensure_length_of(:keywords).is_at_least(2).is_at_most(255) }
View
@@ -4,7 +4,7 @@
context "validations" do
it { should validate_presence_of(:name) }
- it { should ensure_length_of(:name).is_at_least(2).is_at_most(32) }
+ it { should ensure_length_of(:name).is_at_least(2).is_at_most(20) }
it { should ensure_length_of(:keywords).is_at_least(2).is_at_most(255) }
@@ -13,7 +13,7 @@
it { should validate_presence_of(:password) }
it { should validate_presence_of(:name) }
it { should ensure_length_of(:name).is_at_least(3).is_at_most(80) }
- it { should ensure_length_of(:tagline).is_at_least(3).is_at_most(100) }
+ it { should ensure_length_of(:tagline).is_at_least(3).is_at_most(128) }
it { should ensure_length_of(:description).is_at_least(10).is_at_most(255) }
it { should ensure_length_of(:phone).is_at_least(7).is_at_most(20) }
it { should ensure_length_of(:blog_url).is_at_least(10).is_at_most(512) }
View
@@ -4,29 +4,29 @@
context "validations" do
it { should validate_presence_of(:title) }
- it { should ensure_length_of(:title).is_at_least(2).is_at_most(128) }
+ it { should ensure_length_of(:title).is_at_least(2).is_at_most(64) }
it { should ensure_length_of(:keywords).is_at_least(2).is_at_most(255) }
it { should validate_presence_of(:body) }
it { should ensure_length_of(:body).is_at_least(10) }
end
- context "recents" do
+ context "recent" do
it "should return the list of recent posts" do
post = FactoryGirl.create(:post)
FactoryGirl.create(:post)
- Post.recents.size.should be 2
- Post.recents.should include(post)
+ Post.recent.size.should be 2
+ Post.recent.should include(post)
end
it "should refresh the cache when a post is modified" do
post = FactoryGirl.create(:post)
FactoryGirl.create(:post)
- Post.recents.should include(post)
+ Post.recent.should include(post)
post.title = "Changed Title"
post.save
- Post.recents.collect{ |p| p.title }.should include(post.title)
+ Post.recent.collect{ |p| p.title }.should include(post.title)
end
end

0 comments on commit a39467b

Please sign in to comment.