Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
class ProjectsController < ApplicationController
allow_unauthenticated_access only: %i[ index ]

def index
@projects = Project.by_year
end

def new
@project = Project.new
end

def create
@project = Project.new(project_params)
if @project.save
redirect_to projects_url, notice: "Project was successfully created."
else
render :new, status: :unprocessable_content
end
end

def edit
@project = Project.find(params[:id])
end

def update
@project = Project.find(params[:id])
if @project.update(project_params)
redirect_to projects_url, notice: "Project was successfully updated."
else
render :edit, status: :unprocessable_content
end
end

def destroy
@project = Project.find(params[:id])
@project.destroy
redirect_to projects_url, notice: "Project was successfully destroyed."
end

private

def project_params
params.expect(project: [ :name, :year, :github_url, :license, :language, :description ])
end
end
5 changes: 5 additions & 0 deletions app/models/project.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Project < ApplicationRecord
validates :name, presence: true

scope :by_year, -> { order(year: :desc) }
end
37 changes: 37 additions & 0 deletions app/views/projects/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<%= form_with model: project, class: "space-y-6", url: project.persisted? ? project_url(project) : projects_url do |form| %>
<%= render "shared/form_errors", object: project %>

<div class="space-y-2">
<%= form.label :name, class: "block text-sm font-medium text-gray-700 dark:text-gray-200" %>
<%= form.text_field :name, class: "mt-1 block w-full rounded-md border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-gray-900 dark:text-white shadow-xs focus:border-indigo-500 focus:ring-indigo-500" %>
</div>

<div class="space-y-2">
<%= form.label :year, class: "block text-sm font-medium text-gray-700 dark:text-gray-200" %>
<%= form.number_field :year, class: "mt-1 block w-full rounded-md border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-gray-900 dark:text-white shadow-xs focus:border-indigo-500 focus:ring-indigo-500" %>
</div>

<div class="space-y-2">
<%= form.label :github_url, class: "block text-sm font-medium text-gray-700 dark:text-gray-200" %>
<%= form.text_field :github_url, class: "mt-1 block w-full rounded-md border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-gray-900 dark:text-white shadow-xs focus:border-indigo-500 focus:ring-indigo-500" %>
</div>

<div class="space-y-2">
<%= form.label :license, class: "block text-sm font-medium text-gray-700 dark:text-gray-200" %>
<%= form.text_field :license, class: "mt-1 block w-full rounded-md border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-gray-900 dark:text-white shadow-xs focus:border-indigo-500 focus:ring-indigo-500" %>
</div>

<div class="space-y-2">
<%= form.label :language, class: "block text-sm font-medium text-gray-700 dark:text-gray-200" %>
<%= form.text_field :language, class: "mt-1 block w-full rounded-md border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-gray-900 dark:text-white shadow-xs focus:border-indigo-500 focus:ring-indigo-500" %>
</div>

<div class="space-y-2">
<%= form.label :description, class: "block text-sm font-medium text-gray-700 dark:text-gray-200" %>
<%= form.text_area :description, rows: 3, class: "mt-1 block w-full rounded-md border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-gray-900 dark:text-white shadow-xs focus:border-indigo-500 focus:ring-indigo-500" %>
</div>

