Class: Decidim::Generators::AppGenerator

Inherits:
Rails::Generators::AppGenerator
  • Object
show all
Defined in:
lib/generators/decidim/app_generator.rb

Overview

Generates a Rails app and installs decidim to it. Uses the default Rails generator for most of the work.

Remember that, for how generators work, actions are executed based on the definition order of the public methods.

Instance Method Summary collapse

Instance Method Details

#add_ignore_uploadsObject



106
107
108
# File 'lib/generators/decidim/app_generator.rb', line 106

def add_ignore_uploads
  append_file ".gitignore", "\n# Ignore public uploads\npublic/uploads" unless options["skip_git"]
end

#authorization_handlerObject



115
116
117
118
119
# File 'lib/generators/decidim/app_generator.rb', line 115

def authorization_handler
  template "initializer.rb", "config/initializers/decidim.rb"

  template "example_authorization_handler.rb", "app/services/example_authorization_handler.rb" if options[:demo]
end

#cable_ymlObject



78
79
80
# File 'lib/generators/decidim/app_generator.rb', line 78

def cable_yml
  template "cable.yml.erb", "config/cable.yml", force: true
end

#database_ymlObject



65
66
67
# File 'lib/generators/decidim/app_generator.rb', line 65

def database_yml
  template "database.yml.erb", "config/database.yml", force: true
end

#decidim_controllerObject



69
70
71
# File 'lib/generators/decidim/app_generator.rb', line 69

def decidim_controller
  template "decidim_controller.rb.erb", "app/controllers/decidim_controller.rb", force: true
end

#dockerObject



73
74
75
76
# File 'lib/generators/decidim/app_generator.rb', line 73

def docker
  template "Dockerfile.erb", "Dockerfile"
  template "docker-compose.yml.erb", "docker-compose.yml"
end

#gemfileObject



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/generators/decidim/app_generator.rb', line 86

def gemfile
  return if options[:skip_gemfile]

  template path_to_root("Gemfile"), "Gemfile", force: true
  template path_to_root("Gemfile.lock"), "Gemfile.lock", force: true

  gem_modifier = if options[:path]
                   "path: \"#{options[:path]}\""
                 elsif options[:edge]
                   "git: \"https://github.com/decidim/decidim.git\""
                 elsif options[:branch]
                   "git: \"https://github.com/decidim/decidim.git\", branch: \"#{options[:branch]}\""
                 else
                   "\"#{Decidim.version}\""
                 end

  gsub_file "Gemfile", /gem "decidim([^"]*)".*/, "gem \"decidim\\1\", #{gem_modifier}"
  run "BUNDLE_GEMFILE=Gemfile bundle install"
end

#installObject



121
122
123
124
125
126
127
128
129
# File 'lib/generators/decidim/app_generator.rb', line 121

def install
  Decidim::Generators::InstallGenerator.start(
    [
      "--recreate_db=#{options[:recreate_db]}",
      "--seed_db=#{options[:seed_db]}",
      "--app_name=#{app_name}"
    ]
  )
end

#readmeObject



82
83
84
# File 'lib/generators/decidim/app_generator.rb', line 82

def readme
  template "README.md.erb", "README.md", force: true
end

#remove_default_error_pagesObject



110
111
112
113
# File 'lib/generators/decidim/app_generator.rb', line 110

def remove_default_error_pages
  remove_file "public/404.html"
  remove_file "public/500.html"
end

#source_pathsObject



18
19
20
21
22
23
# File 'lib/generators/decidim/app_generator.rb', line 18

def source_paths
  [
    File.expand_path("templates", __dir__),
    Rails::Generators::AppGenerator.source_root
  ]
end