By Charlie Reese at Clientelify
BlogBoi
BlogBoi is a rails gem / engine that provides out-of-the-box blogging functionality to your rails application.
It requires active_storage for photo upload / storage.
Installation
- Add this line to your application's Gemfile:
gem 'blog_boi', '~> 0'
- Add these lines to your config/application.rb file:
require "active_storage/engine"
ActiveStorage::Engine.config
.active_storage
.content_types_to_serve_as_binary
.delete('image/svg+xml')
- And then execute:
$ bundle
$ rake active_storage:install `
$ rake active_storage:update
$ rails blog_boi:install:migrations `
$ rails db:migrate
Your storage.yml file should now have this code:
test:
service: Disk
root: <%= Rails.root.join("tmp/storage") %>
local:
service: Disk
root: <%= Rails.root.join("storage") %>
Note: $ rails railties:install:migrations to copy all new migrations
Note: to run migrations only for certain engine, rails db:migrate SCOPE=blog_boi. To revert all migrations from blog_boi engine you can run rails db:migrate SCOPE=blog_boi VERSION=0
- And then mount the engine in your app's config/routes.rb file:
mount BlogBoi::Engine, at: "/blog"
-
Customize scss colour scheme by creating stylesheets/bootstrap_customizer.scss
. See example in test/dummy/app/assets/stylesheets
.
-
And then add the engines configuration options in an initializer file (named blog_boi.rb):
BlogBoi.author_class = "User"
See lib/blog_boi.rb for all customization options (like setting your Blog's meta description / image).
- Finally, your parent application must define the method
admin_signed_in?
. If you are using Devise, this method may already exist. It should return true if the blog admin is signed in, and false if not. When it returns true, you may create, update, and destroy blog articles. It should be available in controllers and views; it should be defined in ApplicationController, and should be marked a helper method. E.g.
class ApplicationController < ActionController::Base
helper_method :admin_signed_in?
def admin_signed_in?
...
end
end
View partial hooks
List of view partial hooks that are rendered if they exist in parent application:
layouts/blog_boi/head_extension
: (for adding html to head of blog_boi application layout in layouts/blog_boi/application
)
Custom style / SCSS
To override SCSS bootstrap mixins / styles, add a file in parent application called blog_boi/bootstrap_overrides.scss.
Override the header or footer by placing your own files at views/layouts/_header
or views/layouts/_footer
Further, you can add your own css classes / ids to your markup:
Running tests
- Run all tests other than system:
rake app:test
- Run system tests:
rake app:test:system
- Run all tests:
rake
or rake test
Test coverage
Exists in coverage
folder in root directory.
To view in a browser, execute from root directory: open coverage/index.html
License
The gem is currently available as open source software under the terms of the MIT License.
Contributing
If you'd like to make a fix / change, please create a pull request; when I have a moment, I'll have a look!
Updating gem version (for maintainers)
1. Update version
In lib/blog_boi/version.rb
update version.
2. Build gem
gem build blog_boi.gemspec
3. Push gem
gem push blog_boi-X.X.X.gem
(replace X's with version)
4. Tag GitHub
git add -A
git commit -m "Msg"
git push
git tag -a vX.X.X -m "Msg"
git push --tags