<div>
<%= form.submit class: "rounded-md bg-indigo-600 px-4 py-2 text-sm font-semibold text-white shadow-xs hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600" %>
</div>
<% end %>
41 changes: 41 additions & 0 deletions app/views/projects/_project.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<div class="border-b border-gray-200 dark:border-gray-700 py-6">
<div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2 mb-2">
<h3 class="text-lg font-semibold text-gray-900 dark:text-white">
<%= link_to project.name, project.github_url, target: "_blank", rel: "noopener noreferrer",
class: "text-blue-600 dark:text-blue-400 hover:text-blue-800 dark:hover:text-blue-300" %>
</h3>
<div class="flex items-center gap-3 text-sm text-gray-500 dark:text-gray-400">
<% if project.year.present? %>
<span><%= project.year %></span>
<% end %>
<% if project.language.present? %>
<span class="rounded-full bg-gray-100 dark:bg-gray-700 px-2 py-0.5 text-xs font-medium text-gray-700 dark:text-gray-300">
<%= project.language %>
</span>
<% end %>
<% if project.license.present? %>
<span class="rounded-full bg-gray-100 dark:bg-gray-700 px-2 py-0.5 text-xs font-medium text-gray-700 dark:text-gray-300">
<%= project.license %>
</span>
<% end %>
<% if project.github_url.present? %>
<%= link_to project.github_url, target: "_blank", rel: "noopener noreferrer",
class: "text-gray-400 hover:text-gray-600 dark:hover:text-gray-300" do %>
<svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24" aria-hidden="true">
<path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"/>
</svg>
<% end %>
<% end %>
</div>
</div>
<% if project.description.present? %>
<p class="text-gray-600 dark:text-gray-300 text-sm">
<%= project.description %>
</p>
<% end %>
<% if authenticated? %>
<div class="mt-2">
<%= link_to "Edit", edit_project_path(project), class: "text-sm text-gray-400 hover:text-gray-600 dark:hover:text-gray-300" %>
</div>
<% end %>
</div>
3 changes: 3 additions & 0 deletions app/views/projects/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1 class="text-3xl font-bold text-gray-900 dark:text-white mb-6">Editing Project</h1>
<%= button_to "Delete", @project, method: :delete, data: { turbo_confirm: "Are you sure?" }, class: "rounded-md bg-indigo-600 px-4 py-2 text-sm font-semibold text-white shadow-xs hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600 mb-6" %>
<%= render "form", project: @project %>
17 changes: 17 additions & 0 deletions app/views/projects/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<% content_for :title do %>
Projects | <%= Rails.application.config.site_name %>
<% end %>

<article class="max-w-2xl mx-auto">
<header class="mb-8">
<h1 class="text-3xl md:text-4xl font-bold text-gray-900 dark:text-white mb-4">Projects</h1>
</header>

<% if @projects.any? %>
<div>
<%= render @projects %>
</div>
<% else %>
<p class="text-gray-500 dark:text-gray-400">No projects yet.</p>
<% end %>
</article>
2 changes: 2 additions & 0 deletions app/views/projects/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1 class="text-3xl font-bold text-gray-900 dark:text-white mb-6">New Project</h1>
<%= render "form", project: @project %>
4 changes: 4 additions & 0 deletions app/views/shared/_admin_navigation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
class: "text-white hover:text-gray-300 transition-colors" do %>
New Link
<% end %>
<%= link_to new_project_path,
class: "text-white hover:text-gray-300 transition-colors" do %>
New Project
<% end %>
<%= link_to feeds_path,
class: "text-white hover:text-gray-300 transition-colors" do %>
Feeds
Expand Down
4 changes: 2 additions & 2 deletions app/views/shared/_navigation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
<%= link_to "Presentations", "/p/presentations",
class: "#{current_page?('/p/presentations') ? 'text-blue-600 dark:text-blue-400 font-medium' : 'text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white'} transition-colors" %>

<%= link_to "Projects", "/p/projects",
class: "#{current_page?('/p/projects') ? 'text-blue-600 dark:text-blue-400 font-medium' : 'text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white'} transition-colors" %>
<%= link_to "Projects", projects_path,
class: "#{current_page?(projects_path) ? 'text-blue-600 dark:text-blue-400 font-medium' : 'text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white'} transition-colors" %>

<%= link_to "Links", links_path,
class: "#{current_page?(links_path) ? 'text-blue-600 dark:text-blue-400 font-medium' : 'text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white'} transition-colors" %>
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

# handle old pages from capotej.com
get "/about", to: redirect("/p/about")
get "/projects", to: redirect("/p/projects")
resources :projects, only: %i[ index new create edit update destroy ]
get "/presentations", to: redirect("/p/presentations")
get "/render-image-links-directly-inside-adium", to: "blog#redirect"
get "/finagle-with-scala-bootstrapper", to: "blog#redirect"
Expand Down
14 changes: 14 additions & 0 deletions db/migrate/20260430005908_create_projects.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class CreateProjects < ActiveRecord::Migration[8.1]
def change
create_table :projects do |t|
t.string :name, null: false
t.integer :year
t.string :github_url
t.string :license
t.string :language
t.text :description

t.timestamps
end
end
end
83 changes: 47 additions & 36 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading