A compact and composable dashboard component for Ruby.
Main features:
- a Rack app that can be mounted in any Rack-enabled framework or used standalone;
- structured with plugins also for main components that can be replaced with little effort;
- routing is provided by Roda which is small and performant;
- views are Phlex components, so plain Ruby objects for views, no assets are needed.
Please ⭐ if you like it.
- Add to your Gemfile:
gem 'tiny_admin', '~> 0.3' - Mount the app in a route (check some examples with: Hanami, Rails, Roda and standalone in extra)
- in Rails, update config/routes.rb:
mount TinyAdmin::Router => '/admin'
- in Rails, update config/routes.rb:
- Configure the dashboard using
TinyAdmin.configureand/orTinyAdmin.configure_from_file(see configuration below):
TinyAdmin.configure do |settings|
settings.root = {
title: 'Home',
page: Admin::PageRoot
}
endPlugins available:
- SimpleAuth: session authentication based on Warden (
wardengem must be included in the Gemfile) using a password hash provided via config or via environment variable (ADMIN_PASSWORD_HASH); - NoAuth: no authentication.
Plugin available:
- ActiveRecordRepository: isolates the query layer to expose the resources in the admin interface.
Pages available:
- Root: define how to present the content in the main page of the interface;
- PageNotFound: define how to present pages not found;
- RecordNotFound: define how to present record not found page;
- SimpleAuthLogin: define how to present the login form for SimpleAuth plugin;
- Index: define how to present a collection of items;
- Show: define how to present the details of an item.
Components available:
- FiltersForm: define how to present the filters form in the resource collection pages;
- Flash: define how to present the flash messages;
- Head: define how to present the Head tag;
- Navbar: define how to present the navbar (the default one uses the Bootstrap structure);
- Pagination: define how to present the pagination of a collection.
TinyAdmin can be configured using a YAML file and/or programmatically. See extra folder for some usage examples.
The following options are supported:
root (Hash): define the root section of the admin, properties:
title(String): root section's title;page(String): a view object to render;redirect(String): alternative to page option - redirects to a specific slug;
Example:
root:
title: MyAdmin
redirect: postsauthentication (Hash): define the authentication method, properties:
plugin(String): a plugin class to use (ex.TinyAdmin::Plugins::SimpleAuth);password(String): a password hash used by SimpleAuth plugin (generated withDigest::SHA512.hexdigest("some password")).
Example:
authentication:
plugin: TinyAdmin::Plugins::SimpleAuth
password: 'f1891cea80fc05e433c943254c6bdabc159577a02a7395dfebbfbc4f7661d4af56f2d372131a45936de40160007368a56ef216a30cb202c66d3145fd24380906'sections (Array of hashes): define the admin sections, properties:
slug(String): section reference identifier;name(String): section's title;type(String): the type of section:url,pageorresource;- other properties depends on the section's type.
For url sections:
url(String): the URL to load when clicking on the section's menu item;options(Hash): properties:target(String): link target attributes (ex._blank).
Example:
slug: google
name: Google.it
type: url
url: https://www.google.it
options:
target: '_blank'For page sections:
page(String): a view object to render.
Example:
slug: stats
name: Stats
type: page
page: Admin::StatsFor resource sections:
model(String): the class to use to fetch the data on an item of a collection;repository(String): the class to get the properties related to the model;index(Hash): collection's action options;show(Hash): detail's action options;collection_actions(Array of hashes): custom collection's actions;member_actions(Array of hashes): custom details's actions;only(Array of strings): list of supported actions (ex.index);options(Array of strings): resource options (ex.hidden).
Example:
slug: posts
name: Posts
type: resource
model: Poststyle_links (Array of hashes): list of styles files to include, properties:
href(String): URL for the style file;rel(String): type of style file.
scripts (Array of hashes): list of scripts to include, properties:
src(String): source URL for the script.
extra_styles (String): inline CSS styles.
# config/initializers/tiny_admin.rb
config = Rails.root.join('config/tiny_admin.yml').to_s
TinyAdmin.configure_from_file(config)
# Change some settings programmatically
TinyAdmin.configure do |settings|
settings.authentication[:password] = Digest::SHA512.hexdigest('changeme')
end# config/tiny_admin.yml
---
authentication:
plugin: TinyAdmin::Plugins::SimpleAuth
# password: 'f1891cea80fc05e433c943254c6bdabc159577a02a7395df...' <= SHA512
page_not_found: Admin::PageNotFound
record_not_found: Admin::RecordNotFound
root:
title: 'Tiny Admin'
page: Admin::PageRoot
# redirect: posts
sections:
- slug: google
name: Google.it
type: url
url: https://www.google.it
options:
target: '_blank'
- slug: stats
name: Stats
type: page
page: Admin::Stats
- slug: authors
name: Authors
type: resource
model: Author
repository: Admin::AuthorsRepo
collection_actions:
- latests: Admin::LatestAuthorsAction
member_actions:
- csv_export: Admin::CsvExportAuthorAction
# only:
# - index
# options:
# - hidden
- slug: posts
name: Posts
type: resource
model: Post
index:
sort:
- author_id DESC
pagination: 15
attributes:
- id
- title
- field: author_id
link_to: authors
- state
- published
- dt
- field: created_at
converter: Admin::Utils
method: datetime_formatter
filters:
- title
- field: state
type: select
values:
- available
- unavailable
- arriving
- published
show:
attributes:
- id
- title
- description
- field: author_id
link_to: authors
- category
- published
- state
- created_at
style_links:
- href: /bootstrap.min.css
rel: stylesheet
scripts:
- src: /bootstrap.bundle.min.js
extra_styles: >
.navbar {
background-color: var(--bs-cyan);
}
.main-content {
background-color: var(--bs-gray-100);
}
.main-content a {
text-decoration: none;
}If you use this component just star it. A developer is more motivated to improve a project when there is some interest.
Or consider offering me a coffee, it's a small thing but it is greatly appreciated: about me.
- Mattia Roccoberton: author
The gem is available as open source under the terms of the MIT License.
