Skip to content

Commit c483e44

Browse files
authored
Merge pull request #37 from blocknotes/feat/rbs
feat: RBS support
2 parents 36bb4b9 + 6cdb847 commit c483e44

Some content is hidden

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

41 files changed

+546
-26
lines changed

.github/workflows/specs.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,7 @@ jobs:
3232
run: cd spec/dummy_rails && bundle exec rails db:migrate
3333

3434
- name: Run tests
35-
run: bundle exec rspec --profile
35+
env:
36+
RUBYOPT: '-rbundler/setup -rrbs/test/setup'
37+
RBS_TEST_TARGET: 'TinyAdmin::*'
38+
run: bin/rspec --profile

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ group :development, :test do
1313
gem 'warden'
1414
gem 'webrick'
1515

16+
gem 'rbs'
17+
1618
# Testing
1719
gem 'capybara'
1820
gem 'capybara-screenshot'

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
lint:
2+
bin/rubocop
3+
4+
test:
5+
bin/rspec
6+
7+
test_rbs:
8+
RUBYOPT='-rbundler/setup -rrbs/test/setup' RBS_TEST_TARGET='TinyAdmin::*' bin/rspec

bin/rbs

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 'rbs' 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("rbs", "rbs")

lib/tiny_admin/actions/index.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ def prepare_filters(fields)
5858
end
5959
end
6060

61-
def setup_pagination(page, pagination_component_class, total_count:)
61+
def setup_pagination(page, pagination_component, total_count:)
6262
@pages = (total_count / pagination.to_f).ceil
63-
return if pages <= 1 || !pagination_component_class
63+
return if pages <= 1 || !pagination_component
6464

6565
attributes = { current: current_page, pages: pages, query_string: query_string, total_count: total_count }
66-
page.pagination_component = pagination_component_class.new
66+
page.pagination_component = pagination_component.new
6767
page.pagination_component.update_attributes(attributes)
6868
end
6969
end

lib/tiny_admin/router.rb

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,37 +53,37 @@ def render_page(page)
5353
render(inline: page.call)
5454
end
5555

56-
def root_route(router)
56+
def root_route(req)
5757
if TinyAdmin.settings.root[:redirect]
58-
router.redirect route_for(TinyAdmin.settings.root[:redirect])
58+
req.redirect route_for(TinyAdmin.settings.root[:redirect])
5959
else
6060
page_class = to_class(TinyAdmin.settings.root[:page])
6161
attributes = TinyAdmin.settings.root.slice(:content, :title, :widgets)
6262
render_page prepare_page(page_class, attributes: attributes, params: request.params)
6363
end
6464
end
6565

66-
def setup_page_route(router, slug, page_data)
67-
router.get slug do
66+
def setup_page_route(req, slug, page_data)
67+
req.get slug do
6868
attributes = page_data.slice(:content, :title, :widgets)
6969
render_page prepare_page(page_data[:class], slug: slug, attributes: attributes, params: request.params)
7070
end
7171
end
7272

73-
def setup_resource_routes(router, slug, options:)
74-
router.on slug do
75-
setup_collection_routes(router, slug, options: options)
76-
setup_member_routes(router, slug, options: options)
73+
def setup_resource_routes(req, slug, options:)
74+
req.on slug do
75+
setup_collection_routes(req, slug, options: options)
76+
setup_member_routes(req, slug, options: options)
7777
end
7878
end
7979

80-
def setup_collection_routes(router, slug, options:)
80+
def setup_collection_routes(req, slug, options:)
8181
repository = options[:repository].new(options[:model])
8282
action_options = options[:index] || {}
8383

8484
# Custom actions
8585
custom_actions = setup_custom_actions(
86-
router,
86+
req,
8787
options[:collection_actions],
8888
options: action_options,
8989
repository: repository,
@@ -92,12 +92,12 @@ def setup_collection_routes(router, slug, options:)
9292

9393
# Index
9494
if options[:only].include?(:index) || options[:only].include?('index')
95-
router.is do
95+
req.is do
9696
context = Context.new(
9797
actions: custom_actions,
9898
repository: repository,
9999
request: request,
100-
router: router,
100+
router: req,
101101
slug: slug
102102
)
103103
index_action = TinyAdmin::Actions::Index.new
@@ -106,14 +106,14 @@ def setup_collection_routes(router, slug, options:)
106106
end
107107
end
108108

109-
def setup_member_routes(router, slug, options:)
109+
def setup_member_routes(req, slug, options:)
110110
repository = options[:repository].new(options[:model])
111111
action_options = (options[:show] || {}).merge(record_not_found_page: TinyAdmin.settings.record_not_found)
112112

113-
router.on String do |reference|
113+
req.on String do |reference|
114114
# Custom actions
115115
custom_actions = setup_custom_actions(
116-
router,
116+
req,
117117
options[:member_actions],
118118
options: action_options,
119119
repository: repository,
@@ -123,13 +123,13 @@ def setup_member_routes(router, slug, options:)
123123

124124
# Show
125125
if options[:only].include?(:show) || options[:only].include?('show')
126-
router.is do
126+
req.is do
127127
context = Context.new(
128128
actions: custom_actions,
129129
reference: reference,
130130
repository: repository,
131131
request: request,
132-
router: router,
132+
router: req,
133133
slug: slug
134134
)
135135
show_action = TinyAdmin::Actions::Show.new
@@ -139,18 +139,18 @@ def setup_member_routes(router, slug, options:)
139139
end
140140
end
141141

142-
def setup_custom_actions(router, custom_actions, options:, repository:, slug:, reference: nil)
142+
def setup_custom_actions(req, custom_actions = nil, options:, repository:, slug:, reference: nil)
143143
(custom_actions || []).each_with_object({}) do |custom_action, result|
144144
action_slug, action = custom_action.first
145145
action_class = to_class(action)
146146

147-
router.get action_slug.to_s do
147+
req.get action_slug.to_s do
148148
context = Context.new(
149149
actions: {},
150150
reference: reference,
151151
repository: repository,
152152
request: request,
153-
router: router,
153+
router: req,
154154
slug: slug
155155
)
156156
custom_action = action_class.new

lib/tiny_admin/views/actions/index.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@ module TinyAdmin
44
module Views
55
module Actions
66
class Index < DefaultLayout
7-
attr_accessor :actions, :fields, :filters, :links, :pagination_component, :prepare_record, :records, :slug
7+
attr_accessor :actions,
8+
:fields,
9+
:filters,
10+
:links,
11+
:pagination_component,
12+
:prepare_record,
13+
:records,
14+
:slug
815

916
def template
1017
super do

lib/tiny_admin/views/actions/show.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ module TinyAdmin
44
module Views
55
module Actions
66
class Show < DefaultLayout
7-
attr_accessor :actions, :fields, :prepare_record, :record, :reference, :slug
7+
attr_accessor :actions,
8+
:fields,
9+
:prepare_record,
10+
:record,
11+
:reference,
12+
:slug
813

914
def template
1015
super do

sig/tiny_admin.rbs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module TinyAdmin
2+
VERSION: String
3+
4+
def configure: () { (Settings) -> untyped } -> untyped
5+
6+
def configure_from_file: (String) -> void
7+
8+
def route_for: (String, reference: String?, action: String?, query: String?) -> String
9+
10+
def settings: -> Settings
11+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module TinyAdmin
2+
module Actions
3+
class BasicAction
4+
def attribute_options: (Array[untyped]?) -> Hash[untyped, untyped]?
5+
end
6+
end
7+
end

0 commit comments

Comments
 (0)