Class: Blog
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- Blog
- Includes:
- BasedUrlFor, ConfigManager, StringLengthLimit
- Defined in:
- app/models/blog.rb
Overview
The Blog class represents the one and only blog. It stores most configuration settings and is linked to most of the assorted content classes via has_many.
Once upon a time, there were plans to make publify handle multiple blogs, but it never happened and publify is now firmly single-blog.
Defined Under Namespace
Modules: BasedUrlFor
Constant Summary
Constants included from StringLengthLimit
StringLengthLimit::STRING_LIMIT
Instance Attribute Summary collapse
-
#custom_permalink ⇒ Object
Returns the value of attribute custom_permalink.
Class Method Summary collapse
-
.find_blog(base_url) ⇒ Object
Find the Blog that matches a specific base URL.
Instance Method Summary collapse
- #allow_signup? ⇒ Boolean
- #articles_matching(query, args = {}) ⇒ Object
-
#configured? ⇒ Boolean
Check that all required blog settings have a value.
-
#current_theme(reload = nil) ⇒ Object
The
Themeobject for the current theme. -
#file_url(filename) ⇒ Object
The URL for a static file.
- #global_pings_enabled? ⇒ Boolean
- #has_twitter_configured? ⇒ Boolean
- #per_page(format) ⇒ Object
- #permalink_has_identifier ⇒ Object
- #root_path ⇒ Object
- #rss_limit_params ⇒ Object
- #shortener_url ⇒ Object
- #text_filter_object ⇒ Object
Methods included from ConfigManager
#canonicalize, included, #settings_keys
Methods included from BasedUrlFor
Instance Attribute Details
#custom_permalink ⇒ Object
Returns the value of attribute custom_permalink.
29 30 31 |
# File 'app/models/blog.rb', line 29 def custom_permalink @custom_permalink end |
Class Method Details
.find_blog(base_url) ⇒ Object
Find the Blog that matches a specific base URL. If no Blog object is found that matches, then grab the first blog. If that fails, then create a new Blog. The last case should only be used when Publify is first installed.
149 150 151 |
# File 'app/models/blog.rb', line 149 def self.find_blog(base_url) Blog.find_by(base_url: base_url) || Blog.first || Blog.new end |
Instance Method Details
#allow_signup? ⇒ Boolean
256 257 258 |
# File 'app/models/blog.rb', line 256 def allow_signup? allow_signup == 1 end |
#articles_matching(query, args = {}) ⇒ Object
212 213 214 |
# File 'app/models/blog.rb', line 212 def articles_matching(query, args = {}) Article.search(query, args) end |
#configured? ⇒ Boolean
Check that all required blog settings have a value.
158 159 160 |
# File 'app/models/blog.rb', line 158 def configured? settings.key?("blog_name") end |
#current_theme(reload = nil) ⇒ Object
The Theme object for the current theme.
163 164 165 166 |
# File 'app/models/blog.rb', line 163 def current_theme(reload = nil) @current_theme = nil if reload @current_theme ||= Theme.find(theme) || Theme.new("", "") end |
#file_url(filename) ⇒ Object
The URL for a static file.
204 205 206 207 208 209 210 |
# File 'app/models/blog.rb', line 204 def file_url(filename) if CarrierWave.configure { |config| config.storage.name == "CarrierWave::Storage::Fog" } filename else url_for filename, only_path: false end end |
#global_pings_enabled? ⇒ Boolean
153 154 155 |
# File 'app/models/blog.rb', line 153 def global_pings_enabled? !global_pings_disable? end |
#has_twitter_configured? ⇒ Boolean
249 250 251 252 253 254 |
# File 'app/models/blog.rb', line 249 def has_twitter_configured? return false if twitter_consumer_key.nil? || twitter_consumer_secret.nil? return false if twitter_consumer_key.empty? || twitter_consumer_secret.empty? true end |
#per_page(format) ⇒ Object
216 217 218 219 220 |
# File 'app/models/blog.rb', line 216 def per_page(format) return limit_article_display if format.nil? || format == "html" limit_rss_display end |
#permalink_has_identifier ⇒ Object
231 232 233 234 235 236 237 238 239 |
# File 'app/models/blog.rb', line 231 def permalink_has_identifier unless /(%title%)/.match?(permalink_format) errors.add(:base, I18n.t("errors.permalink_need_a_title")) end if /\.(atom|rss)$/.match?(permalink_format) errors.add(:permalink_format, I18n.t("errors.cant_end_with_rss_or_atom")) end end |
#root_path ⇒ Object
241 242 243 |
# File 'app/models/blog.rb', line 241 def root_path split_base_url[:root_path] end |
#rss_limit_params ⇒ Object
222 223 224 225 226 227 228 229 |
# File 'app/models/blog.rb', line 222 def rss_limit_params limit = limit_rss_display.to_i if limit.zero? {} else { limit: limit } end end |
#shortener_url ⇒ Object
260 261 262 |
# File 'app/models/blog.rb', line 260 def shortener_url custom_url_shortener.present? ? custom_url_shortener : base_url end |
#text_filter_object ⇒ Object
245 246 247 |
# File 'app/models/blog.rb', line 245 def text_filter_object TextFilter.find_or_default(text_filter) end |