Module: BiovisionPostsHelper

Defined in:
app/helpers/biovision_posts_helper.rb

Instance Method Summary collapse

Instance Method Details

#admin_post_category_link(entity, text = entity.name) ⇒ Object

Parameters:

  • entity (PostCategory)
  • text (String) (defaults to: entity.name)


10
11
12
# File 'app/helpers/biovision_posts_helper.rb', line 10

def (entity, text = entity.name)
  link_to(text, (id: entity.id))
end

#admin_post_link(entity, text = entity.title) ⇒ Object

Parameters:

  • entity (Post)
  • text (String) (defaults to: entity.title)


16
17
18
# File 'app/helpers/biovision_posts_helper.rb', line 16

def admin_post_link(entity, text = entity.title)
  link_to(text, admin_post_path(id: entity.id))
end

#admin_post_type_link(entity, text = entity.name) ⇒ Object

Parameters:

  • entity (PostType)
  • text (String) (defaults to: entity.name)


4
5
6
# File 'app/helpers/biovision_posts_helper.rb', line 4

def admin_post_type_link(entity, text = entity.name)
  link_to(text, admin_post_type_path(id: entity.id))
end

#post_author_link(entity, options = {}) ⇒ Object

Parameters:

  • entity (Post)
  • options (Hash) (defaults to: {})


48
49
50
51
52
53
54
55
56
57
# File 'app/helpers/biovision_posts_helper.rb', line 48

def (entity, options = {})
  if entity.author_url.blank?
    entity.author_name
  else
    link_options = {
      rel: 'external nofollow noopener noreferrer'
    }
    link_to(entity.author_name, entity.author_url, link_options.merge(options))
  end
end

#post_categories_for_select(post_type_id) ⇒ Object

Parameters:

  • post_type_id (Integer)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/helpers/biovision_posts_helper.rb', line 21

def post_categories_for_select(post_type_id)
  options = [[t(:not_set), '']]
  PostCategory.for_tree(post_type_id).each do |category|
    options << [category.name, category.id]
    if category.child_categories.any?
      PostCategory.for_tree(post_type_id, category.id).each do |subcategory|
        options << ["-#{subcategory.name}", subcategory.id]
        if subcategory.child_categories.any?
          PostCategory.for_tree(post_type_id, subcategory.id).each do |deep_category|
            options << ["--#{deep_category.name}", deep_category.id]
          end
        end
      end
    end
  end
  options
end

#post_image_medium(entity, add_options = {}) ⇒ Object

Medium post image for displaying on post page

Parameters:

  • entity (Post)
  • add_options (Hash) (defaults to: {})


86
87
88
89
90
91
92
93
# File 'app/helpers/biovision_posts_helper.rb', line 86

def post_image_medium(entity, add_options = {})
  return '' if entity.image.blank?

  alt_text = entity.image_alt_text.to_s
  versions = "#{entity.image.big.url} 2x"
  options  = { alt: alt_text, srcset: versions }.merge(add_options)
  image_tag(entity.image.medium.url, options)
end

#post_image_preview(entity) ⇒ Object

Post image preview for displaying in “administrative” lists

Parameters:



62
63
64
65
66
67
# File 'app/helpers/biovision_posts_helper.rb', line 62

def post_image_preview(entity)
  return '' if entity.image.blank?

  versions = "#{entity.image.preview_2x.url} 2x"
  image_tag(entity.image.preview.url, alt: entity.title, srcset: versions)
end

#post_image_small(entity, add_options = {}) ⇒ Object

Small post image for displaying in lists of posts and feeds

Parameters:

  • entity (Post)
  • add_options (Hash) (defaults to: {})


73
74
75
76
77
78
79
80
# File 'app/helpers/biovision_posts_helper.rb', line 73

def post_image_small(entity, add_options = {})
  return '' if entity.image.blank?

  alt_text = entity.image_alt_text.to_s
  versions = "#{entity.image.medium.url} 2x"
  options  = { alt: alt_text, srcset: versions }.merge(add_options)
  image_tag(entity.image.small.url, options)
end

#post_link(entity, text = entity.title, options = {}) ⇒ Object

Parameters:

  • entity (Post)
  • text (String) (defaults to: entity.title)
  • options (Hash) (defaults to: {})


42
43
44
# File 'app/helpers/biovision_posts_helper.rb', line 42

def post_link(entity, text = entity.title, options = {})
  link_to(text, PostManager.handler(entity, locale).post_path, options)
end