diff --git a/CHANGELOG.md b/CHANGELOG.md index d2aa20f95db1e852df405b140fe5164cfc24351d..1b667f4f220fd133daa5a26c14a5f5a92264976a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ ### Upcoming Release +* [#269] [FEATURE] Add a generator for copying default layout files * [#295] [FEATURE] Add dashboard detection for ActiveRecord::Enum fields. * [#297] [I18n] Add Italian translations * [#307] [I18n] Fix German grammatical errors diff --git a/lib/generators/administrate/views/layout_generator.rb b/lib/generators/administrate/views/layout_generator.rb new file mode 100644 index 0000000000000000000000000000000000000000..deeb1cc978b33ccf13b55a3c89f2de38d6f2114e --- /dev/null +++ b/lib/generators/administrate/views/layout_generator.rb @@ -0,0 +1,22 @@ +require "administrate/view_generator" + +module Administrate + module Generators + module Views + class LayoutGenerator < Administrate::ViewGenerator + source_root template_source_path + + def copy_template + copy_file( + "../../layouts/administrate/application.html.erb", + "app/views/layouts/admin/application.html.erb", + ) + + copy_resource_template("_sidebar") + copy_resource_template("_javascript") + copy_resource_template("_flashes") + end + end + end + end +end diff --git a/spec/generators/views/layout_generator_spec.rb b/spec/generators/views/layout_generator_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..dcf029da90a7926278dbd1de0772d8a5e0c4910f --- /dev/null +++ b/spec/generators/views/layout_generator_spec.rb @@ -0,0 +1,48 @@ +require "rails_helper" +require "generators/administrate/views/layout_generator" +require "support/generator_spec_helpers" + +describe Administrate::Generators::Views::LayoutGenerator, :generator do + describe "administrate:views:layout" do + it "copies the layout template into the `admin/application` namespace" do + expected_contents = File.read( + "app/views/layouts/administrate/application.html.erb", + ) + + run_generator [] + contents = File.read(file("app/views/layouts/admin/application.html.erb")) + + expect(contents).to eq(expected_contents) + end + + it "copies the flashes partial into the `admin/application` namespace" do + expected_contents = contents_for_application_template("_flashes") + generated_file = file("app/views/admin/application/_flashes.html.erb") + + run_generator [] + contents = File.read(generated_file) + + expect(contents).to eq(expected_contents) + 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") + + run_generator [] + contents = File.read(generated_file) + + expect(contents).to eq(expected_contents) + end + + it "copies the javascript partial into the `admin/application` namespace" do + expected_contents = contents_for_application_template("_javascript") + generated_file = file("app/views/admin/application/_javascript.html.erb") + + run_generator [] + contents = File.read(generated_file) + + expect(contents).to eq(expected_contents) + end + end +end