From e274bb1757aa3c27645c181bae6164131a7a35dd Mon Sep 17 00:00:00 2001 From: Jeff Shumate Date: Wed, 25 Jan 2012 22:27:46 -0700 Subject: add source url for post --- app/models/refinery/blog/post.rb | 7 ++ app/views/refinery/blog/admin/posts/_form.html.erb | 16 ++++ app/views/refinery/blog/posts/_post.html.erb | 8 +- config/initializers/url_validator.rb | 85 ++++++++++++++++++++++ config/locales/en.yml | 7 +- .../20120103055909_add_source_url_to_blog_posts.rb | 7 ++ lib/refinery/blog.rb | 1 + lib/refinery/blog/configuration.rb | 9 +++ spec/models/refinery/blog/post_spec.rb | 35 ++++++++- 9 files changed, 171 insertions(+), 4 deletions(-) create mode 100644 config/initializers/url_validator.rb create mode 100644 db/migrate/20120103055909_add_source_url_to_blog_posts.rb create mode 100644 lib/refinery/blog/configuration.rb diff --git a/app/models/refinery/blog/post.rb b/app/models/refinery/blog/post.rb index 883f4fc..1eae99a 100644 --- a/app/models/refinery/blog/post.rb +++ b/app/models/refinery/blog/post.rb @@ -22,6 +22,12 @@ module Refinery validates :title, :presence => true, :uniqueness => true validates :body, :presence => true + + validates :source_url, :url => { :if => 'Refinery::Blog.config.validate_source_url', + :update => true, + :allow_nil => true, + :allow_blank => true, + :verify => [:resolve_redirects]} has_friendly_id :friendly_id_source, :use_slug => true, :default_locale => (::Refinery::I18n.default_frontend_locale rescue :en), @@ -48,6 +54,7 @@ module Refinery attr_accessible :title, :body, :custom_teaser, :tag_list, :draft, :published_at, :custom_url attr_accessible :browser_title, :meta_keywords, :meta_description, :user_id, :category_ids + attr_accessible :source_url, :source_url_title self.per_page = Refinery::Setting.find_or_set(:blog_posts_per_page, 10) diff --git a/app/views/refinery/blog/admin/posts/_form.html.erb b/app/views/refinery/blog/admin/posts/_form.html.erb index a33baeb..68b1d31 100644 --- a/app/views/refinery/blog/admin/posts/_form.html.erb +++ b/app/views/refinery/blog/admin/posts/_form.html.erb @@ -81,6 +81,22 @@ <%= f.text_field :custom_url, :class => "widest" %> +
+ + <%= f.label :source_url_title, t('.source_url_title') %> + <%= refinery_help_tag t('.source_url_title_help') %> + + <%= f.text_field :source_url_title, :class => "widest" %> +
+ +
+ + <%= f.label :source_url, t('.source_url') %> + <%= refinery_help_tag t('.source_url_help') %> + + <%= f.text_field :source_url, :class => "widest" %> +
+
<%= f.label :user_id, t('.author') %> diff --git a/app/views/refinery/blog/posts/_post.html.erb b/app/views/refinery/blog/posts/_post.html.erb index 020ba41..77e43ff 100644 --- a/app/views/refinery/blog/posts/_post.html.erb +++ b/app/views/refinery/blog/posts/_post.html.erb @@ -10,7 +10,13 @@ - <%= "#{t('by', :scope => 'refinery.blog.posts.show')} #{@post.author.username}" if @post.author.present? %>. + <%= content_tag(:div, "#{t('by', :scope => 'refinery.blog.posts.show')} #{@post.author.username}", :class => "blog_author") if @post.author.present? %> + <% if @post.source_url.present? %> +
+ <%= "#{t('source', :scope => 'refinery.blog.posts.show')}: " %> + <%= link_to (@post.source_url_title.blank? ? @post.source_url : @post.source_url_title), @post.source_url %> +
+ <% end %> <% if (categories = @post.categories).any? %>