This repository has been archived on 2020-10-16. You can view files and clone it, but cannot push or open issues or pull requests.
2020-05-23 03:54:14 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-05-22 06:39:44 +00:00
|
|
|
# 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
|
2020-05-23 06:39:35 +00:00
|
|
|
create_file "#{component_path}/#{component_name}.pcss"
|
2020-05-22 06:39:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create_js_file
|
|
|
|
create_file "#{component_path}/#{component_name}.js" do
|
2020-05-23 06:39:35 +00:00
|
|
|
"import \"./#{component_name}.pcss\";\n"
|
2020-05-22 06:39:44 +00:00
|
|
|
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
|