Added component generator.
For the like 4 I'm going to make. Because sure?
This commit is contained in:
		
							parent
							
								
									518a464161
								
							
						
					
					
						commit
						dd1ccffb0a
					
				
							
								
								
									
										25
									
								
								lib/generators/component_generator.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								lib/generators/component_generator.rb
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -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
 | 
				
			||||||
		Reference in New Issue
	
	Block a user