Skip to content

LightningRails/lightning_blog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Lightning Blog

A mountable blog engine for any Rails application with enhanced styling for Tailwind CSS and DaisyUI. Originally designed for Lightning Rails but works perfectly with any Rails app!

✨ Universal Rails Compatibility

Lightning Blog is designed to work with:

  • βœ… Lightning Rails (enhanced experience with Tailwind + DaisyUI)
  • βœ… Standard Rails apps with Tailwind CSS (great styling)
  • βœ… Any Rails application (beautiful fallback styles)

Features

  • πŸ“ Full Blog Functionality: Create, manage, and display blog posts
  • πŸ“‚ Categories: Organize posts by categories
  • πŸ” Search: Full-text search across posts
  • πŸ“± Responsive Design: Mobile-friendly interface that works everywhere
  • πŸ–ΌοΈ Image Support: Featured images for posts using Active Storage
  • πŸ“Š Analytics: View counts and post statistics
  • 🎨 Smart Styling: Enhanced UI with Tailwind/DaisyUI, graceful fallbacks without
  • ⚑ Lightning Fast: Optimized for performance
  • πŸŒ™ Dark Mode: Automatic dark mode support

Styling Options

πŸš€ Lightning Rails Users (Recommended)

Get the full experience with Tailwind CSS and DaisyUI components perfectly integrated with your Lightning Rails application.

🎨 Tailwind CSS Users

Enhanced styling with Tailwind classes. Add DaisyUI following the official Rails guide for the complete component library.

πŸ“ Standard Rails Users

Beautiful fallback styles that match modern design principles. No additional dependencies required!

Installation

Add this line to your Rails application's Gemfile:

gem 'lightning_blog', path: '/path/to/lightning_blog'

Or if you're using it from a Git repository:

gem 'lightning_blog', git: 'https://github.com/LightningRails/lightning_blog.git'

And then execute:

$ bundle install

Setup

πŸš€ Quick Setup (Recommended)

Use the automated installer:

$ rails generate lightning_blog:install

This will:

  • βœ… Copy migrations to your app
  • βœ… Mount the blog engine at /blog
  • βœ… Detect your Tailwind/DaisyUI setup automatically
  • βœ… Create a configuration file
  • βœ… Provide setup guidance based on your environment

πŸ“‹ Manual Setup

  1. Copy and run migrations:
$ rails lightning_blog:install:migrations
$ rails db:migrate
  1. Mount the engine in your config/routes.rb:
Rails.application.routes.draw do
  mount LightningBlog::Engine => "/blog"
  # Your other routes...
end
  1. Seed sample data (optional, for development):
$ rails db:seed

Configuration Based on Your Setup

For Lightning Rails Apps

# The gem automatically detects Lightning Rails and uses enhanced styling
# No additional configuration needed! πŸŽ‰

For Tailwind CSS Apps

Following the official DaisyUI Rails guide, you have 3 options:

Method 1: NPM Plugin (Recommended)

# Install DaisyUI via NPM
npm install daisyui@latest

Add to your app/assets/tailwind/application.css:

@import "tailwindcss" source(none);
@source "../../../public/*.html";
@source "../../../app/helpers/**/*.rb";
@source "../../../app/javascript/**/*.js";
@source "../../../app/views/**/*";

@plugin "daisyui";

Method 2: Downloaded JS (No Node.js required)

# Download DaisyUI files
curl -sLo app/assets/tailwind/daisyui.js https://github.com/saadeghi/daisyui/releases/latest/download/daisyui.js

Add to your app/assets/tailwind/application.css:

@import "tailwindcss" source(none);
@source "../../../public/*.html";
@source "../../../app/helpers/**/*.rb";
@source "../../../app/javascript/**/*.js";
@source "../../../app/views/**/*";

@plugin "./daisyui.js";

Method 3: CDN Import (Quick setup)

Add to your app/assets/tailwind/application.css:

@import "tailwindcss" source(none);
@source "../../../public/*.html";
@source "../../../app/helpers/**/*.rb";
@source "../../../app/javascript/**/*.js";
@source "../../../app/views/**/*";

@import "https://cdn.jsdelivr.net/npm/daisyui@5";

For Standard Rails Apps

# The gem includes beautiful fallback styles - works out of the box!
# Optionally add Tailwind CSS + DaisyUI for enhanced experience:
# https://daisyui.com/docs/install/rails/

