Skip to content

Commit

Permalink
Instalar Tailwind y scaffold de workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
KattyaCuevas committed Jul 23, 2022
1 parent d665459 commit 4a4fda6
Show file tree
Hide file tree
Showing 23 changed files with 300 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@

# Ignore master key for decrypting credentials and more.
/config/master.key

/app/assets/builds/*
!/app/assets/builds/.keep
2 changes: 2 additions & 0 deletions Procfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
web: bin/rails server -p 3000
css: bin/rails tailwindcss:watch
Empty file added app/assets/builds/.keep
Empty file.
1 change: 1 addition & 0 deletions app/assets/config/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
//= link_directory ../stylesheets .css
//= link_tree ../../javascript .js
//= link_tree ../../../vendor/javascript .js
//= link_tree ../builds
13 changes: 13 additions & 0 deletions app/assets/stylesheets/application.tailwind.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

/*
@layer components {
.btn-primary {
@apply py-2 px-4 bg-blue-200;
}
}
*/
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
class ApplicationController < ActionController::Base
before_action :authenticate_user!
end
70 changes: 70 additions & 0 deletions app/controllers/workspaces_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
class WorkspacesController < ApplicationController
before_action :set_workspace, only: %i[ show edit update destroy ]

# GET /workspaces or /workspaces.json
def index
@workspaces = Workspace.all
end

# GET /workspaces/1 or /workspaces/1.json
def show
end

# GET /workspaces/new
def new
@workspace = Workspace.new
end

# GET /workspaces/1/edit
def edit
end

# POST /workspaces or /workspaces.json
def create
@workspace = Workspace.new(workspace_params)

respond_to do |format|
if @workspace.save
format.html { redirect_to workspace_url(@workspace), notice: "Workspace was successfully created." }
format.json { render :show, status: :created, location: @workspace }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @workspace.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /workspaces/1 or /workspaces/1.json
def update
respond_to do |format|
if @workspace.update(workspace_params)
format.html { redirect_to workspace_url(@workspace), notice: "Workspace was successfully updated." }
format.json { render :show, status: :ok, location: @workspace }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @workspace.errors, status: :unprocessable_entity }
end
end
end

# DELETE /workspaces/1 or /workspaces/1.json
def destroy
@workspace.destroy

respond_to do |format|
format.html { redirect_to workspaces_url, notice: "Workspace was successfully destroyed." }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_workspace
@workspace = Workspace.find(params[:id])
end

# Only allow a list of trusted parameters through.
def workspace_params
params.require(:workspace).permit(:title)
end
end
2 changes: 2 additions & 0 deletions app/helpers/workspaces_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module WorkspacesHelper
end
3 changes: 2 additions & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
<meta name="viewport" content="width=device-width,initial-scale=1">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag "tailwind", "inter-font", "data-turbo-track": "reload" %>

<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
<%= javascript_importmap_tags %>
</head>

<body>
<body class="container mx-auto">
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
<%= yield %>
Expand Down
22 changes: 22 additions & 0 deletions app/views/workspaces/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<%= form_with(model: workspace, class: "contents") do |form| %>
<% if workspace.errors.any? %>
<div id="error_explanation" class="bg-red-50 text-red-500 px-3 py-2 font-medium rounded-lg mt-3">
<h2><%= pluralize(workspace.errors.count, "error") %> prohibited this workspace from being saved:</h2>

<ul>
<% workspace.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="my-5">
<%= form.label :title %>
<%= form.text_field :title, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %>
</div>

<div class="inline">
<%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %>
</div>
<% end %>
12 changes: 12 additions & 0 deletions app/views/workspaces/_workspace.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div id="<%= dom_id workspace %>">
<p class="my-5">
<strong class="block font-medium mb-1">Title:</strong>
<%= workspace.title %>
</p>

<% if action_name != "show" %>
<%= link_to "Show this workspace", workspace, class: "rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
<%= link_to 'Edit this workspace', edit_workspace_path(workspace), class: "rounded-lg py-3 ml-2 px-5 bg-gray-100 inline-block font-medium" %>
<hr class="mt-6">
<% end %>
</div>
2 changes: 2 additions & 0 deletions app/views/workspaces/_workspace.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! workspace, :id, :title, :created_at, :updated_at
json.url workspace_url(workspace, format: :json)
8 changes: 8 additions & 0 deletions app/views/workspaces/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="mx-auto md:w-2/3 w-full">
<h1 class="font-bold text-4xl">Editing workspace</h1>

<%= render "form", workspace: @workspace %>

<%= link_to "Show this workspace", @workspace, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
<%= link_to "Back to workspaces", workspaces_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
</div>
14 changes: 14 additions & 0 deletions app/views/workspaces/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="w-full">
<% if notice.present? %>
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%= notice %></p>
<% end %>

<div class="flex justify-between items-center">
<h1 class="font-bold text-4xl">Workspaces</h1>
<%= link_to 'New workspace', new_workspace_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %>
</div>

<div id="workspaces" class="min-w-full">
<%= render @workspaces %>
</div>
</div>
1 change: 1 addition & 0 deletions app/views/workspaces/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.array! @workspaces, partial: "workspaces/workspace", as: :workspace
7 changes: 7 additions & 0 deletions app/views/workspaces/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="mx-auto md:w-2/3 w-full">
<h1 class="font-bold text-4xl">New workspace</h1>

<%= render "form", workspace: @workspace %>

<%= link_to 'Back to workspaces', workspaces_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
</div>
15 changes: 15 additions & 0 deletions app/views/workspaces/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="mx-auto md:w-2/3 w-full flex">
<div class="mx-auto">
<% if notice.present? %>
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%= notice %></p>
<% end %>

<%= render @workspace %>

<%= link_to 'Edit this workspace', edit_workspace_path(@workspace), class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
<div class="inline-block ml-2">
<%= button_to 'Destroy this workspace', workspace_path(@workspace), method: :delete, class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium" %>
</div>
<%= link_to 'Back to workspaces', workspaces_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
</div>
</div>
1 change: 1 addition & 0 deletions app/views/workspaces/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.partial! "workspaces/workspace", workspace: @workspace
9 changes: 9 additions & 0 deletions bin/dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

if ! command -v foreman &> /dev/null
then
echo "Installing foreman..."
gem install foreman
fi

foreman start -f Procfile.dev
6 changes: 4 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
Rails.application.routes.draw do
devise_for :users
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html

# Defines the root path route ("/")
# root "articles#index"
root "workspaces#index"
resources :workspaces
resources :users
end
22 changes: 22 additions & 0 deletions config/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const defaultTheme = require('tailwindcss/defaultTheme')

module.exports = {
content: [
'./public/*.html',
'./app/helpers/**/*.rb',
'./app/javascript/**/*.js',
'./app/views/**/*.{erb,haml,html,slim}'
],
theme: {
extend: {
fontFamily: {
sans: ['Inter var', ...defaultTheme.fontFamily.sans],
},
},
},
plugins: [
require('@tailwindcss/forms'),
require('@tailwindcss/aspect-ratio'),
require('@tailwindcss/typography'),
]
}
48 changes: 48 additions & 0 deletions test/controllers/workspaces_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require "test_helper"

class WorkspacesControllerTest < ActionDispatch::IntegrationTest
setup do
@workspace = workspaces(:one)
end

test "should get index" do
get workspaces_url
assert_response :success
end

test "should get new" do
get new_workspace_url
assert_response :success
end

test "should create workspace" do
assert_difference("Workspace.count") do
post workspaces_url, params: { workspace: { title: @workspace.title } }
end

assert_redirected_to workspace_url(Workspace.last)
end

test "should show workspace" do
get workspace_url(@workspace)
assert_response :success
end

test "should get edit" do
get edit_workspace_url(@workspace)
assert_response :success
end

test "should update workspace" do
patch workspace_url(@workspace), params: { workspace: { title: @workspace.title } }
assert_redirected_to workspace_url(@workspace)
end

test "should destroy workspace" do
assert_difference("Workspace.count", -1) do
delete workspace_url(@workspace)
end

assert_redirected_to workspaces_url
end
end
41 changes: 41 additions & 0 deletions test/system/workspaces_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require "application_system_test_case"

class WorkspacesTest < ApplicationSystemTestCase
setup do
@workspace = workspaces(:one)
end

test "visiting the index" do
visit workspaces_url
assert_selector "h1", text: "Workspaces"
end

test "should create workspace" do
visit workspaces_url
click_on "New workspace"

fill_in "Title", with: @workspace.title
click_on "Create Workspace"

assert_text "Workspace was successfully created"
click_on "Back"
end

test "should update Workspace" do
visit workspace_url(@workspace)
click_on "Edit this workspace", match: :first

fill_in "Title", with: @workspace.title
click_on "Update Workspace"

assert_text "Workspace was successfully updated"
click_on "Back"
end

test "should destroy Workspace" do
visit workspace_url(@workspace)
click_on "Destroy this workspace", match: :first

assert_text "Workspace was successfully destroyed"
end
end

0 comments on commit 4a4fda6

Please sign in to comment.