aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorPhilip Arndt <parndt@gmail.com>2010-08-09 16:47:56 +1200
committerPhilip Arndt <parndt@gmail.com>2010-08-09 16:47:56 +1200
commit837ea01a34a7dddeefe8086b2c6fc28e9a14616c (patch)
tree26c3c55c9026518de8b0626001cc55116bc5c87e /app
parent9a8b95e9aa71529d7b4173a3afce49b199a60615 (diff)
downloadrefinerycms-blog-837ea01a34a7dddeefe8086b2c6fc28e9a14616c.tar.gz
refinerycms-blog-837ea01a34a7dddeefe8086b2c6fc28e9a14616c.tar.bz2
refinerycms-blog-837ea01a34a7dddeefe8086b2c6fc28e9a14616c.zip
Initial commit - you can create, edit and delete a blog post and it respects the fact that it is draft or not.
Diffstat (limited to 'app')
-rw-r--r--app/controllers/admin/blog_posts_controller.rb5
-rw-r--r--app/controllers/blog_posts_controller.rb30
-rw-r--r--app/models/blog_category.rb10
-rw-r--r--app/models/blog_comment.rb8
-rw-r--r--app/models/blog_post.rb14
-rw-r--r--app/views/admin/blog_posts/_blog_post.html.erb16
-rw-r--r--app/views/admin/blog_posts/_form.html.erb25
-rw-r--r--app/views/admin/blog_posts/_sortable_list.html.erb7
-rw-r--r--app/views/admin/blog_posts/edit.html.erb1
-rw-r--r--app/views/admin/blog_posts/index.html.erb59
-rw-r--r--app/views/admin/blog_posts/new.html.erb1
-rw-r--r--app/views/blog_posts/index.html.erb11
-rw-r--r--app/views/blog_posts/show.html.erb20
13 files changed, 207 insertions, 0 deletions
diff --git a/app/controllers/admin/blog_posts_controller.rb b/app/controllers/admin/blog_posts_controller.rb
new file mode 100644
index 0000000..0fd5a93
--- /dev/null
+++ b/app/controllers/admin/blog_posts_controller.rb
@@ -0,0 +1,5 @@
+class Admin::BlogPostsController < Admin::BaseController
+
+ crudify :blog_post, :title_attribute => :title, :order => 'created_at DESC'
+
+end
diff --git a/app/controllers/blog_posts_controller.rb b/app/controllers/blog_posts_controller.rb
new file mode 100644
index 0000000..95169c0
--- /dev/null
+++ b/app/controllers/blog_posts_controller.rb
@@ -0,0 +1,30 @@
+class BlogPostsController < ApplicationController
+
+ before_filter :find_all_blog_posts
+ before_filter :find_page
+
+ def index
+ # you can use meta fields from your model instead (e.g. browser_title)
+ # by swapping @page for @blogs in the line below:
+ present(@page)
+ end
+
+ def show
+ @blog_post = BlogPost.live.find(params[:id])
+
+ # you can use meta fields from your model instead (e.g. browser_title)
+ # by swapping @page for @blogs in the line below:
+ present(@page)
+ end
+
+protected
+
+ def find_all_blog_posts
+ @blog_posts = BlogPost.live
+ end
+
+ def find_page
+ @page = Page.find_by_link_url("/blogs")
+ end
+
+end
diff --git a/app/models/blog_category.rb b/app/models/blog_category.rb
new file mode 100644
index 0000000..9060d11
--- /dev/null
+++ b/app/models/blog_category.rb
@@ -0,0 +1,10 @@
+class BlogCategory < ActiveRecord::Base
+
+ acts_as_indexed :fields => [:title]
+
+ validates_presence_of :title
+ validates_uniqueness_of :title
+
+ has_friendly_id :title, :use_slug => true
+
+end
diff --git a/app/models/blog_comment.rb b/app/models/blog_comment.rb
new file mode 100644
index 0000000..4398475
--- /dev/null
+++ b/app/models/blog_comment.rb
@@ -0,0 +1,8 @@
+class BlogPost < ActiveRecord::Base
+
+ acts_as_indexed :fields => [:name, :email, :body]
+
+ validates_presence_of :title
+ validates_uniqueness_of :title
+
+end
diff --git a/app/models/blog_post.rb b/app/models/blog_post.rb
new file mode 100644
index 0000000..481b8cb
--- /dev/null
+++ b/app/models/blog_post.rb
@@ -0,0 +1,14 @@
+class BlogPost < ActiveRecord::Base
+
+ acts_as_indexed :fields => [:title, :body]
+
+ validates_presence_of :title
+ validates_uniqueness_of :title
+
+ has_friendly_id :title, :use_slug => true
+
+ default_scope :order => "created_at DESC"
+
+ named_scope :live, :conditions => {:draft => false}
+
+end
diff --git a/app/views/admin/blog_posts/_blog_post.html.erb b/app/views/admin/blog_posts/_blog_post.html.erb
new file mode 100644
index 0000000..b56a050
--- /dev/null
+++ b/app/views/admin/blog_posts/_blog_post.html.erb
@@ -0,0 +1,16 @@
+<li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%= dom_id(blog_post) -%>">
+ <span class='title'>
+ <%=h blog_post.title %>
+ <span class="preview">&nbsp;</span>
+ </span>
+ <span class='actions'>
+ <%= link_to refinery_icon_tag("application_go.png"), blog_post_url(blog_post),
+ :title => t('.view_live'),
+ :target => "_blank" %>
+ <%= link_to refinery_icon_tag("application_edit.png"), edit_admin_blog_post_path(blog_post),
+ :title => t('.edit') %>
+ <%= link_to refinery_icon_tag("delete.png"), admin_blog_post_path(blog_post),
+ :class => "cancel confirm-delete",
+ :title => t('.delete') %>
+ </span>
+</li>
diff --git a/app/views/admin/blog_posts/_form.html.erb b/app/views/admin/blog_posts/_form.html.erb
new file mode 100644
index 0000000..5d9f347
--- /dev/null
+++ b/app/views/admin/blog_posts/_form.html.erb
@@ -0,0 +1,25 @@
+<% form_for [:admin, @blog_post] do |f| -%>
+ <%= f.error_messages %>
+
+ <div class='field'>
+ <%= f.label :title -%>
+ <%= f.text_field :title, :class => 'larger widest' -%>
+ </div>
+
+ <div class='field'>
+ <%= f.label :body -%>
+ <%= f.text_area :body, :rows => 20, :class => 'wymeditor widest' -%>
+ </div>
+
+ <div class='field'>
+ <%= f.label :draft -%>
+ <%= f.check_box :draft -%>
+ </div>
+
+ <%= render :partial => "/shared/admin/form_actions",
+ :locals => {
+ :f => f,
+ :continue_editing => false,
+ :delete_title => t('admin.blogs.blogs.delete')
+ } %>
+<% end -%>
diff --git a/app/views/admin/blog_posts/_sortable_list.html.erb b/app/views/admin/blog_posts/_sortable_list.html.erb
new file mode 100644
index 0000000..3529b23
--- /dev/null
+++ b/app/views/admin/blog_posts/_sortable_list.html.erb
@@ -0,0 +1,7 @@
+<ul id='sortable_list'>
+ <%= render :partial => 'blog_post', :collection => @blog_posts %>
+</ul>
+<%= render :partial => "/shared/admin/sortable_list",
+ :locals => {
+ :continue_reordering => (defined?(continue_reordering) ? continue_reordering : true)
+ } %>
diff --git a/app/views/admin/blog_posts/edit.html.erb b/app/views/admin/blog_posts/edit.html.erb
new file mode 100644
index 0000000..2872e82
--- /dev/null
+++ b/app/views/admin/blog_posts/edit.html.erb
@@ -0,0 +1 @@
+<%= render :partial => "form" %>
diff --git a/app/views/admin/blog_posts/index.html.erb b/app/views/admin/blog_posts/index.html.erb
new file mode 100644
index 0000000..15fd775
--- /dev/null
+++ b/app/views/admin/blog_posts/index.html.erb
@@ -0,0 +1,59 @@
+<div id='actions'>
+ <ul>
+ <li>
+ <%= render :partial => "/shared/admin/search",
+ :locals => {
+ :url => admin_blog_posts_url
+ } %>
+ </li>
+ <li>
+ <%= link_to t('.create_new'), new_admin_blog_post_url,
+ :class => "add_icon" %>
+ </li>
+ <% if !searching? and BlogPost.count > 1 %>
+ <li>
+ <%= link_to t('refinery.reorder', :what => "BlogPost"), admin_blog_posts_url,
+ :id => "reorder_action",
+ :class => "reorder_icon" %>
+
+ <%= link_to t('refinery.reorder_done', :what => "BlogPost"), admin_blog_posts_url,
+ :id => "reorder_action_done",
+ :style => "display: none;",
+ :class => "reorder_icon" %>
+ </li>
+ <% end %>
+ </ul>
+</div>
+<div id='records'>
+ <% if searching? %>
+ <h2><%= t('admin.search_results_for', :query => params[:search]) %></h2>
+ <% if @blog_posts.any? %>
+ <%= render :partial => "blog_posts",
+ :collection => @blog_posts %>
+ <% else %>
+ <p><%= t('admin.search_no_results') %></p>
+ <% end %>
+ <% else %>
+ <% if @blog_posts.any? %>
+ <%= will_paginate @blog_posts,
+ :previous_label => '&laquo;',
+ :next_label => '&raquo;' %>
+
+ <%= render :partial => "sortable_list" %>
+
+ <%= will_paginate @blog_posts,
+ :previous_label => '&laquo;',
+ :next_label => '&raquo;' %>
+ <% else %>
+ <p>
+ <strong>
+ <%= t('.no_items_yet') %>
+ </strong>
+ </p>
+ <% end %>
+ <% end %>
+</div>
+<%= render :partial => "/shared/admin/make_sortable",
+ :locals => {
+ :tree => false
+ } if !searching? and BlogPost.count > 1 %>
diff --git a/app/views/admin/blog_posts/new.html.erb b/app/views/admin/blog_posts/new.html.erb
new file mode 100644
index 0000000..2872e82
--- /dev/null
+++ b/app/views/admin/blog_posts/new.html.erb
@@ -0,0 +1 @@
+<%= render :partial => "form" %>
diff --git a/app/views/blog_posts/index.html.erb b/app/views/blog_posts/index.html.erb
new file mode 100644
index 0000000..4dddcef
--- /dev/null
+++ b/app/views/blog_posts/index.html.erb
@@ -0,0 +1,11 @@
+<% content_for :body_content_left do %>
+ <ul id="blog_posts">
+ <% @blog_posts.each do |blog_post| %>
+ <li>
+ <%= link_to blog_post.title, blog_post_url(blog_post) %>
+ </li>
+ <% end %>
+ </ul>
+<% end %>
+
+<%= render :partial => "/shared/content_page" %>
diff --git a/app/views/blog_posts/show.html.erb b/app/views/blog_posts/show.html.erb
new file mode 100644
index 0000000..2cd39c6
--- /dev/null
+++ b/app/views/blog_posts/show.html.erb
@@ -0,0 +1,20 @@
+<% content_for :body_content_title, @blog_post.title %>
+
+<% content_for :body_content_left do %>
+
+ <%= @blog_post.body %>
+
+<% end %>
+
+<% content_for :body_content_right do %>
+ <h2><%= t('.other') %></h2>
+ <ul id="blog_post">
+ <% @blog_posts.each do |blog_post| %>
+ <li>
+ <%= link_to blog_post.title, blog_post_url(blog_post) %>
+ </li>
+ <% end %>
+ </ul>
+<% end %>
+
+<%= render :partial => "/shared/content_page" %>