biovision-post 0.2.180325 → 0.21.190513.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +79 -13
- data/app/assets/images/biovision/post/icons/time.svg +6 -0
- data/app/assets/images/biovision/post/publisher_logo.png +0 -0
- data/app/assets/javascripts/biovision/post/biovision-posts.js +258 -0
- data/app/assets/stylesheets/biovision/post/admin/posts.scss +93 -0
- data/app/assets/stylesheets/biovision/post/posts.scss +88 -37
- data/app/controllers/admin/editorial_members_controller.rb +43 -0
- data/app/controllers/admin/featured_posts_controller.rb +23 -0
- data/app/controllers/admin/post_group_categories_controller.rb +19 -0
- data/app/controllers/admin/post_group_tags_controller.rb +19 -0
- data/app/controllers/admin/post_groups_controller.rb +62 -0
- data/app/controllers/admin/post_illustrations_controller.rb +26 -0
- data/app/controllers/admin/post_images_controller.rb +33 -0
- data/app/controllers/admin/post_links_controller.rb +19 -0
- data/app/controllers/admin/post_tags_controller.rb +30 -0
- data/app/controllers/admin/post_types_controller.rb +16 -4
- data/app/controllers/admin/posts_controller.rb +26 -2
- data/app/controllers/articles_controller.rb +23 -11
- data/app/controllers/authors_controller.rb +27 -0
- data/app/controllers/blog_posts_controller.rb +23 -11
- data/app/controllers/editorial_members_controller.rb +65 -0
- data/app/controllers/featured_posts_controller.rb +59 -0
- data/app/controllers/my/posts_controller.rb +124 -0
- data/app/controllers/news_controller.rb +23 -11
- data/app/controllers/post_categories_controller.rb +4 -14
- data/app/controllers/post_groups_controller.rb +76 -0
- data/app/controllers/post_illustrations_controller.rb +22 -0
- data/app/controllers/post_images_controller.rb +62 -0
- data/app/controllers/post_links_controller.rb +37 -0
- data/app/controllers/post_tags_controller.rb +41 -0
- data/app/controllers/posts_controller.rb +119 -14
- data/app/helpers/biovision_posts_helper.rb +114 -5
- data/app/jobs/application_job.rb +7 -0
- data/app/jobs/post_body_parser_job.rb +15 -0
- data/app/models/editorial_member.rb +92 -0
- data/app/models/editorial_member_post_type.rb +15 -0
- data/app/models/featured_post.rb +25 -0
- data/app/models/post.rb +203 -38
- data/app/models/post_category.rb +76 -54
- data/app/models/post_group.rb +84 -0
- data/app/models/post_group_category.rb +36 -0
- data/app/models/post_group_tag.rb +32 -0
- data/app/models/post_illustration.rb +62 -0
- data/app/models/post_image.rb +88 -0
- data/app/models/post_layout.rb +14 -0
- data/app/models/post_link.rb +2 -0
- data/app/models/post_post_category.rb +24 -0
- data/app/models/post_post_tag.rb +21 -0
- data/app/models/post_tag.rb +70 -0
- data/app/models/post_translation.rb +7 -0
- data/app/models/post_type.rb +18 -2
- data/app/models/post_zen_category.rb +6 -0
- data/app/models/zen_category.rb +21 -0
- data/app/services/post_manager.rb +52 -15
- data/app/services/post_parser.rb +80 -0
- data/app/uploaders/post_image_uploader.rb +9 -9
- data/app/views/admin/editorial_members/_nav_item.html.erb +2 -0
- data/app/views/admin/editorial_members/entity/_in_list.html.erb +37 -0
- data/app/views/admin/editorial_members/index.html.erb +15 -0
- data/app/views/admin/editorial_members/show.html.erb +71 -0
- data/app/views/admin/featured_posts/_add.html.erb +140 -0
- data/app/views/admin/featured_posts/_language.html.erb +14 -0
- data/app/views/admin/featured_posts/_nav_item.html.erb +2 -0
- data/app/views/admin/featured_posts/entity/_in_list.html.erb +26 -0
- data/app/views/admin/featured_posts/index.html.erb +18 -0
- data/app/views/admin/index/dashboard/_biovision_post.html.erb +32 -25
- data/app/views/admin/post_categories/entity/_in_list.html.erb +22 -6
- data/app/views/admin/post_categories/show.html.erb +6 -1
- data/app/views/admin/post_group_categories/entity/_in_list.html.erb +18 -0
- data/app/views/admin/post_group_tags/entity/_in_list.html.erb +18 -0
- data/app/views/admin/post_groups/_nav_item.html.erb +6 -0
- data/app/views/admin/post_groups/entity/_categories.html.erb +33 -0
- data/app/views/admin/post_groups/entity/_in_list.html.erb +25 -0
- data/app/views/admin/post_groups/index.html.erb +22 -0
- data/app/views/admin/post_groups/show.html.erb +65 -0
- data/app/views/admin/post_groups/tags.jbuilder +12 -0
- data/app/views/admin/post_illustrations/_nav_item.html.erb +6 -0
- data/app/views/admin/post_illustrations/entity/_in_list.html.erb +19 -0
- data/app/views/admin/post_illustrations/index.html.erb +23 -0
- data/app/views/admin/post_illustrations/show.html.erb +32 -0
- data/app/views/admin/post_images/_nav_item.html.erb +2 -0
- data/app/views/admin/post_images/entity/_in_list.html.erb +30 -0
- data/app/views/admin/post_images/index.html.erb +16 -0
- data/app/views/admin/post_images/show.html.erb +49 -0
- data/app/views/admin/post_links/entity/_in_list.html.erb +43 -0
- data/app/views/admin/post_tags/_nav_item.html.erb +2 -0
- data/app/views/admin/post_tags/entity/_in_list.html.erb +23 -0
- data/app/views/admin/post_tags/index.html.erb +16 -0
- data/app/views/admin/post_tags/posts.html.erb +18 -0
- data/app/views/admin/post_tags/show.html.erb +37 -0
- data/app/views/admin/post_types/authors.html.erb +23 -0
- data/app/views/admin/post_types/post_categories.html.erb +15 -4
- data/app/views/admin/post_types/post_tags.html.erb +18 -0
- data/app/views/admin/post_types/show.html.erb +28 -5
- data/app/views/admin/posts/_filter.html.erb +19 -0
- data/app/views/admin/posts/_nav_item.html.erb +3 -0
- data/app/views/admin/posts/_search_form.html.erb +13 -0
- data/app/views/admin/posts/entity/_in_list.html.erb +31 -7
- data/app/views/admin/posts/entity/_in_search.html.erb +8 -0
- data/app/views/admin/posts/entity/_links.html.erb +125 -0
- data/app/views/admin/posts/images.html.erb +22 -0
- data/app/views/admin/posts/index.html.erb +4 -0
- data/app/views/admin/posts/search.html.erb +21 -0
- data/app/views/admin/posts/search.jbuilder +26 -0
- data/app/views/admin/posts/show.html.erb +118 -18
- data/app/views/articles/category.html.erb +9 -9
- data/app/views/articles/index.html.erb +12 -9
- data/app/views/articles/show.html.erb +2 -4
- data/app/views/articles/tagged.html.erb +14 -0
- data/app/views/authors/_list.html.erb +18 -0
- data/app/views/authors/entity/_in_list.html.erb +9 -0
- data/app/views/authors/index.html.erb +10 -0
- data/app/views/authors/show.html.erb +31 -0
- data/app/views/blog_posts/category.html.erb +9 -9
- data/app/views/blog_posts/index.html.erb +12 -9
- data/app/views/blog_posts/show.html.erb +2 -4
- data/app/views/blog_posts/tagged.html.erb +14 -0
- data/app/views/editorial_members/_form.html.erb +107 -0
- data/app/views/editorial_members/edit.html.erb +17 -0
- data/app/views/editorial_members/new.html.erb +15 -0
- data/app/views/featured_posts/create.jbuilder +10 -0
- data/app/views/index/dashboard/_biovision_post.html.erb +18 -2
- data/app/views/my/index/dashboard/_biovision_post.html.erb +43 -0
- data/app/views/my/posts/_form.html.erb +357 -0
- data/app/views/my/posts/_list.html.erb +9 -0
- data/app/views/my/posts/_post.html.erb +80 -0
- data/app/views/my/posts/_preview.html.erb +35 -0
- data/app/views/my/posts/articles.html.erb +24 -0
- data/app/views/my/posts/blog_posts.html.erb +24 -0
- data/app/views/my/posts/edit.html.erb +19 -0
- data/app/views/my/posts/index.html.erb +14 -0
- data/app/views/my/posts/index/_navigation.html.erb +29 -0
- data/app/views/my/posts/new.html.erb +14 -0
- data/app/views/my/posts/news_index.html.erb +24 -0
- data/app/views/my/posts/show.html.erb +7 -0
- data/app/views/news/category.html.erb +9 -9
- data/app/views/news/index.html.erb +12 -9
- data/app/views/news/show.html.erb +2 -4
- data/app/views/news/tagged.html.erb +14 -0
- data/app/views/post_categories/_form.html.erb +82 -43
- data/app/views/post_groups/_form.html.erb +79 -0
- data/app/views/post_groups/edit.html.erb +17 -0
- data/app/views/post_groups/new.html.erb +15 -0
- data/app/views/post_groups/show.html.erb +10 -0
- data/app/views/post_images/_form.html.erb +121 -0
- data/app/views/post_images/edit.html.erb +19 -0
- data/app/views/post_images/new.html.erb +18 -0
- data/app/views/post_links/create.jbuilder +20 -0
- data/app/views/post_tags/_form.html.erb +26 -0
- data/app/views/post_tags/edit.html.erb +18 -0
- data/app/views/post_tags/new.html.erb +18 -0
- data/app/views/posts/_archive_dates.jbuilder +13 -0
- data/app/views/posts/_breadcrumbs.html.erb +4 -8
- data/app/views/posts/_calendar.html.erb +9 -0
- data/app/views/posts/_collection.html.erb +5 -0
- data/app/views/posts/_form.html.erb +204 -64
- data/app/views/posts/_list.html.erb +1 -1
- data/app/views/{articles/index.jbuilder → posts/_list.jbuilder} +3 -3
- data/app/views/posts/_post.html.erb +43 -16
- data/app/views/posts/_preview.html.erb +32 -21
- data/app/views/posts/_search.html.erb +6 -0
- data/app/views/posts/_wysiwyg.html.erb +25 -0
- data/app/views/posts/archive.jbuilder +3 -0
- data/app/views/posts/archive_day.html.erb +12 -0
- data/app/views/posts/category.html.erb +18 -0
- data/app/views/posts/entity/_gallery.html.erb +54 -0
- data/app/views/posts/entity/_linked_posts.html.erb +7 -0
- data/app/views/posts/entity/_metadata.html.erb +35 -12
- data/app/views/posts/entity/_publisher.html.erb +3 -1
- data/app/views/posts/form/_category_links.html.erb +32 -0
- data/app/views/posts/form/_gallery.html.erb +163 -0
- data/app/views/posts/index.html.erb +13 -0
- data/app/views/posts/index.jbuilder +1 -0
- data/app/views/posts/post_type/_category.html.erb +7 -0
- data/app/views/posts/post_type/_post_page.html.erb +9 -0
- data/app/views/posts/post_type/_posts.html.erb +5 -0
- data/app/views/posts/post_type/_tagged.html.erb +7 -0
- data/app/views/posts/rss.xml.erb +47 -0
- data/app/views/posts/search.html.erb +15 -0
- data/app/views/posts/show.html.erb +5 -3
- data/app/views/posts/tagged.html.erb +10 -0
- data/app/views/posts/tagged.jbuilder +1 -0
- data/app/views/posts/zen.xml.erb +42 -0
- data/config/locales/posts-en.yml +257 -19
- data/config/locales/posts-ru.yml +380 -14
- data/config/locales/posts-sv.yml +416 -0
- data/config/routes.rb +111 -15
- data/db/{migrate → amends}/20180124111113_add_language_to_posts.rb +0 -0
- data/db/{migrate → amends}/20180318215555_add_active_to_post_types.rb +0 -0
- data/db/amends/20180606120000_add_original_title_to_posts.rb +9 -0
- data/db/amends/20180606120001_add_time_required_to_posts.rb +11 -0
- data/db/amends/20180611111111_add_pubdate_and_translator_to_posts.rb +19 -0
- data/db/amends/20180618111111_add_default_category_name_to_post_types.rb +15 -0
- data/db/amends/20180703191919_add_rating_to_posts.rb +14 -0
- data/db/amends/20180810111111_add_explicit_to_posts.rb +11 -0
- data/db/amends/20180825111111_add_meta_description_to_post_categories.rb +11 -0
- data/db/amends/20180927111111_amend_editorial_member_about.rb +13 -0
- data/db/migrate/20170930000001_create_post_types.rb +98 -20
- data/db/migrate/20170930000010_create_posts.rb +194 -0
- data/db/migrate/20180706000000_create_editorial_members.rb +37 -0
- data/db/migrate/20180808000000_create_zen_categories.rb +42 -0
- data/db/migrate/20190202232323_add_spam_to_posts.rb +11 -0
- data/db/migrate/20190224212121_add_data_to_posts.rb +13 -0
- data/db/migrate/20190224212122_rename_post_image_source.rb +26 -0
- data/db/migrate/20190224212123_add_uuid_to_post_images.rb +10 -0
- data/db/migrate/20190313141414_convert_json_post_columns.rb +25 -0
- data/db/migrate/20190401101010_create_post_illustrations.rb +20 -0
- data/db/migrate/20190407101010_create_editorial_member_post_types.rb +18 -0
- data/db/migrate/20190410101010_add_avoid_parsing_to_posts.rb +14 -0
- data/db/migrate/20190410120000_create_post_groups.rb +47 -0
- data/db/migrate/20190412191919_add_nav_text_to_post_categories.rb +14 -0
- data/db/migrate/20190412212121_add_url_part_to_post_types.rb +26 -0
- data/db/migrate/20190420212121_create_post_layouts.rb +27 -0
- data/db/migrate/20190424161616_create_post_post_categories.rb +31 -0
- data/lib/biovision/post/version.rb +3 -1
- data/lib/tasks/posts.rake +6 -0
- metadata +170 -25
- data/app/assets/images/biovision/post/publisher_logo.svg +0 -3
- data/app/services/post_manager/article_handler.rb +0 -10
- data/app/services/post_manager/blog_post_handler.rb +0 -10
- data/app/services/post_manager/news_handler.rb +0 -10
- data/app/views/admin/index/dashboard/biovision_post/_additional_items.html.erb +0 -0
- data/app/views/blog_posts/index.jbuilder +0 -11
- data/app/views/news/index.jbuilder +0 -11
- data/app/views/post_categories/edit.jbuilder +0 -3
- data/app/views/post_categories/edit.js.erb +0 -1
- data/app/views/post_categories/new.jbuilder +0 -3
- data/app/views/post_categories/new.js.erb +0 -1
- data/db/migrate/20170930000002_create_post_categories.rb +0 -29
- data/db/migrate/20170930000003_create_posts.rb +0 -60
- data/db/migrate/20171218111111_add_meta_fields_to_posts.rb +0 -15
- data/db/migrate/20171219111112_add_author_fields_to_posts.rb +0 -11
- data/db/migrate/20180321100000_create_post_references.rb +0 -21
- data/db/migrate/20180321100001_create_post_notes.rb +0 -18
- data/db/migrate/20180321100002_create_post_links.rb +0 -20
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Model for post layout
|
4
|
+
#
|
5
|
+
# Attributes:
|
6
|
+
# name [String]
|
7
|
+
# posts_count [Integer]
|
8
|
+
# slug [String]
|
9
|
+
class PostLayout < ApplicationRecord
|
10
|
+
include RequiredUniqueName
|
11
|
+
include RequiredUniqueSlug
|
12
|
+
|
13
|
+
has_many :posts, dependent: :nullify
|
14
|
+
end
|
data/app/models/post_link.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Link between post and post category
|
4
|
+
#
|
5
|
+
# Attributes:
|
6
|
+
# created_at [DateTime]
|
7
|
+
# post_category_id [PostCategory]
|
8
|
+
# post_id [Post]
|
9
|
+
# updated_at [DateTime]
|
10
|
+
class PostPostCategory < ApplicationRecord
|
11
|
+
belongs_to :post
|
12
|
+
belongs_to :post_category, counter_cache: :posts_count
|
13
|
+
|
14
|
+
validates_uniqueness_of :post_category_id, scope: :post_id
|
15
|
+
validate :category_consistency
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def category_consistency
|
20
|
+
return if post_category&.post_type == post&.post_type
|
21
|
+
|
22
|
+
errors.add(:post_category_id, I18n.t('activerecord.errors.messages.mismatches_post_type'))
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Link between post and post tag
|
4
|
+
#
|
5
|
+
# Attributes:
|
6
|
+
# created_at [DateTime]
|
7
|
+
class PostPostTag < ApplicationRecord
|
8
|
+
belongs_to :post
|
9
|
+
belongs_to :post_tag, counter_cache: :posts_count
|
10
|
+
|
11
|
+
validates_uniqueness_of :post_tag_id, scope: [:post_id]
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def matching_post_type
|
16
|
+
unless post.post_type_id == post_tag.post_type_id
|
17
|
+
error = I18n.t('activerecord.errors.messages.mismatches_post_type')
|
18
|
+
errors.add(:post_tag, error)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Post tag
|
4
|
+
class PostTag < ApplicationRecord
|
5
|
+
NAME_LIMIT = 255
|
6
|
+
|
7
|
+
belongs_to :post_type
|
8
|
+
has_many :post_post_tags, dependent: :delete_all
|
9
|
+
has_many :posts, through: :post_post_tags
|
10
|
+
|
11
|
+
before_validation { self.name = name.to_s.squish[0..NAME_LIMIT] }
|
12
|
+
before_validation { self.slug = Canonizer.canonize(name) unless name.blank? }
|
13
|
+
|
14
|
+
validates_presence_of :name, :slug
|
15
|
+
validates_uniqueness_of :slug, scope: :post_type_id
|
16
|
+
validates_length_of :name, maximum: NAME_LIMIT
|
17
|
+
|
18
|
+
scope :ordered_by_slug, -> { order('slug asc') }
|
19
|
+
scope :popular, -> { order('posts_count desc, slug asc') }
|
20
|
+
scope :with_posts, -> { where('posts_count > 0') }
|
21
|
+
scope :with_name_like, ->(v) { where('name ilike ?', "%#{v}%") unless v.blank? }
|
22
|
+
scope :list_for_administration, -> { ordered_by_slug }
|
23
|
+
scope :list_for_visitors, -> { with_posts.ordered_by_slug }
|
24
|
+
scope :ids_for_name, ->(name) { where(slug: Canonizer.canonize(name)).pluck(:id) }
|
25
|
+
|
26
|
+
# @param [Integer] page
|
27
|
+
def self.page_for_administration(page = 1)
|
28
|
+
list_for_administration.page(page)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.entity_parameters
|
32
|
+
%i[name]
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.creation_parameters
|
36
|
+
entity_parameters + %i[post_type_id]
|
37
|
+
end
|
38
|
+
|
39
|
+
# @param [Integer] post_type_id
|
40
|
+
# @param [String] name
|
41
|
+
def self.match_by_name(post_type_id, name)
|
42
|
+
find_by(post_type_id: post_type_id, slug: Canonizer.canonize(name))
|
43
|
+
end
|
44
|
+
|
45
|
+
# @param [Integer] post_type_id
|
46
|
+
# @param [String] name
|
47
|
+
def self.match_or_create_by_name(post_type_id, name)
|
48
|
+
entity = find_by(post_type_id: post_type_id, slug: Canonizer.canonize(name))
|
49
|
+
entity || create(post_type_id: post_type_id, name: name)
|
50
|
+
end
|
51
|
+
|
52
|
+
def name_for_url
|
53
|
+
Canonizer.urlize name
|
54
|
+
end
|
55
|
+
|
56
|
+
# @param [Post] post
|
57
|
+
def post?(post)
|
58
|
+
post_post_tags.exist?(post: post)
|
59
|
+
end
|
60
|
+
|
61
|
+
# @param [Post] post
|
62
|
+
def add_post(post)
|
63
|
+
post_post_tags.create(post: post) unless post.nil?
|
64
|
+
end
|
65
|
+
|
66
|
+
# @param [Post] post
|
67
|
+
def remove_post(post)
|
68
|
+
post_post_tags.where(post: post).delete_all
|
69
|
+
end
|
70
|
+
end
|
data/app/models/post_type.rb
CHANGED
@@ -1,14 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Post type
|
4
|
+
#
|
5
|
+
# Attributes:
|
6
|
+
# active [Boolean]
|
7
|
+
# category_depth [Integer]
|
8
|
+
# created_at [DateTime]
|
9
|
+
# default_category_name [String], optional
|
10
|
+
# name [String]
|
11
|
+
# slug [String]
|
12
|
+
# updated_at [DateTime]
|
1
13
|
class PostType < ApplicationRecord
|
2
14
|
include RequiredUniqueName
|
3
15
|
include RequiredUniqueSlug
|
4
16
|
|
5
17
|
NAME_LIMIT = 50
|
6
18
|
SLUG_LIMIT = 50
|
7
|
-
SLUG_PATTERN = /\A[a-z]+[0-9a-z_]*[0-9a-z]\z
|
8
|
-
DEPTH_RANGE = (0..10)
|
19
|
+
SLUG_PATTERN = /\A[a-z]+[0-9a-z_]*[0-9a-z]\z/.freeze
|
20
|
+
DEPTH_RANGE = (0..10).freeze
|
9
21
|
|
10
22
|
has_many :post_categories, dependent: :destroy
|
11
23
|
has_many :posts
|
24
|
+
has_many :post_tags, dependent: :delete_all
|
25
|
+
has_many :editorial_member_post_types, dependent: :delete_all
|
26
|
+
has_many :editorial_members, through: :editorial_member_post_types
|
12
27
|
|
13
28
|
validates_length_of :name, maximum: NAME_LIMIT
|
14
29
|
validates_length_of :slug, maximum: SLUG_LIMIT
|
@@ -16,6 +31,7 @@ class PostType < ApplicationRecord
|
|
16
31
|
validates_inclusion_of :category_depth, in: DEPTH_RANGE
|
17
32
|
|
18
33
|
scope :active, -> { where(active: true) }
|
34
|
+
scope :list_for_administration, -> { active.ordered_by_name }
|
19
35
|
|
20
36
|
def self.page_for_administration
|
21
37
|
active.ordered_by_name
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class ZenCategory < ApplicationRecord
|
2
|
+
include RequiredUniqueName
|
3
|
+
|
4
|
+
has_many :post_zen_categories, dependent: :delete_all
|
5
|
+
has_many :posts, through: :post_zen_categories
|
6
|
+
|
7
|
+
# @param [Post] post
|
8
|
+
def post?(post)
|
9
|
+
post_zen_categories.where(post: post).exists?
|
10
|
+
end
|
11
|
+
|
12
|
+
# @param [Post] post
|
13
|
+
def add_post(post)
|
14
|
+
post_zen_categories.create(post: post)
|
15
|
+
end
|
16
|
+
|
17
|
+
# @param [Post] post
|
18
|
+
def remove_post(post)
|
19
|
+
post_zen_categories.where(post: post).destroy_all
|
20
|
+
end
|
21
|
+
end
|
@@ -1,34 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Manager for handling post-related cases
|
1
4
|
class PostManager
|
2
|
-
# @param [Post] entity
|
5
|
+
# @param [Post|PostCategory] entity
|
3
6
|
# @param [Symbol|String] locale
|
4
7
|
def initialize(entity, locale = I18n.locale)
|
5
8
|
@entity = entity
|
6
|
-
@body
|
7
|
-
@prefix = locale.nil? ? '' : "/#{locale}"
|
9
|
+
@body = entity.body.to_s if @entity.is_a?(Post)
|
10
|
+
@prefix = locale.nil? || locale == I18n.default_locale ? '' : "/#{locale}"
|
11
|
+
@url_part = entity.post_type.url_part
|
8
12
|
end
|
9
13
|
|
10
|
-
# @param [
|
11
|
-
# @param [
|
12
|
-
def self.
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
# @param [User] user
|
15
|
+
# @param [String|PostType] type
|
16
|
+
def self.editor?(user, type)
|
17
|
+
return true if UserPrivilege.user_has_privilege?(user, :chief_editor)
|
18
|
+
|
19
|
+
type = PostType.find_by(slug: type) unless type.is_a?(PostType)
|
20
|
+
|
21
|
+
EditorialMember.find_by(user: user)&.post_type?(type)
|
22
|
+
end
|
23
|
+
|
24
|
+
# @param [Post] post
|
25
|
+
def self.enclosures(post)
|
26
|
+
post.parsed_body.scan(/<img[^>]+>/).map do |image|
|
27
|
+
image.scan(/src="([^"]+)"/)[0][0]
|
28
|
+
end
|
16
29
|
end
|
17
30
|
|
18
31
|
def parsed_body
|
19
|
-
@
|
32
|
+
PostParser.new(@entity).parsed_body if @entity.is_a?(Post)
|
20
33
|
end
|
21
34
|
|
22
35
|
def post_path
|
23
|
-
"#{@prefix}
|
36
|
+
"#{@prefix}/#{@url_part}/#{@entity.id}-#{@entity.slug}" if @entity.is_a?(Post)
|
24
37
|
end
|
25
38
|
|
26
39
|
def edit_path
|
27
|
-
"#{@prefix}/posts/#{@entity.id}/edit"
|
40
|
+
"#{@prefix}/posts/#{@entity.id}/edit" if @entity.is_a?(Post)
|
41
|
+
end
|
42
|
+
|
43
|
+
# @param [String] tag_name
|
44
|
+
def tagged_path(tag_name)
|
45
|
+
"#{@prefix}/#{@url_part}/tagged/#{CGI.escape(tag_name)}"
|
46
|
+
end
|
47
|
+
|
48
|
+
def category_path
|
49
|
+
postfix = ''
|
50
|
+
suffix = @entity.is_a?(Post) ? @entity.post_category : @entity
|
51
|
+
postfix += "/#{suffix.long_slug}" unless suffix.nil?
|
52
|
+
|
53
|
+
empty_category_path + postfix
|
54
|
+
end
|
55
|
+
|
56
|
+
def category_name
|
57
|
+
if @entity.is_a?(Post)
|
58
|
+
if @entity.post_category.nil?
|
59
|
+
@entity.post_type.default_category_name
|
60
|
+
else
|
61
|
+
@entity.post_categories.map(&:text_for_link)
|
62
|
+
end
|
63
|
+
else
|
64
|
+
@entity.text_for_link
|
65
|
+
end
|
28
66
|
end
|
29
67
|
|
30
|
-
|
31
|
-
|
32
|
-
"#{@prefix}/posts/#{category.long_slug}"
|
68
|
+
def empty_category_path
|
69
|
+
"#{@prefix}/#{@url_part}"
|
33
70
|
end
|
34
71
|
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Parser for post body
|
4
|
+
class PostParser
|
5
|
+
# @param [Post] entity
|
6
|
+
def initialize(entity)
|
7
|
+
@entity = entity
|
8
|
+
@body = entity.body.clone
|
9
|
+
end
|
10
|
+
|
11
|
+
def parsed_body
|
12
|
+
unless @entity.avoid_parsing?
|
13
|
+
@body = escape_scripts
|
14
|
+
@body = convert_video_links
|
15
|
+
@body = convert_asides
|
16
|
+
end
|
17
|
+
|
18
|
+
@body
|
19
|
+
end
|
20
|
+
|
21
|
+
def escape_scripts
|
22
|
+
@body.gsub(/<script/, '<script')
|
23
|
+
end
|
24
|
+
|
25
|
+
def convert_video_links
|
26
|
+
pattern = %r(<p>{video:(?<url>[^}]{1,100})}</p>)i
|
27
|
+
@body.gsub(pattern) do
|
28
|
+
iframe = video_url_to_iframe($LAST_MATCH_INFO[:url])
|
29
|
+
%(<div class="proportional-container r-16x9">#{iframe}</div>)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def convert_asides
|
34
|
+
pattern = %r{<p>~~\s*(.+?)</p>}i
|
35
|
+
@body.gsub(pattern) do
|
36
|
+
"<aside>#{$LAST_MATCH_INFO[1]}</aside>"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
# @param [String] url
|
43
|
+
def video_url_to_iframe(url)
|
44
|
+
src = video_iframe_url(url)
|
45
|
+
|
46
|
+
src.blank? ? url : %(<iframe src="#{src}" allowfullscreen></iframe>)
|
47
|
+
end
|
48
|
+
|
49
|
+
# @param [String] url
|
50
|
+
def video_iframe_url(url)
|
51
|
+
if url.match?(%r{\Ahttps?://vimeo\.com})
|
52
|
+
process_vimeo_link(url)
|
53
|
+
elsif url.match?(%r{\Ahttps?://www\.youtube\.com/watch})
|
54
|
+
process_youtube_link(url)
|
55
|
+
elsif url.match?(%r{\Ahttps?://youtu\.be/.+})
|
56
|
+
process_youtu_be_link(url)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# @param [String] url
|
61
|
+
def process_vimeo_link(url)
|
62
|
+
video_id = url.gsub(%r{\A\D+/(\d+)/?}, '\\1')
|
63
|
+
api_url = "https://vimeo.com/api/v2/video/#{video_id}.json"
|
64
|
+
json_data = JSON.parse(URI.open(api_url)).first
|
65
|
+
|
66
|
+
json_data.blank? ? '' : "https://player.vimeo.com/video/#{json_data['id']}"
|
67
|
+
end
|
68
|
+
|
69
|
+
# @param [String] url
|
70
|
+
def process_youtube_link(url)
|
71
|
+
video_id = CGI.parse(URI.parse(url).query)['v'].first
|
72
|
+
"//www.youtube.com/embed/#{video_id}"
|
73
|
+
end
|
74
|
+
|
75
|
+
# @param [String] url
|
76
|
+
def process_youtu_be_link(url)
|
77
|
+
video_id = URI.parse(url).path.delete('/')
|
78
|
+
"//www.youtube.com/embed/#{video_id}"
|
79
|
+
end
|
80
|
+
end
|
@@ -1,18 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Image uploader for posts
|
1
4
|
class PostImageUploader < CarrierWave::Uploader::Base
|
2
5
|
include CarrierWave::MiniMagick
|
3
6
|
include CarrierWave::BombShelter
|
4
7
|
|
5
8
|
storage :file
|
9
|
+
process :auto_orient
|
6
10
|
|
7
11
|
def max_pixel_dimensions
|
8
|
-
[
|
12
|
+
[9600, 9600]
|
9
13
|
end
|
10
14
|
|
11
15
|
def store_dir
|
12
|
-
"
|
13
|
-
end
|
16
|
+
slug = "#{model.id / 10_000}/#{model.id / 100}/#{model.id}"
|
14
17
|
|
15
|
-
|
18
|
+
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{slug}"
|
19
|
+
end
|
16
20
|
|
17
21
|
def auto_orient
|
18
22
|
manipulate! do |image|
|
@@ -45,10 +49,6 @@ class PostImageUploader < CarrierWave::Uploader::Base
|
|
45
49
|
end
|
46
50
|
|
47
51
|
def extension_white_list
|
48
|
-
%w
|
49
|
-
end
|
50
|
-
|
51
|
-
def filename
|
52
|
-
"#{model.uuid}.#{file.extension}" if original_filename
|
52
|
+
%w[jpg jpeg png]
|
53
53
|
end
|
54
54
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
<div class="image">
|
2
|
+
<%= profile_avatar(entity.user) %>
|
3
|
+
</div>
|
4
|
+
<div class="data">
|
5
|
+
<div><%= admin_editorial_member_link(entity) %></div>
|
6
|
+
<div class="info">
|
7
|
+
<%= entity.title %>
|
8
|
+
</div>
|
9
|
+
<% unless entity.lead.blank? %>
|
10
|
+
<div class="secondary info">
|
11
|
+
<%= entity.lead %>
|
12
|
+
</div>
|
13
|
+
<% end %>
|
14
|
+
|
15
|
+
<%=
|
16
|
+
render(
|
17
|
+
partial: 'shared/admin/toggleable',
|
18
|
+
locals: {
|
19
|
+
entity: entity,
|
20
|
+
url: toggle_admin_editorial_member_path(id: entity.id)
|
21
|
+
}
|
22
|
+
)
|
23
|
+
%>
|
24
|
+
|
25
|
+
<ul class="actions">
|
26
|
+
<% if entity.visible? %>
|
27
|
+
<li><%= world_icon(author_path(slug: entity.slug)) %></li>
|
28
|
+
<% end %>
|
29
|
+
<li><%= edit_icon(edit_editorial_member_path(id: entity.id)) %></li>
|
30
|
+
<%=
|
31
|
+
render(
|
32
|
+
partial: 'shared/actions/priority_changer',
|
33
|
+
locals: { path: priority_admin_editorial_member_path(id: entity.id) }
|
34
|
+
)
|
35
|
+
%>
|
36
|
+
</ul>
|
37
|
+
</div>
|