feat: quick blogs/news feature

This commit is contained in:
Neetpone 2024-04-06 07:00:46 -04:00
parent 902e2d422b
commit 04a814b71b
15 changed files with 141 additions and 19 deletions

View file

@ -1,3 +1,4 @@
require: rubocop-rails
inherit_from: .rubocop_todo.yml
AllCops:
SuggestExtensions: false

16
Gemfile
View file

@ -4,20 +4,25 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '3.2.2'
gem 'kaminari'
gem 'pg', '~> 1.1'
gem 'puma', '~> 5.0'
gem 'rails', '~> 7.0.8', '>= 7.0.8.1'
gem 'redcarpet'
gem 'slim-rails'
gem 'sprockets-rails'
# Database stuff
gem 'pg', '~> 1.1'
gem 'redis'
# Search
gem 'elasticsearch-model'
gem 'fancy_searchable', github: 'Twibooru/fancy_searchable', ref: '40687c9'
gem 'model-msearch'
# Views
gem 'kaminari'
gem 'redcarpet'
gem 'slim-rails'
# Programs
gem 'puma', '~> 5.0'
gem 'sidekiq'
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
@ -35,6 +40,7 @@ group :development do
gem 'annotate'
gem 'bullet'
gem 'rubocop', require: false
gem 'rubocop-rails', require: false
gem 'web-console'
end

View file

@ -82,6 +82,7 @@ GEM
rake (>= 10.4, < 14.0)
ast (2.4.2)
base64 (0.2.0)
bcrypt (3.1.20)
bindex (0.8.1)
builder (3.2.4)
bullet (7.1.6)
@ -241,6 +242,11 @@ GEM
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.2)
parser (>= 3.3.0.4)
rubocop-rails (2.24.1)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (1.13.0)
rubyzip (2.3.2)
selenium-webdriver (4.19.0)
@ -295,6 +301,7 @@ PLATFORMS
DEPENDENCIES
annotate
bcrypt
bullet
capybara
debug
@ -308,6 +315,7 @@ DEPENDENCIES
redcarpet
redis
rubocop
rubocop-rails
selenium-webdriver
sidekiq
slim-rails

View file

@ -0,0 +1,6 @@
# frozen_string_literal: true
class BlogsController < ApplicationController
def index
@blogs = Blog.order(created_at: :desc)
end
end

View file

@ -38,7 +38,7 @@ class SearchController < ApplicationController
tag_must_nots.map { |t| { term: { tags: t } } }
) if tag_must_nots.any?
s.add_query(bool: boolses ) if boolses.any?
s.add_query(bool: boolses) if boolses.any?
# ratings -> match stories with any of them
s.add_filter(bool: {

View file

@ -0,0 +1,3 @@
# frozen_string_literal: true
module BlogsHelper
end

15
app/models/blog.rb Normal file
View file

@ -0,0 +1,15 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: blogs
#
# id :bigint not null, primary key
# body :text not null
# title :text not null
# created_at :datetime not null
# updated_at :datetime not null
#
class Blog < ApplicationRecord
validates :title, presence: true, length: { maximum: 128 }
validates :body, presence: true
end

View file

@ -0,0 +1,15 @@
.news
#wrap
= render partial: 'layouts/banner'
nav.home
= link_to 'Home', root_path
= link_to 'News', '/news', class: 'current'
= link_to 'About', '/about'
section.news-list
- @blogs.each do |blog|
article
header
h1= blog.title
section
== blog.body
footer Posted by Floorb on #{blog.created_at}.

View file

@ -26,15 +26,17 @@ Bundler.require(*Rails.groups)
#
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")
class Foalfetch::Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 7.0
module Foalfetch
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 7.0
# Configuration for the application, engines, and railties goes here.
#
# These settings can be overridden in specific environments using the files
# in config/environments, which are processed later.
#
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")
end
# Configuration for the application, engines, and railties goes here.
#
# These settings can be overridden in specific environments using the files
# in config/environments, which are processed later.
#
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")
end
end

View file

@ -7,8 +7,12 @@ Rails.application.routes.draw do
get '/images' => 'images#show'
resources :authors, only: [:show]
# using singular-named routes to match FiMFetch/FiMFiction.
resources :stories, only: [:show], path: :story do
resources :chapters, only: [:show], path: :chapter
end
# Different route name again to match FiMFetch
resources :blogs, only: [:index], path: :news
end

View file

@ -0,0 +1,9 @@
class CreateBlogs < ActiveRecord::Migration[7.0]
def change
create_table :blogs do |t|
t.timestamps null: false
t.text :title, null: false
t.text :body, null: false
end
end
end

11
db/schema.rb generated
View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2024_04_02_172140) do
ActiveRecord::Schema[7.0].define(version: 2024_04_06_101101) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -28,13 +28,20 @@ ActiveRecord::Schema[7.0].define(version: 2024_04_02_172140) do
t.datetime "date_joined", null: false
end
create_table "blogs", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "title", null: false
t.text "body", null: false
end
create_table "chapters", force: :cascade do |t|
t.bigint "story_id", null: false
t.integer "number", default: 1, null: false
t.datetime "date_published", null: false
t.datetime "date_modified"
t.integer "num_views", default: 0, null: false
t.integer "num_words", null: false
t.integer "num_words"
t.text "title", null: false
t.text "body"
t.index ["story_id"], name: "index_chapters_on_story_id"

View file

@ -0,0 +1,8 @@
# frozen_string_literal: true
require "test_helper"
class BlogsControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end

20
test/fixtures/blogs.yml vendored Normal file
View file

@ -0,0 +1,20 @@
# == Schema Information
#
# Table name: blogs
#
# id :bigint not null, primary key
# body :text not null
# title :text not null
# created_at :datetime not null
# updated_at :datetime not null
#
# This model initially had no columns defined. If you add columns to the
# model remove the "{}" from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value

18
test/models/blog_test.rb Normal file
View file

@ -0,0 +1,18 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: blogs
#
# id :bigint not null, primary key
# body :text not null
# title :text not null
# created_at :datetime not null
# updated_at :datetime not null
#
require "test_helper"
class BlogTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end