Skip to content

Commit

Permalink
Add more indepth install task
Browse files Browse the repository at this point in the history
  • Loading branch information
justalever committed Feb 23, 2022
1 parent e4f75ab commit 6de19c8
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 42 deletions.
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ GEM
nio4r (2.5.8)
nokogiri (1.13.2-arm64-darwin)
racc (~> 1.4)
nokogiri (1.13.2-x86_64-darwin)
racc (~> 1.4)
parallel (1.21.0)
parser (3.1.0.0)
ast (~> 2.4.1)
Expand Down Expand Up @@ -187,6 +189,7 @@ GEM

PLATFORMS
arm64-darwin-21
x86_64-darwin-20

DEPENDENCIES
cssbundling-rails
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/railsui/docs_controller.rb
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
4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Railsui::Engine.routes.draw do
resource :admin, only: :show
resource :configuration, only: :create
resource :docs, only: :show

resource :docs do
namespace :docs do
get :installation
get :configuration
get :upgrading
end

root to: "admin#show"
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/railsui/generator_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def bulma?
options['c'] == "bulma"
end

def no_?
def none?
!options['c'] || options['c'] == nil
end
end
Expand Down
142 changes: 108 additions & 34 deletions lib/install/install.rb
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
31 changes: 31 additions & 0 deletions lib/install/shared/_meta.html.erb
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">

<%#
<!-- Twitter
<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">
-->
%>
5 changes: 0 additions & 5 deletions lib/railsui.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ module Railsui
mattr_accessor :config
@@config = {}

def self.save_preferences
set_framework
install_pages_and_content
end

def self.restart
run_command "rails restart"
end
Expand Down

0 comments on commit 6de19c8

Please sign in to comment.