nitro_kit 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +20 -0
- data/Rakefile +6 -4
- data/app/components/nitro_kit/accordion.rb +68 -32
- data/app/components/nitro_kit/alert.rb +69 -0
- data/app/components/nitro_kit/avatar.rb +52 -0
- data/app/components/nitro_kit/badge.rb +46 -19
- data/app/components/nitro_kit/button.rb +99 -66
- data/app/components/nitro_kit/button_group.rb +18 -13
- data/app/components/nitro_kit/card.rb +49 -9
- data/app/components/nitro_kit/checkbox.rb +59 -41
- data/app/components/nitro_kit/checkbox_group.rb +38 -0
- data/app/components/nitro_kit/combobox.rb +138 -0
- data/app/components/nitro_kit/component.rb +45 -14
- data/app/components/nitro_kit/datepicker.rb +9 -0
- data/app/components/nitro_kit/dialog.rb +95 -0
- data/app/components/nitro_kit/dropdown.rb +112 -70
- data/app/components/nitro_kit/field.rb +221 -56
- data/app/components/nitro_kit/field_group.rb +12 -6
- data/app/components/nitro_kit/fieldset.rb +42 -7
- data/app/components/nitro_kit/form_builder.rb +45 -22
- data/app/components/nitro_kit/icon.rb +29 -8
- data/app/components/nitro_kit/input.rb +20 -10
- data/app/components/nitro_kit/label.rb +18 -5
- data/app/components/nitro_kit/pagination.rb +98 -0
- data/app/components/nitro_kit/radio_button.rb +28 -27
- data/app/components/nitro_kit/radio_button_group.rb +53 -0
- data/app/components/nitro_kit/select.rb +72 -0
- data/app/components/nitro_kit/switch.rb +49 -39
- data/app/components/nitro_kit/table.rb +56 -0
- data/app/components/nitro_kit/tabs.rb +98 -0
- data/app/components/nitro_kit/textarea.rb +26 -0
- data/app/components/nitro_kit/toast.rb +104 -0
- data/app/components/nitro_kit/tooltip.rb +53 -0
- data/app/helpers/nitro_kit/accordion_helper.rb +2 -0
- data/app/helpers/nitro_kit/alert_helper.rb +11 -0
- data/app/helpers/nitro_kit/avatar_helper.rb +9 -0
- data/app/helpers/nitro_kit/badge_helper.rb +3 -5
- data/app/helpers/nitro_kit/button_group_helper.rb +2 -0
- data/app/helpers/nitro_kit/button_helper.rb +37 -28
- data/app/helpers/nitro_kit/card_helper.rb +2 -0
- data/app/helpers/nitro_kit/checkbox_helper.rb +19 -16
- data/app/helpers/nitro_kit/combobox_helper.rb +9 -0
- data/app/helpers/nitro_kit/datepicker_helper.rb +9 -0
- data/app/helpers/nitro_kit/dialog_helper.rb +9 -0
- data/app/helpers/nitro_kit/dropdown_helper.rb +3 -1
- data/app/helpers/nitro_kit/field_group_helper.rb +9 -0
- data/app/helpers/nitro_kit/field_helper.rb +4 -2
- data/app/helpers/nitro_kit/fieldset_helper.rb +9 -0
- data/app/helpers/nitro_kit/form_helper.rb +13 -0
- data/app/helpers/nitro_kit/icon_helper.rb +3 -1
- data/app/helpers/nitro_kit/input_helper.rb +35 -0
- data/app/helpers/nitro_kit/label_helper.rb +12 -9
- data/app/helpers/nitro_kit/pagination_helper.rb +42 -0
- data/app/helpers/nitro_kit/radio_button_helper.rb +15 -12
- data/app/helpers/nitro_kit/select_helper.rb +24 -0
- data/app/helpers/nitro_kit/switch_helper.rb +4 -10
- data/app/helpers/nitro_kit/table_helper.rb +9 -0
- data/app/helpers/nitro_kit/tabs_helper.rb +9 -0
- data/app/helpers/nitro_kit/textarea_helper.rb +9 -0
- data/app/helpers/nitro_kit/toast_helper.rb +36 -0
- data/app/helpers/nitro_kit/tooltip_helper.rb +9 -0
- data/lib/generators/nitro_kit/add_generator.rb +38 -41
- data/lib/generators/nitro_kit/install_generator.rb +2 -1
- data/lib/nitro_kit/engine.rb +4 -0
- data/lib/nitro_kit/schema_builder.rb +90 -16
- data/lib/nitro_kit/version.rb +1 -1
- data/lib/nitro_kit.rb +39 -1
- data/lib/tasks/nitro_kit_tasks.rake +4 -0
- metadata +37 -10
- data/app/components/nitro_kit/radio_group.rb +0 -35
- data/app/helpers/application_helper.rb +0 -109
- data/lib/nitro_kit/railtie.rb +0 -8
@@ -1,87 +1,84 @@
|
|
1
|
-
require "nitro_kit/schema_builder"
|
2
|
-
|
3
1
|
module NitroKit
|
4
2
|
class AddGenerator < Rails::Generators::Base
|
5
3
|
argument :component_names, type: :array
|
6
4
|
|
7
|
-
source_root File.expand_path("../../../", __dir__)
|
8
|
-
|
9
|
-
extend SchemaBuilder
|
10
|
-
|
11
|
-
SCHEMA = build_schema do |s|
|
12
|
-
s.add(:badge)
|
13
|
-
s.add(
|
14
|
-
:button,
|
15
|
-
components: [:button, :button_group],
|
16
|
-
helpers: [:button, :button_group]
|
17
|
-
)
|
18
|
-
s.add(
|
19
|
-
:dropdown,
|
20
|
-
js: [:dropdown],
|
21
|
-
modules: ["@floating-ui/core", "@floating-ui/dom"]
|
22
|
-
)
|
23
|
-
s.add(
|
24
|
-
:icon,
|
25
|
-
gems: ["lucide-rails"]
|
26
|
-
)
|
27
|
-
end
|
5
|
+
source_root File.expand_path("../../../", __dir__).tap { |path| puts path }
|
28
6
|
|
29
7
|
def copy_base_component
|
30
8
|
copy_file("app/components/nitro_kit/component.rb", "app/components/nitro_kit/component.rb")
|
31
9
|
end
|
32
10
|
|
33
11
|
def copy_component_files
|
34
|
-
components.each do |
|
35
|
-
|
36
|
-
copy_file(path, path)
|
37
|
-
end
|
12
|
+
components.map(&:all_files).flatten.uniq.each do |path|
|
13
|
+
copy_file(path, path)
|
38
14
|
end
|
39
15
|
end
|
40
16
|
|
41
17
|
def add_gems
|
42
|
-
gems = components.flat_map(&:
|
18
|
+
gems = components.flat_map(&:all_gems)
|
43
19
|
|
44
20
|
return unless gems.any?
|
45
21
|
|
46
22
|
gems.each do |name|
|
47
|
-
gem(name)
|
23
|
+
gem(name) unless has_gem?(name)
|
48
24
|
end
|
49
25
|
|
50
26
|
run("bundle install")
|
51
27
|
end
|
52
28
|
|
53
29
|
def install_modules
|
54
|
-
modules = components.flat_map(&:
|
30
|
+
modules = components.flat_map(&:all_modules).uniq
|
55
31
|
|
56
32
|
return unless modules.any?
|
57
33
|
|
58
|
-
|
34
|
+
case js_strategy
|
35
|
+
when :importmaps
|
59
36
|
run("bin/importmap pin #{modules.join(" ")}")
|
37
|
+
when :yarn
|
38
|
+
run("yarn add #{modules.join(" ")}")
|
39
|
+
when :npm
|
40
|
+
run("npm install --save #{modules.join(" ")}")
|
41
|
+
when :bun
|
42
|
+
run("bun add #{modules.join(" ")}")
|
60
43
|
else
|
61
|
-
say("
|
44
|
+
say("Could not determine JS strategy. Please install one of: npm, yarn, bun, or importmaps")
|
62
45
|
end
|
63
46
|
end
|
64
47
|
|
65
48
|
private
|
66
49
|
|
67
50
|
def components
|
68
|
-
|
51
|
+
return @components if @components
|
69
52
|
|
70
|
-
if
|
71
|
-
|
53
|
+
if component_names == ["all"]
|
54
|
+
return @components = SCHEMA.all
|
72
55
|
end
|
73
56
|
|
74
|
-
|
75
|
-
|
76
|
-
|
57
|
+
# Component names + their dependencies
|
58
|
+
@components = component_names
|
59
|
+
.flat_map do |name|
|
60
|
+
component = SCHEMA.find(name)
|
61
|
+
[component] + component.dependencies
|
77
62
|
end
|
63
|
+
end
|
78
64
|
|
79
|
-
|
65
|
+
def js_strategy
|
66
|
+
if File.exist?(File.expand_path("bin/importmap", Rails.root))
|
67
|
+
:importmaps
|
68
|
+
elsif File.exist?(File.expand_path("yarn.lock", Rails.root))
|
69
|
+
:yarn
|
70
|
+
elsif File.exist?(File.expand_path("package-lock.json", Rails.root))
|
71
|
+
:npm
|
72
|
+
elsif File.exist?(File.expand_path("bun.lockb", Rails.root))
|
73
|
+
:bun
|
74
|
+
else
|
75
|
+
nil
|
80
76
|
end
|
81
77
|
end
|
82
78
|
|
83
|
-
def
|
84
|
-
File.
|
79
|
+
def has_gem?(name)
|
80
|
+
gemfile = File.read(File.expand_path("Gemfile", Rails.root))
|
81
|
+
gemfile.include?("gem '#{name}'") || gemfile.include?("gem \"#{name}\"")
|
85
82
|
end
|
86
83
|
end
|
87
84
|
end
|
@@ -2,7 +2,8 @@ module NitroKit
|
|
2
2
|
module Generators
|
3
3
|
class InstallGenerator < Rails::Generators::Base
|
4
4
|
def one
|
5
|
-
puts("
|
5
|
+
puts("Maybe, maybe not. Seems complex. Maybe only support greenfield apps?")
|
6
|
+
puts("Manual instructions: https://nitrokit.dev/getting_started")
|
6
7
|
end
|
7
8
|
end
|
8
9
|
end
|
@@ -1,15 +1,69 @@
|
|
1
1
|
module NitroKit
|
2
2
|
module SchemaBuilder
|
3
|
-
Component
|
3
|
+
class Component
|
4
|
+
def initialize(schema, name, dependencies:, files:, modules:, gems:)
|
5
|
+
@schema = schema
|
6
|
+
@name = name
|
7
|
+
@unresolved_dependencies = dependencies
|
8
|
+
@files = files
|
9
|
+
@modules = modules
|
10
|
+
@gems = gems
|
11
|
+
@resolved = false
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :name, :files, :modules, :gems, :unresolved_dependencies
|
15
|
+
|
16
|
+
def dependencies
|
17
|
+
raise "Component not resolved" unless resolved?
|
18
|
+
@dependencies
|
19
|
+
end
|
20
|
+
|
21
|
+
def resolve!
|
22
|
+
raise "Component already resolved" if resolved?
|
23
|
+
|
24
|
+
@dependencies = @unresolved_dependencies
|
25
|
+
.each_with_object(Set.new) do |name, list|
|
26
|
+
list.add(name)
|
27
|
+
list.merge(@schema.find(name).unresolved_dependencies)
|
28
|
+
end
|
29
|
+
.map { |name| @schema.find(name) }
|
30
|
+
|
31
|
+
@resolved = true
|
32
|
+
end
|
33
|
+
|
34
|
+
def resolved?
|
35
|
+
@resolved
|
36
|
+
end
|
37
|
+
|
38
|
+
def all_files
|
39
|
+
(files + dependencies.flat_map(&:files)).sort
|
40
|
+
end
|
41
|
+
|
42
|
+
def all_modules
|
43
|
+
(modules + dependencies.flat_map(&:modules)).sort
|
44
|
+
end
|
4
45
|
|
5
|
-
|
46
|
+
def all_gems
|
47
|
+
(gems + dependencies.flat_map(&:gems)).sort
|
48
|
+
end
|
49
|
+
|
50
|
+
def has_dependencies?
|
51
|
+
return true if gems.any?
|
52
|
+
return true if modules.any?
|
53
|
+
false
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class Schema
|
6
58
|
def initialize
|
7
|
-
@schema =
|
59
|
+
@schema = []
|
8
60
|
yield self
|
61
|
+
resolve!
|
9
62
|
end
|
10
63
|
|
11
64
|
def add(
|
12
65
|
name,
|
66
|
+
dependencies = [],
|
13
67
|
components: nil,
|
14
68
|
helpers: nil,
|
15
69
|
js: [],
|
@@ -20,28 +74,48 @@ module NitroKit
|
|
20
74
|
components ||= [name]
|
21
75
|
helpers ||= [name]
|
22
76
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
77
|
+
files = [
|
78
|
+
components.map { |c| "app/components/nitro_kit/#{c}.rb" },
|
79
|
+
helpers.map { |c| "app/helpers/nitro_kit/#{c}_helper.rb" },
|
80
|
+
js.map { |c| "app/javascript/controllers/nk/#{c}_controller.js" }
|
81
|
+
].flatten
|
82
|
+
|
83
|
+
component = Component.new(
|
84
|
+
self,
|
85
|
+
name,
|
86
|
+
dependencies:,
|
87
|
+
files:,
|
88
|
+
modules:,
|
89
|
+
gems:
|
31
90
|
)
|
32
|
-
end
|
33
91
|
|
34
|
-
|
35
|
-
@schema[key]
|
92
|
+
@schema.push(component)
|
36
93
|
end
|
37
94
|
|
38
95
|
def all
|
39
|
-
@schema
|
96
|
+
@schema
|
97
|
+
end
|
98
|
+
|
99
|
+
def find(name)
|
100
|
+
component = @schema.find { |c| c.name == name.to_sym }
|
101
|
+
raise "Component not found: #{name}" unless component
|
102
|
+
component
|
103
|
+
end
|
104
|
+
|
105
|
+
def resolved?
|
106
|
+
@resolved
|
107
|
+
end
|
108
|
+
|
109
|
+
private
|
110
|
+
|
111
|
+
def resolve!
|
112
|
+
all.each(&:resolve!)
|
113
|
+
@resolved = true
|
40
114
|
end
|
41
115
|
end
|
42
116
|
|
43
117
|
def build_schema(&block)
|
44
|
-
|
118
|
+
Schema.new(&block)
|
45
119
|
end
|
46
120
|
end
|
47
121
|
end
|
data/lib/nitro_kit/version.rb
CHANGED
data/lib/nitro_kit.rb
CHANGED
@@ -1,8 +1,46 @@
|
|
1
1
|
require "tailwind_merge"
|
2
2
|
require "phlex/rails"
|
3
3
|
|
4
|
+
require "nitro_kit/version"
|
5
|
+
require "nitro_kit/engine"
|
4
6
|
require "nitro_kit/variants"
|
5
|
-
require "nitro_kit/
|
7
|
+
require "nitro_kit/schema_builder"
|
6
8
|
|
7
9
|
module NitroKit
|
10
|
+
extend SchemaBuilder
|
11
|
+
|
12
|
+
SCHEMA = build_schema do |s|
|
13
|
+
s.add(:accordion, js: [:accordion])
|
14
|
+
s.add(:alert)
|
15
|
+
s.add(:avatar)
|
16
|
+
s.add(:badge)
|
17
|
+
s.add(:button, [:icon], components: [:button, :button_group], helpers: [:button, :button_group])
|
18
|
+
s.add(:card)
|
19
|
+
s.add(:checkbox, [:label], components: [:checkbox, :checkbox_group])
|
20
|
+
s.add(
|
21
|
+
:combobox,
|
22
|
+
[:input],
|
23
|
+
js: [:combobox],
|
24
|
+
modules: ["@floating-ui/core", "@floating-ui/dom", "@github/combobox-nav"]
|
25
|
+
)
|
26
|
+
s.add(:datepicker)
|
27
|
+
s.add(:dialog, [:button, :icon], js: [:dialog])
|
28
|
+
s.add(:dropdown, [:button], js: [:dropdown], modules: ["@floating-ui/core", "@floating-ui/dom"])
|
29
|
+
s.add(:field, [:label, :checkbox, :combobox, :label, :radio_button, :select, :switch, :textarea])
|
30
|
+
s.add(:field_group)
|
31
|
+
s.add(:fieldset, [:field_group])
|
32
|
+
s.add(:form_builder, [:field], helpers: [:form])
|
33
|
+
s.add(:icon, gems: ["lucide-rails"])
|
34
|
+
s.add(:input)
|
35
|
+
s.add(:label)
|
36
|
+
s.add(:pagination, [:icon, :button])
|
37
|
+
s.add(:radio_button, [:label], components: [:radio_button, :radio_button_group])
|
38
|
+
s.add(:select)
|
39
|
+
s.add(:switch, js: [:switch])
|
40
|
+
s.add(:table)
|
41
|
+
s.add(:tabs, js: [:tabs])
|
42
|
+
s.add(:textarea)
|
43
|
+
s.add(:toast, js: [:toast])
|
44
|
+
s.add(:tooltip, js: [:tooltip], modules: ["@floating-ui/core", "@floating-ui/dom"])
|
45
|
+
end
|
8
46
|
end
|
metadata
CHANGED
@@ -1,17 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nitro_kit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikkel Malmberg
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-02-07 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
13
|
+
name: rails
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
16
15
|
requirements:
|
17
16
|
- - ">="
|
@@ -59,15 +58,22 @@ executables: []
|
|
59
58
|
extensions: []
|
60
59
|
extra_rdoc_files: []
|
61
60
|
files:
|
61
|
+
- MIT-LICENSE
|
62
62
|
- README.md
|
63
63
|
- Rakefile
|
64
64
|
- app/components/nitro_kit/accordion.rb
|
65
|
+
- app/components/nitro_kit/alert.rb
|
66
|
+
- app/components/nitro_kit/avatar.rb
|
65
67
|
- app/components/nitro_kit/badge.rb
|
66
68
|
- app/components/nitro_kit/button.rb
|
67
69
|
- app/components/nitro_kit/button_group.rb
|
68
70
|
- app/components/nitro_kit/card.rb
|
69
71
|
- app/components/nitro_kit/checkbox.rb
|
72
|
+
- app/components/nitro_kit/checkbox_group.rb
|
73
|
+
- app/components/nitro_kit/combobox.rb
|
70
74
|
- app/components/nitro_kit/component.rb
|
75
|
+
- app/components/nitro_kit/datepicker.rb
|
76
|
+
- app/components/nitro_kit/dialog.rb
|
71
77
|
- app/components/nitro_kit/dropdown.rb
|
72
78
|
- app/components/nitro_kit/field.rb
|
73
79
|
- app/components/nitro_kit/field_group.rb
|
@@ -76,29 +82,52 @@ files:
|
|
76
82
|
- app/components/nitro_kit/icon.rb
|
77
83
|
- app/components/nitro_kit/input.rb
|
78
84
|
- app/components/nitro_kit/label.rb
|
85
|
+
- app/components/nitro_kit/pagination.rb
|
79
86
|
- app/components/nitro_kit/radio_button.rb
|
80
|
-
- app/components/nitro_kit/
|
87
|
+
- app/components/nitro_kit/radio_button_group.rb
|
88
|
+
- app/components/nitro_kit/select.rb
|
81
89
|
- app/components/nitro_kit/switch.rb
|
82
|
-
- app/
|
90
|
+
- app/components/nitro_kit/table.rb
|
91
|
+
- app/components/nitro_kit/tabs.rb
|
92
|
+
- app/components/nitro_kit/textarea.rb
|
93
|
+
- app/components/nitro_kit/toast.rb
|
94
|
+
- app/components/nitro_kit/tooltip.rb
|
83
95
|
- app/helpers/nitro_kit/accordion_helper.rb
|
96
|
+
- app/helpers/nitro_kit/alert_helper.rb
|
97
|
+
- app/helpers/nitro_kit/avatar_helper.rb
|
84
98
|
- app/helpers/nitro_kit/badge_helper.rb
|
85
99
|
- app/helpers/nitro_kit/button_group_helper.rb
|
86
100
|
- app/helpers/nitro_kit/button_helper.rb
|
87
101
|
- app/helpers/nitro_kit/card_helper.rb
|
88
102
|
- app/helpers/nitro_kit/checkbox_helper.rb
|
103
|
+
- app/helpers/nitro_kit/combobox_helper.rb
|
104
|
+
- app/helpers/nitro_kit/datepicker_helper.rb
|
105
|
+
- app/helpers/nitro_kit/dialog_helper.rb
|
89
106
|
- app/helpers/nitro_kit/dropdown_helper.rb
|
107
|
+
- app/helpers/nitro_kit/field_group_helper.rb
|
90
108
|
- app/helpers/nitro_kit/field_helper.rb
|
109
|
+
- app/helpers/nitro_kit/fieldset_helper.rb
|
110
|
+
- app/helpers/nitro_kit/form_helper.rb
|
91
111
|
- app/helpers/nitro_kit/icon_helper.rb
|
112
|
+
- app/helpers/nitro_kit/input_helper.rb
|
92
113
|
- app/helpers/nitro_kit/label_helper.rb
|
114
|
+
- app/helpers/nitro_kit/pagination_helper.rb
|
93
115
|
- app/helpers/nitro_kit/radio_button_helper.rb
|
116
|
+
- app/helpers/nitro_kit/select_helper.rb
|
94
117
|
- app/helpers/nitro_kit/switch_helper.rb
|
118
|
+
- app/helpers/nitro_kit/table_helper.rb
|
119
|
+
- app/helpers/nitro_kit/tabs_helper.rb
|
120
|
+
- app/helpers/nitro_kit/textarea_helper.rb
|
121
|
+
- app/helpers/nitro_kit/toast_helper.rb
|
122
|
+
- app/helpers/nitro_kit/tooltip_helper.rb
|
95
123
|
- lib/generators/nitro_kit/add_generator.rb
|
96
124
|
- lib/generators/nitro_kit/install_generator.rb
|
97
125
|
- lib/nitro_kit.rb
|
98
|
-
- lib/nitro_kit/
|
126
|
+
- lib/nitro_kit/engine.rb
|
99
127
|
- lib/nitro_kit/schema_builder.rb
|
100
128
|
- lib/nitro_kit/variants.rb
|
101
129
|
- lib/nitro_kit/version.rb
|
130
|
+
- lib/tasks/nitro_kit_tasks.rake
|
102
131
|
homepage: https://github.com/mikker/nitro_kit
|
103
132
|
licenses:
|
104
133
|
- MIT
|
@@ -106,7 +135,6 @@ metadata:
|
|
106
135
|
homepage_uri: https://github.com/mikker/nitro_kit
|
107
136
|
source_code_uri: https://github.com/mikker/nitro_kit
|
108
137
|
changelog_uri: https://github.com/mikker/nitro_kit/releases
|
109
|
-
post_install_message:
|
110
138
|
rdoc_options: []
|
111
139
|
require_paths:
|
112
140
|
- lib
|
@@ -121,8 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
149
|
- !ruby/object:Gem::Version
|
122
150
|
version: '0'
|
123
151
|
requirements: []
|
124
|
-
rubygems_version: 3.
|
125
|
-
signing_key:
|
152
|
+
rubygems_version: 3.6.3
|
126
153
|
specification_version: 4
|
127
154
|
summary: WIP, not usable yet
|
128
155
|
test_files: []
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module NitroKit
|
2
|
-
class RadioGroup < Component
|
3
|
-
include ActionView::Helpers::FormTagHelper
|
4
|
-
|
5
|
-
def initialize(name, value: nil, **options)
|
6
|
-
super(**options)
|
7
|
-
@name = name
|
8
|
-
@group_value = value
|
9
|
-
end
|
10
|
-
|
11
|
-
attr_reader :name, :id, :group_value
|
12
|
-
|
13
|
-
def view_template
|
14
|
-
div(class: "flex items-start flex-col gap-2") do
|
15
|
-
yield
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def title(text = nil, **options)
|
20
|
-
render(Label.new(**options)) { text || yield }
|
21
|
-
end
|
22
|
-
|
23
|
-
def item(value, text = nil, **options)
|
24
|
-
render(
|
25
|
-
RadioButton.new(
|
26
|
-
name,
|
27
|
-
id:,
|
28
|
-
value:,
|
29
|
-
checked: group_value.presence == value,
|
30
|
-
**options
|
31
|
-
)
|
32
|
-
) { text || yield }
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,109 +0,0 @@
|
|
1
|
-
module ApplicationHelper
|
2
|
-
def component_page(&block)
|
3
|
-
tag.div(class: "p-5") do
|
4
|
-
capture(&block)
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
def title(text = nil, **attrs, &block)
|
9
|
-
text = capture(&block) if block_given?
|
10
|
-
tag.h1(**attrs, class: class_names("text-3xl font-semibold mb-6", attrs[:class])) { text }
|
11
|
-
end
|
12
|
-
|
13
|
-
def lead(text = nil, &block)
|
14
|
-
text = capture(&block) if block_given?
|
15
|
-
tag.div(class: "text-lg text-gray-600 dark:text-gray-400 mb-6") do
|
16
|
-
text
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def section(**attrs)
|
21
|
-
tag.div(
|
22
|
-
**attrs,
|
23
|
-
class: class_names("mt-8 space-y-4", attrs[:class])
|
24
|
-
) do
|
25
|
-
yield
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def section_title(text)
|
30
|
-
tag.h2(class: "text-2xl font-semibold mb-4") { text }
|
31
|
-
end
|
32
|
-
|
33
|
-
def example(**attrs)
|
34
|
-
tag
|
35
|
-
.div(
|
36
|
-
**attrs,
|
37
|
-
class: class_names(
|
38
|
-
[
|
39
|
-
"flex flex-wrap gap-2 justify-center items-center min-h-[200px] py-12 p-5 w-full rounded border overflow-scroll",
|
40
|
-
attrs[:class]
|
41
|
-
]
|
42
|
-
)
|
43
|
-
) do
|
44
|
-
yield
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def code_example(str = nil, language: :erb, toolbar: true, &block)
|
49
|
-
if block_given?
|
50
|
-
str = capture(&block)
|
51
|
-
.gsub(/{#/, "<%")
|
52
|
-
.gsub(/#}/, "%>")
|
53
|
-
end
|
54
|
-
|
55
|
-
lexer = Rouge::Lexer.find(language)
|
56
|
-
formatter = Rouge::Formatters::HTML.new
|
57
|
-
|
58
|
-
tag
|
59
|
-
.div(
|
60
|
-
class: "bg-[#f7f8fa] dark:bg-[#161b22] divide-y border rounded-sm overflow-hidden",
|
61
|
-
data: {controller: "copy-to-clipboard"}
|
62
|
-
) do
|
63
|
-
if toolbar
|
64
|
-
concat(
|
65
|
-
tag.div(class: "px-1 py-1 flex w-full") do
|
66
|
-
concat(
|
67
|
-
nk_ghost_button(
|
68
|
-
icon: :copy,
|
69
|
-
size: :xs,
|
70
|
-
data: {copy_to_clipboard_target: "button", action: "copy-to-clipboard#copy"}
|
71
|
-
) { "Copy" }
|
72
|
-
)
|
73
|
-
concat(
|
74
|
-
nk_ghost_button(
|
75
|
-
icon: :check,
|
76
|
-
size: :xs,
|
77
|
-
data: {copy_to_clipboard_target: "successMessage"},
|
78
|
-
class: "hidden"
|
79
|
-
) { "Copied!" }
|
80
|
-
)
|
81
|
-
end
|
82
|
-
)
|
83
|
-
end
|
84
|
-
|
85
|
-
concat(
|
86
|
-
tag
|
87
|
-
.pre(
|
88
|
-
class: "text-sm highlight py-3 px-4 font-mono overflow-scroll",
|
89
|
-
data: {copy_to_clipboard_target: "source"}
|
90
|
-
) do
|
91
|
-
tag.code do
|
92
|
-
formatter.format(lexer.lex(str.strip_heredoc.strip)).html_safe
|
93
|
-
end
|
94
|
-
end
|
95
|
-
)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
def markdown(str)
|
100
|
-
Commonmarker
|
101
|
-
.to_html(
|
102
|
-
str.strip_heredoc,
|
103
|
-
options: {
|
104
|
-
parse: {smart: true}
|
105
|
-
}
|
106
|
-
)
|
107
|
-
.html_safe
|
108
|
-
end
|
109
|
-
end
|
data/lib/nitro_kit/railtie.rb
DELETED