blogo 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4fa8f05b64cf6073de50276463fd756e4ae1ea6c
4
- data.tar.gz: e849c0b55e525c40fd2425ca6fc043e3ad7b0d0e
3
+ metadata.gz: 267c58dc478854e27327ad35435293f38555184e
4
+ data.tar.gz: 676ee2ecc4e6f947e929f60ff3d65d3e05632621
5
5
  SHA512:
6
- metadata.gz: caa17c96c373209c272f0a806959ce2c5078dd4e96607c57c1c120625fd988f2b7bbe01f84b349f2bc87cb04e9b7978c96832943dc87baf7b50e5758e01e1ced
7
- data.tar.gz: 43a1e53c9af3c9190403e8a55673f9ff982ab8bcb676791f53ae3f23af86c291ec69b9d32278e862a5341ffae066eb48fabdc482f8b9da80aa51e37514438327
6
+ metadata.gz: 35308726152df9737d2bb597bc58a9bed9e69cbacddf7f058564a669018fe8e6d1df3152584470dbd4f081797c1f4560705521ea0f176dc7cb7bad9053e32cbd
7
+ data.tar.gz: 399072ad5edc5019b984c0f0921d293d79139c523852ea31565ee8164d9c85461e943c22915f0902681c89606d0ab8b8a4acf5bde1eceda6405e1a971edd5ee2
@@ -1,7 +1,11 @@
1
1
  module Blogo::Admin
2
+ # Does nothing, simply displays Disqus comments, that loaded with JS.
2
3
  class CommentsController < BaseController
3
- def index
4
4
 
5
+ # GET /admin/comments
6
+ #
7
+ def index
5
8
  end
9
+
6
10
  end
7
11
  end
@@ -1,14 +1,21 @@
1
1
  module Blogo::Admin
2
+ # Responsible for posts management: creation, editing, deletion, preview.
2
3
  class PostsController < BaseController
3
4
 
5
+ # GET /admin/posts
6
+ #
4
7
  def index
5
8
  @posts = Blogo::Post.all
6
9
  end
7
10
 
11
+ # GET /admin/posts/new
12
+ #
8
13
  def new
9
14
  @post = Blogo::Post.new(published: true)
10
15
  end
11
16
 
17
+ # POST /admin/posts
18
+ #
12
19
  def create
13
20
  service = Blogo::CreatePostService.new(blogo_current_user, post_params)
14
21
 
@@ -22,12 +29,16 @@ module Blogo::Admin
22
29
  end
23
30
  end
24
31
 
32
+ # GET /admin/posts/:id/edit
33
+ #
25
34
  def edit
26
- @post = Blogo::Post.find(params[:id])
35
+ @post = Blogo::Post.where(permalink: params[:id]).first!
27
36
  end
28
37
 
38
+ # PATCH /admin/posts/:id
39
+ #
29
40
  def update
30
- @post = Blogo::Post.find(params[:id])
41
+ @post = Blogo::Post.where(permalink: params[:id]).first!
31
42
  service = Blogo::UpdatePostService.new(@post, post_params)
32
43
 
33
44
  if service.update!
@@ -38,6 +49,8 @@ module Blogo::Admin
38
49
  end
39
50
  end
40
51
 
52
+ # DELETE /admin/posts/:id
53
+ #
41
54
  def destroy
42
55
  post = Blogo::Post.find(params[:id])
43
56
  Blogo::DestroyPostService.new(post).destroy!
@@ -46,6 +59,8 @@ module Blogo::Admin
46
59
  redirect_to blogo_admin_posts_path
47
60
  end
48
61
 
62
+ # POST /admin/posts/preview
63
+ #
49
64
  def preview
50
65
  @post = Blogo::PreviewPostService.new(blogo_current_user, post_params).preview
51
66
 
@@ -57,6 +72,9 @@ module Blogo::Admin
57
72
 
58
73
  private
59
74
 
75
+ # Get post parameters from params.
76
+ #
77
+ # @return [Hash]
60
78
  def post_params
61
79
  params.require(:post).permit(:title, :permalink, :published_at, :raw_content, :published, :tags_string)
62
80
  end
@@ -1,10 +1,18 @@
1
1
  module Blogo::Admin
2
+ # Responsible for authentication of blog users.
3
+ # Simply performs 2 operation: login and logout.
4
+ # User is logged in if it has set sessions[:blogo_user_id].
5
+ #
2
6
  class SessionsController < BaseController
3
7
  skip_before_filter :ensure_authenticated!
