Permalink
Browse files

Merge pull request #5206 from varyonic/sidebar-view-component

Extract Sidebar View Component
  • Loading branch information...
varyonic committed Nov 3, 2017
2 parents abf3c49 + bd34a9e commit 58929997e176318b29f6638b2daf8c915249b9ea
@@ -0,0 +1,13 @@
module ActiveAdmin
module Views
class Sidebar < Component
builder_method :sidebar
def build(sections, attributes = {})
super(attributes)
sections.map(&method(:sidebar_section))
end
end
end
end
@@ -76,7 +76,7 @@ def build_page_content
build_flash_messages
div id: "active_admin_content", class: (skip_sidebar? ? "without_sidebar" : "with_sidebar") do
build_main_content_wrapper
build_sidebar unless skip_sidebar?
sidebar sidebar_sections_for_action, id: 'sidebar' unless skip_sidebar?
end
end
@@ -126,15 +126,6 @@ def action_items_for_action
end
end
# Renders the sidebar
def build_sidebar
div id: "sidebar" do
sidebar_sections_for_action.collect do |section|
sidebar_section(section)
end
end
end
def skip_sidebar?
sidebar_sections_for_action.empty? || assigns[:skip_sidebar] == true
end
@@ -0,0 +1,24 @@
require 'rails_helper'
RSpec.describe ActiveAdmin::Views::Sidebar do
let(:section) do
ActiveAdmin::SidebarSection.new("Section") do
para 'Section content.'
end
end
let(:html) do
render_arbre_component sections: [section] do
sidebar assigns[:sections], id: 'sidebar'
end
end
it "should have an id of 'sidebar'" do
expect(html.id).to eq 'sidebar'
end
it "renders the section" do
expect(html.find_by_tag('p').first.content).to eq 'Section content.'
end
end

0 comments on commit 5892999

Please sign in to comment.