recurrence_ui 0.3.2 → 0.3.3
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 +164 -110
- data/app/javascript/recurrence_ui/index.js +1 -1
- data/app/views/recurrence_ui/_start_at.html.erb +2 -1
- data/lib/generators/recurrence_ui/install/install_generator.rb +52 -54
- data/lib/recurrence_ui/engine.rb +15 -14
- data/lib/recurrence_ui/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 148ea1c9b90cf1ead7565260393624603281a68ffc349fd02b774721e65c1882
|
|
4
|
+
data.tar.gz: 64c351c8e924ef1676ca94e062061f03feb78d9c326c61f07168ba93d50d9859
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0bbe8d72c6582df4257859c890ecf354821f37603090a6bbcaf863ba77a3aaaac9bd7a5b95a1504804fa7c6887b99cbcfc2c5954e38bad573a33bf464f9dc6b2
|
|
7
|
+
data.tar.gz: 105e1e02dec4b660b8365939c752b0bb9373c553bcc363a987f7b19f25d689f31619814544f885c8a3df0afa20c361e76634033bee26b4e1d60c36877d85d022
|
data/README.md
CHANGED
|
@@ -12,8 +12,8 @@ Built on top of [ice_cube](https://github.com/ice-cube-ruby/ice_cube), it provid
|
|
|
12
12
|
- **Form integration:** Ready-to-use components for adding recurrence rule editors to model creation and editing forms.
|
|
13
13
|
- **Human-readable descriptions:** Converts `ice_cube` recurrence rules into readable descriptions.
|
|
14
14
|
- **Built-in internationalization:** Supports English (`en`), Russian (`ru`), Japanese (`ja`), Belarusian (`be`), and Ukrainian (`uk`).
|
|
15
|
-
- **Extensible translations:** Add new locales using standard YAML translation files
|
|
16
|
-
- **Flexible time zones and week starts:** Configure time zones and the first day of the week.
|
|
15
|
+
- **Extensible translations:** Add new locales using standard YAML translation files.
|
|
16
|
+
- **Flexible time zones and week starts:** Configure time zones and the first day of the week.
|
|
17
17
|
- **Customizable styles:** Adjust the color palette using CSS custom properties (design tokens).
|
|
18
18
|
- **Light and dark themes:** Customize the appearance to match your application.
|
|
19
19
|
- **Flexible model attribute mapping:** Use custom database column names for recurrence rules, time zones, durations, and event start and end times.
|
|
@@ -23,102 +23,154 @@ Built on top of [ice_cube](https://github.com/ice-cube-ruby/ice_cube), it provid
|
|
|
23
23
|
Recurrence UI depends on the following components:
|
|
24
24
|
|
|
25
25
|
- **Ruby on Rails** >= 8.0
|
|
26
|
-
- **[ice_cube](https://github.com/ice-cube-ruby/ice_cube)** ~> 0.16
|
|
27
|
-
- **[ViewComponent](https://viewcomponent.org/)** >= 2.0
|
|
28
|
-
- **Tailwind CSS
|
|
26
|
+
- **[ice_cube](https://github.com/ice-cube-ruby/ice_cube)** ~> 0.16
|
|
27
|
+
- **[ViewComponent](https://viewcomponent.org/)** >= 2.0
|
|
28
|
+
- **Tailwind CSS** >= 4.0
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
Tailwind CSS can be integrated through `tailwindcss-rails` or your host application's existing Tailwind CSS setup.
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
## Installation and Configuration
|
|
33
|
+
|
|
34
|
+
### 1. Add the gem
|
|
35
|
+
|
|
36
|
+
Add Recurrence UI to your application's `Gemfile`:
|
|
33
37
|
|
|
34
38
|
```ruby
|
|
35
39
|
gem "recurrence_ui"
|
|
36
40
|
```
|
|
37
41
|
|
|
38
|
-
|
|
42
|
+
Install the dependencies:
|
|
39
43
|
|
|
40
44
|
```bash
|
|
41
45
|
bundle install
|
|
42
46
|
```
|
|
43
|
-
### Automatic Installation
|
|
44
47
|
|
|
45
|
-
|
|
48
|
+
### 2. Automatic Installation (Recommended)
|
|
49
|
+
|
|
50
|
+
Run the installation generator:
|
|
51
|
+
|
|
46
52
|
```bash
|
|
47
53
|
bin/rails g recurrence_ui:install
|
|
48
54
|
```
|
|
49
|
-
### Manual Setup (Alternative)
|
|
50
55
|
|
|
51
|
-
|
|
52
|
-
|
|
56
|
+
The generator configures the necessary integration with your Rails application:
|
|
57
|
+
|
|
58
|
+
- Registers the Recurrence UI Stimulus controller in your application's Stimulus application.
|
|
59
|
+
- Adds the Recurrence UI stylesheet to your application's stylesheets.
|
|
60
|
+
- Creates the configuration initializer with default settings, if applicable.
|
|
61
|
+
|
|
62
|
+
The gem's Engine automatically makes its JavaScript, CSS assets, and translations available to the host application.
|
|
63
|
+
|
|
64
|
+
No additional Importmap configuration or manual locale loading is required.
|
|
65
|
+
|
|
66
|
+
### 3. Manual Installation (Alternative)
|
|
67
|
+
|
|
68
|
+
If you prefer to configure the integration yourself, follow these steps.
|
|
69
|
+
|
|
70
|
+
**Step 1. Create an initializer**
|
|
71
|
+
|
|
72
|
+
Create `config/initializers/recurrence_ui.rb`:
|
|
73
|
+
|
|
53
74
|
```ruby
|
|
54
|
-
require "recurrence_ui"
|
|
55
75
|
RecurrenceUi.configure do |config|
|
|
56
|
-
#
|
|
57
|
-
# Could be redefined in RecurrencePickerComponent
|
|
76
|
+
# General settings
|
|
58
77
|
config.locale = :en
|
|
59
78
|
config.time_zone = "UTC"
|
|
60
79
|
config.week_start = 1
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
config.
|
|
64
|
-
|
|
65
|
-
|
|
80
|
+
|
|
81
|
+
# Default event values
|
|
82
|
+
config.start_time = "09:00"
|
|
83
|
+
config.end_time = "17:00"
|
|
84
|
+
config.duration = 0
|
|
85
|
+
|
|
86
|
+
# UI options
|
|
66
87
|
config.enabled_rule_types = %w[
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
config.
|
|
77
|
-
|
|
78
|
-
config.
|
|
79
|
-
config.
|
|
80
|
-
config.
|
|
81
|
-
config.
|
|
82
|
-
config.
|
|
88
|
+
never
|
|
89
|
+
daily
|
|
90
|
+
weekly
|
|
91
|
+
monthly_by_day_of_month
|
|
92
|
+
monthly_by_weekday
|
|
93
|
+
yearly_by_day_of_month
|
|
94
|
+
yearly_by_weekday
|
|
95
|
+
]
|
|
96
|
+
|
|
97
|
+
config.allow_multiple_rules = true
|
|
98
|
+
|
|
99
|
+
config.show_duration = true
|
|
100
|
+
config.show_start_date_time = true
|
|
101
|
+
config.show_time_zone = true
|
|
102
|
+
config.show_end_date_time = false
|
|
103
|
+
config.show_exceptions = true
|
|
104
|
+
config.show_rdates = true
|
|
105
|
+
config.show_termination = true
|
|
83
106
|
end
|
|
84
107
|
```
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
- end_time — if record dosen't have this field uses DEFAULT_END_TIME = '17:00'.freeze
|
|
93
|
-
- allow_multiple_rules — show only one rule (false) or multiple rules (true).
|
|
94
|
-
- show_duration — show/hide duration fields in the form.
|
|
95
|
-
- show_start_date_time — show/hide start date and time fields in the form.
|
|
96
|
-
- show_time_zone — show/hide time zone in the form.
|
|
97
|
-
- show_end_date_time — show/hide end date and time fields in the form.
|
|
98
|
-
- show_exceptions — show/hide exceptions fields in the form.
|
|
99
|
-
- show_rdates — show/hide additional dates fields in the form.
|
|
100
|
-
- show_termination — show/hide termination fields in the form.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
2. Import JavaScript: Add the following import to your application's main JavaScript file (app/javascript/application.js):
|
|
108
|
+
|
|
109
|
+
**Step 2. Register the Stimulus controller**
|
|
110
|
+
|
|
111
|
+
Register the Recurrence UI controller in your application's Stimulus setup.
|
|
112
|
+
|
|
113
|
+
For example, in `app/javascript/controllers/index.js`:
|
|
114
|
+
|
|
104
115
|
```javascript
|
|
105
|
-
import "recurrence_ui"
|
|
116
|
+
import RecurrenceUiController from "recurrence_ui"
|
|
117
|
+
|
|
118
|
+
application.register("recurrence-ui", RecurrenceUiController)
|
|
106
119
|
```
|
|
107
|
-
|
|
120
|
+
|
|
121
|
+
Use the controller's actual import path and identifier provided by the gem.
|
|
122
|
+
|
|
123
|
+
**Step 3. Import the stylesheet**
|
|
124
|
+
|
|
125
|
+
For Tailwind CSS v4, add the following imports to your application's stylesheet, for example `app/assets/stylesheets/application.tailwind.css`:
|
|
108
126
|
|
|
109
127
|
```css
|
|
110
128
|
@import "tailwindcss";
|
|
111
129
|
@import "recurrence_ui/application.css";
|
|
112
130
|
```
|
|
113
131
|
|
|
114
|
-
Make sure the stylesheet is included in your application's asset pipeline
|
|
132
|
+
Make sure the stylesheet is included in your application's asset pipeline.
|
|
133
|
+
|
|
134
|
+
**Note:** Importmap paths, JavaScript assets, and locale files are provided by the gem's Engine. You do not need to configure them manually.
|
|
115
135
|
|
|
136
|
+
## Configuration
|
|
116
137
|
|
|
117
|
-
|
|
138
|
+
Recurrence UI can be configured globally through `config/initializers/recurrence_ui.rb`.
|
|
139
|
+
|
|
140
|
+
The following settings are available:
|
|
141
|
+
|
|
142
|
+
### General settings
|
|
143
|
+
|
|
144
|
+
| Setting | Description |
|
|
145
|
+
|---|---|
|
|
146
|
+
| `locale` | Default interface locale (`:en`, `:ru`, `:uk`, `:be`, `:ja`). |
|
|
147
|
+
| `time_zone` | Default time zone. |
|
|
148
|
+
| `week_start` | First day of the week: `0` for Sunday or `1` for Monday. |
|
|
149
|
+
| `start_time` | Default event start time. |
|
|
150
|
+
| `end_time` | Default event end time. |
|
|
151
|
+
| `duration` | Default event duration in seconds. |
|
|
152
|
+
|
|
153
|
+
### UI settings
|
|
154
|
+
|
|
155
|
+
| Setting | Description |
|
|
156
|
+
|---|---|
|
|
157
|
+
| `enabled_rule_types` | Recurrence rule types available in the editor. |
|
|
158
|
+
| `allow_multiple_rules` | Allows multiple recurrence rules when `true`. |
|
|
159
|
+
| `show_duration` | Shows or hides duration fields. |
|
|
160
|
+
| `show_start_date_time` | Shows or hides start date and time fields. |
|
|
161
|
+
| `show_time_zone` | Shows or hides the time zone field. |
|
|
162
|
+
| `show_end_date_time` | Shows or hides end date and time fields. |
|
|
163
|
+
| `show_exceptions` | Shows or hides exception dates. |
|
|
164
|
+
| `show_rdates` | Shows or hides additional recurrence dates. |
|
|
165
|
+
| `show_termination` | Shows or hides recurrence termination settings. |
|
|
166
|
+
|
|
167
|
+
Component-level options can override the global configuration where supported.
|
|
168
|
+
|
|
169
|
+
## Model Integration
|
|
118
170
|
|
|
119
171
|
Include `RecurrenceUi::HasRecurrence` in your model and configure the mapping between the gem's attributes and your database columns.
|
|
120
|
-
|
|
121
|
-
|
|
172
|
+
|
|
173
|
+
The recurrence rules attribute is required. Other attributes are optional and can be configured according to your application's database schema.
|
|
122
174
|
|
|
123
175
|
For example:
|
|
124
176
|
|
|
@@ -126,10 +178,10 @@ For example:
|
|
|
126
178
|
class Event < ApplicationRecord
|
|
127
179
|
include RecurrenceUi::HasRecurrence
|
|
128
180
|
|
|
129
|
-
has_recurrence rules: :recurring_rules,
|
|
130
|
-
start_time: :start_at,
|
|
131
|
-
end_time: :end_at,
|
|
132
|
-
time_zone: :time_zone,
|
|
181
|
+
has_recurrence rules: :recurring_rules,
|
|
182
|
+
start_time: :start_at,
|
|
183
|
+
end_time: :end_at,
|
|
184
|
+
time_zone: :time_zone,
|
|
133
185
|
duration: :duration
|
|
134
186
|
end
|
|
135
187
|
```
|
|
@@ -145,51 +197,52 @@ class Task < ApplicationRecord
|
|
|
145
197
|
end
|
|
146
198
|
```
|
|
147
199
|
|
|
148
|
-
|
|
200
|
+
The mapping format is:
|
|
149
201
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
def event_params
|
|
153
|
-
params.require(:event).permit(
|
|
154
|
-
#other params of your model
|
|
155
|
-
*Event.recurrence_permitted_params # add this with name of your Model
|
|
156
|
-
)
|
|
157
|
-
end
|
|
202
|
+
```ruby
|
|
203
|
+
gem_attribute: :database_column
|
|
158
204
|
```
|
|
159
205
|
|
|
206
|
+
If an optional attribute is not configured, the gem can use its applicable default value where supported.
|
|
207
|
+
|
|
208
|
+
### Strong Parameters
|
|
160
209
|
|
|
161
|
-
|
|
210
|
+
Add the recurrence parameters to your controller's permitted parameters:
|
|
211
|
+
|
|
212
|
+
```ruby
|
|
213
|
+
def event_params
|
|
214
|
+
params.require(:event).permit(
|
|
215
|
+
# Other model parameters
|
|
216
|
+
*Event.recurrence_permitted_params
|
|
217
|
+
)
|
|
218
|
+
end
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## View Integration
|
|
162
222
|
|
|
163
223
|
Render the recurrence editor inside a Rails form using `RecurrenceUi::RecurrencePickerComponent`:
|
|
164
224
|
|
|
165
225
|
```erb
|
|
166
226
|
<%= form_with model: @event do |form| %>
|
|
167
|
-
<%= render RecurrenceUi::RecurrencePickerComponent.new(
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
show_end_date_time: true,
|
|
175
|
-
show_exceptions: true,
|
|
176
|
-
show_rdates: true,
|
|
177
|
-
show_termination: true,
|
|
178
|
-
locale: params[:locale],
|
|
179
|
-
time_zone: params[:time_zone],
|
|
180
|
-
week_start: params[:week_start]
|
|
181
|
-
)
|
|
182
|
-
%>
|
|
227
|
+
<%= render RecurrenceUi::RecurrencePickerComponent.new(
|
|
228
|
+
form: form,
|
|
229
|
+
record: @event,
|
|
230
|
+
locale: params[:locale],
|
|
231
|
+
time_zone: params[:time_zone],
|
|
232
|
+
week_start: params[:week_start]
|
|
233
|
+
) %>
|
|
183
234
|
|
|
184
235
|
<%= form.submit "Save" %>
|
|
185
236
|
<% end %>
|
|
186
237
|
```
|
|
187
238
|
|
|
188
|
-
The
|
|
239
|
+
The component uses the application's global configuration by default.
|
|
240
|
+
|
|
241
|
+
You can also override supported component options when rendering it.
|
|
189
242
|
|
|
190
243
|
## Internationalization
|
|
191
244
|
|
|
192
|
-
Recurrence UI currently supports
|
|
245
|
+
Recurrence UI currently supports:
|
|
193
246
|
|
|
194
247
|
- English (`en`)
|
|
195
248
|
- Russian (`ru`)
|
|
@@ -204,18 +257,16 @@ You can extend the interface with additional translations.
|
|
|
204
257
|
For example, to add German (`de`):
|
|
205
258
|
|
|
206
259
|
1. Create a translation file named `config/locales/recurrence_ui.de.yml` in your application.
|
|
207
|
-
2. Add the required translation keys,
|
|
208
|
-
3.
|
|
260
|
+
2. Add the required translation keys, following the structure of the gem's existing locale files.
|
|
261
|
+
3. Use the new locale through your application's I18n configuration or pass it to the component.
|
|
209
262
|
|
|
210
|
-
|
|
263
|
+
The gem's Engine makes its built-in translations available automatically.
|
|
211
264
|
|
|
212
265
|
## Themes and Customization
|
|
213
266
|
|
|
214
267
|
Recurrence UI uses CSS custom properties (design tokens) to control its color palette.
|
|
215
268
|
|
|
216
|
-
You can override these properties in your application's stylesheet
|
|
217
|
-
|
|
218
|
-
For example:
|
|
269
|
+
You can override these properties in your application's stylesheet:
|
|
219
270
|
|
|
220
271
|
```css
|
|
221
272
|
:root {
|
|
@@ -230,14 +281,17 @@ For example:
|
|
|
230
281
|
}
|
|
231
282
|
```
|
|
232
283
|
|
|
233
|
-
Use the CSS variables supported by the gem to customize
|
|
284
|
+
Use the CSS variables supported by the gem to customize its appearance.
|
|
234
285
|
|
|
235
286
|
## Example Application
|
|
236
287
|
|
|
237
|
-
|
|
288
|
+
To see Recurrence UI in action, check out the [rails-recurrence-ui-dummy](https://github.com/assoly/rails-recurrence-ui-dummy) repository.
|
|
289
|
+
|
|
290
|
+
It demonstrates a fully configured Ruby on Rails application featuring:
|
|
291
|
+
|
|
238
292
|
- Database models with `HasRecurrence` integration.
|
|
239
|
-
- Form views using
|
|
240
|
-
- Initializer and internationalization
|
|
293
|
+
- Form views using ViewComponent and Tailwind CSS.
|
|
294
|
+
- Initializer and internationalization setup.
|
|
241
295
|
|
|
242
296
|
## Contributing
|
|
243
297
|
|
|
@@ -264,15 +318,15 @@ Please make sure your changes are covered by tests where appropriate.
|
|
|
264
318
|
|
|
265
319
|
## Testing
|
|
266
320
|
|
|
267
|
-
|
|
321
|
+
The test suite is currently under active development. Contributions are very welcome!
|
|
268
322
|
|
|
269
323
|
### Planned Test Suite
|
|
270
324
|
|
|
271
325
|
- [ ] **Models & Concerns (`HasRecurrence`):** Test attribute mapping, JSON parsing, virtual form attributes, and `IceCube::Schedule` generation.
|
|
272
|
-
- [ ] **Formatter Service
|
|
273
|
-
- [ ] **Internationalization (I18n):** Automated checks to ensure all locales
|
|
274
|
-
- [ ] **ViewComponents:** Test proper rendering and Stimulus data-attribute bindings
|
|
326
|
+
- [ ] **Formatter Service:** Validate human-readable summaries, smart date/time deduplication, and month declensions.
|
|
327
|
+
- [ ] **Internationalization (I18n):** Automated checks to ensure all locales share a consistent translation key structure.
|
|
328
|
+
- [ ] **ViewComponents:** Test proper rendering and Stimulus data-attribute bindings.
|
|
275
329
|
|
|
276
|
-
##
|
|
330
|
+
## License
|
|
277
331
|
|
|
278
|
-
Recurrence UI is available under the [MIT License](https://opensource.org/licenses/MIT).
|
|
332
|
+
Recurrence UI is available under the [MIT License](https://opensource.org/licenses/MIT).
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<%# app/views/recurrence_ui/_start_at.html.erb %>
|
|
2
|
+
<% default_start_time = rec_ui.start_time || RecurrenceUi.config.resolved_start_time %>
|
|
2
3
|
<div class="grid grid-cols-1 sm:grid-cols-2 gap-3">
|
|
3
4
|
|
|
4
5
|
<!-- 1. Дата и время начала (всегда на одной строке, не тянутся) -->
|
|
@@ -11,7 +12,7 @@
|
|
|
11
12
|
data: { "#{identifier}_target": "startDate",
|
|
12
13
|
action: "change->#{identifier}#calculateEndDateFromDuration" } %>
|
|
13
14
|
<%= form.time_field :form_start_time,
|
|
14
|
-
value: form.object.start_time_in_zone(:event)&.strftime('%H:%M') ||
|
|
15
|
+
value: form.object.start_time_in_zone(:event)&.strftime('%H:%M') || default_start_time,
|
|
15
16
|
class: "rui-input w-24 shrink-0",
|
|
16
17
|
data: { "#{identifier}_target": "startTime",
|
|
17
18
|
action: "change->#{identifier}#calculateEndDateFromDuration" }
|
|
@@ -3,53 +3,48 @@ module RecurrenceUi
|
|
|
3
3
|
class InstallGenerator < Rails::Generators::Base
|
|
4
4
|
source_root File.expand_path("templates", __dir__)
|
|
5
5
|
|
|
6
|
-
desc "Installs RecurrenceUi
|
|
7
|
-
|
|
8
|
-
def add_importmap_pin
|
|
9
|
-
importmap_file = "config/importmap.rb"
|
|
10
|
-
if File.exist?(importmap_file)
|
|
11
|
-
pin_code = "\npin \"recurrence_ui\", to: \"recurrence_ui/index.js\"\n"
|
|
12
|
-
if File.read(importmap_file).include?("recurrence_ui")
|
|
13
|
-
say "RecurrenceUi pin already exists in #{importmap_file}", :blue
|
|
14
|
-
else
|
|
15
|
-
append_to_file importmap_file, pin_code
|
|
16
|
-
say "Added recurrence_ui pin to #{importmap_file}", :green
|
|
17
|
-
end
|
|
18
|
-
else
|
|
19
|
-
say "Could not find #{importmap_file}. Importmap configuration skipped.", :yellow
|
|
20
|
-
end
|
|
21
|
-
end
|
|
6
|
+
desc "Installs RecurrenceUi Stimulus controller registration and Tailwind CSS styles"
|
|
22
7
|
|
|
23
8
|
def register_controller
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
9
|
+
say "1. Installing RecurrenceUi Stimulus controller registration", :green
|
|
10
|
+
|
|
11
|
+
app_js_path = Rails.root.join("app/javascript/application.js")
|
|
12
|
+
|
|
13
|
+
unless File.exist?(app_js_path)
|
|
14
|
+
say "Could not find app/javascript/application.js. Please register RecurrenceUi manually.", :red
|
|
15
|
+
return
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
content = File.read(app_js_path)
|
|
19
|
+
additions = []
|
|
20
|
+
|
|
21
|
+
application_import = 'import { application } from "controllers/application"'
|
|
22
|
+
recurrence_import = 'import { registerRecurrenceUiController } from "recurrence_ui"'
|
|
23
|
+
recurrence_registration = "registerRecurrenceUiController(application)"
|
|
24
|
+
|
|
25
|
+
unless content.include?(application_import)
|
|
26
|
+
additions << application_import
|
|
27
|
+
end
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// Register RecurrenceUi Stimulus controller
|
|
40
|
-
import { registerRecurrenceUiController } from "recurrence_ui"
|
|
41
|
-
if (typeof window.Stimulus !== "undefined") {
|
|
42
|
-
registerRecurrenceUiController(window.Stimulus)
|
|
43
|
-
}
|
|
44
|
-
JS
|
|
45
|
-
say "Added RecurrenceUi registration to #{target_js.relative_path_from(Rails.root)}", :green
|
|
46
|
-
end
|
|
29
|
+
unless content.include?(recurrence_import)
|
|
30
|
+
additions << recurrence_import
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
unless content.include?(recurrence_registration)
|
|
34
|
+
additions << recurrence_registration
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
if additions.empty?
|
|
38
|
+
say "RecurrenceUi controller is already registered", :blue
|
|
47
39
|
else
|
|
48
|
-
|
|
40
|
+
append_to_file app_js_path, "\n\n#{additions.join("\n")}\n"
|
|
41
|
+
say "Added RecurrenceUi controller registration to application.js", :green
|
|
49
42
|
end
|
|
50
43
|
end
|
|
51
44
|
|
|
52
45
|
def register_styles
|
|
46
|
+
say "2. Installing RecurrenceUi Tailwind CSS styles", :green
|
|
47
|
+
|
|
53
48
|
tailwind_css_paths = [
|
|
54
49
|
Rails.root.join("app/assets/tailwind/application.css"),
|
|
55
50
|
Rails.root.join("app/assets/stylesheets/application.tailwind.css"),
|
|
@@ -58,23 +53,26 @@ module RecurrenceUi
|
|
|
58
53
|
|
|
59
54
|
target_css = tailwind_css_paths.find { |path| File.exist?(path) }
|
|
60
55
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
56
|
+
unless target_css
|
|
57
|
+
say 'Tailwind CSS file not found. Please add `@import "recurrence_ui/application.css";` manually.', :yellow
|
|
58
|
+
return
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
content = File.read(target_css)
|
|
62
|
+
import_line = '@import "recurrence_ui/application.css";'
|
|
63
|
+
|
|
64
|
+
if content.include?(import_line)
|
|
65
|
+
say "RecurrenceUi styles are already imported in #{target_css.relative_path_from(Rails.root)}", :blue
|
|
66
|
+
return
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
if content.include?('@import "tailwindcss";')
|
|
70
|
+
inject_into_file target_css, "\n#{import_line}", after: '@import "tailwindcss";'
|
|
75
71
|
else
|
|
76
|
-
|
|
72
|
+
prepend_to_file target_css, "#{import_line}\n"
|
|
77
73
|
end
|
|
74
|
+
|
|
75
|
+
say "Added RecurrenceUi styles import to #{target_css.relative_path_from(Rails.root)}", :green
|
|
78
76
|
end
|
|
79
77
|
end
|
|
80
78
|
end
|
data/lib/recurrence_ui/engine.rb
CHANGED
|
@@ -1,32 +1,33 @@
|
|
|
1
|
-
# file: recurrence_ui/lib/recurrence_ui/engine.rb
|
|
2
1
|
require "recurrence_ui"
|
|
3
2
|
|
|
4
3
|
module RecurrenceUi
|
|
5
4
|
class Engine < ::Rails::Engine
|
|
6
5
|
isolate_namespace RecurrenceUi
|
|
7
6
|
|
|
8
|
-
#
|
|
9
|
-
#initializer "recurrence_ui.importmap", before: "importmap" do |app|
|
|
10
|
-
# if app.config.respond_to?(:importmap)
|
|
11
|
-
# app.config.importmap.paths << Engine.root.join("config/importmap.rb")
|
|
12
|
-
# end
|
|
13
|
-
#end
|
|
14
|
-
|
|
15
|
-
# 2. Assets (только стили и картинки, если нужны, т.к. JS обслуживает Importmap)
|
|
7
|
+
# Assets: JavaScript and CSS
|
|
16
8
|
initializer "recurrence_ui.assets" do |app|
|
|
17
9
|
if app.config.respond_to?(:assets)
|
|
18
|
-
app.config.assets.
|
|
10
|
+
app.config.assets.paths << root.join("app/javascript")
|
|
11
|
+
app.config.assets.precompile += %w(recurrence_ui/application.css)
|
|
19
12
|
end
|
|
20
13
|
end
|
|
21
14
|
|
|
22
|
-
#
|
|
15
|
+
# Importmap
|
|
16
|
+
initializer "recurrence_ui.importmap", before: "importmap" do |app|
|
|
17
|
+
app.config.importmap.paths << root.join("config/importmap.rb")
|
|
18
|
+
app.config.importmap.cache_sweepers << root.join("app/javascript")
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# I18n locales
|
|
23
22
|
initializer "recurrence_ui.locales" do |app|
|
|
24
|
-
app.config.i18n.load_path += Dir[
|
|
23
|
+
app.config.i18n.load_path += Dir[
|
|
24
|
+
root.join("config", "locales", "*.{rb,yml}")
|
|
25
|
+
]
|
|
25
26
|
end
|
|
26
27
|
|
|
27
|
-
#
|
|
28
|
+
# ViewComponent / ActionView helpers
|
|
28
29
|
config.to_prepare do
|
|
29
30
|
ApplicationController.helper(RecurrenceUi::Engine.helpers)
|
|
30
31
|
end
|
|
31
32
|
end
|
|
32
|
-
end
|
|
33
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: recurrence_ui
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Katerina German
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|