Class: Decidim::Generators::AppGenerator

Inherits:
Rails::Generators::AppGenerator
  • Object
show all
Defined in:
lib/decidim/generators/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



136
137
138
# File 'lib/decidim/generators/app_generator.rb', line 136

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

#authorization_handlerObject



145
146
147
148
149
150
151
152
153
# File 'lib/decidim/generators/app_generator.rb', line 145

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

  if options[:demo]
    copy_file "dummy_authorization_handler.rb", "app/services/dummy_authorization_handler.rb"
    copy_file "another_dummy_authorization_handler.rb", "app/services/another_dummy_authorization_handler.rb"
    copy_file "verifications_initializer.rb", "config/initializers/decidim_verifications.rb"
  end
end

#cable_ymlObject



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

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

#database_ymlObject



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

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

#decidim_controllerObject



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

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

#dockerObject



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

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

#gemfileObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/decidim/generators/app_generator.rb', line 85

def gemfile
  return if options[:skip_gemfile]

  copy_file target_gemfile, "Gemfile", force: true
  copy_file "#{target_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::Generators.version}\""
                 end

  gsub_file "Gemfile", /gem "#{current_gem}".*/, "gem \"#{current_gem}\", #{gem_modifier}"

  if current_gem == "decidim"
    gsub_file "Gemfile", /gem "decidim-dev".*/, "gem \"decidim-dev\", #{gem_modifier}"

    if options[:demo]
      gsub_file "Gemfile", /gem "decidim-consultations".*/, "gem \"decidim-consultations\", #{gem_modifier}"
      gsub_file "Gemfile", /gem "decidim-initiatives".*/, "gem \"decidim-initiatives\", #{gem_modifier}"
    else
      gsub_file "Gemfile", /gem "decidim-consultations".*/, "# gem \"decidim-consultations\", #{gem_modifier}"
      gsub_file "Gemfile", /gem "decidim-initiatives".*/, "# gem \"decidim-initiatives\", #{gem_modifier}"
    end
  end

  run "bundle install"
end

#installObject



155
156
157
158
159
160
161
162
163
164
# File 'lib/decidim/generators/app_generator.rb', line 155

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

#readmeObject



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

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

#remove_default_error_pagesObject



140
141
142
143
# File 'lib/decidim/generators/app_generator.rb', line 140

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

#source_pathsObject



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

def source_paths
  [
    self.class.source_root,
    Rails::Generators::AppGenerator.source_root
  ]
end

#tweak_bootsnapObject



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/decidim/generators/app_generator.rb', line 118

def tweak_bootsnap
  gsub_file "config/boot.rb", %r{require 'bootsnap/setup'.*$}, <<~RUBY.rstrip
    require "bootsnap"

    env = ENV["RAILS_ENV"] || "development"

    Bootsnap.setup(
      cache_dir: File.expand_path(File.join("..", "tmp", "cache"), __dir__),
      development_mode: env == "development",
      load_path_cache: true,
      autoload_paths_cache: true,
      disable_trace: true,
      compile_cache_iseq: false,
      compile_cache_yaml: true
    )
  RUBY
end