Class: ArticlesController

Inherits:
ContentController show all
Defined in:
app/controllers/articles_controller.rb

Instance Method Summary collapse

Methods included from BlogHelper

#blog_base_url, #this_blog

Instance Method Details

#archivesObject



102
103
104
105
106
107
108
# File 'app/controllers/articles_controller.rb', line 102

def archives
  limit = this_blog.limit_archives_display
  @articles = this_blog.published_articles.includes(:tags).page(params[:page]).per(limit)
  @page_title = this_blog.archives_title_template.to_title(@articles, this_blog, params)
  @keywords = this_blog.meta_keywords
  @description = this_blog.archives_desc_template.to_title(@articles, this_blog, params)
end

#check_passwordObject



68
69
70
71
72
73
74
75
76
77
# File 'app/controllers/articles_controller.rb', line 68

def check_password
  return unless request.xhr?

  @article = Article.find(params[:article][:id])
  if @article.password == params[:article][:password]
    render partial: "articles/full_article_content", locals: { article: @article }
  else
    render partial: "articles/password_form", locals: { article: @article }
  end
end

#indexObject



12
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
# File 'app/controllers/articles_controller.rb', line 12

def index
  wanted_types = this_blog.statuses_in_timeline ? ["Article", "Note"] : ["Article"]

  limit = this_blog.per_page(params[:format])
  articles_base = if params[:year].blank?
                    this_blog.contents.published
                  else
                    this_blog.contents.published_at(params.values_at(:year, :month, :day))
                  end
  @articles = articles_base.includes(:user, :resources, :tags).
    where(type: wanted_types).page(params[:page]).per(limit)

  respond_to do |format|
    format.html do
      set_index_title_and_description(this_blog, params)
      @keywords = this_blog.meta_keywords

      render_paginated_index
    end
    format.atom do
      render_articles_feed("atom")
    end
    format.rss do
      auto_discovery_feed(only_path: false)
      render_articles_feed("rss")
    end
  end
end

#live_searchObject



56
57
58
59
60
# File 'app/controllers/articles_controller.rb', line 56

def live_search
  @search = params[:q]
  @articles = Article.search(@search)
  render :live_search, layout: false
end

#markup_helpObject

TODO: Move to TextfilterController



127
128
129
130
131
132
133
134
# File 'app/controllers/articles_controller.rb', line 127

def markup_help
  filter = TextFilter.make_filter(params[:id])
  if filter
    render html: filter.commenthelp
  else
    render plain: "Unknown filter"
  end
end

#previewObject



62
63
64
65
66
# File 'app/controllers/articles_controller.rb', line 62

def preview
  @article = Article.last_draft(params[:id])
  @page_title = this_blog.article_title_template.to_title(@article, this_blog, params)
  render "read"
end

#preview_pageObject



114
115
116
117
# File 'app/controllers/articles_controller.rb', line 114

def preview_page
  @page = Page.find(params[:id])
  render "view_page"
end

#redirectObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'app/controllers/articles_controller.rb', line 79

def redirect
  from = extract_feed_format(params[:from])
  factory = Article::Factory.new(this_blog, current_user)

  @article = factory.match_permalink_format(from, this_blog.permalink_format)
  return show_article if @article

  # Redirect old version with /:year/:month/:day/:title to new format,
  # because it's changed
  ["%year%/%month%/%day%/%title%", "articles/%year%/%month%/%day%/%title%"].each do |part|
    @article = factory.match_permalink_format(from, part)
    if @article
      return redirect_to URI.parse(@article.permalink_url).path,
                         status: :moved_permanently
    end
  end

  r = Redirect.find_by!(from_path: from)
  # TODO: If linked to article, directly redirect to the article.
  # Let redirection made outside of the blog on purpose (deal with it, Brakeman!)
  redirect_to r.full_to_path, status: :moved_permanently if r
end

#searchObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/articles_controller.rb', line 41

def search
  @articles = this_blog.articles_matching(params[:q],
                                          page: params[:page],
                                          per_page: this_blog.per_page(params[:format]))
  return error! if @articles.empty?

  @page_title = this_blog.search_title_template.to_title(@articles, this_blog, params)
  @description = this_blog.search_desc_template.to_title(@articles, this_blog, params)
  respond_to do |format|
    format.html { render "search" }
    format.rss { render_articles_feed "rss" }
    format.atom { render_articles_feed "atom" }
  end
end

#tagObject



110
111
112
# File 'app/controllers/articles_controller.rb', line 110

def tag
  redirect_to tags_path, status: :moved_permanently
end

#view_pageObject



119
120
121
122
123
124
# File 'app/controllers/articles_controller.rb', line 119

def view_page
  @page = Page.published.find_by!(name: Array(params[:name]).join("/"))
  @page_title = @page.title
  @description = this_blog.meta_description
  @keywords = this_blog.meta_keywords
end