tb_blog 1.3.1 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 250051e40ce087fa0ce2207cfd3f452bb2b6c6dc
4
- data.tar.gz: 8eb90c01fff8917f672846f2e16c1b62f559e842
3
+ metadata.gz: b9170ccda1ef782dbf78a563fa1efc265b2a4f68
4
+ data.tar.gz: 95ca57b1a0bfc7ecba20870a9a78bc168e9e5632
5
5
  SHA512:
6
- metadata.gz: 6290aab7f3741c21640a533c408aaddf096e975a7104e674c7f96906e22482fad28030952bdeb98696df1e7e9dbd876d1d584609e16f1bb08cdec84d3d4ad369
7
- data.tar.gz: a269a9c499629f36a1df5d7a88d1f1c01a52c17cf21e4e0b5f24af6c3473f2b0a044787c60bdd3927a9d2218bd7d82f2c28ba2496c5efd550e999406216f3dc2
6
+ metadata.gz: b11edd82dd1eb74576d3c3278474645fb313d0cdb57f4eb8fc4b265f5fafe15e1666a3aa41626f8b385bc5eacc43c0f9145e3bff7d77bf11d72c02c03b9ce802
7
+ data.tar.gz: ec964ab180f1bbdf53b62fa408ca624c203c79488d64edccd45fe51d59add9b353cf533361d0c3ade859d30c3a475f95d5bb5f83bff94be2dd784b5f4c4098a2
@@ -4,6 +4,8 @@ spud.admin.posts = {
4
4
  edit: function(){
5
5
  $('body').on('click', '.spud-post-add-category', clickedPostAddCategory);
6
6
  $('body').on('submit', '.spud-post-category-form', submittedPostCategoryForm);
7
+ $('body').on('blur', '.spud-post-title', blurredPostTitle);
8
+ $('body').on('click', '.spud-post-url-name-regen', clickedUrlNameRegen);
7
9
  }
8
10
  };
9
11
 
@@ -56,4 +58,37 @@ var savePostCategoryError = function(jqXHR, textStatus, errorThrown){
56
58
  }
57
59
  };
58
60
 
61
+ var blurredPostTitle = function(){
62
+ generateUrlName(false);
63
+ };
64
+
65
+ var clickedUrlNameRegen = function(e){
66
+ e.preventDefault();
67
+ generateUrlName(true);
68
+ };
69
+
70
+ /*
71
+ * Populate the url name field
72
+ *
73
+ * Pass force=true to replace the value currently in the field
74
+ */
75
+ var generateUrlName = function(force){
76
+ var title = $('.spud-post-title').val();
77
+ var $urlNameField = $('.spud-post-url-name');
78
+ if(title !== '' && (force || $urlNameField.val() === '')){
79
+ $urlNameField.val(encodeTitleForUrlName(title));
80
+ }
81
+ };
82
+
83
+ /*
84
+ * Return a url name for a given title
85
+ */
86
+ var encodeTitleForUrlName = function(title){
87
+ var string;
88
+ string = title.toLowerCase();
89
+ string = string.replace(/\s+/g, '-'); // replace spaces with dashes
90
+ string = string.replace(/[^a-z0-9\-]+/g, ''); // remove symbols
91
+ return string;
92
+ };
93
+
59
94
  })();
@@ -10,6 +10,14 @@
10
10
  #spud_post_published_at_1i, #spud_post_published_at_4i{
11
11
  width: 50px;
12
12
  }
13
+ .spud-post-url-name{
14
+ width: calc(100% - 52px);
15
+ float: left;
16
+ }
17
+ .spud-post-url-name-regen{
18
+ width: 50px;
19
+ margin-left: 2px;
20
+ }
13
21
 
14
22
  // Categories
15
23
  //////////////
@@ -1,15 +1,21 @@
1
1
  module BlogHelper
2
2
 
