Class: SolidusAdmin::ComponentGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/solidus_admin/component/component_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_component_filesObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/generators/solidus_admin/component/component_generator.rb', line 22

def create_component_files
  template "component.html.erb", destination(".html.erb")
  unless options["html"]
    say_status :inline, destination(".html.erb"), :blue
    @inline_html = File.read(destination(".html.erb"))
    shell.mute { remove_file(destination(".html.erb")) }
  end
  template "component.rb", destination(".rb")
  template "component.yml", destination(".yml") if options["i18n"]
  template "component.js", destination(".js") if options["js"]
  template "component_spec.rb", destination("_spec.rb", root: "spec/components") if options["spec"]

  if options["preview"]
    preview_destination_path = destination("_preview.rb", root: "spec/components/previews")
    template "component_preview.rb", preview_destination_path
    template "component_preview_overview.html.erb", preview_destination_path.sub(/\.rb/, '/overview.html.erb')
  end
end

#setup_inflectionsObject



15
16
17
18
19
20
# File 'lib/generators/solidus_admin/component/component_generator.rb', line 15

def setup_inflections
  # This is needed because the generator won't run the initialization process,
  # in order to ensure that UI is not rendered as Ui we need to setup inflections
  # manually.
  SolidusAdmin::Engine.initializers.find { _1.name =~ /inflections/ }.run
end