strada-rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/LICENSE.txt +21 -0
- data/README.md +27 -0
- data/Rakefile +11 -0
- data/app/assets/javascripts/strada.js +205 -0
- data/lib/generators/strada/USAGE +10 -0
- data/lib/generators/strada/controller/controller_generator.rb +9 -0
- data/lib/generators/strada/controller/templates/view.html.erb.tt +4 -0
- data/lib/generators/strada/mailer/mailer_generator.rb +9 -0
- data/lib/generators/strada/mailer/templates/view.html.erb.tt +5 -0
- data/lib/generators/strada/mailer/templates/view.text.erb.tt +3 -0
- data/lib/generators/strada/scaffold/scaffold_generator.rb +34 -0
- data/lib/generators/strada/scaffold/templates/_form.html.erb.tt +37 -0
- data/lib/generators/strada/scaffold/templates/edit.html.erb.tt +10 -0
- data/lib/generators/strada/scaffold/templates/index.html.erb.tt +16 -0
- data/lib/generators/strada/scaffold/templates/new.html.erb.tt +9 -0
- data/lib/generators/strada/scaffold/templates/partial.html.erb.tt +17 -0
- data/lib/generators/strada/scaffold/templates/show.html.erb.tt +14 -0
- data/lib/generators/strada/strada_generator.rb +22 -0
- data/lib/generators/strada/templates/controller.js.tt +19 -0
- data/lib/install/app/assets/stylesheets/strada.css +22 -0
- data/lib/install/app/javascript/controllers/bridge/flash_message_controller.js +15 -0
- data/lib/install/app/javascript/controllers/bridge/form_controller.js +31 -0
- data/lib/install/app/javascript/controllers/bridge/nav_button_controller.js +18 -0
- data/lib/install/strada_with_importmap.rb +20 -0
- data/lib/install/strada_with_node.rb +19 -0
- data/lib/strada/engine.rb +21 -0
- data/lib/strada/version.rb +3 -0
- data/lib/strada-rails.rb +5 -0
- data/lib/tasks/strada_tasks.rake +28 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7ba041b765b36676475aae45a8ed1c4a396a82384f3c920dd9b5da13c8ba354d
|
4
|
+
data.tar.gz: c2982c99194493b435c821f44695d8812bd2418d656648d1b70eee0060209531
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 790e4154a5b8a7233559253412fe44fe72bd1e8bff0a142f1b6ed0df21a9715b8a95e1536f1bedb4a0d0504c41b0645099c75561c4d0487736465089a0dda9ee
|
7
|
+
data.tar.gz: 3710682666422aaafcb85c924a568deacde3b9cd7383848ac79212fbbd942778538e2db64fb6cc3f7bb03f3efb6082cdc2734de98fe651fc27585f95777ae2fe
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at lazaronixon@hotmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Nixon
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Strada for Rails
|
2
|
+
|
3
|
+
[Strada](https://strada.hotwired.dev) enables you to create native controls in your hybrid mobile apps, driven by the web. Build web components and native components that work together in `WebView` screens to elevate your [Turbo Native](https://turbo.hotwired.dev/handbook/native) apps to the next level.
|
4
|
+
|
5
|
+
Strada for Rails makes it easy to use [strada-web](https://github.com/hotwired/strada-web) with both import-mapped and JavaScript-bundled apps. It relies on either `importmap-rails` to make Stimulus available via ESM or a Node-capable Rails (like via `jsbundling-rails`) to include Strada in the bundle. Make sure to install one of these first!
|
6
|
+
|
7
|
+
Read more on [strada.hotwired.dev](https://strada.hotwired.dev).
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
1. Run `bundle add strada-rails`.
|
12
|
+
2. Run `rails strada:install`.
|
13
|
+
3. Generate your mobile projects using [turbo-native-initializer](https://github.com/lazaronixon/turbo-native-initializer).
|
14
|
+
|
15
|
+
The installer will automatically detect whether you're using an [import map](https://github.com/rails/importmap-rails) or [JavaScript bundler](https://github.com/rails/jsbundling-rails) to manage your application's JavaScript. If you're using an import map, the Strada dependencies will be pinned to the versions of the library included with this gem. If you're using Node, yarn will add the dependencies to your `package.json` file.
|
16
|
+
|
17
|
+
## Contributing
|
18
|
+
|
19
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/lazaronixon/strada-rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/lazaronixon/strada-rails/blob/master/CODE_OF_CONDUCT.md).
|
20
|
+
|
21
|
+
## License
|
22
|
+
|
23
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
24
|
+
|
25
|
+
## Code of Conduct
|
26
|
+
|
27
|
+
Everyone interacting in the Strada::Rails project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/lazaronixon/strada-rails/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,205 @@
|
|
1
|
+
/*
|
2
|
+
Strada 1.0.0-beta1
|
3
|
+
Copyright © 2023 37signals LLC
|
4
|
+
*/
|
5
|
+
var __defProp = Object.defineProperty;
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
7
|
+
var __publicField = (obj, key, value) => {
|
8
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
9
|
+
return value;
|
10
|
+
};
|
11
|
+
|
12
|
+
// src/bridge.js
|
13
|
+
var Bridge = class {
|
14
|
+
#adapter;
|
15
|
+
#lastMessageId;
|
16
|
+
#pendingMessages;
|
17
|
+
#pendingCallbacks;
|
18
|
+
constructor() {
|
19
|
+
this.#adapter = null;
|
20
|
+
this.#lastMessageId = 0;
|
21
|
+
this.#pendingMessages = [];
|
22
|
+
this.#pendingCallbacks = /* @__PURE__ */ new Map();
|
23
|
+
}
|
24
|
+
start() {
|
25
|
+
this.notifyApplicationAfterStart();
|
26
|
+
}
|
27
|
+
notifyApplicationAfterStart() {
|
28
|
+
document.dispatchEvent(new Event("web-bridge:ready"));
|
29
|
+
}
|
30
|
+
supportsComponent(component) {
|
31
|
+
if (this.#adapter) {
|
32
|
+
return this.#adapter.supportsComponent(component);
|
33
|
+
} else {
|
34
|
+
return false;
|
35
|
+
}
|
36
|
+
}
|
37
|
+
send({ component, event, data, callback }) {
|
38
|
+
if (!this.#adapter) {
|
39
|
+
this.#savePendingMessage({ component, event, data, callback });
|
40
|
+
return null;
|
41
|
+
}
|
42
|
+
if (!this.supportsComponent(component))
|
43
|
+
return null;
|
44
|
+
const id = this.generateMessageId();
|
45
|
+
const message = { id, component, event, data: data || {} };
|
46
|
+
this.#adapter.receive(message);
|
47
|
+
if (callback) {
|
48
|
+
this.#pendingCallbacks.set(id, callback);
|
49
|
+
}
|
50
|
+
return id;
|
51
|
+
}
|
52
|
+
receive(message) {
|
53
|
+
this.executeCallbackFor(message);
|
54
|
+
}
|
55
|
+
executeCallbackFor(message) {
|
56
|
+
const callback = this.#pendingCallbacks.get(message.id);
|
57
|
+
if (callback) {
|
58
|
+
callback(message);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
removeCallbackFor(messageId) {
|
62
|
+
if (this.#pendingCallbacks.has(messageId)) {
|
63
|
+
this.#pendingCallbacks.delete(messageId);
|
64
|
+
}
|
65
|
+
}
|
66
|
+
removePendingMessagesFor(component) {
|
67
|
+
this.#pendingMessages = this.#pendingMessages.filter((message) => message.component != component);
|
68
|
+
}
|
69
|
+
generateMessageId() {
|
70
|
+
const id = ++this.#lastMessageId;
|
71
|
+
return id.toString();
|
72
|
+
}
|
73
|
+
setAdapter(adapter) {
|
74
|
+
this.#adapter = adapter;
|
75
|
+
document.documentElement.dataset.bridgePlatform = this.#adapter.platform;
|
76
|
+
this.adapterDidUpdateSupportedComponents();
|
77
|
+
this.#sendPendingMessages();
|
78
|
+
}
|
79
|
+
adapterDidUpdateSupportedComponents() {
|
80
|
+
if (this.#adapter) {
|
81
|
+
document.documentElement.dataset.bridgeComponents = this.#adapter.supportedComponents.join(" ");
|
82
|
+
}
|
83
|
+
}
|
84
|
+
#savePendingMessage(message) {
|
85
|
+
this.#pendingMessages.push(message);
|
86
|
+
}
|
87
|
+
#sendPendingMessages() {
|
88
|
+
this.#pendingMessages.forEach((message) => this.send(message));
|
89
|
+
this.#pendingMessages = [];
|
90
|
+
}
|
91
|
+
};
|
92
|
+
|
93
|
+
// src/bridge_component.js
|
94
|
+
import { Controller } from "@hotwired/stimulus";
|
95
|
+
|
96
|
+
// src/bridge_element.js
|
97
|
+
var BridgeElement = class {
|
98
|
+
constructor(element) {
|
99
|
+
this.element = element;
|
100
|
+
}
|
101
|
+
get title() {
|
102
|
+
return (this.bridgeAttribute("title") || this.attribute("aria-label") || this.element.textContent || this.element.value).trim();
|
103
|
+
}
|
104
|
+
get enabled() {
|
105
|
+
return !this.disabled;
|
106
|
+
}
|
107
|
+
get disabled() {
|
108
|
+
const disabled = this.bridgeAttribute("disabled");
|
109
|
+
return disabled === "true" || disabled === this.platform;
|
110
|
+
}
|
111
|
+
enableForComponent(component) {
|
112
|
+
if (component.enabled) {
|
113
|
+
this.removeBridgeAttribute("disabled");
|
114
|
+
}
|
115
|
+
}
|
116
|
+
hasClass(className) {
|
117
|
+
return this.element.classList.contains(className);
|
118
|
+
}
|
119
|
+
attribute(name) {
|
120
|
+
return this.element.getAttribute(name);
|
121
|
+
}
|
122
|
+
bridgeAttribute(name) {
|
123
|
+
return this.attribute(`data-bridge-${name}`);
|
124
|
+
}
|
125
|
+
setBridgeAttribute(name, value) {
|
126
|
+
this.element.setAttribute(`data-bridge-${name}`, value);
|
127
|
+
}
|
128
|
+
removeBridgeAttribute(name) {
|
129
|
+
this.element.removeAttribute(`data-bridge-${name}`);
|
130
|
+
}
|
131
|
+
click() {
|
132
|
+
if (this.platform == "android") {
|
133
|
+
this.element.removeAttribute("target");
|
134
|
+
}
|
135
|
+
this.element.click();
|
136
|
+
}
|
137
|
+
get platform() {
|
138
|
+
return document.documentElement.dataset.bridgePlatform;
|
139
|
+
}
|
140
|
+
};
|
141
|
+
|
142
|
+
// src/helpers/user_agent.js
|
143
|
+
var { userAgent } = window.navigator;
|
144
|
+
var isStradaNativeApp = /bridge-components: \[.+\]/.test(userAgent);
|
145
|
+
|
146
|
+
// src/bridge_component.js
|
147
|
+
var BridgeComponent = class extends Controller {
|
148
|
+
static get shouldLoad() {
|
149
|
+
return isStradaNativeApp;
|
150
|
+
}
|
151
|
+
pendingMessageCallbacks = [];
|
152
|
+
initialize() {
|
153
|
+
this.pendingMessageCallbacks = [];
|
154
|
+
}
|
155
|
+
connect() {
|
156
|
+
}
|
157
|
+
disconnect() {
|
158
|
+
this.removePendingCallbacks();
|
159
|
+
this.removePendingMessages();
|
160
|
+
}
|
161
|
+
get component() {
|
162
|
+
return this.constructor.component;
|
163
|
+
}
|
164
|
+
get platformOptingOut() {
|
165
|
+
const { bridgePlatform } = document.documentElement.dataset;
|
166
|
+
return this.identifier == this.element.getAttribute(`data-controller-optout-${bridgePlatform}`);
|
167
|
+
}
|
168
|
+
get enabled() {
|
169
|
+
return !this.platformOptingOut && this.bridge.supportsComponent(this.component);
|
170
|
+
}
|
171
|
+
send(event, data = {}, callback) {
|
172
|
+
data.metadata = {
|
173
|
+
url: window.location.href
|
174
|
+
};
|
175
|
+
const message = { component: this.component, event, data, callback };
|
176
|
+
const messageId = this.bridge.send(message);
|
177
|
+
if (callback) {
|
178
|
+
this.pendingMessageCallbacks.push(messageId);
|
179
|
+
}
|
180
|
+
}
|
181
|
+
removePendingCallbacks() {
|
182
|
+
this.pendingMessageCallbacks.forEach((messageId) => this.bridge.removeCallbackFor(messageId));
|
183
|
+
}
|
184
|
+
removePendingMessages() {
|
185
|
+
this.bridge.removePendingMessagesFor(this.component);
|
186
|
+
}
|
187
|
+
get bridgeElement() {
|
188
|
+
return new BridgeElement(this.element);
|
189
|
+
}
|
190
|
+
get bridge() {
|
191
|
+
return window.Strada.web;
|
192
|
+
}
|
193
|
+
};
|
194
|
+
__publicField(BridgeComponent, "component", "");
|
195
|
+
|
196
|
+
// src/index.js
|
197
|
+
if (!window.Strada) {
|
198
|
+
const webBridge = new Bridge();
|
199
|
+
window.Strada = { web: webBridge };
|
200
|
+
webBridge.start();
|
201
|
+
}
|
202
|
+
export {
|
203
|
+
BridgeComponent,
|
204
|
+
BridgeElement
|
205
|
+
};
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Description:
|
2
|
+
============
|
3
|
+
Generates a new Strada controller at the passed path. If running under node,
|
4
|
+
it'll also call the stimulus:manifest:update task to update the controllers/index.js.
|
5
|
+
|
6
|
+
Examples:
|
7
|
+
=========
|
8
|
+
bin/rails generate strada notice
|
9
|
+
|
10
|
+
creates: app/javascript/controllers/bridge/notice_controller.js
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "rails/generators/erb/scaffold/scaffold_generator"
|
2
|
+
require "rails/generators/resource_helpers"
|
3
|
+
|
4
|
+
module Strada
|
5
|
+
module Generators
|
6
|
+
class ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
7
|
+
include Rails::Generators::ResourceHelpers
|
8
|
+
|
9
|
+
source_root File.expand_path("../templates", __FILE__)
|
10
|
+
|
11
|
+
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
12
|
+
|
13
|
+
def create_root_folder
|
14
|
+
empty_directory File.join("app/views", controller_file_path)
|
15
|
+
end
|
16
|
+
|
17
|
+
def copy_view_files
|
18
|
+
available_views.each do |view|
|
19
|
+
formats.each do |format|
|
20
|
+
filename = filename_with_extensions(view, format)
|
21
|
+
template filename, File.join("app/views", controller_file_path, filename)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
template "partial.html.erb", File.join("app/views", controller_file_path, "_#{singular_name}.html.erb")
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def available_views
|
30
|
+
%w(index edit show new _form)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
<%%= form_with(model: <%= model_resource_name %>, data: { controller: "bridge--form", action: "turbo:submit-start->bridge--form#submitStart turbo:submit-end->bridge--form#submitEnd" }) do |form| %>
|
2
|
+
<%% if <%= singular_table_name %>.errors.any? %>
|
3
|
+
<div style="color: red">
|
4
|
+
<h2><%%= pluralize(<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
|
5
|
+
|
6
|
+
<ul>
|
7
|
+
<%% <%= singular_table_name %>.errors.each do |error| %>
|
8
|
+
<li><%%= error.full_message %></li>
|
9
|
+
<%% end %>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<%% end %>
|
13
|
+
|
14
|
+
<% attributes.each do |attribute| -%>
|
15
|
+
<div>
|
16
|
+
<% if attribute.password_digest? -%>
|
17
|
+
<%%= form.label :password, style: "display: block" %>
|
18
|
+
<%%= form.password_field :password %>
|
19
|
+
</div>
|
20
|
+
|
21
|
+
<div>
|
22
|
+
<%%= form.label :password_confirmation, style: "display: block" %>
|
23
|
+
<%%= form.password_field :password_confirmation %>
|
24
|
+
<% elsif attribute.attachments? -%>
|
25
|
+
<%%= form.label :<%= attribute.column_name %>, style: "display: block" %>
|
26
|
+
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, multiple: true %>
|
27
|
+
<% else -%>
|
28
|
+
<%%= form.label :<%= attribute.column_name %>, style: "display: block" %>
|
29
|
+
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %> %>
|
30
|
+
<% end -%>
|
31
|
+
</div>
|
32
|
+
|
33
|
+
<% end -%>
|
34
|
+
<div>
|
35
|
+
<%%= form.submit nil, data: { "bridge--form-target": "submit", "bridge-title": "Save" } %>
|
36
|
+
</div>
|
37
|
+
<%% end %>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<h1 class="hide-on-mobile">Editing <%= human_name.downcase %></h1>
|
2
|
+
|
3
|
+
<%%= render "form", <%= singular_table_name %>: @<%= singular_table_name %> %>
|
4
|
+
|
5
|
+
<br>
|
6
|
+
|
7
|
+
<div class="hide-on-mobile">
|
8
|
+
<%%= link_to "Show this <%= human_name.downcase %>", <%= model_resource_name(prefix: "@") %> %> |
|
9
|
+
<%%= link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper(type: :path) %> %>
|
10
|
+
</div>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<%% if notice.present? %>
|
2
|
+
<p style="color: green" data-controller="bridge--flash-message"><%%= notice %></p>
|
3
|
+
<%% end %>
|
4
|
+
|
5
|
+
<h1 class="hide-on-mobile"><%= human_name.pluralize %></h1>
|
6
|
+
|
7
|
+
<div id="<%= plural_table_name %>">
|
8
|
+
<%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
|
9
|
+
<%%= render <%= singular_table_name %> %>
|
10
|
+
<p>
|
11
|
+
<%%= link_to "Show this <%= human_name.downcase %>", <%= model_resource_name(singular_table_name) %> %>
|
12
|
+
</p>
|
13
|
+
<%% end %>
|
14
|
+
</div>
|
15
|
+
|
16
|
+
<%%= link_to "New <%= human_name.downcase %>", <%= new_helper(type: :path) %>, data: { controller: "bridge--nav-button", bridge_title: "+ New" } %>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<h1 class="hide-on-mobile">New <%= human_name.downcase %></h1>
|
2
|
+
|
3
|
+
<%%= render "form", <%= singular_table_name %>: @<%= singular_table_name %> %>
|
4
|
+
|
5
|
+
<br>
|
6
|
+
|
7
|
+
<div class="hide-on-mobile">
|
8
|
+
<%%= link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper(type: :path) %> %>
|
9
|
+
</div>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<div id="<%%= dom_id <%= singular_name %> %>">
|
2
|
+
<% attributes.reject(&:password_digest?).each do |attribute| -%>
|
3
|
+
<p>
|
4
|
+
<strong><%= attribute.human_name %>:</strong>
|
5
|
+
<% if attribute.attachment? -%>
|
6
|
+
<%%= link_to <%= singular_name %>.<%= attribute.column_name %>.filename, <%= singular_name %>.<%= attribute.column_name %> if <%= singular_name %>.<%= attribute.column_name %>.attached? %>
|
7
|
+
<% elsif attribute.attachments? -%>
|
8
|
+
<%% <%= singular_name %>.<%= attribute.column_name %>.each do |<%= attribute.singular_name %>| %>
|
9
|
+
<div><%%= link_to <%= attribute.singular_name %>.filename, <%= attribute.singular_name %> %></div>
|
10
|
+
<%% end %>
|
11
|
+
<% else -%>
|
12
|
+
<%%= <%= singular_name %>.<%= attribute.column_name %> %>
|
13
|
+
<% end -%>
|
14
|
+
</p>
|
15
|
+
|
16
|
+
<% end -%>
|
17
|
+
</div>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<%% if notice.present? %>
|
2
|
+
<p style="color: green" data-controller="bridge--flash-message"><%%= notice %></p>
|
3
|
+
<%% end %>
|
4
|
+
|
5
|
+
<%%= render @<%= singular_table_name %> %>
|
6
|
+
|
7
|
+
<div>
|
8
|
+
<div class="hide-on-mobile">
|
9
|
+
<%%= link_to "Edit this <%= human_name.downcase %>", <%= edit_helper(type: :path) %>, data: { controller: "bridge--nav-button", bridge_title: "Edit" } %> |
|
10
|
+
<%%= link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper(type: :path) %> %>
|
11
|
+
</div>
|
12
|
+
|
13
|
+
<%%= link_to "Destroy this <%= human_name.downcase %>", <%= model_resource_name(prefix: "@") %>, "data-turbo-method": :delete %>
|
14
|
+
</div>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "rails/generators/named_base"
|
2
|
+
|
3
|
+
class StradaGenerator < Rails::Generators::NamedBase # :nodoc:
|
4
|
+
source_root File.expand_path("templates", __dir__)
|
5
|
+
|
6
|
+
class_option :skip_manifest, type: :boolean, default: false, desc: "Don't update the stimulus manifest"
|
7
|
+
|
8
|
+
def copy_view_files
|
9
|
+
@attribute = strada_attribute_value(controller_name)
|
10
|
+
template "controller.js", "app/javascript/controllers/bridge/#{controller_name}_controller.js"
|
11
|
+
rails_command "stimulus:manifest:update" unless Rails.root.join("config/importmap.rb").exist? || options[:skip_manifest]
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
def controller_name
|
16
|
+
name.underscore.gsub(/_controller$/, "")
|
17
|
+
end
|
18
|
+
|
19
|
+
def strada_attribute_value(controller_name)
|
20
|
+
controller_name.gsub(/\//, "--").gsub("_", "-")
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { BridgeComponent } from "@hotwired/strada"
|
2
|
+
|
3
|
+
// Connects to data-controller="bridge--<%= @attribute %>"
|
4
|
+
export default class extends BridgeComponent {
|
5
|
+
static component = "<%= @attribute %>"
|
6
|
+
|
7
|
+
connect() {
|
8
|
+
super.connect()
|
9
|
+
this.notifyBridgeOfConnect()
|
10
|
+
}
|
11
|
+
|
12
|
+
notifyBridgeOfConnect() {
|
13
|
+
const title = this.bridgeElement.title
|
14
|
+
|
15
|
+
this.send("connect", { title }, () => {
|
16
|
+
this.element.click()
|
17
|
+
})
|
18
|
+
}
|
19
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
/* Strada — hide elements for registered bridge components */
|
2
|
+
|
3
|
+
/*
|
4
|
+
* Hide the submit button when the "form" component is registered.
|
5
|
+
*/
|
6
|
+
[data-bridge-components~=form] [data-controller~=bridge--form] [type=submit] {
|
7
|
+
display: none
|
8
|
+
}
|
9
|
+
|
10
|
+
/*
|
11
|
+
* Hide when the "nav-button" component is registered.
|
12
|
+
*/
|
13
|
+
[data-bridge-components~=nav-button] [data-controller~=bridge--nav-button] {
|
14
|
+
display: none;
|
15
|
+
}
|
16
|
+
|
17
|
+
/*
|
18
|
+
* Hide when the "flash-message" component is registered.
|
19
|
+
*/
|
20
|
+
[data-bridge-components~=flash-message] [data-controller~=bridge--flash-message] {
|
21
|
+
display: none
|
22
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { BridgeComponent } from "@hotwired/strada"
|
2
|
+
|
3
|
+
export default class extends BridgeComponent {
|
4
|
+
static component = "flash-message"
|
5
|
+
|
6
|
+
connect() {
|
7
|
+
super.connect()
|
8
|
+
this.notifyBridgeOfConnect()
|
9
|
+
}
|
10
|
+
|
11
|
+
notifyBridgeOfConnect() {
|
12
|
+
const title = this.bridgeElement.title
|
13
|
+
this.send("connect", { title })
|
14
|
+
}
|
15
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { BridgeComponent } from "@hotwired/strada"
|
2
|
+
import { BridgeElement } from "@hotwired/strada"
|
3
|
+
|
4
|
+
export default class extends BridgeComponent {
|
5
|
+
static component = "form"
|
6
|
+
static targets = [ "submit" ]
|
7
|
+
|
8
|
+
connect() {
|
9
|
+
super.connect()
|
10
|
+
this.notifyBridgeOfConnect()
|
11
|
+
}
|
12
|
+
|
13
|
+
notifyBridgeOfConnect() {
|
14
|
+
const submitButton = new BridgeElement(this.submitTarget)
|
15
|
+
const title = submitButton.title
|
16
|
+
|
17
|
+
this.send("connect", { title }, () => {
|
18
|
+
this.submitTarget.click()
|
19
|
+
})
|
20
|
+
}
|
21
|
+
|
22
|
+
submitStart(event) {
|
23
|
+
this.submitTarget.disabled = true
|
24
|
+
this.send("submitDisabled")
|
25
|
+
}
|
26
|
+
|
27
|
+
submitEnd(event) {
|
28
|
+
this.submitTarget.disabled = false
|
29
|
+
this.send("submitEnabled")
|
30
|
+
}
|
31
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { BridgeComponent } from "@hotwired/strada"
|
2
|
+
|
3
|
+
export default class extends BridgeComponent {
|
4
|
+
static component = "nav-button"
|
5
|
+
|
6
|
+
connect() {
|
7
|
+
super.connect()
|
8
|
+
this.notifyBridgeOfConnect()
|
9
|
+
}
|
10
|
+
|
11
|
+
notifyBridgeOfConnect() {
|
12
|
+
const title = this.bridgeElement.title
|
13
|
+
|
14
|
+
this.send("connect", { title }, () => {
|
15
|
+
this.element.click()
|
16
|
+
})
|
17
|
+
}
|
18
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
APPLICATION_LAYOUT_PATH = Rails.root.join("app/views/layouts/application.html.erb")
|
2
|
+
|
3
|
+
HIDE_ON_MOBILE_STYLE = <<-HTML.chomp
|
4
|
+
<% if turbo_native_app? %>
|
5
|
+
<style>.hide-on-mobile { display: none; }</style>
|
6
|
+
<% end %>
|
7
|
+
HTML
|
8
|
+
|
9
|
+
say "Copy bridge controllers"
|
10
|
+
directory "#{__dir__}/app/javascript/controllers/bridge", "app/javascript/controllers/bridge"
|
11
|
+
|
12
|
+
say "Copy strada stylesheet"
|
13
|
+
copy_file "#{__dir__}/app/assets/stylesheets/strada.css", "app/assets/stylesheets/strada.css"
|
14
|
+
|
15
|
+
say "Add hide-on-mobile style in application layout"
|
16
|
+
insert_into_file APPLICATION_LAYOUT_PATH.to_s, "\n\n#{HIDE_ON_MOBILE_STYLE}", before: /\s*<\/head>/
|
17
|
+
|
18
|
+
say "Pin Strada"
|
19
|
+
say %(Appending: pin "@hotwired/strada", to: "strada.js", preload: true")
|
20
|
+
append_to_file "config/importmap.rb", %(pin "@hotwired/strada", to: "strada.js", preload: true\n)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
APPLICATION_LAYOUT_PATH = Rails.root.join("app/views/layouts/application.html.erb")
|
2
|
+
|
3
|
+
HIDE_ON_MOBILE_STYLE = <<-HTML.chomp
|
4
|
+
<% if turbo_native_app? %>
|
5
|
+
<style>.hide-on-mobile { display: none; }</style>
|
6
|
+
<% end %>
|
7
|
+
HTML
|
8
|
+
|
9
|
+
say "Copy bridge controllers"
|
10
|
+
directory "#{__dir__}/app/javascript/controllers/bridge", "app/javascript/controllers/bridge"
|
11
|
+
|
12
|
+
say "Copy strada stylesheet"
|
13
|
+
copy_file "#{__dir__}/app/assets/stylesheets/strada.css", "app/assets/stylesheets/strada.css"
|
14
|
+
|
15
|
+
say "Add hide-on-mobile style in application layout"
|
16
|
+
insert_into_file APPLICATION_LAYOUT_PATH.to_s, "\n\n#{HIDE_ON_MOBILE_STYLE}", before: /\s*<\/head>/
|
17
|
+
|
18
|
+
say "Install Strada"
|
19
|
+
run "yarn add @hotwired/strada"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Strada
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
# If you don't want to precompile Strada's assets (e.g., you're using jsbundling),
|
4
|
+
# you can do this in an initializer:
|
5
|
+
#
|
6
|
+
# config.after_initialize do
|
7
|
+
# config.assets.precompile -= Strada::Engine::PRECOMPILE_ASSETS
|
8
|
+
# end
|
9
|
+
PRECOMPILE_ASSETS = %w( strada.js ).freeze
|
10
|
+
|
11
|
+
initializer "strada.assets" do
|
12
|
+
if Rails.application.config.respond_to?(:assets)
|
13
|
+
Rails.application.config.assets.precompile += PRECOMPILE_ASSETS
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
config.app_generators do |g|
|
18
|
+
g.template_engine :strada
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/strada-rails.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
def run_strada_install_template(path)
|
2
|
+
system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../install/#{path}.rb", __dir__)}"
|
3
|
+
end
|
4
|
+
|
5
|
+
namespace :strada do
|
6
|
+
desc "Install Strada into the app"
|
7
|
+
task :install do
|
8
|
+
if Rails.root.join("config/importmap.rb").exist?
|
9
|
+
Rake::Task["strada:install:importmap"].invoke
|
10
|
+
elsif Rails.root.join("package.json").exist?
|
11
|
+
Rake::Task["strada:install:node"].invoke
|
12
|
+
else
|
13
|
+
puts "You must either be running with node (package.json) or importmap-rails (config/importmap.rb) to use this gem."
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
namespace :install do
|
18
|
+
desc "Install Strada on an app running importmap-rails"
|
19
|
+
task :importmap do
|
20
|
+
run_strada_install_template "strada_with_importmap"
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "Install Strada on an app running node"
|
24
|
+
task :node do
|
25
|
+
run_strada_install_template "strada_with_node"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: strada-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nixon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-09-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: railties
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 6.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 6.0.0
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- lazaronixon@hotmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- CHANGELOG.md
|
35
|
+
- CODE_OF_CONDUCT.md
|
36
|
+
- LICENSE.txt
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- app/assets/javascripts/strada.js
|
40
|
+
- lib/generators/strada/USAGE
|
41
|
+
- lib/generators/strada/controller/controller_generator.rb
|
42
|
+
- lib/generators/strada/controller/templates/view.html.erb.tt
|
43
|
+
- lib/generators/strada/mailer/mailer_generator.rb
|
44
|
+
- lib/generators/strada/mailer/templates/view.html.erb.tt
|
45
|
+
- lib/generators/strada/mailer/templates/view.text.erb.tt
|
46
|
+
- lib/generators/strada/scaffold/scaffold_generator.rb
|
47
|
+
- lib/generators/strada/scaffold/templates/_form.html.erb.tt
|
48
|
+
- lib/generators/strada/scaffold/templates/edit.html.erb.tt
|
49
|
+
- lib/generators/strada/scaffold/templates/index.html.erb.tt
|
50
|
+
- lib/generators/strada/scaffold/templates/new.html.erb.tt
|
51
|
+
- lib/generators/strada/scaffold/templates/partial.html.erb.tt
|
52
|
+
- lib/generators/strada/scaffold/templates/show.html.erb.tt
|
53
|
+
- lib/generators/strada/strada_generator.rb
|
54
|
+
- lib/generators/strada/templates/controller.js.tt
|
55
|
+
- lib/install/app/assets/stylesheets/strada.css
|
56
|
+
- lib/install/app/javascript/controllers/bridge/flash_message_controller.js
|
57
|
+
- lib/install/app/javascript/controllers/bridge/form_controller.js
|
58
|
+
- lib/install/app/javascript/controllers/bridge/nav_button_controller.js
|
59
|
+
- lib/install/strada_with_importmap.rb
|
60
|
+
- lib/install/strada_with_node.rb
|
61
|
+
- lib/strada-rails.rb
|
62
|
+
- lib/strada/engine.rb
|
63
|
+
- lib/strada/version.rb
|
64
|
+
- lib/tasks/strada_tasks.rake
|
65
|
+
homepage: https://strada.hotwired.dev
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
metadata:
|
69
|
+
homepage_uri: https://strada.hotwired.dev
|
70
|
+
source_code_uri: https://github.com/lazaronixon/strada-rails
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubygems_version: 3.4.19
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: Create fully native controls, driven by your web app.
|
90
|
+
test_files: []
|