3
+ def options_for_post_category_select
4
+ return options_from_collection_for_select(SpudPostCategory.ordered, :url_name, :name, params[:category_url_name])
5
+ end
6
+
7
+ def options_for_post_archive_select
8
+ return options_for_select(SpudPost.months_with_public_posts.collect{ |d|
9
+ [d.strftime('%B %Y'), d.strftime('%Y-%b').downcase]
10
+ }, params[:archive_date])
11
+ end
12
+
3
13
  def spud_post_category_select
4
- return select_tag('category_url_name',
5
- options_from_collection_for_select(SpudPostCategory.ordered, :url_name, :name, params[:category_url_name]),
6
- {:prompt => 'All Categories'})
14
+ return select_tag('category_url_name', options_for_post_category_select(), {:prompt => 'All Categories', :class => 'form-control'})
7
15
  end
8
16
 
9
17
  def spud_post_archive_select
10
- return select_tag 'archive_date', options_for_select(SpudPost.months_with_public_posts.collect{ |d|
11
- [d.strftime('%B %Y'), d.strftime('%Y-%b').downcase]
12
- }, params[:archive_date]), :prompt => 'All Dates', :rel => 'archive'
18
+ return select_tag 'archive_date', options_for_post_archive_select(), :prompt => 'All Dates', :rel => 'archive', :class => 'form-control'
13
19
  end
14
20
 
15
21
  def spud_blog_rss_link
@@ -31,7 +31,8 @@ class Spud::SpudPostModel < ActiveRecord::Base
31
31
  end
32
32
  }
33
33
 
34
- validates_presence_of :title, :content, :published_at, :spud_user_id, :url_name
34
+ validates_presence_of :title, :content, :published_at, :spud_user_id
35
+ validates :url_name, :presence => true, :uniqueness => true, :format => {:with => /\A[\w\-]+\z/, :message => 'must contain only letters, numbers, and dashes'}
35
36
  validates_uniqueness_of :url_name
36
37
  before_validation :set_url_name
37
38
 
@@ -69,18 +70,7 @@ class Spud::SpudPostModel < ActiveRecord::Base
69
70
  return self.read_attribute(:is_news)
70
71
  end
71
72
 
72
- #def self.posts_for_category_archive(category, )
73
-
74
- # Returns an array of Date objects for months with public posts
75
73
  def self.months_with_public_posts
76
- # Select
77
- # Month(published_at) as published_month,
78
- # Year(published_at) as published_year
79
- # From spud_posts
80
- # Where visible = 1
81
- # And published_at < '2012-01-30'
82
- # Group By published_month, published_year
83
- # Order By published_year desc, published_month desc
84
74
  records = SpudPost.select('Extract(Month from published_at) as published_month, Extract(Year from published_at) as published_year').where('visible = ? AND published_at < ?', true, DateTime.now).group('published_month, published_year').order('published_year desc, published_month desc')
85
75
  begin
86
76
  return records.collect{ |r| Date.new(r[:published_year].to_i, r[:published_month].to_i) }
@@ -91,16 +81,8 @@ class Spud::SpudPostModel < ActiveRecord::Base
91
81
  end
92
82
 
93
83
  def postprocess_content
94
- # if self.content_format == 'Markdown'
95
- # require 'redcarpet'
96
- # renderer = Redcarpet::Render::HTML.new
97
- # extensions = {fenced_code_blocks: true}
98
- # redcarpet = Redcarpet::Markdown.new(renderer, extensions)
99
- # self.content_processed = redcarpet.render self.content
100
- # else
101
- template = Liquid::Template.parse(self.content)
102
- self.content_processed = template.render()
103
- # end
84
+ template = Liquid::Template.parse(self.content)
85
+ self.content_processed = template.render()
104
86
  end
105
87
 
106
88
  def content_processed
@@ -133,6 +115,9 @@ class Spud::SpudPostModel < ActiveRecord::Base
133
115
  private
134
116
 
135
117
  def set_url_name
