easy_blog 0.0.0 → 0.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c1b18fb8b6a7b33520ca9461b0ccb44bf46d4b1c75753e9c8ad2f2f034404f9c
4
- data.tar.gz: 5669167da40cc360b87073d2da723f4339ae8e512693b0cf13b874a1197362dd
3
+ metadata.gz: 7d6590bea493566a3d320dd6093f6d288a2f7500a10c1c0e332381e45e48c04b
4
+ data.tar.gz: e3be3b0223fff89000f8346b2e08cc8220530ac828371962c9b5f43b5265c6d2
5
5
  SHA512:
6
- metadata.gz: 43fe261a13466b6242a65251c46dba0b42322230255e5b1ae9540e746679df48ab5ae65243542b0c1b497feec27a1010616b8d7d56b4fa1ac4cd2ac92f228632
7
- data.tar.gz: adecf216fee0d673125b8830de3db911d218280609e72d74a21292b2a55f0a662152ce46ca8c1b6700bf2bd0a204d1653cb474fb740d6ab9995bba1e871368af
6
+ metadata.gz: 1e40def081e0d3803fb49c866ee14fbbbcfeb240aa344fe4197ae5e99a05494c86816fcb459cc9307b73b400f74f4be60a47156ba571d65d11645a91d652917a
7
+ data.tar.gz: 4c700bab9d3d8c6b02cd13b0a8642dffbe43edae6c40285d8f33458092f98018ac938231b74d2065b38afc40b190a68fa61996fed208246ae82d619381a91471
@@ -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,9 @@
1
+ class BlogPostsController < ApplicationController
2
+ def index
3
+ @blog_posts = BlogPost.where(active: true).order(created_at: :desc)
4
+ end
5
+
6
+ def show
7
+ @blog_post = BlogPost.where(active: true).find(params[:id])
8
+ end
9
+ 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,7 @@
1
+ <div class="w-full flex flex-col">
2
+ <h1 class="text-5xl text-gray-900 dark:text-gray-100"> Blog Posts </h1>
3
+
4
+ <div class="w-full grid lg:grid-cols-3 2xl:grid-cols-4 mt-8">
5
+ <%= render partial: "blog_post", collection: @blog_posts %>
6
+ </div>
7
+ </div>
@@ -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.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Indigo Tech Tutorials
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-04-14 00:00:00.000000000 Z
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,6 +36,17 @@ 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