Skip to content

Commit b168645

Browse files
author
Mattia Roccoberton
committed
feat: first version
0 parents  commit b168645

File tree

112 files changed

+3172
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+3172
-0
lines changed

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/.rspec_failures
2+
/.rubocop-*
3+
/*.gem
4+
5+
/Gemfile.lock
6+
7+
/_misc/
8+
/coverage/
9+
/log/
10+
/tmp/
11+
12+
/extra/*/log
13+
/extra/*/tmp
14+
/spec/dummy/log
15+
/spec/dummy/tmp
16+
/spec/dummy/db/*.sqlite3

.rspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--format documentation
2+
--require spec_helper

.rubocop.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
inherit_from:
3+
- https://relaxed.ruby.style/rubocop.yml
4+
5+
require:
6+
- rubocop-packaging
7+
- rubocop-performance
8+
- rubocop-rspec
9+
10+
AllCops:
11+
Exclude:
12+
- bin/*
13+
- spec/dummy/**/*
14+
- vendor/**/*
15+
NewCops: enable
16+
SuggestExtensions: false
17+
TargetRubyVersion: 2.7
18+
19+
Lint/MissingSuper:
20+
Exclude:
21+
- lib/tiny_admin/views/**/*
22+
23+
Lint/UnusedMethodArgument:
24+
AllowUnusedKeywordArguments: true
25+
26+
RSpec/ExampleLength:
27+
Max: 20
28+
29+
RSpec/Rails/InferredSpecType:
30+
Enabled: false
31+
32+
Style/ExplicitBlockArgument:
33+
Enabled: false
34+
35+
Style/GuardClause:
36+
Exclude:
37+
- lib/tiny_admin/router.rb

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# TinyAdmin

Gemfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# frozen_string_literal: true
2+
3+
source 'https://rubygems.org'
4+
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
5+
6+
gemspec
7+
8+
group :development, :test do
9+
gem 'rails', '~> 7.0'
10+
11+
gem 'sqlite3'
12+
gem 'tilt'
13+
gem 'warden'
14+
gem 'webrick'
15+
16+
# Testing
17+
gem 'capybara'
18+
gem 'capybara-screenshot'
19+
gem 'rspec-rails'
20+
gem 'simplecov', require: false
21+
22+
# Linters
23+
# gem 'brakeman'
24+
# gem 'fasterer'
25+
# gem 'reek'
26+
gem 'rubocop'
27+
gem 'rubocop-packaging'
28+
gem 'rubocop-performance'
29+
gem 'rubocop-rspec'
30+
31+
# Tools
32+
# gem 'overcommit', '~> 0.59'
33+
gem 'pry-rails'
34+
end

