active_blog 0.9.0 → 1.0.0.pre1

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: a132034523aa9b46cb6600df99b8c728ca180a2d
4
- data.tar.gz: 239db73d0d581133b932359e047bdeaf62546162
3
+ metadata.gz: 9540117a71563fb2de175948f8464c193fa876e5
4
+ data.tar.gz: 706360981815fa312ec3ffa09f902ede3a36bc62
5
5
  SHA512:
6
- metadata.gz: 04a980d9ceafb8ff0d6acecab25f2fe73dd0e9c3f3a4866664a8fca241a7324b59fe947fcebf853ea78d566299d85332ee315d9b4b58475c5735f71ca52ce460
7
- data.tar.gz: 96c5cbfedd524097c2caeacbc75e1ff3f69456f7f725485c7a80d83cc100665975b59fecd75dc09ae5887ffd6de345e01200376f5ce7d015c8c828812541668c
6
+ metadata.gz: 064324faa28367f2957d560b5cbe31d9fb9be030155831cd2c7b96cf137d89867eee10700a176080bc12ff2040dac42f9c9bb02ad1c78f60b37265545e360d5e
7
+ data.tar.gz: 54376d3bc24e3cec8afddde49781d7d2c471ca1e28f60c168e7a008bc3440c5edc7a4b0acb61e51e5faac8d7b2b9eee230412a17a34f910b8ce2de1ba58b9e7e
@@ -1,5 +1,6 @@
1
1
  module ActiveBlog
2
2
  class BlogPostsController < ApplicationController
3
+ layout ActiveBlog.template_layout
3
4
 
4
5
  before_filter :only => [:index, :show, :archives] do
5
6
  @recent_blog_posts = BlogPost.live.recent
@@ -14,17 +15,12 @@ module ActiveBlog
14
15
  end
15
16
 
16
17
  def show
17
- @blog_post = BlogPost.live.where(:cached_slug => params[:cached_slug]).first
18
- if @blog_post
19
- render
20
- else
21
- # TODO(mc): Should 404
22
- redirect_to active_blog_path, :notice => "No blog post with that URL"
23
- end
18
+ @blog_post = BlogPost.blog_post(params[:cached_slug])
24
19
  end
25
20
 
21
+ # Move into ActiveAdmin responsibility
26
22
  def preview
27
- @blog_post = BlogPost.new(params[:active_blog_blog_post])
23
+ @active_blog_blog_post = BlogPost.new(post_params)
28
24
  @blog_post_partial = render_to_string(:partial => 'active_blog/active_admin/blog_post_show')
29
25
 
30
26
  respond_to do |format|
@@ -33,10 +29,16 @@ module ActiveBlog
33
29
  end
34
30
 
35
31
  def atom
36
- @blog_posts = BlogPost.live.order('published_at DESC').limit(10)
32
+ @blog_posts = BlogPost.live.limit(10)
37
33
  respond_to do |format|
38
34
  format.xml
39
35
  end
40
36
  end
37
+
38
+ private
39
+
40
+ def post_params
41
+ params.require(:active_blog_blog_post).permit(:title, :body, :draft, :published_at)
42
+ end
41
43
  end
42
44
  end
@@ -1,17 +1,12 @@
1
1
  module ActiveBlog
2
2
  module BlogPostsHelper
3
- def markdown(text)
4
- regular = { :hard_wrap => true, :autolink => true, :space_after_headers => true }
5
- make_markdown(regular).render(text).html_safe
6
- end
7
3
 
8
- def markdown_for_schema(text)
9
- truncate(strip_tags(markdown(text)).strip.gsub(/\n/, ' '), :length => 250)
4
+ def markdown
5
+ @markdown ||= ActiveBlog::Markdown.renderer
10
6
  end
11
7
 
12
- def make_markdown(opts)
13
- markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, opts)
14
- markdown
8
+ def schema_blog_post(text, length = 250)
9
+ truncate(strip_tags(markdown.render(text)).strip.gsub(/\n/, ' '), :length => length)
15
10
  end
16
11
 
17
12
  def schema_date(date)
@@ -2,10 +2,11 @@ module ActiveBlog
2
2
  class BlogPost < ActiveRecord::Base
3
3
  self.table_name = 'active_blog_blog_posts'
4
4
  paginates_per ActiveBlog.paginates_per
5
- default_scope :order => 'published_at DESC'
5
+ default_scope { order(:published_at).reverse_order }
6
6
 
7
- scope :live, where('published_at < ? AND draft = ?', Time.zone.now, false)
8
- scope :recent, limit(5)
7
+ scope :live, -> { where('published_at < ? AND draft = ?', Time.zone.now, false) }
8
+ scope :recent, -> { limit(5) }
9
+ scope :blog_post, ->(slug) { live.where(:cached_slug => slug).first! }
9
10
 
10
11
  validates_presence_of :title, :allow_blank => false, :allow_nil => false, :message => "can't be blank"
11
12
  validates_presence_of :body, :allow_blank => false, :allow_nil => false, :message => "can't be blank"
@@ -13,6 +13,6 @@
13
13
 
14
14
  </div>
15
15
  <div>
16
- <%= markdown(@active_blog_blog_post.body || "Body") %>
16
+ <%= markdown.render(@active_blog_blog_post.body || "Body") %>
17
17
  </div>
18
18
  </div>
@@ -4,7 +4,7 @@
4
4
 
5
5
  Google Rich Snippets doesn't like nested schemas in certain cases.
6
6
  %>
7
- <div class="active_blog entry" <%= show ? '' : "itemscope itemtype='http://schema.org/BlogPosting'" %>>
7
+ <div class="active_blog entry" <%= show ? '' : 'itemscope itemtype="http://schema.org/BlogPosting"'.html_safe %>>
8
8
  <%- if show %>
9
9
  <%= content_for :schema do %>
10
10
  <%= render :partial => 'blog_post_schema', :locals => {:blog_post => blog_post} %>
@@ -13,20 +13,15 @@
13
13
  <%= render :partial => 'blog_post_schema', :locals => {:blog_post => blog_post} %>
14
14
  <% end %>
15
15
 
16
- <h6>
17
- <%= blog_post.published_at.strftime("%B %e %G") %>
18
- <% if blog_post.new_record? %>
19
- <a href="" itemscope itemprop="url">∞</a>
20
- <% else %>
21
- <a href="<%= active_blog_post_path(blog_post.cached_slug) %>">∞</a>
22
- <% end %>
23
- </h6>
16
+ <h4>
17
+ <%= blog_post.published_at.strftime("%B %-e, %G") %>
18
+ </h4>
19
+
24
20
  <h2>
25
- <%= blog_post.title %>
21
+ <%= link_to(blog_post.title, active_blog_post_path(blog_post.cached_slug)) %>
26
22
  </h2>
27
23
 
28
24
  <div class="active_blog body">
29
- <%= markdown(blog_post.body || "") %>
25
+ <%= markdown.render(blog_post.body || "") %>
30
26
  </div>
31
27
  </div>
32
- <hr/>
@@ -1,5 +1,5 @@
1
1
  <%= schema_span_for 'name', "#{blog_post.title} | #{active_blog_title}" %>
2
- <%= schema_span_for 'description', markdown_for_schema(blog_post.body) %>
2
+ <%= schema_span_for 'description', schema_blog_post(blog_post.body) %>
3
3
  <%= schema_span_for 'datePublished', schema_date(blog_post.published_at) %>
4
4
  <%= schema_span_for 'headline', blog_post.title %>
5
5
  <%= schema_span_for 'url', active_blog_post_url(blog_post.cached_slug) %>
@@ -1,11 +1,13 @@
1
1
  <%= active_blog_sidebar do %>
2
- <div class='section active_blog sidebar'>
3
- <h6>Recent posts</h6>
4
- </div>
5
- <ul class='unstyled recent'>
2
+ <div class="panel panel-default panel-recent-posts section active_blog sidebar">
3
+ <div class="panel-heading">Recent posts</div>
4
+ <ul class="list-group list-recent-posts">
6
5
  <% @recent_blog_posts.each do |recent_blog_post| %>
7
- <li><a href='<%= active_blog_post_path(recent_blog_post.cached_slug) %>' title='<%= recent_blog_post.title %>'><%= recent_blog_post.title %></a></li>
6
+ <li class="list-group-item recent-post"><a href='<%= active_blog_post_path(recent_blog_post.cached_slug) %>' title='<%= recent_blog_post.title %>'><%= recent_blog_post.title %></a></li>
8
7
  <% end %>
9
8
  </ul>
10
- <%= link_to 'Archives', active_blog_archives_path %>
9
+ <div class="panel-footer">
10
+ <%= link_to 'Archives', active_blog_archives_path %>
11
+ </div>
12
+ </div>
11
13
  <% end %>
@@ -9,7 +9,7 @@ atom_feed({}) do |feed|
9
9
  :url => active_blog_post_url(post.cached_slug)
10
10
  }) do |entry|
11
11
  entry.title(post.title)
12
- entry.content(markdown(post.body), :type => 'html')
12
+ entry.content(markdown.render(post.body), :type => 'html')
13
13
 
14
14
  entry.author do |author|
15
15
  author.name(active_blog_author_name) if active_blog_author_name
@@ -5,6 +5,7 @@
5
5
  <%= schema_span_for 'description', active_blog_description %>
6
6
  <%= schema_span_for 'url', active_blog_url %>
7
7
  <% end %>
8
+
8
9
  <div class="section active_blog index">
9
10
  <h1><%= active_blog_title %></h1>
10
11
 
@@ -1,6 +1,6 @@
1
1
  require 'active_blog/engine'
2
2
  require 'active_blog/mapper'
3
- require 'redcarpet'
3
+ require 'active_blog/markdown'
4
4
  require 'active_blog/ext/string'
5
5
 
6
6
  module ActiveBlog
@@ -33,6 +33,10 @@ module ActiveBlog
33
33
  mattr_accessor :paginates_per
34
34
  @@paginates_per = 10
35
35
 
36
+ # Blog Rails template
37
+ mattr_accessor :template_layout
38
+ @@template_layout = "layouts/application"
39
+
36
40
  def self.setup
37
41
  yield self
38
42
  end
@@ -13,8 +13,8 @@ module ActionDispatch::Routing
13
13
  # match '/:cached_slug', :action => :show, :on => :collection, :as => :post, :via => [:get]
14
14
  end
15
15
  match '/' => 'active_blog/blog_posts#index', :as => :active_blog, :via => [:get]
16
- match '/-/preview' => 'active_blog/blog_posts#preview', :as => :active_blog_preview, :via => [:post, :put]
17
- match '/atom.xml' => 'active_blog/blog_posts#atom', :as => :active_blog_feed, :via => [:get], :format => :xml
16
+ match '/-/preview' => 'active_blog/blog_posts#preview', :as => :active_blog_preview, :via => [:post, :put, :patch]
17
+ get '/atom', :to => 'active_blog/blog_posts#atom', :as => :active_blog_feed, :constraints => { :format => 'xml' }
18
18
  match '/archives' => 'active_blog/blog_posts#archives', :as => :active_blog_archives, :via => [:get]
19
19
  # Always last.
20
20
  match '/:cached_slug' => 'active_blog/blog_posts#show', :as => :active_blog_post, :via => [:get]
