From a7c1591315b49e94798d6d51446cbc4139463140 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 1 Jul 2009 21:23:30 +0200 Subject: Added stylesheets controller which is invoked by scaffold. --- railties/lib/generators/base.rb | 31 ++++++------- .../rails/scaffold/scaffold_generator.rb | 4 +- railties/lib/generators/rails/stylesheets/USAGE | 5 ++ .../rails/stylesheets/stylesheets_generator.rb | 9 ++++ .../rails/stylesheets/templates/scaffold.css | 54 ++++++++++++++++++++++ .../test/generators/stylesheets_generator_test.rb | 18 ++++++++ 6 files changed, 103 insertions(+), 18 deletions(-) create mode 100644 railties/lib/generators/rails/stylesheets/USAGE create mode 100644 railties/lib/generators/rails/stylesheets/stylesheets_generator.rb create mode 100644 railties/lib/generators/rails/stylesheets/templates/scaffold.css create mode 100644 railties/test/generators/stylesheets_generator_test.rb (limited to 'railties') diff --git a/railties/lib/generators/base.rb b/railties/lib/generators/base.rb index 81f6c7b343..aeb79dd339 100644 --- a/railties/lib/generators/base.rb +++ b/railties/lib/generators/base.rb @@ -13,6 +13,7 @@ module Rails :resource_controller => 'controller', :scaffold_controller => 'scaffold_controller', :singleton => false, + :stylesheets => true, :test_framework => 'test_unit', :template_engine => 'erb', :timestamps => true @@ -24,6 +25,7 @@ module Rails :orm => '-o', :resource_controller => '-c', :scaffold_controller => '-c', + :stylesheets => '-y', :test_framework => '-t', :template_engine => '-e' } @@ -132,8 +134,9 @@ module Rails # def invoke_for_test_framework # return unless options[:test_framework] # - # klass = Rails::Generators.find_by_namespace(options[:test_framework], - # "rails", "model") + # klass_name = options[:test_framework] + # klass_name = :test_framework if TrueClass === klass_name + # klass = Rails::Generators.find_by_namespace(klass_name, "rails", "model") # # if klass # say_status :invoke, options[:test_framework], :blue @@ -142,18 +145,20 @@ module Rails # say "Could not find and invoke '#{options[:test_framework]}'" # end # end + # class_eval <<-METHOD, __FILE__, __LINE__ def invoke_for_#{name} return unless options[#{name.inspect}] - klass = Rails::Generators.find_by_namespace(options[#{name.inspect}], - #{base_name.inspect}, #{as.inspect}) + klass_name = options[#{name.inspect}] + klass_name = #{name.inspect} if TrueClass === klass_name + klass = Rails::Generators.find_by_namespace(klass_name, #{base_name.inspect}, #{as.inspect}) if klass - say_status :invoke, options[#{name.inspect}], #{verbose.inspect} + say_status :invoke, klass_name, #{verbose.inspect} invoke_class_with_block #{name.inspect}, klass else - say "Could not find and invoke '\#{options[#{name.inspect}]}'." + say "Could not find and invoke '\#{klass_name}'." end end METHOD @@ -205,9 +210,7 @@ module Rails # # def invoke_if_helper # return unless options[:helper] - # - # klass = Rails::Generators.find_by_namespace(:helper, - # "rails", "controller") + # klass = Rails::Generators.find_by_namespace(:helper, "rails", "controller") # # if klass # say_status :invoke, :helper, :blue @@ -216,12 +219,11 @@ module Rails # say "Could not find and invoke 'helper'" # end # end + # class_eval <<-METHOD, __FILE__, __LINE__ def invoke_if_#{name} return unless options[#{name.inspect}] - - klass = Rails::Generators.find_by_namespace(#{name.inspect}, - #{base_name.inspect}, #{as.inspect}) + klass = Rails::Generators.find_by_namespace(#{name.inspect}, #{base_name.inspect}, #{as.inspect}) if klass say_status :invoke, #{name.inspect}, #{verbose.inspect} @@ -340,10 +342,7 @@ module Rails end # Overwrite class options help to allow invoked generators options to be - # shown when invoking a generator. Only first and second level options - # are shown, for instance, if a generator invokes an ORM that invokes - # a test framework, both options are shown, but if a third one is - # involved, those options do not appear. + # shown recursively when invoking a generator. # def self.class_options_help(shell, ungrouped_name=nil, extra_group=nil) group_options = Thor::CoreExt::OrderedHash.new diff --git a/railties/lib/generators/rails/scaffold/scaffold_generator.rb b/railties/lib/generators/rails/scaffold/scaffold_generator.rb index 0bfbed42a0..af44c8ba65 100644 --- a/railties/lib/generators/rails/scaffold/scaffold_generator.rb +++ b/railties/lib/generators/rails/scaffold/scaffold_generator.rb @@ -4,9 +4,9 @@ module Rails module Generators class ScaffoldGenerator < ResourceGenerator #metagenerator remove_hook_for :actions, :resource_controller - hook_for :scaffold_controller, :required => true - # invoke_if stylesheets + hook_for :scaffold_controller, :required => true + hook_for :stylesheets end end end diff --git a/railties/lib/generators/rails/stylesheets/USAGE b/railties/lib/generators/rails/stylesheets/USAGE new file mode 100644 index 0000000000..d6a81e51d0 --- /dev/null +++ b/railties/lib/generators/rails/stylesheets/USAGE @@ -0,0 +1,5 @@ +Description: + Copies scaffold stylesheets to public/stylesheets/. + +Examples: + `./script/generate stylesheets` diff --git a/railties/lib/generators/rails/stylesheets/stylesheets_generator.rb b/railties/lib/generators/rails/stylesheets/stylesheets_generator.rb new file mode 100644 index 0000000000..256b9a208f --- /dev/null +++ b/railties/lib/generators/rails/stylesheets/stylesheets_generator.rb @@ -0,0 +1,9 @@ +module Rails + module Generators + class StylesheetsGenerator < Base + def copy_stylesheets_file + copy_file "scaffold.css", "public/stylesheets/scaffold.css" + end + end + end +end diff --git a/railties/lib/generators/rails/stylesheets/templates/scaffold.css b/railties/lib/generators/rails/stylesheets/templates/scaffold.css new file mode 100644 index 0000000000..093c20994d --- /dev/null +++ b/railties/lib/generators/rails/stylesheets/templates/scaffold.css @@ -0,0 +1,54 @@ +body { background-color: #fff; color: #333; } + +body, p, ol, ul, td { + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +pre { + background-color: #eee; + padding: 10px; + font-size: 11px; +} + +a { color: #000; } +a:visited { color: #666; } +a:hover { color: #fff; background-color:#000; } + +.fieldWithErrors { + padding: 2px; + background-color: red; + display: table; +} + +#errorExplanation { + width: 400px; + border: 2px solid red; + padding: 7px; + padding-bottom: 12px; + margin-bottom: 20px; + background-color: #f0f0f0; +} + +#errorExplanation h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px; + background-color: #c00; + color: #fff; +} + +#errorExplanation p { + color: #333; + margin-bottom: 0; + padding: 5px; +} + +#errorExplanation ul li { + font-size: 12px; + list-style: square; +} + diff --git a/railties/test/generators/stylesheets_generator_test.rb b/railties/test/generators/stylesheets_generator_test.rb new file mode 100644 index 0000000000..89bcbc87a3 --- /dev/null +++ b/railties/test/generators/stylesheets_generator_test.rb @@ -0,0 +1,18 @@ +require 'abstract_unit' +require 'generators/generators_test_helper' +require 'generators/rails/stylesheets/stylesheets_generator' + +class StylesheetsGeneratorTest < GeneratorsTestCase + + def test_copy_stylesheets + run_generator + assert_file "public/stylesheets/scaffold.css" + end + + protected + + def run_generator(args=[]) + silence(:stdout) { Rails::Generators::StylesheetsGenerator.start args, :root => destination_root } + end + +end -- cgit v1.2.3