Sha256: 457142870244d49fb344863cfb4ff9084522cfc2be00d526c846ddfe53a85e06

Contents?: true

Size: 1.3 KB

Versions: 10

Compression:

Stored size: 1.3 KB

Contents

class Blog::BlogpostController < Blog::MainController
  LATEST_FOR_PREVIEW    = 2
  BLOGPOSTS_FOR_PREVIEW = 6
  RELATED_FOR_PREVIEW   = 3

  def index
    #   Fetch data as Json
    data = BlogpostParser.fetch_all_published

    categories = CategoryParser.fetch_all_categories

    #  Build Blogposts by category
    @categories_with_blogposts = categories.map do |category|
      Blog::Category.new(category).build_n_blogposts_by_category(data, BLOGPOSTS_FOR_PREVIEW)
    end

    #   Build latest Blogposts
    @latest_blogposts = data.first(LATEST_FOR_PREVIEW)
                            .map { |attributes| Blog::Blogpost.new(attributes) }
  end

  def show
    @blogpost = Blog::Blogpost.build_blogpost_from_path(params[:blog_path], 'en')

    @blog_button_path = "https://dashboard.nexmo.com/sign-up?icid=tryitfree_adpblog-#{params[:blog_path]}_nexmodashbdfreetrialsignup_banner"
    redirect_to blog_path unless @blogpost.published

    data = BlogpostParser.fetch_all_published

    @related_blogposts = data.select { |b| b['category']['slug'] == @blogpost.category.slug && b['title'] != @blogpost.title }
                             .first(RELATED_FOR_PREVIEW)
                             .sort_by { |b| b['updated_at'] }.reverse
                             .map { |attributes| Blog::Blogpost.new attributes }
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
station-0.5.14 lib/nexmo_developer/app/controllers/blog/blogpost_controller.rb
station-0.5.13 lib/nexmo_developer/app/controllers/blog/blogpost_controller.rb
station-0.5.12 lib/nexmo_developer/app/controllers/blog/blogpost_controller.rb
station-0.5.11 lib/nexmo_developer/app/controllers/blog/blogpost_controller.rb
station-0.5.10 lib/nexmo_developer/app/controllers/blog/blogpost_controller.rb
station-0.5.9 lib/nexmo_developer/app/controllers/blog/blogpost_controller.rb
station-0.5.8 lib/nexmo_developer/app/controllers/blog/blogpost_controller.rb
station-0.5.7 lib/nexmo_developer/app/controllers/blog/blogpost_controller.rb
station-0.5.6 lib/nexmo_developer/app/controllers/blog/blogpost_controller.rb
station-0.5.5 lib/nexmo_developer/app/controllers/blog/blogpost_controller.rb