Module: Notee::Helpers::NoteeHelper

Defined in:
lib/notee/helpers/notee_helper.rb

Instance Method Summary collapse

Instance Method Details

#notee(search_txt) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/notee/helpers/notee_helper.rb', line 5

def notee(search_txt)
  return false unless search_txt
  @notee = Notee::Post.find_by(id: search_txt)
  @notee = Notee::Post.find_by(slug: search_txt) unless @notee

  return if @notee.status == Notee::STATUS[:draft] ||
            @notee.status == Notee::STATUS[:deleted] ||
            @notee.status == Notee::STATUS[:privated]
  @notee
end

#notee_archives(year, month) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/notee/helpers/notee_helper.rb', line 52

def notee_archives(year, month)
  start_date = Date.new(year, month, 1)
  end_date = Date.new(year, month, -1)
  @notee_archives = Notee::Post.where(status: Notee::STATUS[:published], :published_at => start_date...end_date)

  @notee_archives
end

#notee_archives_menu(type = nil) ⇒ Object



60
61
62
63
64
65
66
67
68
69
# File 'lib/notee/helpers/notee_helper.rb', line 60

def notee_archives_menu(type = nil)
  case type
    when 'year'
      return Notee::Post.where(status: Notee::STATUS[:published]).group('year(published_at)').count
    when 'month'
      return Notee::Post.where(status: Notee::STATUS[:published]).group('year(published_at)').group('month(published_at)').count
    else
      return Notee::Post.where(status: Notee::STATUS[:published]).group('year(published_at)').group('month(published_at)').count
  end
end

#notee_categories(sort = nil) ⇒ Object

TODO: secret_mode def secret_notees

@notees = Notee::Post.where(status: Notee::STATUS[:secret_published]).order(published_at: :desc)

end



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/notee/helpers/notee_helper.rb', line 39

def notee_categories(sort = nil)
  @notee_categories = Notee::Category.all.order(created_at: :desc)

  case sort
    when 'alphabetal'
      @notee_categories = @notee_categories.sort
    when 'size'
      @notee_categories = @notee_categories.sort_by {|category| category.name.size }
  end

  @notee_categories
end

#notee_comments(id) ⇒ Object



71
72
73
74
75
# File 'lib/notee/helpers/notee_helper.rb', line 71

def notee_comments(id)
  return if id.nil?
  @notee_comments = Notee::Post.where(post_id: id)
  @notee_comments
end

#notees(search_txt = 'all') ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/notee/helpers/notee_helper.rb', line 16

def notees(search_txt = 'all')
  @notees = []

  if search_txt == 'all'
    # all_notees
    @notees = Notee::Post.where(status: Notee::STATUS[:published]).order(published_at: :desc)
  else
    # search_by_category_slug
    category_id = Notee::Category.find_by(slug: search_txt)
    category_id = Notee::Category.find_by(name: search_txt) unless category_id
    return false unless category_id

    @notees = Notee::Post.where(category_id: category_id, status: Notee::STATUS[:published]).order(published_at: :desc)
  end

  @notees
end