4
8
 
9
+ # GET /admin/login
10
+ #
5
11
  def new
6
12
  end
7
13
 
14
+ # POST /admin/sessions
15
+ #
8
16
  def create
9
17
  user = Blogo::User.find_by_email(params[:email])
10
18
  if user && user.authenticate(params[:password])
@@ -16,6 +24,9 @@ module Blogo::Admin
16
24
  end
17
25
  end
18
26
 
27
+
28
+ # GET /admin/logout
29
+ #
19
30
  def destroy
20
31
  session[:blogo_user_id] = nil
21
32
  redirect_to blogo_admin_url, notice: "You have logged out"
@@ -1,38 +1,45 @@
1
1
  module Blogo
2
+ # Responsible for showing posts and atom feeds to visitors.
2
3
  class PostsController < ApplicationController
3
4
  layout 'blogo/blog'
4
5
 
5
6
  # Number of posts shown in feed.
6
7
  FEED_POSTS_LIMIT = 20
7
8
 
9
+ # GET /posts
10
+ #
8
11
  def index
9
12
  @tag = params[:tag]
10
13
  set_vars
11
14
  set_paginator
12
15
 
13
16
  @meta = {}
14
- @meta[:title] = "#{Blogo.config.site_title} - #{Blogo.config.site_subtitle}"
15
- @meta[:site_name] = Blogo.config.site_title
16
- @meta[:keywords] = Blogo.config.keywords
17
- @meta[:type] = 'website'
17
+ @meta[:title] = "#{Blogo.config.site_title} - #{Blogo.config.site_subtitle}"
18
+ @meta[:site_name] = Blogo.config.site_title
19
+ @meta[:keywords] = Blogo.config.keywords
20
+ @meta[:type] = 'website'
18
21
  end
19
22
 
23
+ # GET /posts/:permalink
24
+ #
20
25
  def show
21
26
  @post = Post.published.where(:permalink => params[:permalink]).first!
22
27
  set_vars
23
28
 
24
29
  @meta = {}
25
- @meta[:title] = "#{@post.title} - #{Blogo.config.site_title}"
26
- @meta[:description] = @post.meta_description
27
- @meta[:keywords] = [@post.tags_string, Blogo.config.keywords].flatten.join(", ")
28
- @meta[:url] = request.url
29
- @meta[:image] = meta_image
30
- @meta[:type] = 'article'
31
- @meta[:site_name] = Blogo.config.site_title
30
+ @meta[:title] = "#{@post.title} - #{Blogo.config.site_title}"
31
+ @meta[:description] = @post.meta_description
32
+ @meta[:keywords] = [@post.tags_string, Blogo.config.keywords].flatten.join(", ")
33
+ @meta[:url] = request.url
34
+ @meta[:image] = meta_image
35
+ @meta[:type] = 'article'
36
+ @meta[:site_name] = Blogo.config.site_title
32
37
  end
33
38
 
39
+ # GET /posts/feed
40
+ #
34
41
  def feed
35
- @posts = published_posts.limit(FEED_POSTS_LIMIT)
42
+ @posts = Post.published.limit(FEED_POSTS_LIMIT)
36
43
  @updated = @posts.first.try(:updated_at)
37
44
 
38
45
  render 'feed', layout: false
@@ -41,25 +48,28 @@ module Blogo
41
48
 
42
49
  private
43
50
 
51
+ # Build a paginator object and set to @paginator.
52
+ #
53
+ # @return [Blogo::Paginator]
44
54
  def set_paginator
45
- posts = published_posts
46
- posts = posts.joins(:tags).where("#{Tag.table_name}.name = ?", @tag) if @tag
55
+ posts_scope = Post.published
56
+
57
+ if @tag
58
+ posts_scope = posts_scope.joins(:tags).where("#{Tag.table_name}.name = ?", @tag)
59
+ end
47
60
 
48
61
  @paginator = Paginator.new(
49
- posts,
62
+ posts_scope,
50
63
  :page => (params[:page] || 1),
51
64
  :per_page => conf.posts_per_page,
52
65
  :size => conf.paginator_size)
53
66
  end
54
67
 
68
+ # Sets @recent_posts and @tags.
69
+ #
55
70
  def set_vars
56
- @recent_posts = published_posts.limit(conf.recent_posts) if conf.recent_posts
57
- @tags = Tag.all
58
- end
59
-
60
-
61
- def published_posts
62
- Post.published
71
+ @recent_posts = Post.published.limit(conf.recent_posts) if conf.recent_posts
72
+ @tags = Tag.all
63
73
  end