@@ -0,0 +1,29 @@
1
+ require 'redcarpet'
2
+
3
+ module ActiveBlog
4
+ class Markdown
5
+ attr_reader :markdown
6
+
7
+ def initialize
8
+ options = {
9
+ hard_wrap: true,
10
+ space_after_headers: true
11
+ }
12
+
13
+ extensions = {
14
+ autolink: true,
15
+ }
16
+
17
+ renderer = Redcarpet::Render::HTML.new(options)
18
+ @markdown = Redcarpet::Markdown.new(renderer, extensions)
19
+ end
20
+
21
+ def render(markdown_syntax)
22
+ markdown.render(markdown_syntax).html_safe
23
+ end
24
+
25
+ def self.renderer
26
+ ActiveBlog::Markdown.new
27
+ end
28
+ end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module ActiveBlog
2
- VERSION = "0.9.0"
2
+ VERSION = '1.0.0.pre1'
3
3
  end
@@ -9,7 +9,7 @@ ActiveBlog.setup do |config|
9
9
  # config.author_name = "John Doe"
10
10
 
11
11
  # Blog author's URI
12
- # config.author_name = "http://example.com"
12
+ # config.author_uri = "http://example.com"
13
13
 
14
14
  # Blog author's email
15
15
  # config.author_email = "mchung@example.com"
@@ -19,4 +19,7 @@ ActiveBlog.setup do |config|
19
19
 
20
20
  # Blog posts per page
21
21
  # config.paginates_per = 10
22
+
23
+ # Blog Rails template
24
+ # config.template_layout = "layouts/application"
22
25
  end
@@ -3,4 +3,5 @@ ActiveAdmin.register ActiveBlog::BlogPost do
3
3
  show :title => :title do
4
4
  render 'active_blog/active_admin/show'
5
5
  end
6
+ permit_params :title, :body, :draft, :published_at
6
7
  end
metadata CHANGED
@@ -1,71 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_blog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 1.0.0.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc Chung
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-13 00:00:00.000000000 Z
11
+ date: 2015-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 3.2.1
19
+ version: 4.2.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 3.2.1
26
+ version: 4.2.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activeadmin
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.5.1
33
+ version: 1.0.0.pre1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.5.1
40
+ version: 1.0.0.pre1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: redcarpet
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 2.0.0b5
47
+ version: 3.2.3
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 2.0.0b5
54
+ version: 3.2.3
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: kaminari
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 0.16.3
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 0.16.3
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: pg
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -118,6 +118,7 @@ files:
118
118
  - lib/active_blog/engine.rb
119
119
  - lib/active_blog/ext/string.rb
120
120
  - lib/active_blog/mapper.rb
121
+ - lib/active_blog/markdown.rb
121
122
  - lib/active_blog/version.rb
122
123
  - lib/generators/active_blog/install/USAGE
123
124
  - lib/generators/active_blog/install/install_generator.rb
@@ -149,7 +150,7 @@ files:
149
150
  - test/dummy/config/locales/en.yml
150
151
  - test/dummy/config/routes.rb
151
152
  - test/dummy/db/schema.rb
152
- - test/dummy/log/development.log
153
+ - test/dummy/log/test.log
153
154
  - test/dummy/public/404.html
154
155
  - test/dummy/public/422.html
155
156
  - test/dummy/public/500.html
@@ -177,12 +178,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
177
178
  version: '0'
178
179
  required_rubygems_version: !ruby/object:Gem::Requirement
179
180
  requirements:
180
- - - ">="
181
+ - - ">"
181
182
  - !ruby/object:Gem::Version
182
- version: '0'
183
+ version: 1.3.1
183
184
  requirements: []
184
185
  rubyforge_project:
185
- rubygems_version: 2.2.2
186
+ rubygems_version: 2.4.6
186
187
  signing_key:
187
188
  specification_version: 4
188
189
  summary: A barebones, markdown, blogging Rails Engine.
@@ -210,7 +211,7 @@ test_files:
210
211
  - test/dummy/config/routes.rb
211
212
  - test/dummy/config.ru
212
213
  - test/dummy/db/schema.rb
213
- - test/dummy/log/development.log
214
+ - test/dummy/log/test.log
214
215
  - test/dummy/public/404.html
215
216
  - test/dummy/public/422.html
216
217
  - test/dummy/public/500.html