From b1886030f345ed010f7ab140b43d8a3c16c34670 Mon Sep 17 00:00:00 2001
From: Mattia Roccoberton <mattia.roccoberton@telepass.com>
Date: Tue, 11 Apr 2023 08:54:54 +0200
Subject: [PATCH 1/2] docs: improve sample_features_app example

---
 extra/sample_features_app/Gemfile        | 14 +++++++
 extra/sample_features_app/Gemfile.lock   | 52 ++++++++++++++++++++++++
 extra/sample_features_app/admin/items.rb | 15 ++++---
 extra/sample_features_app/app.rb         | 22 ++--------
 extra/sample_features_app/config.ru      |  5 +++
 5 files changed, 81 insertions(+), 27 deletions(-)
 create mode 100644 extra/sample_features_app/Gemfile
 create mode 100644 extra/sample_features_app/Gemfile.lock
 create mode 100644 extra/sample_features_app/config.ru

diff --git a/extra/sample_features_app/Gemfile b/extra/sample_features_app/Gemfile
new file mode 100644
index 0000000..ee60378
--- /dev/null
+++ b/extra/sample_features_app/Gemfile
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+source 'https://rubygems.org'
+git_source(:github) { |repo| "https://github.com/#{repo}.git" }
+
+gem 'faker'
+gem 'rack'
+gem 'rackup'
+gem 'webrick'
+
+gem 'pry'
+
+gem 'tiny_admin', path: '../../'
+# gem 'tiny_admin'
diff --git a/extra/sample_features_app/Gemfile.lock b/extra/sample_features_app/Gemfile.lock
new file mode 100644
index 0000000..37ca21f
--- /dev/null
+++ b/extra/sample_features_app/Gemfile.lock
@@ -0,0 +1,52 @@
+PATH
+  remote: ../..
+  specs:
+    tiny_admin (0.2.0)
+      phlex (~> 1)
+      roda (~> 3)
+      tilt (~> 2)
+      zeitwerk (~> 2)
+
+GEM
+  remote: https://rubygems.org/
+  specs:
+    cgi (0.3.6)
+    coderay (1.1.3)
+    concurrent-ruby (1.2.2)
+    erb (4.0.2)
+      cgi (>= 0.3.3)
+    faker (3.1.1)
+      i18n (>= 1.8.11, < 2)
+    i18n (1.12.0)
+      concurrent-ruby (~> 1.0)
+    method_source (1.0.0)
+    phlex (1.6.1)
+      concurrent-ruby (~> 1.2)
+      erb (>= 4)
+      zeitwerk (~> 2.6)
+    pry (0.14.2)
+      coderay (~> 1.1)
+      method_source (~> 1.0)
+    rack (3.0.7)
+    rackup (2.1.0)
+      rack (>= 3)
+      webrick (~> 1.8)
+    roda (3.66.0)
+      rack
+    tilt (2.1.0)
+    webrick (1.8.1)
+    zeitwerk (2.6.7)
+
+PLATFORMS
+  arm64-darwin-22
+
+DEPENDENCIES
+  faker
+  pry
+  rack
+  rackup
+  tiny_admin!
+  webrick
+
+BUNDLED WITH
+   2.4.7
diff --git a/extra/sample_features_app/admin/items.rb b/extra/sample_features_app/admin/items.rb
index d6a6640..4884530 100644
--- a/extra/sample_features_app/admin/items.rb
+++ b/extra/sample_features_app/admin/items.rb
@@ -1,18 +1,16 @@
 # frozen_string_literal: true
 
 module Admin
-  COLUMNS = %i[id first_col second_col third_col].freeze
+  COLUMNS = %i[id name full_address phone_number].freeze
 
   Column = Struct.new(:name, :title, :type, :options)
   Item = Struct.new(*COLUMNS)
 
-  RECORDS = [
-    Item.new(1, 'value a1', 'value a2', 'value a3'),
-    Item.new(2, 'value b1', 'value b2', 'value b3'),
-    Item.new(3, 'value c1', 'value c2', 'value c3')
-  ].freeze
+  RECORDS = 1.upto(100).map do |i|
+    Item.new(i, Faker::Name.name, Faker::Address.full_address, Faker::PhoneNumber.phone_number)
+  end
 
-  class ItemsRepo < TinyAdmin::Plugins::BaseRepository
+  class ItemsRepo < ::TinyAdmin::Plugins::BaseRepository
     def fields(options: nil)
       COLUMNS.map do |name|
         Column.new(name, name.to_s.tr('_', ' '), :string, {})
@@ -28,8 +26,9 @@ def index_title
     end
 
     def list(page: 1, limit: 10, filters: nil, sort: ['id'])
+      page_offset = page.positive? ? (page - 1) * limit : 0
       [
-        RECORDS,
+        RECORDS[page_offset...page_offset + limit],
         RECORDS.size
       ]
     end
diff --git a/extra/sample_features_app/app.rb b/extra/sample_features_app/app.rb
index bed5be2..66d937b 100644
--- a/extra/sample_features_app/app.rb
+++ b/extra/sample_features_app/app.rb
@@ -1,25 +1,9 @@
 # frozen_string_literal: true
 
-# --- dependencies -------------------------------------------------------------
-begin
-  require 'bundler/inline'
-rescue LoadError => e
-  abort "#{e} - Bundler version 1.10 or later is required. Please update your Bundler"
-end
+require 'bundler'
+Bundler.require
 
-gemfile(true) do
-  source 'https://rubygems.org'
-
-  gem 'rack'
-  gem 'rackup'
-  gem 'webrick'
-
-  gem 'tiny_admin', path: '../../'
-end
-
-# --- Sample features application ----------------------------------------------
 Dir[File.expand_path('admin/**/*.rb', __dir__)].each { |f| require f }
-
 TinyAdmin.configure_from_file('./tiny_admin.yml')
 
-Rackup::Server.new(app: TinyAdmin::Router, Port: 3000).start
+Rackup::Server.new(app: TinyAdmin::Router, Port: 3000).start if __FILE__ == $PROGRAM_NAME
diff --git a/extra/sample_features_app/config.ru b/extra/sample_features_app/config.ru
new file mode 100644
index 0000000..243f81b
--- /dev/null
+++ b/extra/sample_features_app/config.ru
@@ -0,0 +1,5 @@
+# frozen_string_literal: true
+
+require_relative 'app'
+
+run TinyAdmin::Router

From b22b0e11997d36ccf33f04ff60ab8abe4853ebc1 Mon Sep 17 00:00:00 2001
From: Mattia Roccoberton <mattia.roccoberton@telepass.com>
Date: Tue, 11 Apr 2023 09:00:39 +0200
Subject: [PATCH 2/2] docs: improve README

---
 README.md | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/README.md b/README.md
index 43b4dd0..c26f39c 100644
--- a/README.md
+++ b/README.md
@@ -4,11 +4,11 @@
 
 A compact and composable dashboard component for Ruby.
 
-The main features are:
-- a Rack app that can be mounted in any Rack-enabled framework, it can even work standalone;
+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 and no assets are needed.
+- 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.
 
@@ -16,9 +16,19 @@ Please ⭐ if you like it.
 
 ## Install
 
-- Add to your Gemfile: `gem 'tiny_admin', '~> 0.1'`
+- Add to your Gemfile: `gem 'tiny_admin', '~> 0.2'`
 - Mount the app in a route (check some examples with: Hanami, Rails, Roda and standalone in [extra](extra))
-- Configure the dashboard using `TinyAdmin.configure` and/or `TinyAdmin.configure_from_file` (see [configuration](#configuration) below)
+  + in Rails, update _config/routes.rb_: `mount TinyAdmin::Router => '/admin'`
+- Configure the dashboard using `TinyAdmin.configure` and/or `TinyAdmin.configure_from_file` (see [configuration](#configuration) below):
+
+```rb
+TinyAdmin.configure do |settings|
+  settings.root = {
+    title: 'Home',
+    page: Admin::PageRoot
+  }
+end
+```
 
 ## Plugins and components
 
