Class: ArticlesController
Instance Method Summary
collapse
Methods included from BlogHelper
#blog_base_url, #this_blog
Instance Method Details
#archives ⇒ Object
93
94
95
96
97
98
99
|
# File 'app/controllers/articles_controller.rb', line 93
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_password ⇒ Object
63
64
65
66
67
68
69
70
71
|
# File 'app/controllers/articles_controller.rb', line 63
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
|
#index ⇒ Object
10
11
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
|
# File 'app/controllers/articles_controller.rb', line 10
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, :text_filter).
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. do
auto_discovery_feed(only_path: false)
render_articles_feed('rss')
end
end
end
|
#live_search ⇒ Object
51
52
53
54
55
|
# File 'app/controllers/articles_controller.rb', line 51
def live_search
@search = params[:q]
@articles = Article.search(@search)
render :live_search, layout: false
end
|
#markup_help ⇒ Object
TODO: Move to TextfilterController?
118
119
120
|
# File 'app/controllers/articles_controller.rb', line 118
def markup_help
render html: TextFilter.find(params[:id]).
end
|
#preview ⇒ Object
57
58
59
60
61
|
# File 'app/controllers/articles_controller.rb', line 57
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_page ⇒ Object
105
106
107
108
|
# File 'app/controllers/articles_controller.rb', line 105
def preview_page
@page = Page.find(params[:id])
render 'view_page'
end
|
#redirect ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'app/controllers/articles_controller.rb', line 73
def redirect
from = (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
['%year%/%month%/%day%/%title%', 'articles/%year%/%month%/%day%/%title%'].each do |part|
@article = factory.match_permalink_format(from, part)
return redirect_to URI.parse(@article.permalink_url).path, status: 301 if @article
end
r = Redirect.find_by!(from_path: from)
redirect_to r.full_to_path, status: 301 if r
end
|
#search ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
|
# File 'app/controllers/articles_controller.rb', line 39
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. { render_articles_feed 'rss' }
format.atom { render_articles_feed 'atom' }
end
end
|
#tag ⇒ Object
101
102
103
|
# File 'app/controllers/articles_controller.rb', line 101
def tag
redirect_to tags_path, status: 301
end
|
#view_page ⇒ Object
110
111
112
113
114
115
|
# File 'app/controllers/articles_controller.rb', line 110
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
|