biovision-post 0.0.171104
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +26 -0
- data/app/assets/config/biovision_post_manifest.js +2 -0
- data/app/assets/images/biovision/post/publisher_logo.svg +3 -0
- data/app/assets/javascripts/biovision/post/application.js +13 -0
- data/app/assets/stylesheets/biovision/post/posts.scss +0 -0
- data/app/controllers/admin/post_categories_controller.rb +25 -0
- data/app/controllers/admin/post_types_controller.rb +30 -0
- data/app/controllers/admin/posts_controller.rb +2 -0
- data/app/controllers/articles_controller.rb +2 -0
- data/app/controllers/biovision/post/application_controller.rb +7 -0
- data/app/controllers/post_categories_controller.rb +77 -0
- data/app/controllers/posts_controller.rb +110 -0
- data/app/helpers/biovision/post/application_helper.rb +6 -0
- data/app/helpers/biovision_posts_helper.rb +77 -0
- data/app/jobs/biovision/post/application_job.rb +6 -0
- data/app/mailers/biovision/post/application_mailer.rb +8 -0
- data/app/models/application_record.rb +3 -0
- data/app/models/biovision/post/application_record.rb +7 -0
- data/app/models/post.rb +98 -0
- data/app/models/post_category.rb +145 -0
- data/app/models/post_type.rb +21 -0
- data/app/services/post_manager.rb +22 -0
- data/app/uploaders/post_image_uploader.rb +54 -0
- data/app/views/admin/post_categories/entity/_in_list.html.erb +21 -0
- data/app/views/admin/post_categories/show.html.erb +70 -0
- data/app/views/admin/post_types/_nav_item.html.erb +2 -0
- data/app/views/admin/post_types/entity/_in_list.html.erb +11 -0
- data/app/views/admin/post_types/index.html.erb +14 -0
- data/app/views/admin/post_types/new_post.html.erb +16 -0
- data/app/views/admin/post_types/post_categories.html.erb +18 -0
- data/app/views/admin/post_types/show.html.erb +33 -0
- data/app/views/admin/posts/_nav_item.html.erb +2 -0
- data/app/views/layouts/biovision/post/application.html.erb +14 -0
- data/app/views/post_categories/_form.html.erb +69 -0
- data/app/views/post_categories/edit.html.erb +23 -0
- data/app/views/post_categories/edit.jbuilder +3 -0
- data/app/views/post_categories/edit.js.erb +1 -0
- data/app/views/post_categories/new.html.erb +18 -0
- data/app/views/post_categories/new.jbuilder +3 -0
- data/app/views/post_categories/new.js.erb +1 -0
- data/app/views/posts/_form.html.erb +136 -0
- data/app/views/posts/_post.html.erb +79 -0
- data/app/views/posts/edit.js.erb +1 -0
- data/app/views/posts/entity/_metadata.html.erb +10 -0
- data/app/views/posts/entity/_publisher.html.erb +5 -0
- data/app/views/posts/form/_wysiwyg.html.erb +14 -0
- data/app/views/posts/new.js.erb +1 -0
- data/app/views/posts/show.html.erb +4 -0
- data/config/locales/posts-ru.yml +126 -0
- data/config/routes.rb +23 -0
- data/db/migrate/20170930000001_create_post_types.rb +25 -0
- data/db/migrate/20170930000002_create_post_categories.rb +29 -0
- data/db/migrate/20170930000003_create_posts.rb +53 -0
- data/lib/biovision/post.rb +7 -0
- data/lib/biovision/post/engine.rb +19 -0
- data/lib/biovision/post/version.rb +5 -0
- data/lib/tasks/biovision/post_tasks.rake +4 -0
- metadata +257 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 871f4df57bc36185ad704b40973eac86de0dc805
|
4
|
+
data.tar.gz: 5a6597244a86d50a0d22f6a831bfd6642f62d5d3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6764d17960b4ec4761885b21b9731e0d2d268a3d79a0ee69af5a9bb556397cfab5b8635b070d1be8674acc670be483452d5cf4a5032f3b31e97b6b3e58cf6f0d
|
7
|
+
data.tar.gz: 5aed65b3c46a6f6b2b75bb7b95a204be0471cadb76e25483145d2796ce07c02793e46ea8659ea2541796911013aa73fd902acfa44481b40be69c6cb74101ee7e
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017 Maxim Khan-Magomedov
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Biovision::Post
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'biovision-post'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install biovision-post
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
Contribution directions go here.
|
26
|
+
|
27
|
+
## License
|
28
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Biovision::Post'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
require 'bundler/gem_tasks'
|
26
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
File without changes
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Admin::PostCategoriesController < AdminController
|
2
|
+
include LockableEntity
|
3
|
+
include ToggleableEntity
|
4
|
+
include EntityPriority
|
5
|
+
|
6
|
+
before_action :set_entity
|
7
|
+
|
8
|
+
# get /admin/post_categories/:id
|
9
|
+
def show
|
10
|
+
@collection = @entity.posts.page_for_administration(current_page)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def set_entity
|
16
|
+
@entity = PostCategory.find_by(id: params[:id])
|
17
|
+
if @entity.nil?
|
18
|
+
handle_http_404('Cannot find post category')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def restrict_access
|
23
|
+
require_privilege :chief_editor
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class Admin::PostTypesController < AdminController
|
2
|
+
before_action :set_entity, except: [:index]
|
3
|
+
|
4
|
+
# get /admin/post_types
|
5
|
+
def index
|
6
|
+
@collection = PostType.page_for_administration
|
7
|
+
end
|
8
|
+
|
9
|
+
# get /admin/post_types/:id
|
10
|
+
def show
|
11
|
+
@collection = @entity.posts.page_for_administration(current_page)
|
12
|
+
end
|
13
|
+
|
14
|
+
# get /admin/post_types/:id/post_categories
|
15
|
+
def post_categories
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def set_entity
|
21
|
+
@entity = PostType.find_by(id: params[:id])
|
22
|
+
if @entity.nil?
|
23
|
+
handle_http_404('Cannot find post type')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def restrict_access
|
28
|
+
require_privilege :chief_editor
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
class PostCategoriesController < AdminController
|
2
|
+
before_action :set_entity, only: [:edit, :update, :destroy]
|
3
|
+
before_action :restrict_editing, only: [:edit, :update, :destroy]
|
4
|
+
|
5
|
+
# get /post_categories/new
|
6
|
+
def new
|
7
|
+
@entity = PostCategory.new
|
8
|
+
end
|
9
|
+
|
10
|
+
# post /post_categories
|
11
|
+
def create
|
12
|
+
@entity = PostCategory.new(creation_parameters)
|
13
|
+
if @entity.save
|
14
|
+
next_page = admin_post_category_path(@entity.id)
|
15
|
+
respond_to do |format|
|
16
|
+
format.html { redirect_to(next_page) }
|
17
|
+
format.json { render json: { links: { self: next_page } } }
|
18
|
+
format.js { render(js: "document.location.href = '#{next_page}'") }
|
19
|
+
end
|
20
|
+
else
|
21
|
+
render :new, status: :bad_request
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# get /post_categories/:id/edit
|
26
|
+
def edit
|
27
|
+
end
|
28
|
+
|
29
|
+
# patch /post_categories/:id
|
30
|
+
def update
|
31
|
+
if @entity.update entity_parameters
|
32
|
+
next_page = admin_post_category_path(@entity)
|
33
|
+
respond_to do |format|
|
34
|
+
format.html { redirect_to(next_page, notice: t('post_categories.update.success')) }
|
35
|
+
format.json { render json: { links: { self: next_page } } }
|
36
|
+
format.js { render(js: "document.location.href = '#{next_page}'") }
|
37
|
+
end
|
38
|
+
else
|
39
|
+
render :edit, status: :bad_request
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# delete /post_categories/:id
|
44
|
+
def destroy
|
45
|
+
if @entity.destroy
|
46
|
+
flash[:notice] = t('post_categories.destroy.success')
|
47
|
+
end
|
48
|
+
redirect_to(post_categories_admin_post_type_path(@entity.post_type_id))
|
49
|
+
end
|
50
|
+
|
51
|
+
protected
|
52
|
+
|
53
|
+
def restrict_access
|
54
|
+
require_privilege :chief_editor
|
55
|
+
end
|
56
|
+
|
57
|
+
def restrict_editing
|
58
|
+
if @entity.locked?
|
59
|
+
redirect_to admin_post_category_path(@entity.id), alert: t('post_categories.edit.forbidden')
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def set_entity
|
64
|
+
@entity = PostCategory.find_by(id: params[:id])
|
65
|
+
if @entity.nil?
|
66
|
+
handle_http_404('Cannot find post_category')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def entity_parameters
|
71
|
+
params.require(:post_category).permit(PostCategory.entity_parameters)
|
72
|
+
end
|
73
|
+
|
74
|
+
def creation_parameters
|
75
|
+
params.require(:post_category).permit(PostCategory.creation_parameters)
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
class PostsController < ApplicationController
|
2
|
+
before_action :restrict_access, only: [:new, :create]
|
3
|
+
before_action :set_entity, only: [:edit, :update, :destroy]
|
4
|
+
before_action :restrict_editing, only: [:edit, :update, :destroy]
|
5
|
+
|
6
|
+
layout 'admin', only: [:new, :edit]
|
7
|
+
|
8
|
+
# get /posts
|
9
|
+
def index
|
10
|
+
@collection = Post.page_for_visitors(current_page)
|
11
|
+
end
|
12
|
+
|
13
|
+
# get /posts/:category_slug
|
14
|
+
def category
|
15
|
+
@category = PostCategory.find_by! long_slug: params[:category_slug]
|
16
|
+
@collection = @category.posts.page_for_visitors(current_page)
|
17
|
+
end
|
18
|
+
|
19
|
+
# post /posts
|
20
|
+
def create
|
21
|
+
@entity = Post.new(creation_parameters)
|
22
|
+
if @entity.save
|
23
|
+
next_page = PostManager.handler(@entity).post_path
|
24
|
+
respond_to do |format|
|
25
|
+
format.html { redirect_to next_page }
|
26
|
+
format.json { render json: { links: { self: next_page } } }
|
27
|
+
format.js { render js: "document.location.href = '#{next_page}'" }
|
28
|
+
end
|
29
|
+
else
|
30
|
+
render :new, status: :bad_request
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# get /posts/:id
|
35
|
+
def show
|
36
|
+
@entity = Post.find_by(id: params[:id], deleted: false)
|
37
|
+
if @entity.nil?
|
38
|
+
handle_http_404("Cannot find non-deleted post #{params[:id]}")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# get /posts/:category_slug/:slug
|
43
|
+
def show_in_category
|
44
|
+
@category = PostCategory.find_by(slug: params[:category_slug])
|
45
|
+
@entity = Post.find_by(slug: params[:slug], deleted: false)
|
46
|
+
if @entity.nil? || !@entity.visible_to?(current_user)
|
47
|
+
handle_http_404("Cannot show posts #{params[:slug]} to user #{current_user&.id}")
|
48
|
+
elsif @entity.posts_category == @category
|
49
|
+
@entity.increment! :view_count
|
50
|
+
else
|
51
|
+
parameters = { category_slug: @entity.posts_category.slug, slug: @entity.slug }
|
52
|
+
redirect_to posts_in_category_posts_index_path(parameters)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# get /posts/:id/edit
|
57
|
+
def edit
|
58
|
+
end
|
59
|
+
|
60
|
+
# patch /posts/:id
|
61
|
+
def update
|
62
|
+
if @entity.update(entity_parameters)
|
63
|
+
next_page = PostManager.handler(@entity).post_path
|
64
|
+
respond_to do |format|
|
65
|
+
format.html { redirect_to next_page }
|
66
|
+
format.json { render json: { links: { self: next_page } } }
|
67
|
+
format.js { render js: "document.location.href = '#{next_page}'" }
|
68
|
+
end
|
69
|
+
else
|
70
|
+
render :edit, status: :bad_request
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# delete /posts/:id
|
75
|
+
def destroy
|
76
|
+
if @entity.update(deleted: true)
|
77
|
+
flash[:notice] = t('posts.destroy.success')
|
78
|
+
end
|
79
|
+
redirect_to admin_posts_index_path
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def set_entity
|
85
|
+
@entity = Post.find params[:id]
|
86
|
+
end
|
87
|
+
|
88
|
+
def restrict_access
|
89
|
+
require_privilege_group :reporters
|
90
|
+
end
|
91
|
+
|
92
|
+
def restrict_editing
|
93
|
+
raise record_not_found unless @entity.editable_by? current_user
|
94
|
+
end
|
95
|
+
|
96
|
+
def entity_parameters
|
97
|
+
params.require(:post).permit(Post.entity_parameters)
|
98
|
+
end
|
99
|
+
|
100
|
+
def creation_parameters
|
101
|
+
parameters = params.require(:post).permit(Post.creation_parameters)
|
102
|
+
parameters.merge(owner_for_entity(true))
|
103
|
+
end
|
104
|
+
|
105
|
+
def add_figures
|
106
|
+
params[:figures].values.reject { |f| f[:slug].blank? || f[:image].blank? }.each do |data|
|
107
|
+
@entity.figures.create!(data.select { |key, _| Figure.creation_parameters.include? key.to_sym })
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module BiovisionPostsHelper
|
2
|
+
# @param [PostType] entity
|
3
|
+
# @param [String] text
|
4
|
+
def admin_post_type_link(entity, text = entity.name)
|
5
|
+
link_to(text, admin_post_type_path(entity.id))
|
6
|
+
end
|
7
|
+
|
8
|
+
# @param [PostCategory] entity
|
9
|
+
# @param [String] text
|
10
|
+
def admin_post_category_link(entity, text = entity.name)
|
11
|
+
link_to(text, admin_post_category_path(entity.id))
|
12
|
+
end
|
13
|
+
|
14
|
+
# @param [Post] entity
|
15
|
+
# @param [String] text
|
16
|
+
def admin_post_link(entity, text = entity.title)
|
17
|
+
link_to(text, admin_post_path(entity.id))
|
18
|
+
end
|
19
|
+
|
20
|
+
# @param [Integer] post_type_id
|
21
|
+
def post_categories_for_select(post_type_id)
|
22
|
+
options = [[t(:not_set), '']]
|
23
|
+
PostCategory.for_tree(post_type_id).each do |category|
|
24
|
+
options << [category.name, category.id]
|
25
|
+
if category.child_categories.any?
|
26
|
+
PostCategory.for_tree(post_type_id, category.id).each do |subcategory|
|
27
|
+
options << ["-#{subcategory.name}", subcategory.id]
|
28
|
+
if subcategory.child_categories.any?
|
29
|
+
PostCategory.for_tree(post_type_id, subcategory.id).each do |deep_category|
|
30
|
+
options << ["--#{deep_category.name}", deep_category.id]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
options
|
37
|
+
end
|
38
|
+
|
39
|
+
# @param [Post] entity
|
40
|
+
def post_link(entity, text = entity.title)
|
41
|
+
link_to(text, PostManager.handler(entity).post_path)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Post image preview for displaying in "administrative" lists
|
45
|
+
#
|
46
|
+
# @param [Post] entity
|
47
|
+
def post_image_preview(entity)
|
48
|
+
return '' if entity.image.blank?
|
49
|
+
|
50
|
+
versions = "#{entity.image.preview_2x.url} 2x"
|
51
|
+
image_tag(entity.image.preview.url, alt: entity.title, srcset: versions)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Small post image for displaying in lists of posts and feeds
|
55
|
+
#
|
56
|
+
# @param [Post] entity
|
57
|
+
# @param [Hash] add_options
|
58
|
+
def post_image_small(entity, add_options = {})
|
59
|
+
return '' if entity.image.blank?
|
60
|
+
|
61
|
+
versions = "#{entity.image.medium.url} 2x"
|
62
|
+
options = { alt: entity.title, srcset: versions }.merge(add_options)
|
63
|
+
image_tag(entity.image.small.url, options)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Medium post image for displaying on post page
|
67
|
+
#
|
68
|
+
# @param [Post] entity
|
69
|
+
# @param [Hash] add_options
|
70
|
+
def post_image_medium(entity, add_options = {})
|
71
|
+
return '' if entity.image.blank?
|
72
|
+
|
73
|
+
versions = "#{entity.image.big.url} 2x"
|
74
|
+
options = { alt: entity.title, srcset: versions }.merge(add_options)
|
75
|
+
image_tag(entity.image.medium.url, options)
|
76
|
+
end
|
77
|
+
end
|