Class: Decidim::Generators::ComponentGenerator

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
decidim-generators/lib/decidim/generators/component_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#component_descriptionObject (readonly)

Returns the value of attribute component_description.


14
15
16
# File 'decidim-generators/lib/decidim/generators/component_generator.rb', line 14

def component_description
  @component_description
end

#component_folderObject (readonly)

Returns the value of attribute component_folder.


14
15
16
# File 'decidim-generators/lib/decidim/generators/component_generator.rb', line 14

def component_folder
  @component_folder
end

#component_module_nameObject (readonly)

Returns the value of attribute component_module_name.


14
15
16
# File 'decidim-generators/lib/decidim/generators/component_generator.rb', line 14

def component_module_name
  @component_module_name
end

#component_nameObject (readonly)

Returns the value of attribute component_name.


14
15
16
# File 'decidim-generators/lib/decidim/generators/component_generator.rb', line 14

def component_name
  @component_name
end

#component_resource_nameObject (readonly)

Returns the value of attribute component_resource_name.


14
15
16
# File 'decidim-generators/lib/decidim/generators/component_generator.rb', line 14

def component_resource_name
  @component_resource_name
end

#core_versionObject (readonly)

Returns the value of attribute core_version.


14
15
16
# File 'decidim-generators/lib/decidim/generators/component_generator.rb', line 14

def core_version
  @core_version
end

Instance Method Details

#component(component_name) ⇒ Object


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'decidim-generators/lib/decidim/generators/component_generator.rb', line 22

def component(component_name)
  @component_name = component_name
  @component_module_name = component_name.camelize
  @component_folder = options[:destination_folder] || "decidim-module-#{component_name}"
  @core_version = Decidim::Core.version
  @component_description = ask "Write a description for the new component:"

  template "decidim-component.gemspec.erb", "#{component_folder}/decidim-#{component_name}.gemspec"
  template "Gemfile.erb", "#{component_folder}/Gemfile" if options[:external]
  template "Rakefile", "#{component_folder}/Rakefile"
  template "LICENSE-AGPLv3.txt", "#{component_folder}/LICENSE-AGPLv3.txt"
  template "README.md.erb", "#{component_folder}/README.md"
  template "gitignore", "#{component_folder}/.gitignore"
  template "circleci/config.yml", "#{component_folder}/.circleci/config.yml"

  app_folder = "#{component_folder}/app"
  template "app/packs/js/entrypoint.js", "#{app_folder}/packs/entrypoints/decidim_#{component_name}.js"
  template "app/packs/images/decidim/component/icon.svg", "#{app_folder}/packs/images/decidim/#{component_name}/icon.svg"
  template "app/packs/stylesheets/decidim/default.scss", "#{app_folder}/packs/stylesheets/decidim/#{component_name}/#{component_name}.scss"
  template "app/controllers/decidim/component/application_controller.rb.erb", "#{app_folder}/controllers/decidim/#{component_name}/application_controller.rb"
  template "app/controllers/decidim/component/admin/application_controller.rb.erb", "#{app_folder}/controllers/decidim/#{component_name}/admin/application_controller.rb"
  template "app/helpers/decidim/component/application_helper.rb.erb", "#{app_folder}/helpers/decidim/#{component_name}/application_helper.rb"
  template "app/models/decidim/component/application_record.rb.erb", "#{app_folder}/models/decidim/#{component_name}/application_record.rb"

  bin_folder = "#{component_folder}/bin"
  template "bin/rails.erb", "#{bin_folder}/rails"
  chmod "#{bin_folder}/rails", "+x"

  config_folder = "#{component_folder}/config"
  template "config/assets.rb.erb", "#{config_folder}/assets.rb"
  template "config/locales/en.yml.erb", "#{config_folder}/locales/en.yml"
  template "config/i18n-tasks.yml.erb", "#{config_folder}/i18n-tasks.yml"

  lib_folder = "#{component_folder}/lib"
  template "lib/decidim/component.rb.erb", "#{lib_folder}/decidim/#{component_name}.rb"
  template "lib/decidim/component/engine.rb.erb", "#{lib_folder}/decidim/#{component_name}/engine.rb"
  template "lib/decidim/component/admin.rb.erb", "#{lib_folder}/decidim/#{component_name}/admin.rb"
  template "lib/decidim/component/admin_engine.rb.erb", "#{lib_folder}/decidim/#{component_name}/admin_engine.rb"
  template "lib/decidim/component/component.rb.erb", "#{lib_folder}/decidim/#{component_name}/component.rb"
  template "lib/decidim/component/version.rb.erb", "#{lib_folder}/decidim/#{component_name}/version.rb"
  template "lib/decidim/component/test/factories.rb.erb", "#{lib_folder}/decidim/#{component_name}/test/factories.rb"

  spec_folder = "#{component_folder}/spec"
  template "spec/spec_helper.rb.erb", "#{spec_folder}/spec_helper.rb"
  template "spec/factories.rb.erb", "#{spec_folder}/factories.rb"

  if options[:external]
    inside(component_folder) do
      Bundler.with_original_env { run "bundle install" }
    end
  end
end