Top Level Namespace
Defined Under Namespace
Modules: ApplicationHelper, BootstrapHelper, RailsApp, VCRSetup
Instance Method Summary
collapse
Instance Method Details
#add_binstubs ⇒ Object
144
145
146
147
|
# File 'lib/rails_app/template/template.rb', line 144
def add_binstubs
run "bundle binstub rubocop"
run "bundle binstub rspec-core" if options[:skip_test]
end
|
#add_esbuild_script ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/rails_app/template/template.rb', line 33
def add_esbuild_script
copy_file "esbuild.config.mjs", "esbuild.config.mjs"
build_script = "node esbuild.config.mjs"
case `npx -v`.to_f
when 7.1...8.0
run %(npm set-script build "#{build_script}")
run %(yarn build)
when (8.0..)
run %(npm pkg set scripts.build="#{build_script}")
run %(yarn build)
else
say %(Add "scripts": { "build": "#{build_script}" } to your package.json), :green
end
end
|
#add_gems ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/rails_app/template/template.rb', line 12
def add_gems
gsub_file "Gemfile", /^ruby ['"].*['"]/, "ruby file: '.ruby-version'"
inject_into_file "Gemfile", after: "ruby file: '.ruby-version'" do
"\neval_gemfile 'config/gems/app.rb'"
end
inject_into_file "Gemfile", after: "eval_gemfile 'config/gems/app.rb'" do
"\neval_gemfile 'config/gems/rspec_gemfile.rb'"
end
directory "config", "config", force: true
end
|
#add_javascript ⇒ Object
26
27
28
29
30
31
|
# File 'lib/rails_app/template/template.rb', line 26
def add_javascript
run "yarn add chokidar -D"
run "yarn add esbuild-rails"
run "echo | node -v | cut -c 2- > .node-version"
end
|
#add_static ⇒ Object
83
84
85
86
87
|
# File 'lib/rails_app/template/template.rb', line 83
def add_static
generate "controller static home"
route "root to: 'static#home'"
end
|
#add_styling ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/rails_app/template/template.rb', line 89
def add_styling
if options[:css] == "bootstrap"
directory "app_bootstrap", "app", force: true
elsif options[:css] == "tailwind"
config_tailwind
say "TAILWIND CSS COMING SOON", :red
elsif options[:css] == "bulma"
directory "app_bulma", "app", force: true
elsif options[:css] == "postcss"
directory "app_postcss", "app", force: true
elsif options[:css] == "sass"
directory "app_sass", "app", force: true
end
end
|
#add_template_to_source_path ⇒ Object
8
9
10
|
# File 'lib/rails_app/template/template.rb', line 8
def add_template_to_source_path
source_paths.unshift(File.expand_path(File.join(__dir__)))
end
|
#add_users ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/rails_app/template/template.rb', line 49
def add_users
generate "devise:install"
environment "config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }", env: "development"
environment "config.action_mailer.default_url_options = { host: 'example.com' }", env: "test"
generate :devise, "User", "admin:boolean"
in_root do
migration = Dir.glob("db/migrate/*").max_by { |f| File.mtime(f) }
gsub_file migration, /:admin/, ":admin, default: false"
end
gsub_file "config/initializers/devise.rb", / {2}# config.secret_key = .+/, " config.secret_key = Rails.application.credentials.secret_key_base"
end
|
#command_available?(command) ⇒ Boolean
133
134
135
|
# File 'lib/rails_app/template/template.rb', line 133
def command_available?(command)
system("command -v #{command} >/dev/null 2>&1")
end
|
#config_tailwind ⇒ Object
104
105
106
107
108
109
110
111
|
# File 'lib/rails_app/template/template.rb', line 104
def config_tailwind
run "yarn add flowbite postcss-import postcss-nested"
copy_file "app_tailwind/tailwind.config.js", "tailwind.config.js", force: true
copy_file "app_tailwind/postcss.config.js", "postcss.config.js", force: true
gsub_file "package.json", "tailwindcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css --minify", "tailwindcss --postcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css --minify"
end
|
#copy_templates ⇒ Object
118
119
120
121
122
123
124
125
126
|
# File 'lib/rails_app/template/template.rb', line 118
def copy_templates
copy_file ".rubocop.yml", ".rubocop.yml"
copy_file ".rubocop_todo.yml", ".rubocop_todo.yml"
copy_file "Brewfile", "Brewfile"
directory "bin", "bin", force: true
gsub_file "config/environments/development.rb", / {2}# config.action_view.annotate_rendered_view_with_filenames = true/, " config.action_view.annotate_rendered_view_with_filenames = true"
end
|
#database_setup ⇒ Object
128
129
130
131
|
# File 'lib/rails_app/template/template.rb', line 128
def database_setup
rails_command("db:create")
rails_command("db:migrate")
end
|
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/rails_app/template/template.rb', line 66
def dev_tools
generate "annotate:install"
inject_into_file "config/environments/development.rb", after: "Rails.application.configure do\n" do
<<-CODE
config.after_initialize do
Bullet.enable = true
Bullet.alert = false
Bullet.bullet_logger = true
Bullet.console = true
Bullet.rails_logger = true
Bullet.add_footer = true
end\n
CODE
end
end
|
#initial_commit ⇒ Object
153
154
155
156
|
# File 'lib/rails_app/template/template.rb', line 153
def initial_commit
run "git init"
run "git add . && git commit -m \"Initial_commit\""
end
|
#lint_code ⇒ Object
149
150
151
|
# File 'lib/rails_app/template/template.rb', line 149
def lint_code
run "bundle exec rubocop -a"
end
|
#run_setup ⇒ Object
137
138
139
140
141
142
|
# File 'lib/rails_app/template/template.rb', line 137
def run_setup
if command_available?("brew")
system("brew bundle check --no-lock --no-upgrade") || system!("brew bundle --no-upgrade --no-lock")
end
end
|
#setup_rspec ⇒ Object
113
114
115
116
|
# File 'lib/rails_app/template/template.rb', line 113
def setup_rspec
copy_file ".rspec", ".rspec"
directory "spec", "spec", force: true
end
|