-
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.
Instalar Tailwind y scaffold de workspaces
- Loading branch information
1 parent
d665459
commit 4a4fda6
Showing
23 changed files
with
300 additions
and
3 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,2 @@ | ||
web: bin/rails server -p 3000 | ||
css: bin/rails tailwindcss:watch |
Empty file.
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,13 @@ | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; | ||
|
||
/* | ||
@layer components { | ||
.btn-primary { | ||
@apply py-2 px-4 bg-blue-200; | ||
} | ||
} | ||
*/ |
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,2 +1,3 @@ | ||
class ApplicationController < ActionController::Base | ||
before_action :authenticate_user! | ||
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
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 |
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,2 @@ | ||
module WorkspacesHelper | ||
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
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 %> |
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,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> |
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,2 @@ | ||
json.extract! workspace, :id, :title, :created_at, :updated_at | ||
json.url workspace_url(workspace, format: :json) |
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 @@ | ||
<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> |
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,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> |
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 @@ | ||
json.array! @workspaces, partial: "workspaces/workspace", as: :workspace |
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,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> |
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,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> |
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 @@ | ||
json.partial! "workspaces/workspace", workspace: @workspace |
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,9 @@ | ||
#!/usr/bin/env bash | ||
|
||
if ! command -v foreman &> /dev/null | ||
then | ||
echo "Installing foreman..." | ||
gem install foreman | ||
fi | ||
|
||
foreman start -f Procfile.dev |
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,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 |
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,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'), | ||
] | ||
} |
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,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 |
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,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 |