Skip to content

Commit 2b38390

Browse files
authored
Merge pull request #11 from blocknotes/docs/improve-documentation-3
docs: improve documentation 3
2 parents 0a9638c + b22b0e1 commit 2b38390

File tree

6 files changed

+97
-33
lines changed

6 files changed

+97
-33
lines changed

README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,31 @@
44

55
A compact and composable dashboard component for Ruby.
66

7-
The main features are:
8-
- a Rack app that can be mounted in any Rack-enabled framework, it can even work standalone;
7+
Main features:
8+
- a Rack app that can be mounted in any Rack-enabled framework or used standalone;
99
- structured with plugins also for main components that can be replaced with little effort;
10-
- routing is provided by Roda, which is small and performant;
11-
- views are Phlex components, so plain Ruby objects for views and no assets are needed.
10+
- routing is provided by Roda which is small and performant;
11+
- views are Phlex components, so plain Ruby objects for views, no assets are needed.
1212

1313
Please ⭐ if you like it.
1414

1515
![screenshot](extra/screenshot.png)
1616

1717
## Install
1818

19-
- Add to your Gemfile: `gem 'tiny_admin', '~> 0.1'`
19+
- Add to your Gemfile: `gem 'tiny_admin', '~> 0.2'`
2020
- Mount the app in a route (check some examples with: Hanami, Rails, Roda and standalone in [extra](extra))
21-
- Configure the dashboard using `TinyAdmin.configure` and/or `TinyAdmin.configure_from_file` (see [configuration](#configuration) below)
21+
+ in Rails, update _config/routes.rb_: `mount TinyAdmin::Router => '/admin'`
22+
- Configure the dashboard using `TinyAdmin.configure` and/or `TinyAdmin.configure_from_file` (see [configuration](#configuration) below):
23+
24+
```rb
25+
TinyAdmin.configure do |settings|
26+
settings.root = {
27+
title: 'Home',
28+
page: Admin::PageRoot
29+
}
30+
end
31+
```
2232

2333
## Plugins and components
2434

extra/sample_features_app/Gemfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
source 'https://rubygems.org'
4+
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
5+
6+
gem 'faker'
7+
gem 'rack'
8+
gem 'rackup'
9+
gem 'webrick'
10+
11+
gem 'pry'
12+
13+
gem 'tiny_admin', path: '../../'
14+
# gem 'tiny_admin'
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
PATH
2+
remote: ../..
3+
specs:
4+
tiny_admin (0.2.0)
5+
phlex (~> 1)
6+
roda (~> 3)
7+
tilt (~> 2)
8+
zeitwerk (~> 2)
9+
10+
GEM
11+
remote: https://rubygems.org/
12+
specs:
13+
cgi (0.3.6)
14+
coderay (1.1.3)
15+
concurrent-ruby (1.2.2)
16+
erb (4.0.2)
17+
cgi (>= 0.3.3)
18+
faker (3.1.1)
19+
i18n (>= 1.8.11, < 2)
20+
i18n (1.12.0)
21+
concurrent-ruby (~> 1.0)
22+
method_source (1.0.0)
23+
phlex (1.6.1)
24+
concurrent-ruby (~> 1.2)
25+
erb (>= 4)
26+
zeitwerk (~> 2.6)
27+
pry (0.14.2)
28+
coderay (~> 1.1)
29+
method_source (~> 1.0)
30+
rack (3.0.7)
31+
rackup (2.1.0)
32+
rack (>= 3)
33+
webrick (~> 1.8)
34+
roda (3.66.0)
35+
rack
36+
tilt (2.1.0)
37+
webrick (1.8.1)
38+
zeitwerk (2.6.7)
39+
40+
PLATFORMS
41+
arm64-darwin-22
42+
43+
DEPENDENCIES
44+
faker
45+
pry
46+
rack
47+
rackup
48+
tiny_admin!
49+
webrick
50+
51+
BUNDLED WITH
52+
2.4.7

extra/sample_features_app/admin/items.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
# frozen_string_literal: true
22

33
module Admin
4-
COLUMNS = %i[id first_col second_col third_col].freeze
4+
COLUMNS = %i[id name full_address phone_number].freeze
55

66
Column = Struct.new(:name, :title, :type, :options)
77
Item = Struct.new(*COLUMNS)
88

9-
RECORDS = [
10-
Item.new(1, 'value a1', 'value a2', 'value a3'),
11-
Item.new(2, 'value b1', 'value b2', 'value b3'),
12-
Item.new(3, 'value c1', 'value c2', 'value c3')
13-
].freeze
9+
RECORDS = 1.upto(100).map do |i|
10+
Item.new(i, Faker::Name.name, Faker::Address.full_address, Faker::PhoneNumber.phone_number)
11+
end
1412

15-
class ItemsRepo < TinyAdmin::Plugins::BaseRepository
13+
class ItemsRepo < ::TinyAdmin::Plugins::BaseRepository
1614
def fields(options: nil)
1715
COLUMNS.map do |name|
1816
Column.new(name, name.to_s.tr('_', ' '), :string, {})
@@ -28,8 +26,9 @@ def index_title
2826
end
2927

3028
def list(page: 1, limit: 10, filters: nil, sort: ['id'])
29+
page_offset = page.positive? ? (page - 1) * limit : 0
3130
[
32-
RECORDS,
31+
RECORDS[page_offset...page_offset + limit],
3332
RECORDS.size
3433
]
3534
end

extra/sample_features_app/app.rb

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,9 @@
11
# frozen_string_literal: true
22

3-
# --- dependencies -------------------------------------------------------------
4-
begin
5-
require 'bundler/inline'
6-
rescue LoadError => e
7-
abort "#{e} - Bundler version 1.10 or later is required. Please update your Bundler"
8-
end
3+
require 'bundler'
4+
Bundler.require
95

10-
gemfile(true) do
11-
source 'https://rubygems.org'
12-
13-
gem 'rack'
14-
gem 'rackup'
15-
gem 'webrick'
16-
17-
gem 'tiny_admin', path: '../../'
18-
end
19-
20-
# --- Sample features application ----------------------------------------------
216
Dir[File.expand_path('admin/**/*.rb', __dir__)].each { |f| require f }
22-
237
TinyAdmin.configure_from_file('./tiny_admin.yml')
248

25-
Rackup::Server.new(app: TinyAdmin::Router, Port: 3000).start
9+
Rackup::Server.new(app: TinyAdmin::Router, Port: 3000).start if __FILE__ == $PROGRAM_NAME
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# frozen_string_literal: true
2+
3+
require_relative 'app'
4+
5+
run TinyAdmin::Router

0 commit comments

Comments
 (0)