diff options
-rw-r--r-- | app/controllers/blog/posts_controller.rb | 33 | ||||
-rw-r--r-- | app/views/admin/blog/comments/show.html.erb | 2 | ||||
-rw-r--r-- | app/views/blog/posts/_nav.html.erb | 3 | ||||
-rw-r--r-- | app/views/blog/posts/show.html.erb | 7 | ||||
-rw-r--r-- | config/routes.rb | 1 | ||||
-rw-r--r-- | public/javascripts/refinerycms-blog.js | 22 |
6 files changed, 58 insertions, 10 deletions
diff --git a/app/controllers/blog/posts_controller.rb b/app/controllers/blog/posts_controller.rb index 8c627fd..10ec867 100644 --- a/app/controllers/blog/posts_controller.rb +++ b/app/controllers/blog/posts_controller.rb @@ -1,18 +1,36 @@ class Blog::PostsController < BlogController before_filter :find_all_blog_posts, :except => [:archive] - before_filter :find_blog_post, :only => [:show, :comment] + before_filter :find_blog_post, :only => [:show, :comment, :update_nav] + + respond_to :html, :js, :rss if Rails.version >= '3.0.0' def index - respond_to do |format| - format.html - format.rss + if Rails.version < '3.0.0' + # TODO: respond_to block + else + respond_with (@blog_posts) do |format| + format.html + format.rss + end end end def show @blog_comment = BlogComment.new - present(@page) + + if Rails.version < '3.0.0' + # TODO: respond_to block + else + respond_with (@blog_post) do |format| + format.html { present(@page) } + format.js { render :partial => 'post', :layout => false } + end + end + end + + def update_nav + render :partial => 'nav' end def comment @@ -49,6 +67,11 @@ class Blog::PostsController < BlogController :page => params[:page], :per_page => RefinerySetting.find_or_set(:blog_posts_per_page, 10) }) + if Rails.version < '3.0.0' + # TODO: respond_to block + else + respond_with (@blog_posts) + end end protected diff --git a/app/views/admin/blog/comments/show.html.erb b/app/views/admin/blog/comments/show.html.erb index f22edd8..d4c2186 100644 --- a/app/views/admin/blog/comments/show.html.erb +++ b/app/views/admin/blog/comments/show.html.erb @@ -60,4 +60,4 @@ </table> </div> -<% content_for :stylesheets, stylesheet_link_tag('refinery/refinerycms-blog') %>
\ No newline at end of file +<% content_for :stylesheets, stylesheet_link_tag('refinery/refinerycms-blog') %> diff --git a/app/views/blog/posts/_nav.html.erb b/app/views/blog/posts/_nav.html.erb new file mode 100644 index 0000000..6a36a10 --- /dev/null +++ b/app/views/blog/posts/_nav.html.erb @@ -0,0 +1,3 @@ +<%= link_to raw(truncate(@blog_post.next.title) + " »"), @blog_post.next, :class => 'next', :"data-nav-url" => update_blog_nav_path(@blog_post.next) if @blog_post.next.present? %> +<%= link_to 'Blog Home', blog_root_path, :class => 'home' %> +<%= link_to "« ".html_safe + truncate(@blog_post.prev.title), @blog_post.prev, :class => 'prev', :"data-nav-url" => update_blog_nav_path(@blog_post.prev) if @blog_post.prev.present? %>
\ No newline at end of file diff --git a/app/views/blog/posts/show.html.erb b/app/views/blog/posts/show.html.erb index 530bede..778b011 100644 --- a/app/views/blog/posts/show.html.erb +++ b/app/views/blog/posts/show.html.erb @@ -13,9 +13,7 @@ </article> <% if next_or_previous?(@blog_post) -%> <nav id="next_prev_article"> - <%= link_to raw(truncate(@blog_post.next.title) + " »"), @blog_post.next, :class => 'next' if @blog_post.next.present? %> - <%= link_to 'Blog Home', blog_root_path, :class => 'home' %> - <%= link_to "« ".html_safe + truncate(@blog_post.prev.title), @blog_post.prev, :class => 'prev' if @blog_post.prev.present? %> + <%= render 'nav' %> </nav><!-- /next_prev_article --> <% end -%> <% if BlogPost.comments_allowed? %> @@ -79,4 +77,5 @@ <% end %> <%= render :partial => "/shared/content_page", :locals => { :remove_automatic_sections => true } %> -<% content_for :stylesheets, stylesheet_link_tag('refinerycms-blog') %>
\ No newline at end of file +<% content_for :stylesheets, stylesheet_link_tag('refinerycms-blog') %> +<% content_for :javascripts, javascript_include_tag('jquery','refinerycms-blog') %>
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 01fb501..1474c3f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -42,6 +42,7 @@ else match 'categories/:id', :to => 'categories#show', :as => 'blog_category' match ':id/comments', :to => 'posts#comment', :as => 'blog_post_blog_comments' get 'archive/:year/:month', :to => 'posts#archive', :as => 'archive_blog_posts' + get ':id/update_nav.js', :to => 'posts#update_nav', :as => 'update_blog_nav' end scope(:path => 'refinery', :as => 'admin', :module => 'admin') do diff --git a/public/javascripts/refinerycms-blog.js b/public/javascripts/refinerycms-blog.js new file mode 100644 index 0000000..f55e279 --- /dev/null +++ b/public/javascripts/refinerycms-blog.js @@ -0,0 +1,22 @@ +$(document).ready(function(){ + height = $('#show_blog_post').height(); + $('#show_blog_post').height(height); + $('#next_prev_article a:not(".home")').click(function(){ + url = this.href + ".js"; + nav_url = $(this).attr('data-nav-url'); + $('#show_blog_post, #next_prev_article').fadeOut(); + $.ajax({ + url: url, + success: function(data) { + $('#show_blog_post').html(data).fadeIn().height('auto'); + $.ajax({ + url: nav_url, + success: function(data) { + $('#next_prev_article').html(data).fadeIn(); + } + }) + } + }); + return false; + }) +})
\ No newline at end of file |