Skip to content
Browse files

Added support for 'draft' pages.

Bugfix: error when trying to access a missing page due to sidebar check
Bugfix: Sitemap links leading to current year blog entries would list the entire year entries instead of just the selected month.
  • Loading branch information...
1 parent 51d6108 commit 44066be098f7f8048e4eaf4872aa7bbcd1f82b69 @battlehorse committed May 19, 2011
View
4 app/controllers/edit_controller.rb
@@ -38,7 +38,7 @@ def save
def delete
raise "You tried to delete a folder" unless is_content? path_from_params
- p = Page.fromPath(path_from_params)
+ p = Page.fromPath(path_from_params, :include_drafts => true)
if p.nil?
render :json => { :status => "ERR" , :message => "Page not found"}.to_json
else
@@ -71,6 +71,6 @@ def check_permission
def load_page_if_any
raise "You tried editing a list page" unless is_content? path_from_params
- @page = Page.fromPath(path_from_params) || Page.new
+ @page = Page.fromPath(path_from_params, :include_drafts => true) || Page.new
end
end
View
17 app/controllers/list_controller.rb
@@ -2,13 +2,17 @@ class ListController < ApplicationController
def list
# non-recursive listing
- @pages = Page.allFromPath(path_from_params, false).each { |page| page.summarize }
+ can_see_drafts = session[:user_id] && session[:user_id].is_editor
+ @pages = Page.allFromPath(
+ path_from_params,
+ :recursive => false, :include_drafts => can_see_drafts).each { |page| page.summarize }
end
def blog
+ params["year"] ||= Time.now.year.to_s
path = [] << params["year"] << params["month"] << params["day"]
params[:path] = path.compact
-
+
# recursive listing
@pages = get_blog_pages
@@ -29,7 +33,10 @@ def comment
end
def get_blog_pages
- pages = Page.allFromPath(path_from_params).each { |page| page.summarize }
+ can_see_drafts = session[:user_id] && session[:user_id].is_editor
+ pages = Page.allFromPath(
+ path_from_params,
+ :recursive => true, :include_drafts => can_see_drafts).each { |page| page.summarize }
if yearly_path? && path_from_params[0].to_i < Time.now.year
return pages
@@ -42,7 +49,9 @@ def get_blog_pages
# empty at the beginning of every new year.
year = (yearly_path? ? path_from_params[0].to_i : Time.now.year) - 1
while pages.size < 10 && yearly_path? do
- pages << Page.allFromPath([ year.to_s ]).each { |page| page.summarize }
+ pages << Page.allFromPath(
+ [ year.to_s ],
+ :recursive => true, :include_drafts => can_see_drafts).each { |page| page.summarize }
pages.flatten!
year -= 1
end
View
6 app/controllers/page_controller.rb
@@ -1,9 +1,11 @@
class PageController < ApplicationController
def view
- @page = Page.fromPath(path_from_params)
- @show_sidebar = @page.enable_sidebar?
+ # Only editors can see pages that are still drafts
+ can_see_drafts = session[:user_id] && session[:user_id].is_editor
+ @page = Page.fromPath(path_from_params, :include_drafts => can_see_drafts)
render_404 and return if @page.nil?
+ @show_sidebar = @page.enable_sidebar?
end
end
View
6 app/controllers/sitemap_controller.rb
@@ -4,7 +4,11 @@ class SitemapController < ApplicationController
include RedClothHelper
def view # for HTML sitemap page
- @pages = Page.allFromPath([]).sort_by { |page| page.path.join('/') }.reverse
+ can_see_drafts = session[:user_id] && session[:user_id].is_editor
+ @pages = Page.allFromPath(
+ [],
+ :recursive => true,
+ :include_drafts => can_see_drafts).sort_by { |page| page.path.join('/') }.reverse
build_sitemap
build_blogmap
View
9 app/controllers/tags_controller.rb
@@ -4,9 +4,11 @@ class TagsController < ApplicationController
def index
@tags = {}
+ can_see_drafts = session[:user_id] && session[:user_id].is_editor
- # scan all the contents recursively
- Page.allFromPath([]).each do |page|
+ # scan all the contents recursively
+ Page.allFromPath(
+ [], :recursive => true, :include_drafts => can_see_drafts).each do |page|
if page.h(:tags)
([] << page.h(:tags)).flatten.each do |tag|
@tags[tag] ||= 0
@@ -18,10 +20,11 @@ def index
def show
@tag = params["id"].gsub(/_/," ") # replace underscores with spaces
+ can_see_drafts = session[:user_id] && session[:user_id].is_editor
# scan all the contents recursively
@pages = Page.
- allFromPath([]).
+ allFromPath([], :recursive => true, :include_drafts => can_see_drafts).
reject { |page| !([] << page.h(:tags)).flatten.include?(@tag) }.
each { |page| page.summarize }
end
View
4 app/helpers/application_helper.rb
@@ -51,5 +51,9 @@ def kind(obj)
:generic
end
end
+
+ def is_draft(obj)
+ obj.respond_to?(:draft?) && obj.draft?
+ end
end
View
29 app/models/page.rb
@@ -23,18 +23,31 @@ def self.fromRawData(path, raw_data)
end
end
- def self.fromPath(path)
+ def self.fromPath(path, params = {:include_drafts => false})
rpath = @@finder.find(path, base_folder, true)
- rpath.blank? ? nil : Page.new(rpath[0])
+ if rpath.blank?
+ nil
+ else
+ p = Page.new(rpath[0])
+ if !params[:include_drafts] && p.draft?
+ nil
+ else
+ p
+ end
+ end
end
- def self.allFromPath(path, recursive=true)
- rpaths = recursive ?
+ def self.allFromPath(path, params = {:recursive => true, :include_drafts => false})
+ rpaths = params[:recursive] ?
@@lister.list(path, base_folder, true, true) :
@@finder.find_and_prune(path, base_folder, true)
rpaths = [] if rpaths.blank?
- rpaths.map { |rpath| Page.new(rpath) }
+ rpaths.map! { |rpath| Page.new(rpath) }
+ if !params[:include_drafts]
+ rpaths.delete_if { |p| p.draft? }
+ end
+ return rpaths
end
def initialize(rpath=nil)
@@ -57,6 +70,10 @@ def fresh?
@fresh
end
+ def draft?
+ !['true', 'yes', '1'].index(h(:draft)).nil?
+ end
+
def headers
parse if fresh?
@headers
@@ -76,7 +93,7 @@ def author_mail
end
def enable_sidebar?
- !['enabled', 'enable', 'true', 'yes', 1].index(h(:sidebar, 'enabled')).nil?
+ !['enabled', 'enable', 'true', 'yes', '1'].index(h(:sidebar, 'enabled')).nil?
end
def title
View
24 app/views/shared/_content.html.erb
@@ -1,12 +1,14 @@
-<% if kind(content) == :page_with_date -%>
- <div class="calendar"><p class="calendar-month"><%= content.date.strftime('%b').upcase %></p><p class="calendar-day"><%= content.date.day.ordinalize %></p></div>
- <h1 class="article-title"><%= link_to content.title , page_path({ :path => content.path }) %></h1>
- <div class='article-content'>
+<div class="<%= is_draft(content) ? "article-draft" : '' %>" >
+ <% if kind(content) == :page_with_date -%>
+ <div class="calendar"><p class="calendar-month"><%= content.date.strftime('%b').upcase %></p><p class="calendar-day"><%= content.date.day.ordinalize %></p></div>
+ <h1 class="article-title"><%= link_to content.title , page_path({ :path => content.path }) %></h1>
+ <div class='article-content'>
+ <%= textile(content.titleless_content)%>
+ </div>
+ <% elsif kind(content) == :page_with_title -%>
+ <h1><%= link_to content.title , page_path({ :path => content.path }) %></h1>
<%= textile(content.titleless_content)%>
- </div>
-<% elsif kind(content) == :page_with_title -%>
- <h1><%= link_to content.title , page_path({ :path => content.path }) %></h1>
- <%= textile(content.titleless_content)%>
-<% else -%>
- <%= textile(content) %>
-<% end -%>
+ <% else -%>
+ <%= textile(content) %>
+ <% end -%>
+</div>
View
1 config/routes.rb
@@ -17,7 +17,6 @@
match 'tag/:id' => 'tags#show', :as => :tag
match 'blog(/:year(/:month(/:day)))' => 'list#blog',
:constraints => { :year => /(19|20)\d\d/ , :month => /[01]\d/ , :day => /[0-3]\d/ },
- :defaults => {:year => Time.now.year.to_s, :day => nil, :month => nil},
:as => :blog
# Feeds
View
6 public/stylesheets/CoolWater.css
@@ -389,6 +389,12 @@ input.edit {
.article-meta .comments { padding-left: 0px; margin: 0 5px; }
.article-meta .readmore { padding-left: 0px; margin: 0 5px; }
+/* drafts */
+.article-draft {
+ background-color: rgba(255, 255, 0, 0.1);
+ border-radius: 5px;
+}
+
/* alignment classes */
.float-left { float: left; }
.float-right { float: right; }
View
6 public/stylesheets/InternetSharing.css
@@ -256,6 +256,12 @@ UL.formError {
color: green;
}
+/* drafts */
+.article-draft {
+ background-color: rgba(255, 255, 0, 0.1);
+ border-radius: 5px;
+}
+
.blog_archive {
font-size: 160%;
color: #003B6E;
View
6 public/stylesheets/bigG.css
@@ -395,6 +395,12 @@ UL.formError {
font-size: 0.9em;
}
+/* drafts */
+.article-draft {
+ background-color: rgba(255, 255, 0, 0.1);
+ border-radius: 5px;
+}
+
.blog_archive {
font-size: 1.6em;
color: rgb(42, 93, 176);
View
6 public/stylesheets/bigG_mobile.css
@@ -421,6 +421,12 @@ UL.formError {
font-size: 0.9em;
}
+/* drafts */
+.article-draft {
+ background-color: rgba(255, 255, 0, 0.1);
+ border-radius: 5px;
+}
+
.blog_archive {
font-size: 1.6em;
color: rgb(42, 93, 176);

0 comments on commit 44066be

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