ruflet_rails 0.0.13 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +165 -62
- data/lib/generators/ruflet/install/install_generator.rb +3 -3
- data/lib/ruflet/rails/configuration.rb +13 -7
- data/lib/ruflet/rails/install_support.rb +19 -637
- data/lib/ruflet/rails/native_app/actions.rb +167 -0
- data/lib/ruflet/rails/native_app/customization.rb +118 -0
- data/lib/ruflet/rails/native_app/html_adapter.rb +248 -0
- data/lib/ruflet/rails/native_app/navigation.rb +645 -0
- data/lib/ruflet/rails/native_app/overlays.rb +222 -0
- data/lib/ruflet/rails/native_app/shell.rb +390 -0
- data/lib/ruflet/rails/native_app.rb +25 -222
- data/lib/ruflet/rails/protocol/web_app.rb +1 -1
- data/lib/ruflet/rails/railtie.rb +3 -20
- data/lib/ruflet/rails/view_helpers.rb +205 -0
- data/lib/ruflet/rails.rb +22 -55
- data/lib/ruflet/version.rb +1 -1
- data/lib/ruflet_rails.rb +0 -4
- metadata +14 -15
- data/lib/generators/ruflet/form/form_generator.rb +0 -55
- data/lib/generators/ruflet/scaffold/scaffold_generator.rb +0 -54
- data/lib/ruflet/rails/form_helpers.rb +0 -161
- data/lib/ruflet/rails/generator_hooks.rb +0 -25
- data/lib/ruflet/rails/resource_component.rb +0 -370
- data/lib/ruflet/rails/route_stack.rb +0 -90
- data/lib/ruflet/rails/webview_app.rb +0 -54
data/lib/ruflet_rails.rb
CHANGED
|
@@ -10,10 +10,6 @@ end
|
|
|
10
10
|
require "ruflet_core"
|
|
11
11
|
require "ruflet_server"
|
|
12
12
|
require_relative "ruflet/rails/session_registry"
|
|
13
|
-
require_relative "ruflet/rails/form_helpers"
|
|
14
|
-
require_relative "ruflet/rails/resource_component"
|
|
15
|
-
require_relative "ruflet/rails/route_stack"
|
|
16
|
-
require_relative "ruflet/rails/webview_app"
|
|
17
13
|
require_relative "ruflet/rails/native_app"
|
|
18
14
|
require_relative "ruflet/rails/view_helpers"
|
|
19
15
|
require_relative "ruflet/rails/desktop_launcher"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruflet_rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.14
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Adam Moussa Ali
|
|
@@ -29,42 +29,42 @@ dependencies:
|
|
|
29
29
|
requirements:
|
|
30
30
|
- - ">="
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: 0.0.
|
|
32
|
+
version: 0.0.17
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
37
|
- - ">="
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: 0.0.
|
|
39
|
+
version: 0.0.17
|
|
40
40
|
- !ruby/object:Gem::Dependency
|
|
41
41
|
name: ruflet_core
|
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
|
43
43
|
requirements:
|
|
44
44
|
- - ">="
|
|
45
45
|
- !ruby/object:Gem::Version
|
|
46
|
-
version: 0.0.
|
|
46
|
+
version: 0.0.17
|
|
47
47
|
type: :runtime
|
|
48
48
|
prerelease: false
|
|
49
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
50
50
|
requirements:
|
|
51
51
|
- - ">="
|
|
52
52
|
- !ruby/object:Gem::Version
|
|
53
|
-
version: 0.0.
|
|
53
|
+
version: 0.0.17
|
|
54
54
|
- !ruby/object:Gem::Dependency
|
|
55
55
|
name: ruflet_server
|
|
56
56
|
requirement: !ruby/object:Gem::Requirement
|
|
57
57
|
requirements:
|
|
58
58
|
- - ">="
|
|
59
59
|
- !ruby/object:Gem::Version
|
|
60
|
-
version: 0.0.
|
|
60
|
+
version: 0.0.17
|
|
61
61
|
type: :runtime
|
|
62
62
|
prerelease: false
|
|
63
63
|
version_requirements: !ruby/object:Gem::Requirement
|
|
64
64
|
requirements:
|
|
65
65
|
- - ">="
|
|
66
66
|
- !ruby/object:Gem::Version
|
|
67
|
-
version: 0.0.
|
|
67
|
+
version: 0.0.17
|
|
68
68
|
description: Build cross-platform mobile and desktop apps with Ruby on Rails using
|
|
69
69
|
Ruflet.
|
|
70
70
|
email:
|
|
@@ -74,17 +74,19 @@ extensions: []
|
|
|
74
74
|
extra_rdoc_files: []
|
|
75
75
|
files:
|
|
76
76
|
- README.md
|
|
77
|
-
- lib/generators/ruflet/form/form_generator.rb
|
|
78
77
|
- lib/generators/ruflet/install/install_generator.rb
|
|
79
|
-
- lib/generators/ruflet/scaffold/scaffold_generator.rb
|
|
80
78
|
- lib/ruflet/rails.rb
|
|
81
79
|
- lib/ruflet/rails/assets.rb
|
|
82
80
|
- lib/ruflet/rails/configuration.rb
|
|
83
81
|
- lib/ruflet/rails/desktop_launcher.rb
|
|
84
|
-
- lib/ruflet/rails/form_helpers.rb
|
|
85
|
-
- lib/ruflet/rails/generator_hooks.rb
|
|
86
82
|
- lib/ruflet/rails/install_support.rb
|
|
87
83
|
- lib/ruflet/rails/native_app.rb
|
|
84
|
+
- lib/ruflet/rails/native_app/actions.rb
|
|
85
|
+
- lib/ruflet/rails/native_app/customization.rb
|
|
86
|
+
- lib/ruflet/rails/native_app/html_adapter.rb
|
|
87
|
+
- lib/ruflet/rails/native_app/navigation.rb
|
|
88
|
+
- lib/ruflet/rails/native_app/overlays.rb
|
|
89
|
+
- lib/ruflet/rails/native_app/shell.rb
|
|
88
90
|
- lib/ruflet/rails/protocol.rb
|
|
89
91
|
- lib/ruflet/rails/protocol/context.rb
|
|
90
92
|
- lib/ruflet/rails/protocol/endpoint.rb
|
|
@@ -94,12 +96,9 @@ files:
|
|
|
94
96
|
- lib/ruflet/rails/protocol/web_app.rb
|
|
95
97
|
- lib/ruflet/rails/protocol/websocket_detection.rb
|
|
96
98
|
- lib/ruflet/rails/railtie.rb
|
|
97
|
-
- lib/ruflet/rails/resource_component.rb
|
|
98
|
-
- lib/ruflet/rails/route_stack.rb
|
|
99
99
|
- lib/ruflet/rails/session_registry.rb
|
|
100
100
|
- lib/ruflet/rails/view_helpers.rb
|
|
101
101
|
- lib/ruflet/rails/web_installer.rb
|
|
102
|
-
- lib/ruflet/rails/webview_app.rb
|
|
103
102
|
- lib/ruflet/version.rb
|
|
104
103
|
- lib/ruflet_rails.rb
|
|
105
104
|
homepage: https://github.com/AdamMusa/ruflet/tree/main/packages/ruflet_rails
|
|
@@ -120,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
120
119
|
- !ruby/object:Gem::Version
|
|
121
120
|
version: '0'
|
|
122
121
|
requirements: []
|
|
123
|
-
rubygems_version:
|
|
122
|
+
rubygems_version: 4.0.11
|
|
124
123
|
specification_version: 4
|
|
125
124
|
summary: Rails integration for Ruflet.
|
|
126
125
|
test_files: []
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "rails/generators"
|
|
4
|
-
require "active_support/core_ext/string/inflections"
|
|
5
|
-
require "ruflet/rails/install_support"
|
|
6
|
-
|
|
7
|
-
module Ruflet
|
|
8
|
-
module Generators
|
|
9
|
-
class FormGenerator < ::Rails::Generators::Base
|
|
10
|
-
argument :model_name, type: :string
|
|
11
|
-
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
|
12
|
-
|
|
13
|
-
desc "Generate only a Ruflet form for an existing Rails model."
|
|
14
|
-
|
|
15
|
-
def create_application_component
|
|
16
|
-
target = File.join(destination_root, Ruflet::Rails::InstallSupport.application_component_path)
|
|
17
|
-
return if File.exist?(target)
|
|
18
|
-
|
|
19
|
-
create_file target, Ruflet::Rails::InstallSupport.application_component_template
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def create_ruflet_form
|
|
23
|
-
target = File.join(destination_root, form_view_path)
|
|
24
|
-
|
|
25
|
-
create_file(
|
|
26
|
-
target,
|
|
27
|
-
Ruflet::Rails::InstallSupport.form_view_template(
|
|
28
|
-
model_name: model_name,
|
|
29
|
-
attributes: form_attributes
|
|
30
|
-
)
|
|
31
|
-
)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def print_form_status
|
|
35
|
-
names = Ruflet::Rails::InstallSupport.model_names(model_name)
|
|
36
|
-
say "Ruflet form generated at #{form_view_path}"
|
|
37
|
-
say "Call #{names[:class_name]}Form.render(page, record: #{names[:class_name]}.new) from any Ruflet view."
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
private
|
|
41
|
-
|
|
42
|
-
def form_view_path
|
|
43
|
-
Ruflet::Rails::InstallSupport.form_view_path(model_name)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def form_attributes
|
|
47
|
-
return attributes unless attributes.empty?
|
|
48
|
-
|
|
49
|
-
model_class = model_name.to_s.camelize.safe_constantize
|
|
50
|
-
inferred = Ruflet::Rails::InstallSupport.attributes_from_model(model_class)
|
|
51
|
-
inferred.empty? ? attributes : inferred
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "rails/generators"
|
|
4
|
-
require "active_support/core_ext/string/inflections"
|
|
5
|
-
require "ruflet/rails/install_support"
|
|
6
|
-
|
|
7
|
-
module Ruflet
|
|
8
|
-
module Generators
|
|
9
|
-
class ScaffoldGenerator < ::Rails::Generators::Base
|
|
10
|
-
argument :model_name, type: :string
|
|
11
|
-
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
|
12
|
-
|
|
13
|
-
desc "Generate a Rails-first Ruflet resource component for an existing model."
|
|
14
|
-
|
|
15
|
-
def create_ruflet_resource_component
|
|
16
|
-
create_file(
|
|
17
|
-
File.join(destination_root, scaffold_component_path),
|
|
18
|
-
Ruflet::Rails::InstallSupport.scaffold_component_template(
|
|
19
|
-
model_name: model_name,
|
|
20
|
-
attributes: scaffold_attributes
|
|
21
|
-
)
|
|
22
|
-
)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def print_scaffold_status
|
|
26
|
-
say "Ruflet resource component generated at #{scaffold_component_path}"
|
|
27
|
-
say "Mount it in config/routes.rb:"
|
|
28
|
-
say " mount Ruflet::Rails.web_app(view: #{scaffold_component_class.inspect}), at: \"/#{scaffold_route_segment}\""
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
private
|
|
32
|
-
|
|
33
|
-
def scaffold_component_class
|
|
34
|
-
"#{model_name.to_s.camelize}Component"
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def scaffold_route_segment
|
|
38
|
-
model_name.to_s.underscore.pluralize
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def scaffold_component_path
|
|
42
|
-
Ruflet::Rails::InstallSupport.scaffold_component_path(model_name)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def scaffold_attributes
|
|
46
|
-
return attributes unless attributes.empty?
|
|
47
|
-
|
|
48
|
-
model_class = model_name.to_s.camelize.safe_constantize
|
|
49
|
-
inferred = Ruflet::Rails::InstallSupport.attributes_from_model(model_class)
|
|
50
|
-
inferred.empty? ? attributes : inferred
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Ruflet
|
|
4
|
-
module Rails
|
|
5
|
-
module FormHelpers
|
|
6
|
-
def ruflet_form_bindings(record, form_fields)
|
|
7
|
-
form_fields.to_h do |field|
|
|
8
|
-
[field[:name], ruflet_field_binding(field, record)]
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def ruflet_form_controls(bindings)
|
|
13
|
-
bindings.values.map { |binding| binding[:control] }
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def ruflet_form_attributes(bindings, form_fields)
|
|
17
|
-
bindings.to_h do |name, binding|
|
|
18
|
-
field = form_fields.find { |candidate| candidate[:name] == name }
|
|
19
|
-
control = binding[:input] || binding[:control] || binding
|
|
20
|
-
[name, ruflet_control_value(control, field[:type])]
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def ruflet_show_errors(record)
|
|
25
|
-
ruflet_show_snackbar(ruflet_error_message(record))
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def ruflet_show_snackbar(message)
|
|
29
|
-
page.snackbar = snackbar(text(message), open: true)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
private
|
|
33
|
-
|
|
34
|
-
def ruflet_field_binding(field, record)
|
|
35
|
-
type = field[:type].to_s
|
|
36
|
-
return ruflet_picker_field_binding(field, record) if %w[date datetime timestamp time].include?(type)
|
|
37
|
-
|
|
38
|
-
control = ruflet_field_control(field, record)
|
|
39
|
-
{ control: control, input: control }
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def ruflet_field_control(field, record)
|
|
43
|
-
name = field[:name]
|
|
44
|
-
type = field[:type].to_s
|
|
45
|
-
value = record.public_send(name)
|
|
46
|
-
label = name.humanize
|
|
47
|
-
|
|
48
|
-
case type
|
|
49
|
-
when "association", "references", "belongs_to"
|
|
50
|
-
dropdown(
|
|
51
|
-
ruflet_association_options(field),
|
|
52
|
-
value: value.to_s,
|
|
53
|
-
label: label
|
|
54
|
-
)
|
|
55
|
-
when "boolean"
|
|
56
|
-
checkbox(label: label, value: !!value)
|
|
57
|
-
when "integer", "float", "decimal"
|
|
58
|
-
text_field(value: value.to_s, label: label, keyboard_type: "number")
|
|
59
|
-
when "text"
|
|
60
|
-
text_field(value: value.to_s, label: label, multiline: true, min_lines: 3)
|
|
61
|
-
else
|
|
62
|
-
text_field(value: value.to_s, label: label)
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def ruflet_picker_field_binding(field, record)
|
|
67
|
-
name = field[:name]
|
|
68
|
-
type = field[:type].to_s
|
|
69
|
-
value = record.public_send(name)
|
|
70
|
-
label = name.humanize
|
|
71
|
-
picker = ruflet_picker_control(type, value, label)
|
|
72
|
-
display = text(ruflet_picker_display_text(label, picker.props["value"]))
|
|
73
|
-
|
|
74
|
-
picker.on(:change) do |_event|
|
|
75
|
-
page.update(picker, open: false)
|
|
76
|
-
page.close_dialog(picker)
|
|
77
|
-
page.update(display, value: ruflet_picker_display_text(label, picker.props["value"]))
|
|
78
|
-
end
|
|
79
|
-
picker.on(:dismiss) do |_event|
|
|
80
|
-
page.update(picker, open: false)
|
|
81
|
-
page.close_dialog(picker)
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
{
|
|
85
|
-
control: column(
|
|
86
|
-
spacing: 6,
|
|
87
|
-
children: [
|
|
88
|
-
display,
|
|
89
|
-
outlined_button(
|
|
90
|
-
content: text("Choose #{label}"),
|
|
91
|
-
on_click: ->(_e) { page.show_dialog(picker) }
|
|
92
|
-
)
|
|
93
|
-
]
|
|
94
|
-
),
|
|
95
|
-
input: picker
|
|
96
|
-
}
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
def ruflet_picker_control(type, value, label)
|
|
100
|
-
case type
|
|
101
|
-
when "time"
|
|
102
|
-
time_picker(value: value.respond_to?(:strftime) ? value.strftime("%H:%M") : value.to_s, help_text: label, open: false)
|
|
103
|
-
when "datetime", "timestamp"
|
|
104
|
-
date_picker(value: ruflet_date_value(value), help_text: label, open: false)
|
|
105
|
-
else
|
|
106
|
-
date_picker(value: ruflet_date_value(value), help_text: label, open: false)
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
def ruflet_control_value(control, type)
|
|
111
|
-
value = control.props["value"]
|
|
112
|
-
return nil if value.to_s.empty?
|
|
113
|
-
return value if type.to_s == "boolean"
|
|
114
|
-
return value if %w[association references belongs_to].include?(type.to_s)
|
|
115
|
-
return value.to_s.split("T", 2).first if type.to_s == "date"
|
|
116
|
-
return value.to_s if %w[datetime timestamp time].include?(type.to_s)
|
|
117
|
-
|
|
118
|
-
value.to_s
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
def ruflet_association_options(field)
|
|
122
|
-
model = ruflet_association_model(field)
|
|
123
|
-
return [] unless model.respond_to?(:all)
|
|
124
|
-
|
|
125
|
-
model.all.map do |record|
|
|
126
|
-
dropdown_option(record.id.to_s, text: ruflet_association_label(record))
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
def ruflet_association_model(field)
|
|
131
|
-
class_name = field[:class_name] || field[:name].to_s.sub(/_id\z/, "").camelize
|
|
132
|
-
class_name.safe_constantize if class_name.respond_to?(:safe_constantize)
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
def ruflet_association_label(record)
|
|
136
|
-
return record.name.to_s if record.respond_to?(:name)
|
|
137
|
-
return record.title.to_s if record.respond_to?(:title)
|
|
138
|
-
|
|
139
|
-
record.to_s
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
def ruflet_date_value(value)
|
|
143
|
-
return nil if value.nil?
|
|
144
|
-
return value.iso8601 if value.respond_to?(:iso8601)
|
|
145
|
-
return value.to_date.iso8601 if value.respond_to?(:to_date)
|
|
146
|
-
|
|
147
|
-
value.to_s
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
def ruflet_picker_display_text(label, value)
|
|
151
|
-
visible = value.to_s.empty? ? "Not selected" : value.to_s.split("T", 2).first
|
|
152
|
-
"#{label}: #{visible}"
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
def ruflet_error_message(record)
|
|
156
|
-
messages = record.errors.full_messages
|
|
157
|
-
messages.respond_to?(:to_sentence) ? messages.to_sentence : messages.join(", ")
|
|
158
|
-
end
|
|
159
|
-
end
|
|
160
|
-
end
|
|
161
|
-
end
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Ruflet
|
|
4
|
-
module Rails
|
|
5
|
-
module GeneratorHooks
|
|
6
|
-
module_function
|
|
7
|
-
|
|
8
|
-
def install!
|
|
9
|
-
require "active_support/core_ext/string/filters"
|
|
10
|
-
require "rails/generators/rails/scaffold/scaffold_generator"
|
|
11
|
-
require "generators/ruflet/scaffold/scaffold_generator"
|
|
12
|
-
|
|
13
|
-
generator = ::Rails::Generators::ScaffoldGenerator
|
|
14
|
-
return if generator.class_options.key?(:ruflet)
|
|
15
|
-
|
|
16
|
-
generator.hook_for(
|
|
17
|
-
:ruflet,
|
|
18
|
-
type: :boolean,
|
|
19
|
-
default: true,
|
|
20
|
-
desc: "Generate a Ruflet resource component"
|
|
21
|
-
)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|