136
- self.url_name = "#{self.published_at.strftime('%Y-%m-%d')}-#{self.title.parameterize}"
118
+ if url_name.blank?
119
+ self.url_name = title.parameterize
120
+ end
137
121
  end
122
+
138
123
  end
@@ -3,7 +3,7 @@
3
3
  <div class="form-group">
4
4
  <div class="col-sm-12">
5
5
  <%= f.label :title, :required => true,:class=> "control-label" %>
6
- <%= f.text_field :title, :class=>'form-control', :placeholder => "Enter title here" %>
6
+ <%= f.text_field :title, :class=>'form-control spud-post-title', :placeholder => "Enter title here" %>
7
7
  </div>
8
8
  </div>
9
9
 
@@ -73,17 +73,27 @@
73
73
 
74
74
  <h4>Meta Data</h4>
75
75
 
76
+ <div class="form-group">
77
+ <%= f.label :url_name, :required => true, :class=> "col-sm-2 control-label" %>
78
+ <div class="col-sm-10">
79
+ <%= f.text_field :url_name, :class=>'form-control spud-post-url-name', :placeholder => 'Optional' %>
80
+ <a href="#" class="btn btn-default spud-post-url-name-regen" title="Regenerate URL Slug">
81
+ <span class="glyphicon glyphicon-refresh"></span>
82
+ </a>
83
+ </div>
84
+ </div>
85
+
76
86
  <div class="form-group">
77
87
  <%= f.label :meta_keywords, :required => true, :class=> "col-sm-2 control-label" %>
78
88
  <div class="col-sm-10">
79
- <%= f.text_field :meta_keywords, :class=>'form-control' %>
89
+ <%= f.text_field :meta_keywords, :class=>'form-control', :placeholder => 'Optional' %>
80
90
  </div>
81
91
  </div>
82
92
 
83
93
  <div class="form-group">
84
94
  <%= f.label :meta_description, :required => true, :class=> "col-sm-2 control-label" %>
85
95
  <div class="col-sm-10">
86
- <%= f.text_field :meta_description, :class=>'form-control' %>
96
+ <%= f.text_field :meta_description, :class=>'form-control', :placeholder => 'Optional' %>
87
97
  </div>
88
98
  </div>
89
99
 
@@ -1,3 +1,3 @@
1
- <%= form_for @post, :url => admin_post_path(@post), :html => {:class => 'form-horizontal'} do |f| %>
1
+ <%= tb_form_for @post, :url => admin_post_path(@post), :html => {:class => 'form-horizontal'}, :remote => true, :data => {:errors => :inline, :success => admin_posts_path} do |f| %>
2
2
  <%= render :partial => 'form', :locals => {:f => f} %>
3
3
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= form_for @post, :url => admin_posts_path, :html => {:class => 'form-horizontal'} do |f| %>
1
+ <%= tb_form_for @post, :url => admin_posts_path, :html => {:class => 'form-horizontal'}, :remote => true, :data => {:errors => :inline, :success => admin_posts_path} do |f| %>
2
2
  <%= render :partial => 'form', :locals => {:f => f} %>
3
- <% end %>
3
+ <% end %>
@@ -11,20 +11,20 @@
11
11
  </div>
12
12
  <% end %>
13
13
 
14
- <div>
14
+ <div class="form-group">
15
15
  <%= f.label :author %>
16
- <%= f.text_field :author %>
16
+ <%= f.text_field :author, :class => 'form-control' %>
17
17
  </div>
18
- <div>
18
+ <div class="form-group">
19
19
  <%= f.label :content %>
20
- <%= f.text_area :content %>
20
+ <%= f.text_area :content, :class => 'form-control' %>
21
21
  </div>
22
- <div class="comment_validity">
22
+ <div class="comment_validity hidden">
23
23
  <%= label_tag 'Comment Validation' %>
24
24
  <%= text_field_tag 'comment_validation' %>
25
25
  </div>
26
- <div>
27
- <%= f.submit 'Post Comment' %>
26
+ <div class="form-group">
27
+ <%= f.submit 'Post Comment', :class => 'btn btn-primary' %>
28
28
  </div>
