class Kiso::Generators::ComponentGenerator
bin/rails generate kiso:component pricing_card –theme modern
@example With a custom theme
bin/rails generate kiso:component pricing_card –sub-parts header footer
@example With sub-parts
bin/rails generate kiso:component pricing_card
@example Basic usage
helper.Kiso.config.app_theme. Components are rendered using the +appui()+app/themes/default/). The active theme is configured via
Theme files are placed in +app/themes/<active_theme>/+ (default:
Scaffolds a component with a ClassVariants theme module and ERB partial.
def class_name_without_namespace
-
(String)- the component name in PascalCase (e.g. "PricingCard")
def class_name_without_namespace file_name.camelize end
def component_class_path
-
(Array- namespace segments from the name argument)
def component_class_path regular_class_path end
def component_path_dir
-
(String)- namespace directory path (empty string for simple names)
def component_path_dir component_class_path.join("/") end
def create_partial_file
def create_partial_file template "partial.html.erb.tt", File.join("app/views/components", component_path_dir, "_#{file_name}.html.erb") end
def create_sub_part_files
def create_sub_part_files options[:sub_parts].each do |part| @current_part = part template "sub_part_theme.rb.tt", File.join(theme_dir, component_path_dir, "#{file_name}_#{part}.rb") template "sub_part_partial.html.erb.tt", File.join("app/views/components", component_path_dir, file_name, "_#{part}.html.erb") end end
def create_theme_file
def create_theme_file template "theme.rb.tt", File.join(theme_dir, component_path_dir, "#{file_name}.rb") end
def has_namespace?
-
(Boolean)- whether the component has a namespace prefix (e.g. admin/pricing_card)
def has_namespace? component_class_path.any? end
def module_prefix
-
(String)- full module nesting prefix (e.g. "Admin::" for admin/pricing_card)
def module_prefix component_class_path.map(&:camelize).join("::") end
def slot_name
-
(String)- the kebab-case data-slot value (e.g. "pricing-card")
def slot_name file_name.dasherize end
def sub_part_class_name
-
(String)- the PascalCase theme constant name for a sub-part (e.g. "PricingCardHeader")
def sub_part_class_name "#{class_name_without_namespace}#{current_part.camelize}" end
def sub_part_slot_name
-
(String)- the kebab-case data-slot value for a sub-part (e.g. "pricing-card-header")
def sub_part_slot_name "#{slot_name}-#{current_part.dasherize}" end
def theme_dir
-
(String)- the theme directory path (e.g. "app/themes/default")
def theme_dir name = (options[:theme] || Kiso.config.app_theme).to_s File.join("app/themes", name) end