class Generators::Avo::FieldGenerator
def destination_components_path
def destination_components_path "#{::Avo.configuration.view_component_path}/avo/fields/#{singular_name}_field" end
def destination_field_path
def destination_field_path "app/avo/fields/#{singular_name}_field.rb" end
def field_from_template
def field_from_template if !File.file? ::Avo::Engine.root.join(template_field_path) return say("Failed to find the `#{field_template}` template field.", :yellow) end if !Dir.exist? ::Avo::Engine.root.join(template_components_path) return say("Failed to find the `#{field_template}` template field components.", :yellow) end directory ::Avo::Engine.root.join(template_components_path), destination_components_path copy_file ::Avo::Engine.root.join(template_field_path), destination_field_path Dir.glob("#{destination_components_path}/*").push(destination_field_path).each do |file| modified_content = File.read(file).gsub("#{field_template.camelize}Field", "#{singular_name.camelize}Field") File.open(file, "w") do |open_file| open_file.puts modified_content end end end
def field_template
def field_template options["field-template"] end
def handle
def handle return field_from_template if field_template.present? directory "field/components", destination_components_path template "field/%singular_name%_field.rb.tt", destination_field_path end
def template_components_path
def template_components_path "app/components/avo/fields/#{field_template}_field" end
def template_field_path
def template_field_path "lib/avo/fields/#{field_template}_field.rb" end