From 60fc7839f8b6227951eed454442b69836840df01 Mon Sep 17 00:00:00 2001 From: Michael Gall Date: Tue, 31 May 2011 11:38:28 +1000 Subject: Add page-like tab functionality --- app/models/blog_post.rb | 2 ++ app/views/admin/blog/posts/_form.html.erb | 29 ++++++++++++++++++++++++-- app/views/admin/blog/posts/_form.js.erb | 1 + app/views/admin/blog/posts/_form_part.html.erb | 3 +++ lib/refinery/blog/tab.rb | 28 +++++++++++++++++++++++++ lib/refinerycms-blog.rb | 3 ++- 6 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 app/views/admin/blog/posts/_form_part.html.erb create mode 100644 lib/refinery/blog/tab.rb diff --git a/app/models/blog_post.rb b/app/models/blog_post.rb index 63c66ba..e298bcf 100644 --- a/app/models/blog_post.rb +++ b/app/models/blog_post.rb @@ -22,6 +22,8 @@ class BlogPost < ActiveRecord::Base validates :body, :presence => true has_friendly_id :title, :use_slug => true + + attr_accessible :title, :body, :tag_list, :draft, :published_at, :browser_title, :meta_keywords, :meta_description, :user_id scope :by_archive, lambda { |archive_date| where(['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month]) diff --git a/app/views/admin/blog/posts/_form.html.erb b/app/views/admin/blog/posts/_form.html.erb index 7bcca84..7d95052 100644 --- a/app/views/admin/blog/posts/_form.html.erb +++ b/app/views/admin/blog/posts/_form.html.erb @@ -11,8 +11,33 @@
- <%= f.label :body -%> - <%= f.text_area :body, :rows => 20, :class => 'wymeditor widest' -%> +
+
    +
  • + <%= link_to "Body", "#page_part_body" %> +
  • + <% Refinery::Blog.tabs.each_with_index do |tab, tab_index| %> +
  • + <%= link_to tab.name.titleize, "#custom_tab_#{tab_index}" %> +
  • + <% end %> +
+ +
+ + <% part_index = -1 %> + <%= render :partial => 'form_part', + :locals => { + :f => f, + :part_index => (part_index += 1), + } -%> + <% Refinery::Blog.tabs.each_with_index do |tab, tab_index| %> +
+ <%= render :partial => tab.partial, :locals => {:f => f} %> +
+ <% end %> +
+
diff --git a/app/views/admin/blog/posts/_form.js.erb b/app/views/admin/blog/posts/_form.js.erb index 1d65448..98a61d0 100644 --- a/app/views/admin/blog/posts/_form.js.erb +++ b/app/views/admin/blog/posts/_form.js.erb @@ -10,4 +10,5 @@ }, 250); }); }); + var tabs = $('#page-tabs').tabs(); diff --git a/app/views/admin/blog/posts/_form_part.html.erb b/app/views/admin/blog/posts/_form_part.html.erb new file mode 100644 index 0000000..114e493 --- /dev/null +++ b/app/views/admin/blog/posts/_form_part.html.erb @@ -0,0 +1,3 @@ +
+ <%= f.text_area :body, :rows => 20, :class => 'wymeditor widest' -%> +
diff --git a/lib/refinery/blog/tab.rb b/lib/refinery/blog/tab.rb new file mode 100644 index 0000000..083d50b --- /dev/null +++ b/lib/refinery/blog/tab.rb @@ -0,0 +1,28 @@ +module Refinery + module Blog + attr_accessor :tabs + + def self.tabs + @tabs ||= [] + end + + class Tab + attr_accessor :name, :partial + + def self.register(&block) + tab = self.new + + yield tab + + raise "A tab MUST have a name!: #{tab.inspect}" if tab.name.blank? + raise "A tab MUST have a partial!: #{tab.inspect}" if tab.partial.blank? + end + + protected + + def initialize + ::Refinery::Blog.tabs << self # add me to the collection of registered page tabs + end + end + end +end \ No newline at end of file diff --git a/lib/refinerycms-blog.rb b/lib/refinerycms-blog.rb index 901535d..db9beda 100644 --- a/lib/refinerycms-blog.rb +++ b/lib/refinerycms-blog.rb @@ -2,8 +2,9 @@ require 'filters_spam' module Refinery module Blog - autoload :Version, File.expand_path('../refinery/blog/version', __FILE__) + autoload :Tab, File.expand_path("../refinery/blog/tab", __FILE__) + class << self def version ::Refinery::Blog::Version.to_s -- cgit v1.2.3