Class: Integral::Widgets::RecentPosts

Inherits:
Object
  • Object
show all
Defined in:
lib/integral/widgets/recent_posts.rb

Overview

Outputs recent posts

Example Widget Markup <p class=‘integral-widget’ data-widget-type=‘recent_posts’ data-widget-value-tagged=‘awesome-tag’>

Class Method Summary collapse

Class Method Details

.controllerObject

Frontend controller used to render views



21
22
23
# File 'lib/integral/widgets/recent_posts.rb', line 21

def self.controller
  Integral.frontend_parent_controller.constantize
end

.default_optionsObject

Default widget options



26
27
28
29
30
31
# File 'lib/integral/widgets/recent_posts.rb', line 26

def self.default_options
  {
    amount: 2,
    tagged: ''
  }
end

.render(options = {}) ⇒ Object

Render the recent posts



10
11
12
13
14
15
16
17
18
# File 'lib/integral/widgets/recent_posts.rb', line 10

def self.render(options = {})
  options = options.reverse_merge(default_options)

  controller.render(
    partial: 'integral/posts/collection',
    locals: { collection: skope(options) },
    layout: false
  )
end

.skope(options) ⇒ Object

Scope of the widget



34
35
36
37
38
# File 'lib/integral/widgets/recent_posts.rb', line 34

def self.skope(options)
  skope = Integral::Post.published.order(published_at: :desc)
  skope = skope.tagged_with(options[:tagged].split) if options[:tagged].present?
  skope.limit(options[:amount])
end