29
29
 
30
30
  <% end %>
@@ -5,33 +5,53 @@
5
5
  <% end %>
6
6
 
7
7
  <% cache(cache_key_for_spud_collection(@posts, :cache_params => [:category_url_name, :archive_date, :page], :for_user => true)) do %>
8
- <div id="spud_blog_filters">
9
- <%= form_tag posts_path, :class => 'spud_blog_filter_form' do %>
10
- <label>Category:</label>
11
- <%= spud_post_category_select %>
12
- <label>Month:</label>
13
- <%= spud_post_archive_select %>
14
- <input type="submit" value="Submit" />
15
- <% end %>
8
+
9
+ <div class="row">
10
+ <div class="col-sm-12">
11
+ <%= form_tag posts_path, :class => 'form-inline blog-filters' do %>
12
+ <div class="form-group">
13
+ <label>Category:</label>
14
+ <%= spud_post_category_select %>
15
+ </div>
16
+ <div class="form-group">
17
+ <label>Month:</label>
18
+ <%= spud_post_archive_select %>
19
+ </div>
20
+ <input type="submit" value="Submit" class="btn btn-default" />
21
+ <% end %>
22
+ </div>
16
23
  </div>
17
24
 
18
- <div id="spud_blog_posts">
19
- <% if @posts.length > 0 %>
20
- <% @posts.includes(:categories, :author).each do |post| %>
21
- <% cache(post) do %>
22
- <div class="spud_blog_post">
23
- <h3><%= link_to post.title, post_path(post.url_name) %></h3>
24
- <h4>Posted by <%= post.author.full_name %> on <%= post.display_date %></h4>
25
- <div class="spud_blog_post_content">
26
- <%= truncate_html post.content_processed.html_safe, :length => 250 %>
25
+ <div class="row">
26
+
27
+ <div class="col-sm-8 blog-posts">
28
+ <% if @posts.length > 0 %>
29
+ <% @posts.includes(:categories, :author).each do |post| %>
30
+ <% cache(post) do %>
31
+ <div class="blog-post blog-post-partial">
32
+ <h3 class="blog-post-title"><%= link_to post.title, post_path(post.url_name) %></h3>
33
+ <h4 class="blog-post-author">Posted by <%= post.author.full_name %> on <%= post.display_date %></h4>
34
+ <div class="blog-post-content">
35
+ <%= truncate_html post.content_processed.html_safe, :length => 250 %>
36
+ </div>
27
37
  </div>
28
- </div>
38
+ <% end %>
29
39
  <% end %>
40
+ <% else %>
41
+ <p>No posts were found in this category</p>
30
42
  <% end %>
31
- <% else %>
32
- <p>No posts were found in this category</p>
33
- <% end %>
43
+ <%= will_paginate @posts %>
44
+ </div>
45
+
46
+ <div class="col-sm-4 blog-recent-posts">
47
+ <h3>Recent Posts</h3>
48
+ <ul class="blog-recent-posts-list">
49
+ <% SpudPost.for_blog(params[:blog_key]).recent_posts.each do |post| %>
50
+ <li><%= link_to post.title, post_path(post.url_name) %></li>
51
+ <% end %>
52
+ </ul>
53
+ </div>
54
+
34
55
  </div>
35
56
 
36
- <%= will_paginate @posts %>
37
57
  <% end %>
@@ -13,36 +13,45 @@
13
13
  <% end %>
14
14
 
15
15
  <% cache(@post) do %>
