easy_blog 0.0.0 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/generators/easy_blog_generator.rb +43 -0
- data/lib/generators/templates/controllers/admin/blog_posts_controller.rb +47 -0
- data/lib/generators/templates/controllers/blog_posts_controller.rb +9 -0
- data/lib/generators/templates/views/admin/blog_posts/_blog_post.html.erb +6 -0
- data/lib/generators/templates/views/admin/blog_posts/_blog_post_fields.html.erb +34 -0
- data/lib/generators/templates/views/admin/blog_posts/edit.html.erb +11 -0
- data/lib/generators/templates/views/admin/blog_posts/index.html.erb +12 -0
- data/lib/generators/templates/views/admin/blog_posts/new.html.erb +12 -0
- data/lib/generators/templates/views/blog_posts/_blog_post.html.erb +8 -0
- data/lib/generators/templates/views/blog_posts/index.html.erb +7 -0
- data/lib/generators/templates/views/blog_posts/show.html.erb +26 -0
- metadata +36 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0fd8ef70b18cb7fb5e00b0e52c2f046b3921cc9c027a387acc14bdc7dcf38d5
|
4
|
+
data.tar.gz: 309c8e27010ed4a1d4b32eecd3b236847502239170413beb5513022633fa4125
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 926acb61b17397f2ca365c9a2ed2ee33d80d3c969e615ff0afe56f6be3acbac6281ca4b001b32b5faa8a70a879976a04ee76a7aa6dbab4d638921d40db8e3499
|
7
|
+
data.tar.gz: 70264aa6cff814991217df00612447ad4ff3dc8312f6882323f6cc6bea324f972ac960fcdc3122927e6b5eeeeadfe3bbb635fcde505c471a4dbcd00b6dd36d5a
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
|
3
|
+
class EasyBlogGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path("templates", __dir__)
|
5
|
+
# TODO: Add code to generate blog
|
6
|
+
def hello_world
|
7
|
+
puts "Hello world! Generator is working!"
|
8
|
+
end
|
9
|
+
|
10
|
+
def setup_prerequisites
|
11
|
+
rails_command "active_storage:install"
|
12
|
+
generate "action_text:install"
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_blog_model
|
16
|
+
generate "model", "blog_post", "title", "body:rich_text", "banner_image:attachment", "meta_description:text", "tags:text", "author_name", "active:boolean"
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_routes
|
20
|
+
route "resources :blog_posts, only: [:index, :show], path: 'blog'"
|
21
|
+
route "resources :blog_posts, only: [:index, :new, :create, :edit, :update]", namespace: :admin
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_nested_folders
|
25
|
+
# Create the admin nested folder if it doesnt already exist
|
26
|
+
FileUtils.mkdir_p("app/controllers/admin")
|
27
|
+
FileUtils.mkdir_p("app/views/admin")
|
28
|
+
end
|
29
|
+
|
30
|
+
def copy_controllers
|
31
|
+
copy_file "controllers/blog_posts_controller.rb", "app/controllers/blog_posts_controller.rb"
|
32
|
+
copy_file "controllers/admin/blog_posts_controller.rb", "app/controllers/admin/blog_posts_controller.rb"
|
33
|
+
end
|
34
|
+
|
35
|
+
def copy_views
|
36
|
+
directory "views/blog_posts", "app/views/blog_posts"
|
37
|
+
directory "views/admin/blog_posts", "app/views/admin/blog_posts"
|
38
|
+
end
|
39
|
+
|
40
|
+
def migrate_db
|
41
|
+
rails_command "db:migrate"
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Admin
|
2
|
+
class BlogPostsController < ApplicationController
|
3
|
+
before_action :authorize_admin
|
4
|
+
before_action :set_blog_post, only: [:edit, :update]
|
5
|
+
def new
|
6
|
+
@blog_post = BlogPost.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def create
|
10
|
+
if @blog_post = BlogPost.create(blog_post_params)
|
11
|
+
redirect_to admin_blog_posts_path, notice: "Blog post was created successfully"
|
12
|
+
else
|
13
|
+
render :new
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def index
|
18
|
+
@blog_posts = BlogPost.all
|
19
|
+
end
|
20
|
+
|
21
|
+
def edit
|
22
|
+
end
|
23
|
+
|
24
|
+
def update
|
25
|
+
if @blog_post.update(blog_post_params)
|
26
|
+
redirect_to @blog_post, notice: "Blog post has been updated successfully"
|
27
|
+
else
|
28
|
+
render :edit
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
def authorize_admin
|
34
|
+
redirect_to root_path, alert: "You are not authorized to view this page" unless Current.user.admin?
|
35
|
+
rescue
|
36
|
+
Logger.info("No user has been set to check for admin make sure you have a user model with an admin? method defined.")
|
37
|
+
end
|
38
|
+
|
39
|
+
def set_blog_post
|
40
|
+
@blog_post = BlogPost.find(params[:id])
|
41
|
+
end
|
42
|
+
|
43
|
+
def blog_post_params
|
44
|
+
params.expect(blog_post: [:title, :body, :banner_image, :meta_description, :tags, :author_name, :active])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<div class="w-full rounded-lg p-2 bg-gray-300 dark:bg-gray-700 flex flex-col">
|
2
|
+
<p class="text-xl text-gray-900 dark:text-gray-100 font-semibold"> <%= blog_post.title %> </p>
|
3
|
+
<p class="text-lg text-gray-900 dark:text-gray-100 mt-2"> <%= blog_post.body.body.to_plain_text.first(50) %> </p>
|
4
|
+
<p class="text-sm text-gray-900 dark:text-gray-100 mt-2"> <%= blog_post.created_at.strftime("%B %d, %Y") %> </p>
|
5
|
+
<%= link_to "Edit post", edit_admin_blog_post_path(blog_post), class: "bg-blue-500 text-blue-100 rounded-lg px-3 py-2 my-2 mr-auto" %>
|
6
|
+
</div>
|
@@ -0,0 +1,34 @@
|
|
1
|
+
<div class="flex flex-col gap-2 mt-4">
|
2
|
+
<%= f.label :title, class: "text-lg text-gray-900 dark:text-gray-100" %>
|
3
|
+
<%= f.text_field :title, class: "w-full p-2 rounded-lg bg-gray-300 dark:bg-gray-800 text-gray-800 dark:text-gray-100 block" %>
|
4
|
+
</div>
|
5
|
+
|
6
|
+
<div class="flex flex-col gap-2 mt-4">
|
7
|
+
<%= f.label :body, class: "text-lg text-gray-900 dark:text-gray-100" %>
|
8
|
+
<%= f.rich_text_area :body, class: "w-full p-2 rounded-lg bg-gray-300 dark:bg-gray-800 text-gray-800 dark:text-gray-100 block" %>
|
9
|
+
</div>
|
10
|
+
|
11
|
+
<div class="flex flex-col gap-2 mt-4">
|
12
|
+
<%= f.label :banner_image, class: "text-lg text-gray-900 dark:text-gray-100" %>
|
13
|
+
<%= f.file_field :banner_image, class: "w-full p-2 rounded-lg bg-gray-300 dark:bg-gray-800 text-gray-800 dark:text-gray-100 block" %>
|
14
|
+
</div>
|
15
|
+
|
16
|
+
<div class="flex flex-col gap-2 mt-4">
|
17
|
+
<%= f.label :metadata_description, class: "text-lg text-gray-900 dark:text-gray-100" %>
|
18
|
+
<%= f.text_area :metadata_description, class: "w-full p-2 rounded-lg bg-gray-300 dark:bg-gray-800 text-gray-800 dark:text-gray-100 block" %>
|
19
|
+
</div>
|
20
|
+
|
21
|
+
<div class="flex flex-col gap-2 mt-4">
|
22
|
+
<%= f.label :tags, class: "text-lg text-gray-900 dark:text-gray-100" %>
|
23
|
+
<%= f.text_field :tags, class: "w-full p-2 rounded-lg bg-gray-300 dark:bg-gray-800 text-gray-800 dark:text-gray-100 block" %>
|
24
|
+
</div>
|
25
|
+
|
26
|
+
<div class="flex flex-col gap-2 mt-4">
|
27
|
+
<%= f.label :author_name, class: "text-lg text-gray-900 dark:text-gray-100" %>
|
28
|
+
<%= f.text_field :author_name, class: "w-full p-2 rounded-lg bg-gray-300 dark:bg-gray-800 text-gray-800 dark:text-gray-100 block" %>
|
29
|
+
</div>
|
30
|
+
|
31
|
+
<div class="flex items-center gap-2 mt-4">
|
32
|
+
<%= f.label :active, class: "text-lg text-gray-900 dark:text-gray-100" %>
|
33
|
+
<%= f.check_box :active, class: "p-2 rounded-lg bg-gray-300 dark:bg-gray-800 text-gray-800 dark:text-gray-100" %>
|
34
|
+
</div>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<div class="w-full flex flex-col pb-16">
|
2
|
+
<h1 class="text-5xl text-gray-900 dark:text-gray-100"> Edit <%= @blog_post.title %> </h1>
|
3
|
+
<%= link_to "Back to all posts", admin_blog_posts_path, class: "text-lg text-gray-800 dark:text-gray-200 mt-2" %>
|
4
|
+
|
5
|
+
<div class="mt-8 w-full flex flex-col">
|
6
|
+
<%= form_with url: admin_blog_post_path(@blog_post), model: @blog_post do |f| %>
|
7
|
+
<%= render "blog_post_fields", f: f %>
|
8
|
+
<%= f.submit "Update blog post", class: "bg-blue-500 text-lg text-blue-50 px-3 py-2 rounded-lg cursor-pointer mt-4" %>
|
9
|
+
<% end %>
|
10
|
+
</div>
|
11
|
+
</div>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<div class="w-full flex flex-col">
|
2
|
+
<h1 class="text-5xl text-gray-900 dark:text-gray-100"> Admin/Blog Posts </h1>
|
3
|
+
<p class="text-lg text-gray-800 dark:text-gray-200 mt-2"> Manange the blog posts for your app </p>
|
4
|
+
|
5
|
+
<div class="w-full flex gap-4 items-center my-4">
|
6
|
+
<%= link_to "Create new blog post", new_admin_blog_post_path, class: "px-3 py-2 rounded-lg bg-gradient-to-br hover:bg-gradient-to-tl from-green-500 to-blue-500 text-green-50 transition-all duration-250" %>
|
7
|
+
</div>
|
8
|
+
|
9
|
+
<div class="w-full grid lg:grid-cols-3 2xl:grid-cols-4">
|
10
|
+
<%= render partial: "blog_post", collection: @blog_posts %>
|
11
|
+
</div>
|
12
|
+
</div>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<div class="w-full flex flex-col pb-16">
|
2
|
+
<h1 class="text-5xl text-gray-900 dark:text-gray-100"> New Blog Post </h1>
|
3
|
+
<%= link_to "Back to all posts", admin_blog_posts_path, class: "text-lg text-gray-800 dark:text-gray-200 mt-2" %>
|
4
|
+
|
5
|
+
<div class="mt-8 w-full flex flex-col">
|
6
|
+
<%= form_with url: admin_blog_posts_path, model: BlogPost.new do |f| %>
|
7
|
+
<%= render "blog_post_fields", f: f %>
|
8
|
+
|
9
|
+
<%= f.submit "Create blog post", class: "bg-blue-500 text-lg text-blue-50 px-3 py-2 rounded-lg cursor-pointer mt-4" %>
|
10
|
+
<% end %>
|
11
|
+
</div>
|
12
|
+
</div>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<%= link_to blog_post do %>
|
2
|
+
<div class="w-full rounded-lg p-2 bg-gray-300 hover:bg-gray-400 dark:bg-gray-700 dark:hover:bg-gray-800 flex flex-col">
|
3
|
+
<%= image_tag(blog_post.banner_image, class: "h-32 w-full object-cover") if blog_post.banner_image.attached? %>
|
4
|
+
<p class="text-2xl text-gray-900 dark:text-gray-100 font-semibold mt-2"> <%= blog_post.title %> </p>
|
5
|
+
<p class="text-lg text-gray-900 dark:text-gray-100 mt-2"> <%= blog_post.body.body.to_plain_text.first(50) %> </p>
|
6
|
+
<p class="text-sm text-gray-900 dark:text-gray-100 mt-2"> <%= blog_post.created_at.strftime("%B %d, %Y") %> </p>
|
7
|
+
</div>
|
8
|
+
<% end %>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<% content_for :head do %>
|
2
|
+
<meta name="description" content="<%= @blog_post.meta_description %>">
|
3
|
+
<meta name="keywords" content="<%= @blog_post.tags %>">
|
4
|
+
<% end %>
|
5
|
+
|
6
|
+
<div class="w-full flex flex-col">
|
7
|
+
<h1 class="text-5xl text-gray-900 dark:text-gray-100"> <%= @blog_post.title %> </h1>
|
8
|
+
<%= link_to "Back to all posts", blog_posts_path, class: "text-lg text-gray-800 dark:text-gray-200 mt-2" %>
|
9
|
+
<%= image_tag(@blog_post.banner_image, class: "h-40 w-full object-cover mt-4") if @blog_post.banner_image.attached? %>
|
10
|
+
|
11
|
+
<p class="text-gray-900 dark:text-gray-100 text-2xl mt-8">
|
12
|
+
<%= @blog_post.body %>
|
13
|
+
</p>
|
14
|
+
|
15
|
+
<p class="text-gray-900 dark:text-gray-100 text-lg mt-4">
|
16
|
+
Authored by <%= @blog_post.author_name %>
|
17
|
+
</p>
|
18
|
+
|
19
|
+
<p class="text-gray-900 dark:text-gray-100 text-lg mt-4">
|
20
|
+
Tags: <%= @blog_post.tags %>
|
21
|
+
</p>
|
22
|
+
|
23
|
+
<p class="text-gray-900 dark:text-gray-100 text-lg mt-4">
|
24
|
+
<%= @blog_post.created_at.strftime("%B %d, %Y") %>
|
25
|
+
</p>
|
26
|
+
</div>
|
metadata
CHANGED
@@ -1,14 +1,34 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_blog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Indigo Tech Tutorials
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-04-
|
11
|
-
dependencies:
|
10
|
+
date: 2025-04-16 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: rails
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: 8.0.2
|
19
|
+
- - ">="
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '8.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - "~>"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: 8.0.2
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '8.0'
|
12
32
|
description: The easiest way to add a blog into your Rails app.
|
13
33
|
email: indigo@indigotechtutorials.com
|
14
34
|
executables: []
|
@@ -16,10 +36,22 @@ extensions: []
|
|
16
36
|
extra_rdoc_files: []
|
17
37
|
files:
|
18
38
|
- lib/easy_blog.rb
|
39
|
+
- lib/generators/easy_blog_generator.rb
|
40
|
+
- lib/generators/templates/controllers/admin/blog_posts_controller.rb
|
41
|
+
- lib/generators/templates/controllers/blog_posts_controller.rb
|
42
|
+
- lib/generators/templates/views/admin/blog_posts/_blog_post.html.erb
|
43
|
+
- lib/generators/templates/views/admin/blog_posts/_blog_post_fields.html.erb
|
44
|
+
- lib/generators/templates/views/admin/blog_posts/edit.html.erb
|
45
|
+
- lib/generators/templates/views/admin/blog_posts/index.html.erb
|
46
|
+
- lib/generators/templates/views/admin/blog_posts/new.html.erb
|
47
|
+
- lib/generators/templates/views/blog_posts/_blog_post.html.erb
|
48
|
+
- lib/generators/templates/views/blog_posts/index.html.erb
|
49
|
+
- lib/generators/templates/views/blog_posts/show.html.erb
|
19
50
|
homepage: https://rubygems.org/gems/easy_blog
|
20
51
|
licenses:
|
21
52
|
- MIT
|
22
|
-
metadata:
|
53
|
+
metadata:
|
54
|
+
source_code_uri: https://github.com/indigotechtutorials/easy-blog-gem
|
23
55
|
rdoc_options: []
|
24
56
|
require_paths:
|
25
57
|
- lib
|