-
Notifications
You must be signed in to change notification settings - Fork 2
/
minimal.rb
642 lines (549 loc) · 16.7 KB
/
minimal.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
74
75
76
77
78
79
80
81
82
83
84
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
def add_gems
<<-RUBY
source 'https://rubygems.org'
ruby '#{RUBY_VERSION}'
#{"gem 'bootsnap', require: false" if Rails.version >= "5.2"}
gem 'devise'
gem 'jbuilder', '~> 2.0'
gem 'pg', '~> 0.21'
gem 'puma'
gem 'rails', '#{Rails.version}'
gem 'redis'
gem 'autoprefixer-rails'
gem 'font-awesome-sass', '~> 5.6.1'
gem 'sassc-rails'
gem 'simple_form'
gem 'uglifier'
gem 'webpacker'
gem 'slim'
group :development do
gem 'rails-erd'
gem 'web-console', '>= 3.3.0'
end
group :development, :test do
gem 'pry-byebug'
gem 'pry-rails'
gem 'listen', '~> 3.0.5'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'dotenv-rails'
end
RUBY
end
def add_layout
<<-HTML
<!DOCTYPE html>
<html>
<head>
<%= render "layouts/google_analytics" %>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title><%= meta_title %></title>
<meta name="description" content="<%= meta_description %>">
<!-- Facebook Open Graph data -->
<meta property="og:title" content="<%= meta_title %>" />
<meta property="og:type" content="website" />
<meta property="og:url" content="<%= request.original_url %>" />
<meta property="og:image" content="<%= meta_image %>" />
<meta property="og:description" content="<%= meta_description %>" />
<meta property="og:site_name" content="<%= meta_title %>" />
<%= yield(:robots) %>
<%= csrf_meta_tags %>
<%= action_cable_meta_tag %>
<%= stylesheet_link_tag 'application', media: 'all' %>
<%#= stylesheet_pack_tag 'application', media: 'all' %> <!-- Uncomment if you import CSS in app/javascript/packs/application.js -->
</head>
<body>
<%= render 'shared/navbar' %>
<%= render 'shared/flashes' %>
<%= yield %>
#{" <%= javascript_include_tag 'application' %>\n" if Rails.version < "6"}
<%= javascript_pack_tag 'application' %>
<%= render 'shared/footer' %>
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Organization",
"name": "yourdomain",
"url": "https://www.yourdomain.com/",
"logo": "",
"contactPoint": [{
"@type": "ContactPoint",
"url": "https://www.yourdomain.com",
"email": "[email protected]",
"telephone": "+33-30000000",
"contactType": "customer service"
}],
"image": "",
"description": ""
}
</script>
</body>
</html>
HTML
end
def add_pages_home
<<-HTML
<%= content_for :meta_title, "Yourdomain - Your Meta" %>
<div class="container page-min-height">
<h1>Pages#Home</h1>
<p>Find me in app/views/pages/home.html.erb</p>
</div>
HTML
end
def add_pages_legal
<<-HTML
<% content_for(:robots) do %>
<meta name="robots" content='noindex, nofollow'>
<% end %>
<div class="container page-min-height">
<h1>Pages#Legal</h1>
<p>Find me in app/views/pages/legal.html.erb</p>
</div>
HTML
end
def update_error_page(var)
<<-HTML
<!DOCTYPE html>
<html>
<head>
<title> Yourdomain - Erreur</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta charset="UTF-8">
<style>
body {
background-color: white;
color: #2E2F30;
text-align: center;
font-family: arial, sans-serif;
margin: 20px;
}
.banner-logo img {
max-width: 90%;
}
.container {
margin: 40px auto;
}
h1 {
font-size: 32px;
margin: 0px;
}
p {
font-size: 20px;
}
.link_mail_to {
text-decoration: none;
color: #2e2f30ad;
}
.link_mail_to:hover {
text-decoration: none;
color: #2E2F30;
}
.button-green {
border-radius: 2px;
margin: 20px 0px;
text-decoration: none;
padding: 10px 41px;
color: white;
background-color: #888485;
font-weight: lighter;
}
.button-green:hover {
text-decoration: none;
background-color: #a7a4a5;
}
</style>
</head>
<body class="rails-default-error-page">
<!-- This file lives in public/500.html -->
<div class="banner-logo">
<img src="logo.png" alt="logo">
</div>
<div class="container">
<h1>
Page d'erreur
</h1>
<p>
Une erreur est revenue. <br> Veuillez nous excuser pour la gêne occasionée.
</p>
<p>
N'hésitez pas à retourner sur la page précédente et à réessayer.
</p>
<p>
<a class="link_mail_to" href="mailto:[email protected]">Reporter le probléme</a>
</p>
</div>
<div class="container">
<a class="button-green" href="/">Retour sur le site</a>
</div>
</body>
</html>
HTML
end
def add_navbar
<<-HTML
<div class="navbar-mihivai">
<!-- Logo -->
<a href="/" class="navbar-mihivai-brand">
<%= image_tag "logo.png" %>
</a>
<div class="d-none d-md-block">
<div class="d-flex align-items-center justify-content-between">
<%= link_to "Notre Activité", "#", class: "navbar-mihivai-item navbar-mihivai-link" %>
<%= link_to "Nos Services", "/", class: "navbar-mihivai-item navbar-mihivai-link" %>
<%= link_to "Contact", "/", class: "navbar-mihivai-item navbar-mihivai-link" %>
<% if user_signed_in? %>
<%= link_to t(".sign_out", default: "Log out"), destroy_user_session_path, method: :delete , class: "navbar-mihivai-item navbar-mihivai-link"%>
<% else %>
<%= link_to t(".sign_in", default: "Login"), new_user_session_path , class: "navbar-mihivai-item navbar-mihivai-link"%>
<% end %>
</div>
</div>
<div class="d-block d-md-none">
<div class="navbar-dropdown">
<input id="toggle" type="checkbox"/>
<label class="hamburger" for="toggle">
<div class="top"></div>
<div class="meat"></div>
<div class="bottom"></div>
</label>
<div class="nav">
<div class="nav-wrapper">
<nav class= "d-flex flex-column">
<%= link_to "Accueil", root_path, class: "navbar-link" %>
<% if user_signed_in? %>
<%= link_to "Se Déconnecter", destroy_user_session_path, class: "navbar-link", method: :delete %>
<% else %>
<%= link_to "Créer un Compte", new_user_registration_path, class: "navbar-link" %>
<%= link_to "Se Connecter", new_user_session_path, class: "navbar-link" %>
<% end %>
</nav>
</div>
</div>
</div>
</div>
</div>
<div style="height: 70px;"></div>
HTML
end
def add_footer
<<-HTML
<div class="footer d-flex justify-content-between align-items-center">
<div class="footer-links">
</div>
<div class="footer-copyright d-flex flex-column">
© 2018 Your Domain
<%= link_to legal_path do %>
Mentions légales
<% end %>
<%= link_to "https://www.mihivai.com/", target: "_blank" do %>
Site réalisé par Mihivai
<% end %>
</div>
</div>
HTML
end
def add_flash
<<-HTML
<% if notice %>
<div class="alert alert-info alert-dismissible fade show m-1" role="alert">
<%= notice %>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<% end %>
<% if alert %>
<div class="alert alert-warning alert-dismissible fade show m-1" role="alert">
<%= alert %>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<% end %>
HTML
end
def add_google_analytics
<<-HTML
<% if Rails.env == "production" %>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=<%= ENV['GOOGLE_ANALYTICS_KEY'] %>"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', "<%= ENV['GOOGLE_ANALYTICS_KEY'] %>");
</script>
<% end %>
HTML
end
run "if uname | grep -q 'Darwin'; then pgrep spring | xargs kill -9; fi"
# GEMFILE
########################################
run 'rm Gemfile'
file 'Gemfile',
add_gems
# Procfile
########################################
file 'Procfile', <<-YAML
web: bundle exec puma -C config/puma.rb
YAML
# Assets
########################################
run 'rm -rf app/assets/stylesheets'
run 'rm -rf vendor'
file 'app/assets/stylesheets/layouts/_index.scss', <<-CSS
// Import your layouts CSS files here.
// Examples:
// @import "dashboard";
// @import "profile";
// @import "map";
CSS
file 'app/assets/stylesheets/components/_alert.scss', <<-CSS
/* -------------------------------------
* Your CSS code for flash notices and alerts
* ------------------------------------- */
.alert {
position: fixed;
bottom: 16px;
right: 16px;
z-index: 1000;
}
.alert-info {
background: #32B796;
}
.alert-warning {
background: #EE5F5B;
}
CSS
run 'curl -L https://raw.githubusercontent.com/ClaudineP435433/rails-template-mihivai-rails6/master/navbar-mihivai.scss > app/assets/stylesheets/components/_navbar.scss'
run 'curl -L https://raw.githubusercontent.com/ClaudineP435433/rails-template-mihivai-rails6/master/footer-mihivai.scss > app/assets/stylesheets/components/_footer.scss'
file 'app/assets/stylesheets/components/_utilities.scss', <<-CSS
.page-min-height {
min-height: calc(100vh - 170px)
}
CSS
file 'app/assets/stylesheets/components/_index.scss', <<-CSS
@import "alert";
@import 'footer';
@import 'navbar';
@import 'utilities';
CSS
file 'app/assets/stylesheets/config/_fonts.scss', <<-CSS
// Import Google fonts
@import url("https://fonts.googleapis.com/css?family=Open+Sans:400,300,700|Raleway:400,100,300,700,500");
CSS
file 'app/assets/stylesheets/config/_colors.scss', <<-CSS
CSS
file 'app/assets/stylesheets/config/_bootstrap_variables.scss', <<-CSS
CSS
file 'app/assets/stylesheets/application.scss', <<-JS
// Graphical variables
@import "config/fonts";
@import "config/colors";
@import "config/bootstrap_variables";
// External libraries
@import "bootstrap/scss/bootstrap";
// @import "font-awesome-sprockets";
// @import "font-awesome";
// Your CSS partials
@import "layouts/index";
@import "components/index";
//@import "pages/index";
JS
if Rails.version < "6"
run 'rm app/assets/javascripts/application.js'
file 'app/assets/javascripts/application.js', <<-JS
//= require rails-ujs
//= require_tree .
JS
end
# Dev environment
########################################
gsub_file('config/environments/development.rb', /config\.assets\.debug.*/, 'config.assets.debug = false')
# Layout
########################################
file 'app/views/layouts/_google_analytics.html.erb',
add_google_analytics
run 'rm app/views/layouts/application.html.erb'
file 'app/views/layouts/application.html.erb',
add_layout
file 'app/views/shared/_footer.html.erb',
add_footer
run 'rm public/500.html'
file 'public/500.html',
update_error_page(500)
run 'rm public/404.html'
file 'public/404.html',
update_error_page(404)
run 'rm public/422.html'
file 'public/422.html',
update_error_page(422)
file 'app/views/shared/_navbar.html.erb',
add_navbar
file 'app/views/shared/_flashes.html.erb',
add_flash
# run 'curl -L https://github.com/lewagon/awesome-navbars/raw/master/templates/_navbar_wagon.html.erb > app/views/shared/_navbar.html.erb'
# run 'curl -L https://raw.githubusercontent.com/lewagon/rails-templates/master/logo.png > app/assets/images/logo.png'
run 'curl -L https://raw.githubusercontent.com/ClaudineP435433/rails-template-mihivai-rails6/master/logo.png > app/assets/images/logo.png'
run 'curl -L https://raw.githubusercontent.com/ClaudineP435433/rails-template-mihivai-rails6/master/logo.png > public/logo.png'
# README
########################################
markdown_file_content = <<-MARKDOWN
Rails app generated with MihiVai template.
MARKDOWN
file 'README.md', markdown_file_content, force: true
# Generators
########################################
generators = <<-RUBY
config.generators do |generate|
generate.assets false
generate.helper false
generate.test_framework :test_unit, fixture: false
end
RUBY
environment generators
########################################
# AFTER BUNDLE
########################################
after_bundle do
# Generators: db + simple form + pages controller
########################################
rails_command 'db:drop db:create db:migrate'
generate('simple_form:install', '--bootstrap')
generate(:controller, 'pages', 'home', '--skip-routes', '--no-test-framework')
# Routes
########################################
route "root to: 'pages#home'"
route "get '/legal', to: 'pages#legal', as: 'legal'"
# Git ignore
########################################
append_file '.gitignore', <<-TXT
# Ignore .env file containing credentials.
.env*
# Ignore Mac and Linux file system files
*.swp
.DS_Store
.bundle
log/*.log
tmp/**/*
tmp/*
!log/.keep
!tmp/.keep
public/assets
public/packs
public/packs-test
node_modules
yarn-error.log
.byebug_history
TXT
# Devise install + user
########################################
generate('devise:install')
generate('devise', 'User')
# App controller
########################################
run 'rm app/controllers/application_controller.rb'
file 'app/controllers/application_controller.rb', <<-RUBY
class ApplicationController < ActionController::Base
#{" protect_from_forgery with: :exception\n" if Rails.version < "5.2"} before_action :authenticate_user!
def default_url_options
{ host: ENV["DOMAIN"] || "localhost:3000" }
end
end
RUBY
# migrate + devise views
########################################
rails_command 'db:migrate'
generate('devise:views')
# Pages Controller
########################################
run 'rm app/controllers/pages_controller.rb'
file 'app/controllers/pages_controller.rb', <<-RUBY
class PagesController < ApplicationController
skip_before_action :authenticate_user!, only: [:home, :legal]
def home
end
def legal
end
end
RUBY
file 'app/views/pages/legal.html.erb',
add_pages_legal
run 'rm app/views/pages/home.html.erb'
file 'app/views/pages/home.html.erb',
add_pages_home
# Creation des Meta
########################################
file 'config/meta.yml', <<-YAML
meta_product_name: "Product Name"
meta_title: "Product name - Product tagline"
meta_description: "Relevant description"
meta_image: "logo.png" # should exist in `app/assets/images/`
YAML
file 'config/initializers/default_meta.rb', <<-RUBY
DEFAULT_META = YAML.load_file(Rails.root.join("config/meta.yml"))
RUBY
file 'app/helpers/meta_tags_helper.rb', <<-RUBY
module MetaTagsHelper
def meta_title
content_for?(:meta_title) ? content_for(:meta_title) : DEFAULT_META["meta_title"]
end
def meta_description
content_for?(:meta_description) ? content_for(:meta_description) : DEFAULT_META["meta_description"]
end
def meta_image
meta_image = (content_for?(:meta_image) ? content_for(:meta_image) : DEFAULT_META["meta_image"])
# little twist to make it work equally with an asset or a url
meta_image.starts_with?("http") ? meta_image : image_url(meta_image)
end
# def meta_keywords
# content_for?(:meta_keywords) ? content_for(:meta_keywords) : DEFAULT_META["meta_keywords"]
# end
end
RUBY
# Environments
########################################
environment 'config.action_mailer.default_url_options = { host: "http://localhost:3000" }', env: 'development'
environment 'config.action_mailer.default_url_options = { host: "http://TODO_PUT_YOUR_DOMAIN_HERE" }', env: 'production'
# Webpacker / Yarn
########################################
run 'rm app/javascript/packs/application.js'
run 'yarn add popper.js jquery bootstrap'
file 'app/javascript/packs/application.js', <<-JS
import "bootstrap";
JS
if Rails.version >= "6"
prepend_file 'app/javascript/packs/application.js', <<-JS
require("@rails/ujs").start()
require("@rails/activestorage").start()
require("channels")
JS
end
inject_into_file 'config/webpack/environment.js', before: 'module.exports' do
<<-JS
const webpack = require('webpack')
// Preventing Babel from transpiling NodeModules packages
environment.loaders.delete('nodeModules');
// Bootstrap 4 has a dependency over jQuery & Popper.js:
environment.plugins.prepend('Provide',
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
Popper: ['popper.js', 'default']
})
)
JS
end
# Dotenv
########################################
run 'touch .env'
# Rubocop
########################################
# run 'curl -L https://raw.githubusercontent.com/lewagon/rails-templates/master/.rubocop.yml > .rubocop.yml'
# Git
########################################
git :init
git add: '.'
git commit: "-m 'Initial commit with devise template from Mihivai'"
end