Usage

Accessing the Blog

Once mounted, your blog will be available at:

  • Blog Index: /blog - Lists all published posts
  • Individual Posts: /blog/post-slug - Shows a specific post
  • Categories: /blog/categories - Lists all categories
  • Category Posts: /blog/category/category-slug - Posts by category
  • Search: /blog?search=query - Search posts

Managing Content

Lightning Blog provides models for managing your blog content:

Creating Posts

# Create a new category
category = LightningBlog::Category.create!(
  name: "Technology",
  slug: "technology",
  description: "Posts about technology"
)

# Create a new post
post = LightningBlog::Post.create!(
  title: "My First Blog Post",
  slug: "my-first-blog-post",
  content: "This is the content of my blog post...",
  excerpt: "A brief excerpt...",
  category: category,
  published: true
)

Image Hosting with Cloudinary

Lightning Blog supports Cloudinary for professional image hosting and delivery. Cloudinary provides automatic image optimization, transformations, and CDN delivery for better performance.

Quick Setup

  1. Add Cloudinary to your Gemfile:
gem 'cloudinary'
  1. Install the gem:
bundle install
  1. Configure Active Storage to use Cloudinary in your config/storage.yml:
cloudinary:
  service: Cloudinary
  # Your credentials will be loaded from CLOUDINARY_URL env variable
  # or set them here directly:
  # cloud_name: your_cloud_name
  # api_key: your_api_key
  # api_secret: your_api_secret
  1. Set Cloudinary as your Active Storage service in the appropriate environment file:
# config/environments/production.rb
config.active_storage.variant_processor = :image_processing
config.active_storage.service = :cloudinary

# config/environments/development.rb (optional)
config.active_storage.service = :cloudinary
  1. Get your Cloudinary credentials:
    • Sign up at cloudinary.com
    • Copy your CLOUDINARY_URL from the dashboard
    • Add it to your environment variables or .env file:
CLOUDINARY_URL=cloudinary://api_key:api_secret@cloud_name

Why Use Cloudinary?

  • βœ… Automatic optimization - Images served in optimal format and size
  • βœ… Global CDN delivery - Fast loading worldwide
  • βœ… Real-time transformations - Resize, crop, format images on-the-fly
  • βœ… Responsive images - Automatic device-appropriate sizing
  • βœ… SEO benefits - Faster page loads improve search rankings

Usage with Lightning Blog

Once configured, Lightning Blog will automatically use Cloudinary for:

  • Featured images on blog posts
  • Image attachments in post content
  • Category images (if you add them)
  • User avatars (if you extend the models)
# Example: Creating a post with featured image
post = LightningBlog::Post.create!(
  title: "My Post with Image",
  content: "Post content...",
  category: category,
  published: true
)

# Attach image from file upload
post.featured_image.attach(params[:featured_image])

# Or attach from URL
post.featured_image.attach(
  io: URI.open('https://example.com/image.jpg'),
  filename: 'featured-image.jpg'
)

Advanced Cloudinary Features

Lightning Blog views are optimized for Cloudinary transformations:

<!-- Automatic responsive images -->
<%= image_tag post.featured_image.variant(resize: "800x600"), 
    class: "responsive-image",
    alt: post.title %>

<!-- Multiple sizes for different devices -->
<%= image_tag post.featured_image, 
    sizes: "100vw",
    srcset: [
      "#{url_for(post.featured_image.variant(resize: '400x'))} 400w",
      "#{url_for(post.featured_image.variant(resize: '800x'))} 800w",
      "#{url_for(post.featured_image.variant(resize: '1200x'))} 1200w"
    ].join(', ') %>

Note: Lightning Blog works perfectly without Cloudinary using Rails' default Active Storage with local files. Cloudinary is recommended for production applications requiring professional image handling.

Customization

🎨 For Tailwind/DaisyUI Users

The gem uses Tailwind classes and DaisyUI components. You can customize themes following the Lightning Rails theming guide:

/* Custom theme in your application.css */
[data-theme="lightning-blog"]{
  --color-primary: #F9462F;
  --color-primary-content: #ffffff;
  --color-secondary: #000000;
  --color-base-100: #ffffff;
  /* ... other DaisyUI variables */
}

πŸ“ For Standard Rails Users

Override styles in your application.css:

/* Override Lightning Blog styles */
body:not(.tailwind-loaded) .card {
  background-color: your-color;
  /* Your custom styles */
}

πŸ”§ Custom Views

Override any view by creating the corresponding file in your application:

app/views/lightning_blog/
β”œβ”€β”€ posts/
β”‚   β”œβ”€β”€ index.html.erb
β”‚   └── show.html.erb
β”œβ”€β”€ categories/
β”‚   β”œβ”€β”€ index.html.erb
β”‚   └── show.html.erb
└── layouts/
    └── application.html.erb

πŸ›  Routes Customization

# config/routes.rb
Rails.application.routes.draw do
  # Mount at root path
  mount LightningBlog::Engine => "/"
  
  # Or mount at custom path
  mount LightningBlog::Engine => "/articles"
  
  # Add custom routes
  get "/latest-posts", to: "lightning_blog/posts#index"
end

Integration Examples

With Lightning Rails

# Works seamlessly - enhanced styling automatically applied!
# Perfect integration with your Lightning Rails design system

With Devise Authentication

# app/controllers/lightning_blog/application_controller.rb
module LightningBlog
  class ApplicationController < ::ApplicationController
    before_action :authenticate_user!, if: :admin_required?
    
    private
    
    def admin_required?
      params[:action].in?(['new', 'create', 'edit', 'update', 'destroy'])
    end
  end
end

With Your Analytics

# Track blog performance
<% if params[:controller] == 'lightning_blog/posts' && params[:action] == 'show' %>
  gtag('event', 'page_view', {
    page_title: '<%= @post.title %>',
    page_location: '<%= request.url %>'
  });
<% end %>

API Reference

Post Model

LightningBlog::Post.published          # Published posts only
LightningBlog::Post.recent             # Ordered by creation date
LightningBlog::Post.by_category(cat)   # Posts in specific category
LightningBlog::Post.search("query")    # Search posts

post = LightningBlog::Post.first
post.reading_time                      # Estimated reading time
post.increment_views!                  # Increment view count
post.published?                        # Check if published

Category Model

LightningBlog::Category.with_published_posts  # Categories with published posts

category = LightningBlog::Category.first
category.posts.published                      # Published posts in category

Development

Testing

# Run all tests
$ bundle exec rspec

# Build the gem
$ gem build lightning_blog.gemspec

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/LightningRails/lightning_blog.

FAQ

Q: Will this work with my existing Rails app?

A: Yes! Lightning Blog works with any Rails application (Rails 7.0+). It includes fallback styles for apps without Tailwind.

Q: Do I need Tailwind CSS?

A: No, but it's recommended for the best experience. The gem includes beautiful fallback styles for standard Rails apps.

Q: How do I properly set up DaisyUI?

A: Follow the official DaisyUI Rails installation guide - our installer will detect your setup automatically.

Q: Can I use this with Bootstrap or other CSS frameworks?

A: Absolutely! The gem's styles are designed to coexist with other CSS frameworks.

Q: How do I add admin functionality?

A: Create admin controllers in your main app to manage Lightning Blog models, or integrate with existing admin panels.

Support Matrix

Rails Version Ruby Version Tailwind DaisyUI Status
7.0+ 3.0+ βœ… βœ… (NPM Plugin) βœ… Full Support
7.0+ 3.0+ βœ… βœ… (Downloaded JS) βœ… Full Support
7.0+ 3.0+ βœ… βœ… (CDN Import) βœ… Full Support
7.0+ 3.0+ βœ… ❌ βœ… Enhanced Styling
7.0+ 3.0+ ❌ ❌ βœ… Fallback Styles

Official Resources

License

The gem is available as open source under the terms of the MIT License.

Changelog

Version 0.1.0

  • βœ… Universal Rails compatibility
  • βœ… Official DaisyUI Rails integration (all 3 methods)
  • βœ… Automatic setup detection
  • βœ… Fallback styles for standard Rails
  • βœ… Search functionality
  • βœ… Category management
  • βœ… Responsive design
  • βœ… SEO optimization

Support

For support, please:

  1. Check the official DaisyUI Rails guide
  2. Review the documentation above
  3. Search existing issues on GitHub
  4. Create a new issue with detailed information

Built with ❀️ for the Rails community. Optimized for Lightning Rails, perfect for everyone! ⚑

About

A mountable blog engine for Rails applications with Tailwind/DaisyUI support

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published