16
- <div class="spud_blog_post">
17
- <h3><%= @post.title %></h3>
18
- <h4>Posted by <%= @post.author.full_name %> on <%= @post.display_date %></h4>
19
- <% if @post.categories.any? %>
20
- <p id="spud_blog_post_categories">
21
- Filed under
22
- <%= raw(@post.categories.collect{ |c| link_to c.name, post_category_path(c.url_name) }.join(', ')) %>
23
- </p>
24
- <% end %>
25
- <div id="spud_blog_post_content">
26
- <%= raw @post.content_processed %>
16
+ <div class="row">
17
+ <div class="col-sm-12">
18
+ <div class="blog-post blog-post-partial">
19
+ <h1 class="blog-post-title"><%= @post.title %></h1>
20
+ <h4 class="blog-post-author">Posted by <%= @post.author.full_name %> on <%= @post.display_date %></h4>
21
+ <% if @post.categories.any? %>
22
+ <p class="blog-post-categories">
23
+ <span>Filed under</span>
24
+ <%= raw(@post.categories.collect{ |c| link_to c.name, post_category_path(c.url_name) }.join(', ')) %>
25
+ </p>
26
+ <% end %>
27
+ <div class="blog-post-content">
28
+ <%= raw @post.content_processed %>
29
+ </div>
30
+ <p><%= link_to 'Back to all posts', posts_path %></p>
31
+ </div>
27
32
  </div>
28
33
  </div>
29
34
 
30
35
  <% if @post.comments_enabled %>
31
- <div class="spud_blog_post_comment">
32
- <h5>Post a Comment:</h5>
33
- <%= render 'comment_form' %>
34
- </div>
35
- <% cache(cache_key_for_spud_collection(@post.visible_comments, key:'comments')) do %>
36
- <ul id="spud_blog_post_comments">
37
- <% @post.visible_comments.each do |comment| %>
38
- <% cache(comment) do %>
39
- <li>
40
- <h6>Posted by: <%= comment.author %></h6>
41
- <p><%= comment.content %></p>
42
- </li>
43
- <% end %>
36
+ <div class="row">
37
+ <div class="col-sm-12">
38
+ <div class="blog-post-comment">
39
+ <h5>Post a Comment:</h5>
40
+ <%= render 'comment_form' %>
41
+ </div>
42
+ <% cache(cache_key_for_spud_collection(@post.visible_comments, key:'comments')) do %>
43
+ <ul id="blog-post-comments">
44
+ <% @post.visible_comments.each do |comment| %>
45
+ <% cache(comment) do %>
46
+ <li>
47
+ <h6>Posted by: <%= comment.author %></h6>
48
+ <p><%= comment.content %></p>
49
+ </li>
50
+ <% end %>
51
+ <% end %>
52
+ </ul>
44
53
  <% end %>
45
- </ul>
46
- <% end %>
54
+ </div>
55
+ </div>
47
56
  <% end %>
48
57
  <% end %>
@@ -0,0 +1,5 @@
1
+ en:
2
+ activerecord:
3
+ attributes:
4
+ spud_post:
5
+ url_name: 'URL Slug'
@@ -1,5 +1,5 @@
1
1
  module Spud
2
2
  module Blog
3
- VERSION = "1.3.1"
3
+ VERSION = "1.3.2"
4
4
  end
5
5
  end
@@ -8,8 +8,8 @@ class AddNestedSetToPostCategories < ActiveRecord::Migration
8
8
  end
9
9
 
10
10
  # Populates lft, rgt, and depth values for nested set
11
- SpudPostCategory.where(:parent_id => 0).update_all({:parent_id => nil})
12
- SpudPostCategory.rebuild!
11
+ #SpudPostCategory.where(:parent_id => 0).update_all({:parent_id => nil})
12
+ #SpudPostCategory.rebuild!
13
13
  end
14
14
 
15
15
  def down
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tb_blog
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Westlake Design
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-29 00:00:00.000000000 Z
11
+ date: 2015-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -202,6 +202,7 @@ files:
202
202
  - app/views/posts/index.html.erb
203
203
  - app/views/posts/index.rss.builder
204
204
  - app/views/posts/show.html.erb
205
+ - config/locales/en.yml
205
206
  - config/routes.rb
206
207
  - db/migrate/20120125180945_create_spud_posts.rb
207
208
  - db/migrate/20120125181022_create_spud_post_categories.rb