Module: LatoBlog::Interface::Tags
- Included in:
- LatoBlog::Interface
- Defined in:
- lib/lato_blog/interfaces/tags.rb
Overview
This module contains a list of functions used to manage tags for the blog.
Instance Method Summary collapse
-
#blog__clean_tag_parents ⇒ Object
This function cleans all old tag parents without any child.
-
#blog__get_category(id: nil, permalink: nil) ⇒ Object
This function returns a single category searched by id or permalink.
-
#blog__get_tags(order: nil, language: nil, search: nil, page: nil, per_page: nil) ⇒ Object
This function returns an object with the list of tags with some filters.
Instance Method Details
#blog__clean_tag_parents ⇒ Object
This function cleans all old tag parents without any child.
7 8 9 10 |
# File 'lib/lato_blog/interfaces/tags.rb', line 7 def blog__clean_tag_parents tag_parents = LatoBlog::TagParent.all tag_parents.map { |tp| tp.destroy if tp..empty? } end |
#blog__get_category(id: nil, permalink: nil) ⇒ Object
This function returns a single category searched by id or permalink.
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/lato_blog/interfaces/tags.rb', line 50 def blog__get_category(id: nil, permalink: nil) return {} unless id || permalink if id category = LatoBlog::Category.find_by(id: id.to_i) else category = LatoBlog::Category.find_by(meta_permalink: permalink) end category.serialize end |
#blog__get_tags(order: nil, language: nil, search: nil, page: nil, per_page: nil) ⇒ Object
This function returns an object with the list of tags with some filters.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/lato_blog/interfaces/tags.rb', line 13 def ( order: nil, language: nil, search: nil, page: nil, per_page: nil ) = LatoBlog::Tag.all # apply filters order = order && order == 'ASC' ? 'ASC' : 'DESC' = (, order) = (, language) = (, search) # take tags uniqueness = .uniq(&:id) # save total tags total = .length # manage pagination page = page&.to_i || 1 per_page = per_page&.to_i || 20 = core__paginate_array(, per_page, page) # return result { tags: && !.empty? ? .map(&:serialize) : [], page: page, per_page: per_page, order: order, total: total } end |