From dd1ccffb0ab8f9ce5dcfcfc5e603575ad0faac48 Mon Sep 17 00:00:00 2001 From: James Patrick Date: Fri, 22 May 2020 02:39:44 -0400 Subject: [PATCH] Added component generator. For the like 4 I'm going to make. Because sure? --- lib/generators/component_generator.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 lib/generators/component_generator.rb diff --git a/lib/generators/component_generator.rb b/lib/generators/component_generator.rb new file mode 100644 index 0000000..2fc939d --- /dev/null +++ b/lib/generators/component_generator.rb @@ -0,0 +1,25 @@ +# Generator for building scaffolding frontend components. +# e.g. rails g component NAME +class ComponentGenerator < Rails::Generators::Base + argument :component_name, required: true, desc: 'Component name, e.g: button' + + def create_css_file + create_file "#{component_path}/#{component_name}.css" + end + + def create_js_file + create_file "#{component_path}/#{component_name}.js" do + "import \"./#{component_name}.css\";\n" + end + end + + def create_view_file + create_file "#{component_path}/_#{component_name}.html.erb" + end + + protected + + def component_path + "frontend/components/#{component_name}" + end +end