LICENSE.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2023 Mattia Roccoberton
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
# Tiny Admin
2+
3+
A compact and composible dashboard component for Ruby.
4+
5+
The main features are:
6+
- a Rack app that can be mounted in any Rack-enabled framework;
7+
- some features are handled as plugins, so they can be replaced with little effort;
8+
- routing is provided by Roda (which is small and performant);
9+
- views are Phlex components.
10+
11+
See (extra)[extra] folder for usage examples.
12+
13+
Please ⭐ if you like it.
14+
15+
## Install
16+
17+
- Add to your Gemfile: `gem 'tiny_admin'`
18+
- For a Rails project: add an initializer and the YAML config - see (configuration)[#configuration] below.
19+
20+
## Plugins and components
21+
22+
Every plugin or component can be replaced.
23+
24+
### Authentication
25+
26+
There are 2 plugins included:
27+
- _SimpleAuth_: provides a simple session authentication based on Warden (`warden` gem must be included in the host project);
28+
- _NoAuth_: no authentication.
29+
30+
### Repository
31+
32+
There is 1 plugin included:
33+
- _ActiveRecordRepository_: isolates the query layer to expose the resources in the admin interface.
34+
35+
### View pages
36+
37+
There are 5 view pages included:
38+
- _Root_: define how to present the content in the main page of the interface;
39+
- _PageNotFound_: define how to present pages not found;
40+
- _RecordNotFound_: define how to present record not found page;
41+
- _SimpleAuthLogin_: define how to present the login form for SimpleAuth plugin;
42+
- _Index_: define how to present a collection of items;
43+
- _Show_: define how to present the details of an item.
44+
45+
### View components
46+
47+
There are 5 view components included:
48+
- _FiltersForm_: define how to present the filters form in the resource collection pages;
49+
- _Flash_: define how to present the flash messages;
50+
- _Head_: define how to present the Head tag;
51+
- _Navbar_: define how to present the navbar (the default one uses the Bootstrap structure);
52+
- _Pagination_: define how to present the pagination of a collection.
53+
54+
## Configuration
55+
56+
TinyAdmin can be configured programmatically or using a YAML config.
57+
58+
Example:
59+
60+
```rb
61+
# config/initializers/tiny_admin.rb
62+
63+
# hash generated using: Digest::SHA512.hexdigest("changeme")
64+
ENV['ADMIN_PASSWORD_HASH'] = 'f1891cea80fc05e433c943254c6bdabc159577a02a7395dfebbfbc4f7661d4af56f2d372131a45936de40160007368a56ef216a30cb202c66d3145fd24380906'
65+
config = Rails.root.join('config/tiny_admin.yml').to_s
66+
TinyAdmin.configure_from_file(config)
67+
```
68+
69+
```yml
70+
---
71+
authentication:
72+
plugin: TinyAdmin::Plugins::SimpleAuth
73+
page_not_found: Admin::PageNotFound
74+
record_not_found: Admin::RecordNotFound
75+
root:
76+
title: 'Tiny Admin'
77+
page: Admin::PageRoot
78+
# redirect: posts
79+
sections:
80+
- slug: google
81+
name: Google.it
82+
type: url
83+
url: https://www.google.it
84+
options:
85+
target: '_blank'
86+
- slug: stats
87+
name: Stats
88+
type: page
89+
page: Admin::Stats
90+
- slug: authors
91+
name: Authors
92+
type: resource
93+
model: Author
94+
repository: Admin::AuthorsRepo
95+
collection_actions:
96+
- latests: Admin::LatestAuthorsAction
97+
member_actions:
98+
- csv_export: Admin::CsvExportAuthorAction
99+
# only:
100+
# - index
101+
# options:
102+
# - hidden
103+
- slug: posts
104+
name: Posts
105+
type: resource
106+
model: Post
107+
index:
108+
sort:
109+
- author_id DESC
110+
pagination: 15
111+
attributes:
112+
- id
113+
- title
114+
- field: author_id
115+
link_to: authors
116+
- state
117+
- published
118+
- dt
119+
- field: created_at
120+
converter: Admin::Utils
121+
method: datetime_formatter
122+
filters:
123+
- title
124+
- field: state
125+
type: select
126+
values:
127+
- available
128+
- unavailable
129+
- arriving
130+
- published
131+
show:
132+
attributes:
133+
- id
134+
- title
135+
- description
136+
- field: author_id
137+
link_to: authors
138+
- category
139+
- published
140+
- state
141+
- created_at
142+
style_links:
143+
- href: /bootstrap.min.css
144+
rel: stylesheet
145+
scripts:
146+
- src: /bootstrap.bundle.min.js
147+
extra_styles: >
148+
.navbar {
149+
background-color: var(--bs-cyan);
150+
}
151+
.main-content {
152+
background-color: var(--bs-gray-100);
153+
}
154+
.main-content a {
155+
text-decoration: none;
156+
}
157+
```
158+
159+
## Do you like it? Star it!
160+
161+
If you use this component just star it. A developer is more motivated to improve a project when there is some interest.
162+
163+
Or consider offering me a coffee, it's a small thing but it is greatly appreciated: [about me](https://www.blocknot.es/about-me).
164+
165+
## Contributors
166+
167+
- [Mattia Roccoberton](https://blocknot.es/): author
168+
169+
## License
170+
171+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

bin/rails

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env ruby
2+
# This command will automatically be run when you run "rails" with Rails gems
3+
# installed from the root of your application.
4+
5+
ENV['RAILS_ENV'] ||= 'test'
6+
7+
ENGINE_ROOT = File.expand_path('..', __dir__)
8+
APP_PATH = File.expand_path("../spec/dummy/config/application", __dir__)
9+
10+
# Set up gems listed in the Gemfile.
11+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
12+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
13+
14+
require 'rails/all'
15+
require 'rails/engine/commands'

bin/rspec

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
#
5+
# This file was generated by Bundler.
6+
#
7+
# The application 'rspec' is installed as part of a gem, and
8+
# this file is here to facilitate running it.
9+
#
10+
11+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
12+
13+
bundle_binstub = File.expand_path("bundle", __dir__)
14+
15+
if File.file?(bundle_binstub)
16+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
17+
load(bundle_binstub)
18+
else
19+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
20+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
21+
end
22+
end
23+
24+
require "rubygems"
25+
require "bundler/setup"
26+
27+
load Gem.bin_path("rspec-core", "rspec")

bin/rubocop

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
#
5+
# This file was generated by Bundler.
6+
#
7+
# The application 'rubocop' is installed as part of a gem, and
8+
# this file is here to facilitate running it.
9+
#
10+
11+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
12+
13+
bundle_binstub = File.expand_path("bundle", __dir__)
14+
15+
if File.file?(bundle_binstub)
16+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
17+
load(bundle_binstub)
18+
else
19+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
20+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
21+
end
22+
end
23+
24+
require "rubygems"
25+
require "bundler/setup"
26+
27+
load Gem.bin_path("rubocop", "rubocop")

0 commit comments

Comments
 (0)