forked from getrailsui/railsui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e4f75ab
commit 6de19c8
Showing
7 changed files
with
153 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require_dependency "railsui/application_controller" | ||
|
||
module Railsui | ||
class DocsController < ApplicationController | ||
def show | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,121 @@ | ||
source_root = File.expand_path('../templates', __FILE__) | ||
|
||
say "Generate StaticController" | ||
generate "controller", "static index --skip-test-framework --skip-assets --skip-helper --skip-routes" | ||
def add_gems | ||
gem 'devise', '~> 4.8', '>= 4.8.1' | ||
gem 'name_of_person' | ||
gem 'sidekiq' | ||
end | ||
|
||
# TODO: Copy content to index view | ||
# Install Devise | ||
def add_users | ||
# Install Devise | ||
generate "devise:install" | ||
|
||
say "Add default RailsUI routing and engine" | ||
content = <<-RUBY | ||
if Rails.env.development? || Rails.env.test? | ||
mount Railsui::Engine, at: "/railsui" | ||
end | ||
# Configure Devise | ||
environment "config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }", | ||
env: 'development' | ||
|
||
scope controller: :static do | ||
# Create Devise User | ||
generate :devise, "User", "first_name", "last_name", "admin:boolean" | ||
|
||
# set admin boolean to false by default | ||
in_root do | ||
migration = Dir.glob("db/migrate/*").max_by{ |f| File.mtime(f) } | ||
gsub_file migration, /:admin/, ":admin, default: false" | ||
end | ||
|
||
root to: "static#index" | ||
RUBY | ||
# name_of_person gem | ||
append_to_file("app/models/user.rb", "\nhas_person_name\n", after: "class User < ApplicationRecord") | ||
end | ||
|
||
# Add active storage and action text | ||
def add_storage_and_rich_text | ||
rails_command "active_storage:install" | ||
rails_command "action_text:install" | ||
end | ||
|
||
# Add sidkiq | ||
def add_sidekiq | ||
environment "config.active_job.queue_adapter = :sidekiq" | ||
|
||
insert_into_file "config/routes.rb", | ||
"require 'sidekiq/web'\n\n", | ||
before: "Rails.application.routes.draw do" | ||
|
||
content = <<-RUBY | ||
authenticate :user, lambda { |u| u.admin? } do | ||
mount Sidekiq::Web => '/sidekiq' | ||
end | ||
RUBY | ||
|
||
insert_into_file "config/routes.rb", "#{content}\n\n", after: "Rails.application.routes.draw do\n" | ||
end | ||
|
||
def add_static_assets | ||
say "⚡️ Generate StaticController" | ||
generate "controller", "static index --skip-test-framework --skip-assets --skip-helper --skip-routes" | ||
|
||
# TODO: Copy content to index view | ||
|
||
insert_into_file "#{Rails.root}/config/routes.rb", "#{content}\n", after: "Rails.application.routes.draw do\n" | ||
say "⚡️ Add default RailsUI routing and engine" | ||
content = <<-RUBY | ||
if Rails.env.development? || Rails.env.test? | ||
mount Railsui::Engine, at: "/railsui" | ||
end | ||
if Rails.root.join("app/views/shared").exist? | ||
say "app/views/shared already exists. Files can't be copied. Refer to the gem source for reference." | ||
else | ||
say "Adding shared partials" | ||
directory "#{__dir__}/shared", Rails.root.join("app/views/shared") | ||
scope controller: :static do | ||
end | ||
root to: "static#index" | ||
RUBY | ||
|
||
insert_into_file "#{Rails.root}/config/routes.rb", "#{content}\n", after: "Rails.application.routes.draw do\n" | ||
end | ||
|
||
if (app_layout_path = Rails.root.join("app/views/layouts/application.html.erb")).exist? | ||
say "Add meta tag partial" | ||
insert_into_file( | ||
app_layout_path.to_s, | ||
%(\n <%= render "shared/meta" %>), | ||
before:/\s*<\/head>/ | ||
) | ||
|
||
say "Add flash and nav partials" | ||
insert_into_file( | ||
app_layout_path.to_s, | ||
%( | ||
<%= render "shared/flash" %> | ||
<%= render "shared/nav" %> | ||
), | ||
after:"<body>" | ||
) | ||
def extend_layout_and_views | ||
if Rails.root.join("app/views/shared").exist? | ||
say "🛑 app/views/shared already exists. Files can't be copied. Refer to the gem source for reference." | ||
else | ||
say "⚡️ Adding shared partials" | ||
directory "#{__dir__}/shared", Rails.root.join("app/views/shared") | ||
end | ||
|
||
if (app_layout_path = Rails.root.join("app/views/layouts/application.html.erb")).exist? | ||
say "⚡️ Add meta tag partial" | ||
insert_into_file( | ||
app_layout_path.to_s, | ||
%(\n <%= render "shared/meta" %>), | ||
before:/\s*<\/head>/ | ||
) | ||
|
||
say "⚡️ Add flash and nav partials" | ||
insert_into_file( | ||
app_layout_path.to_s, | ||
%( | ||
<%= render "shared/flash" %> | ||
<%= render "shared/nav" %> | ||
), | ||
after:"<body>" | ||
) | ||
end | ||
end | ||
|
||
# Add the gems! | ||
add_gems | ||
|
||
run "bundle install" | ||
|
||
add_users | ||
add_storage_and_rich_text | ||
add_static_assets | ||
add_sidekiq | ||
extend_layout_and_views | ||
|
||
# Migrate | ||
rails_command "db:create" | ||
rails_command "db:migrate" | ||
|
||
say | ||
say "Rails UI installation successful! 👍", :green | ||
say "Visit localhost:3000/railsui to configure your app 👩💻", :blue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"> | ||
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"> | ||
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png"> | ||
<link rel="manifest" href="/site.webmanifest"> | ||
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#2d89ef"> | ||
<meta name="msapplication-TileColor" content="#2d89ef"> | ||
<meta name="theme-color" content="#ffffff"> | ||
|
||
<%# | ||
<meta name="twitter:card" content="summary_large_image"> | ||
<meta name="twitter:site" content="@YourAccount"> | ||
<meta name="twitter:creator" content="@YourAccount"> | ||
<meta name="twitter:title" content="Title of your page"> | ||
<meta name="twitter:url" content="URL of your page"> | ||
<meta name="twitter:description" content="Your description here"> | ||
<meta name="twitter:image:src" content="URL of image"> | ||
--> | ||
<!-- Open Graph | ||
<meta property="og:title" content="ENTER PAGE TITLE"> | ||
<meta property="og:type" content="website"> | ||
<meta property="og:url" content="ENTER PAGE URL"> | ||
<meta property="og:image" content="URL OF IMAGE"> | ||
<meta property="og:image:width" content="1240"> | ||
<meta property="og:image:height" content="650"> | ||
<meta property="og:site_name" content="ENTER YOUR SITE NAME"> | ||
<meta property="og:description" content="ENTER YOUR PAGE DESCRIPTION"> | ||
<meta property="fb:app_id" content="ENTER YOUR FB APP ID"> | ||
--> | ||
%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters