Sha256: a73de0b195b2a5fabb40ce746c75d28cc1b4f887cf72250fc1feea3c313f0770

Contents?: true

Size: 940 Bytes

Versions: 9

Compression:

Stored size: 940 Bytes

Contents

module SimpleDiscussion::ForumThreadsHelper
  # Used for flagging links in the navbar as active
  def forum_link_to(path, opts={}, &block)
    link_to path, class: forum_link_class(path, opts), &block
  end

  def forum_link_class(matches, opts={})
    case matches
    when Array
      "active" if matches.any?{ |m| request.path.starts_with?(m) }
    when String
      "active" if opts.fetch(:exact, false) ? request.path == matches : request.path.starts_with?(matches)
    end
  end

  # A nice hack to manipulate the layout so we can have sub-layouts
  # without any changes in the user's application.
  #
  # We use this for rendering the sidebar layout for all the forum pages
  #
  # https://mattbrictson.com/easier-nested-layouts-in-rails
  #
  def parent_layout(layout)
    @view_flow.set(:layout, output_buffer)
    output = render(file: "layouts/#{layout}")
    self.output_buffer = ActionView::OutputBuffer.new(output)
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
simple_discussion-1.2.0 app/helpers/simple_discussion/forum_threads_helper.rb
simple_discussion-1.0.1 app/helpers/simple_discussion/forum_threads_helper.rb
simple_discussion-1.0.0 app/helpers/simple_discussion/forum_threads_helper.rb
simple_discussion-0.9.5 app/helpers/simple_discussion/forum_threads_helper.rb
simple_discussion-0.9.4 app/helpers/simple_discussion/forum_threads_helper.rb
simple_discussion-0.9.3 app/helpers/simple_discussion/forum_threads_helper.rb
simple_discussion-0.9.2 app/helpers/simple_discussion/forum_threads_helper.rb
simple_discussion-0.9.1 app/helpers/simple_discussion/forum_threads_helper.rb
simple_discussion-0.9.0 app/helpers/simple_discussion/forum_threads_helper.rb