Skip to content

Commit

Permalink
Add administrate:views:sidebar generator
Browse files Browse the repository at this point in the history
Problem:

Users often want to customize the sidebar markup.
Although the sidbar can be generated through the layout generator,
the sidebar is customized often enough to warrant its own command.

Solution:

Add a sidebar generator.
  • Loading branch information
acrogenesis authored and c-lliope committed Dec 15, 2015
1 parent c132777 commit 04ee51c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
### Upcoming Release

* [#269] [FEATURE] Add a generator for copying default layout files
* [#328] [FEATURE] Add a generator for copying default sidebar partial
* [#295] [FEATURE] Add dashboard detection for ActiveRecord::Enum fields.
* [#297] [I18n] Add Italian translations
* [#307] [I18n] Fix German grammatical errors
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/administrate/views/layout_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def copy_template
"app/views/layouts/admin/application.html.erb",
)

copy_resource_template("_sidebar")
Rails::Generators.invoke("administrate:views:sidebar")
copy_resource_template("_javascript")
copy_resource_template("_flashes")
end
Expand Down
15 changes: 15 additions & 0 deletions lib/generators/administrate/views/sidebar_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "administrate/view_generator"

module Administrate
module Generators
module Views
class SidebarGenerator < Administrate::ViewGenerator
source_root template_source_path

def copy_sidebar
copy_resource_template("_sidebar")
end
end
end
end
end
7 changes: 3 additions & 4 deletions spec/generators/views/layout_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@
end

it "copies the sidebar partial into the `admin/application` namespace" do
expected_contents = contents_for_application_template("_sidebar")
generated_file = file("app/views/admin/application/_sidebar.html.erb")
allow(Rails::Generators).to receive(:invoke)

run_generator []
contents = File.read(generated_file)

expect(contents).to eq(expected_contents)
expect(Rails::Generators).
to invoke_generator("administrate:views:sidebar")
end

it "copies the javascript partial into the `admin/application` namespace" do
Expand Down
17 changes: 17 additions & 0 deletions spec/generators/views/sidebar_generator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require "spec_helper"
require "generators/administrate/views/sidebar_generator"
require "support/generator_spec_helpers"

describe Administrate::Generators::Views::SidebarGenerator, :generator do
describe "administrate:views:sidebar" do
it "copies the sidebar partial into the `admin/application` namespace" do
expected_contents = contents_for_application_template("_sidebar")
generated_file = file("app/views/admin/application/_sidebar.html.erb")

run_generator []

contents = File.read(generated_file)
expect(contents).to eq(expected_contents)
end
end
end

0 comments on commit 04ee51c

Please sign in to comment.