64
74
 
65
75
  # Engine configuration. Method +config+ is already used by Rails.
@@ -69,9 +79,10 @@ module Blogo
69
79
  Blogo.config
70
80
  end
71
81
 
72
-
82
+ # @return [String, nil] full URL to image or nil
73
83
  def meta_image
74
84
  return nil unless @post.meta_image.present?
85
+
75
86
  if @post.meta_image =~ /\Ahttp/
76
87
  @post.meta_image
77
88
  else
@@ -3,19 +3,6 @@ module Blogo
3
3
  module ApplicationHelper
4
4
  include Rails.application.routes.url_helpers
5
5
 
6
- # Path to a post with year prefix.
7
- #
8
- # @param post [Blogo::Post]
9
- #
10
- # @return [String]
11
- def path_to_post(post)
12
- blogo_post_path(:permalink => post.permalink)
13
- end
14
-
15
- def url_to_post(post)
16
- blogo_post_url(:permalink => post.permalink)
17
- end
18
-
19
6
  # Path to a page or a page in scope of a particular tag.
20
7
  #
21
8
  # @param page [Integer]
@@ -36,7 +23,7 @@ module Blogo
36
23
  #
37
24
  # @return [String]
38
25
  def post_overview(post)
39
- post.html_overiew ? post.html_overiew : post.html_content
26
+ post.html_overview ? post.html_overview : post.html_content
40
27
  end
41
28
  end
42
29
  end
@@ -31,13 +31,18 @@ class Blogo::Post < ActiveRecord::Base
31
31
  end
32
32
 
33
33
 
34
+ def to_param
35
+ permalink
36
+ end
37
+
38
+
34
39
  private
35
40
 
36
41
  # Filter html content to get plain text and set first 200 characters as meta_description.
37
42
  #
38
43
  # @return [void]
39
44
  def set_meta_description
40
- html = html_overiew || html_content
45
+ html = html_overview || html_content
41
46
 
42
47
  self.meta_description =
43
48
  html.gsub(/<\/?[^>]*>/, ' '). # replace HTML tags with spaces
@@ -36,14 +36,16 @@ module Blogo
36
36
  end
37
37
 
38
38
  def render_and_set_content!
39
- renderer = Blogo::Renderer.get(Blogo.config.markup_lang)
39
+ return unless @post.raw_content
40
40
 
41
+ renderer = Blogo::Renderer.get(Blogo.config.markup_lang)
41
42
  overview, rest = @post.raw_content.split(JUMP_BREAK, 2)
43
+
42
44
  if rest.present?
43
- @post.html_overiew = renderer.render(overview)
45
+ @post.html_overview = renderer.render(overview)
44
46
  @post.html_content = renderer.render(overview + rest)
45
47
  else
46
- @post.html_overiew = nil
48
+ @post.html_overview = nil
47
49
  @post.html_content = renderer.render(@post.raw_content)
48
50
  end
49
51
  end
@@ -9,7 +9,7 @@
9
9
  <script type="text/javascript">
10
10
  var disqus_shortname = '<%= Blogo.config.disqus_shortname %>';
11
11
  var disqus_identifier = 'blog-post-<%= @post.id %>';
12
- var disqus_url = '<%= url_to_post(@post) %>';
12
+ var disqus_url = '<%= blogo_post_url(@post) %>';
13
13
  var disqus_title = '<%= @post.title %>';
14
14
  var disqus_script = 'embed.js';
15
15
 
@@ -1,5 +1,5 @@
1
1
  <header>
2
- <h1><%= link_to post.title, path_to_post(post) %></h1>
2
+ <h1><%= link_to post.title, blogo_post_path(post) %></h1>
3
3
 
4
4
  <div class="posted">
5
5
  <span>
@@ -5,5 +5,5 @@
5
5
  <%= raw post_overview(post) %>
6
6
  </div>
7
7
 
8
- <%= link_to "Read ➞", path_to_post(post), class: 'pure-button button-secondary' %>
8
+ <%= link_to "Read ➞", blogo_post_path(post), class: 'pure-button button-secondary' %>
9
9
  </section>
@@ -4,8 +4,8 @@ atom_feed do |feed|
4
4
  feed.updated @updated
5
5
 
6
6
  @posts.each do |post|
