aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/helpers/blog_posts_helper.rb12
-rw-r--r--app/models/blog_post.rb2
-rw-r--r--app/views/admin/blog/posts/_form.css.erb8
-rw-r--r--app/views/admin/blog/posts/_form.html.erb10
-rw-r--r--app/views/admin/blog/posts/_form.js.erb20
-rw-r--r--app/views/admin/blog/posts/_teaser_part.html.erb11
-rw-r--r--app/views/blog/shared/_post.html.erb4
-rw-r--r--config/locales/en.yml2
-rw-r--r--db/migrate/7_add_custom_teaser_field_to_blog_posts.rb10
9 files changed, 73 insertions, 6 deletions
diff --git a/app/helpers/blog_posts_helper.rb b/app/helpers/blog_posts_helper.rb
index 6b4066a..1922862 100644
--- a/app/helpers/blog_posts_helper.rb
+++ b/app/helpers/blog_posts_helper.rb
@@ -41,4 +41,16 @@ module BlogPostsHelper
def next_or_previous?(post)
post.next.present? or post.prev.present?
end
+
+ def blog_post_teaser(post)
+ if post.custom_teaser.present?
+ post.custom_teaser.html_safe
+ else
+ truncate(
+ post.body,
+ :length => RefinerySetting.find_or_set(:blog_post_teaser_length, 250),
+ :preserve_html_tags => true
+ )
+ end
+ end
end
diff --git a/app/models/blog_post.rb b/app/models/blog_post.rb
index a010d98..2126827 100644
--- a/app/models/blog_post.rb
+++ b/app/models/blog_post.rb
@@ -26,7 +26,7 @@ class BlogPost < ActiveRecord::Base
:approximate_ascii => RefinerySetting.find_or_set(:approximate_ascii, false, :scoping => 'blog'),
:strip_non_ascii => RefinerySetting.find_or_set(:strip_non_ascii, false, :scoping => 'blog')
- attr_accessible :title, :body, :tag_list, :draft, :published_at, :browser_title, :meta_keywords, :meta_description, :user_id, :category_ids, :custom_url
+ attr_accessible :title, :body, :tag_list, :draft, :published_at, :browser_title, :meta_keywords, :meta_description, :user_id, :category_ids, :custom_url, :custom_teaser
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.css.erb b/app/views/admin/blog/posts/_form.css.erb
index 05c18cf..48bbbfa 100644
--- a/app/views/admin/blog/posts/_form.css.erb
+++ b/app/views/admin/blog/posts/_form.css.erb
@@ -4,4 +4,12 @@
margin: 0px;
padding: 0px;
}
+ a#copy_body_link {
+ background: url("/images/refinery/icons/add.png") no-repeat scroll 0 6px transparent;
+ border-bottom: 0 none;
+ display: inline;
+ line-height: 29px;
+ margin-top: 0;
+ padding-left: 20px;
+ }
</style>
diff --git a/app/views/admin/blog/posts/_form.html.erb b/app/views/admin/blog/posts/_form.html.erb
index abff4f2..20a8fe1 100644
--- a/app/views/admin/blog/posts/_form.html.erb
+++ b/app/views/admin/blog/posts/_form.html.erb
@@ -13,9 +13,12 @@
<div class='field'>
<div id='page-tabs' class='clearfix ui-tabs ui-widget ui-widget-content ui-corner-all'>
<ul id='page_parts'>
- <li class='ui-state-default'>
+ <li class='ui-state-default ui-state-active'>
<%= link_to "Body", "#page_part_body" %>
</li>
+ <li class='ui-state-default'>
+ <%= link_to "Teaser", "#page_part_teaser" %>
+ </li>
<% Refinery::Blog.tabs.each_with_index do |tab, tab_index| %>
<li class='ui-state-default' id="custom_<%= tab.name %>_tab">
<%= link_to tab.name.titleize, "#custom_tab_#{tab_index}" %>
@@ -31,6 +34,11 @@
:f => f,
:part_index => (part_index += 1),
} -%>
+ <%= render :partial => 'teaser_part',
+ :locals => {
+ :f => f,
+ :part_index => (part_index += 1),
+ } -%>
<% Refinery::Blog.tabs.each_with_index do |tab, tab_index| %>
<div class='page_part' id='<%= "custom_tab_#{tab_index}" %>'>
<%= render :partial => tab.partial, :locals => {:f => f} %>
diff --git a/app/views/admin/blog/posts/_form.js.erb b/app/views/admin/blog/posts/_form.js.erb
index b829ec2..87ad23f 100644
--- a/app/views/admin/blog/posts/_form.js.erb
+++ b/app/views/admin/blog/posts/_form.js.erb
@@ -1,5 +1,23 @@
<script>
(function($) {
- $('#page-tabs').tabs();
+ $(function() {
+ $('#page-tabs').tabs();
+ $('#copy_body_link').click(function(event) {
+ // Find the WYMEditor that maps to the custom_teaser field
+ var teaserTextArea = $('#blog_post_custom_teaser')[0];
+ var teaserEditor = null;
+ $.each(WYMeditor.INSTANCES, function(index, editor) {
+ if (editor._element[0] == teaserTextArea) {
+ teaserEditor = editor;
+ }
+ });
+
+ if (teaserEditor) {
+ teaserEditor.html($('#blog_post_body').attr('value'));
+ }
+
+ event.preventDefault();
+ });
+ });
})(jQuery);
</script>
diff --git a/app/views/admin/blog/posts/_teaser_part.html.erb b/app/views/admin/blog/posts/_teaser_part.html.erb
new file mode 100644
index 0000000..d615812
--- /dev/null
+++ b/app/views/admin/blog/posts/_teaser_part.html.erb
@@ -0,0 +1,11 @@
+<div class='page_part' id='page_part_teaser'>
+ <%= f.text_area :custom_teaser, :rows => 20, :class => 'wymeditor widest' -%>
+ <p>
+ <span class='clearfix label_inline_with_link'>
+ <%= link_to t('admin.blog.posts.form.copy_body'), "#",
+ :id => 'copy_body_link',
+ :title => t('admin.blog.posts.form.copy_body_help') %>
+ </span>
+ </p>
+</div>
+
diff --git a/app/views/blog/shared/_post.html.erb b/app/views/blog/shared/_post.html.erb
index 00e5d23..4750ef8 100644
--- a/app/views/blog/shared/_post.html.erb
+++ b/app/views/blog/shared/_post.html.erb
@@ -21,9 +21,7 @@
</section>
</header>
<section class='clearfix'>
- <%= truncate(post.body,
- :length => RefinerySetting.find_or_set(:blog_post_teaser_length, 250),
- :preserve_html_tags => true) %>
+ <%= blog_post_teaser(post) %>
</section>
<footer>
<p>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index a4ad0fd..a14f18c 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -40,6 +40,8 @@ en:
published_at: Publish Date
custom_url: Custom Url
custom_url_help: Generate the url for the blog post from this text instead of the title.
+ copy_body: Copy Post Body to Teaser
+ copy_body_help: Copies the post body to the teaser. Leave teaser blank to let Refinery automatically make the teaser.
index:
no_items_yet: 'There are no Blog Posts yet. Click "%{create}" to add your first blog post.'
uncategorized:
diff --git a/db/migrate/7_add_custom_teaser_field_to_blog_posts.rb b/db/migrate/7_add_custom_teaser_field_to_blog_posts.rb
new file mode 100644
index 0000000..daa4d04
--- /dev/null
+++ b/db/migrate/7_add_custom_teaser_field_to_blog_posts.rb
@@ -0,0 +1,10 @@
+class AddCustomTeaserFieldToBlogPosts < ActiveRecord::Migration
+ def self.up
+ add_column :blog_posts, :custom_teaser, :text
+ end
+
+ def self.down
+ remove_column :blog_posts, :custom_teaser
+ end
+end
+