Module: Railspress::ApplicationHelper

Defined in:
app/helpers/railspress/application_helper.rb

Instance Method Summary collapse

Instance Method Details

Returns the featured image URL for a post, useful for og:image meta tags

Parameters:

  • post (Railspress::Post)

    the post

  • variant (Hash) (defaults to: { resize_to_limit: [ 1200, 630 ] })

    image variant options (default: resize_to_limit: [1200, 630])

Returns:

  • (String, nil)

    the image URL or nil if no image attached



21
22
23
24
25
# File 'app/helpers/railspress/application_helper.rb', line 21

def rp_featured_image_url(post, variant: { resize_to_limit: [ 1200, 630 ] })
  return nil unless post.header_image.attached?

  main_app.url_for(post.header_image.variant(variant))
end

#rp_reading_time(post, format: :short) ⇒ String

Formats reading time for display

Parameters:

  • post (Railspress::Post)

    the post to format reading time for

  • format (Symbol) (defaults to: :short)

    :short for “5 min” or :long for “5 minute read”

Returns:

  • (String)

    formatted reading time



7
8
9
10
11
12
13
14
15
# File 'app/helpers/railspress/application_helper.rb', line 7

def rp_reading_time(post, format: :short)
  minutes = post.reading_time_display
  case format
  when :long
    "#{minutes} minute read"
  else
    "#{minutes} min"
  end
end