7
- feed.entry(post, url: url_to_post(post)) do |entry|
8
- entry.url url_to_post(post)
7
+ feed.entry(post, url: blogo_post_url(post)) do |entry|
8
+ entry.url blogo_post_url(post)
9
9
  entry.title post.title
10
10
  entry.content post_overview(post), :type => 'html'
11
11
  entry.updated post.updated_at.strftime("%Y-%m-%dT%H:%M:%SZ")
@@ -1,5 +1,5 @@
1
1
  <div id="main">
2
- <%= render 'blogo/shared/post' %>
2
+ <%= render 'blogo/posts/post' %>
3
3
  <%= render 'blogo/posts/social_share' %>
4
- <%= render 'blogo/shared/disqus_comments' %>
4
+ <%= render 'blogo/posts/disqus_comments' %>
5
5
  </div>
@@ -6,7 +6,7 @@
6
6
  <ul class="blogo-recent-posts">
7
7
  <% @recent_posts.each do |post| %>
8
8
  <li>
9
- <%= link_to post.title, path_to_post(post) %>
9
+ <%= link_to post.title, blogo_post_path(post) %>
10
10
  </li>
11
11
  <% end %>
12
12
  </ul>
@@ -4,7 +4,7 @@
4
4
  <title><%= @meta[:title] %></title>
5
5
  <meta charset="UTF-8">
6
6
 
7
- <%= render partial: 'blogo/posts/meta' %>
7
+ <%= render partial: 'blogo/shared/meta' %>
8
8
 
9
9
  <%= csrf_meta_tags %>
10
10
  <%= stylesheet_link_tag "blogo/blog" %>
@@ -21,7 +21,7 @@
21
21
  </div>
22
22
 
23
23
  <div class='header-icons'>
24
- <%= render partial: 'blogo/posts/icons' %>
24
+ <%= render partial: 'blogo/shared/social_icons' %>
25
25
  </div>
26
26
  </header>
27
27
 
@@ -13,7 +13,7 @@ class CreateBlogoPosts < ActiveRecord::Migration
13
13
  t.text :raw_content , null: false
14
14
 
15
15
  t.text :html_content , null: false
16
- t.text :html_overiew , null: true
16
+ t.text :html_overview, null: true
17
17
 
18
18
  t.string :tags_string , null: true
19
19
  t.string :meta_description , null: false
@@ -26,6 +26,7 @@ class CreateBlogoPosts < ActiveRecord::Migration
26
26
  add_index posts_table, :permalink, unique: true
27
27
  add_index posts_table, :published_at
28
28
 
29
+ # NOTE: respond_to?(:add_foreign_key) does not work
29
30
  if defined?(Foreigner)
30
31
  users_table = "#{Blogo.table_name_prefix}users"
31
32
  add_foreign_key posts_table, users_table, column: :user_id
@@ -1,3 +1,3 @@
1
1
  module Blogo
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blogo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Potapov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-13 00:00:00.000000000 Z
11
+ date: 2014-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,6 +24,34 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: jquery-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: coffee-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: bcrypt-ruby
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -106,9 +134,9 @@ files:
106
134
  - app/views/blogo/admin/posts/new.html.erb
107
135
  - app/views/blogo/admin/sessions/new.html.erb
108
136
  - app/views/blogo/admin/shared/_nav_bar.html.erb
109
- - app/views/blogo/posts/_icons.html.erb
110
- - app/views/blogo/posts/_meta.html.erb
137
+ - app/views/blogo/posts/_disqus_comments.html.erb
111
138
  - app/views/blogo/posts/_paginator.html.erb
139
+ - app/views/blogo/posts/_post.html.erb
112
140
  - app/views/blogo/posts/_post_header.html.erb
113
141
  - app/views/blogo/posts/_post_overview.html.erb
114
142
  - app/views/blogo/posts/_social_share.html.erb
@@ -116,9 +144,9 @@ files:
116
144
  - app/views/blogo/posts/index.html.erb
117
145
  - app/views/blogo/posts/show.html.erb
118
146
  - app/views/blogo/shared/_aside.html.erb
119
- - app/views/blogo/shared/_disqus_comments.html.erb
120
147
  - app/views/blogo/shared/_google_analytics.html.erb
121
- - app/views/blogo/shared/_post.html.erb
148
+ - app/views/blogo/shared/_meta.html.erb
149
+ - app/views/blogo/shared/_social_icons.html.erb
122
150
  - app/views/layouts/blogo/admin.html.erb
123
151
  - app/views/layouts/blogo/blog.html.erb
124
152
  - config/environment.rb