Class: Blog

Inherits:
ApplicationRecord
  • Object
show all
Includes:
BasedUrlFor, ConfigManager
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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ConfigManager

append_features, #canonicalize

Methods included from BasedUrlFor

#url_for

Instance Attribute Details

Returns the value of attribute custom_permalink.



27
28
29
# File 'app/models/blog.rb', line 27

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.



146
147
148
# File 'app/models/blog.rb', line 146

def self.find_blog(base_url)
  Blog.find_by(base_url: base_url) || Blog.first || Blog.new
end

Instance Method Details

#allow_signup?Boolean

Returns:

  • (Boolean)


256
257
258
# File 'app/models/blog.rb', line 256

def 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.

Returns:

  • (Boolean)


155
156
157
# File 'app/models/blog.rb', line 155

def configured?
  settings.key?("blog_name")
end

#current_theme(reload = nil) ⇒ Object

The Theme object for the current theme.



160
161
162
163
# File 'app/models/blog.rb', line 160

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

Returns:

  • (Boolean)


150
151
152
# File 'app/models/blog.rb', line 150

def global_pings_enabled?
  !global_pings_disable?
end

#has_twitter_configured?Boolean

Returns:

  • (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


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_pathObject



241
242
243
# File 'app/models/blog.rb', line 241

def root_path
  split_base_url[:root_path]
end

#rss_limit_paramsObject



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_urlObject



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_objectObject



245
246
247
# File 'app/models/blog.rb', line 245

def text_filter_object
  TextFilter.find_or_default(text_filter)
end