shimmer 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +172 -14
- data/lib/shimmer/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: bfbc6b047d278bdb23bcb528277c436b79bc625b577d1d8c94c113644fdcbcf3
|
4
|
+
data.tar.gz: 5002fecacde7a232259b2f0bd8652f8ab2e1a544758efe42db324f4e99907b27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6a8c5ed0339cb8ae2f924b0d4eeb97554388e479ff37cfa76a688db62d4bcb7303385567c2cf673c983c656fc49bdd808189a188dca52bb30cff4725be02292
|
7
|
+
data.tar.gz: 7c027ab85b75df7b495539486f702f054d794fb393b18b3676f4c99e083fe822b8cd22c313a649ab509ea8f3428d08a533a65e7ef000bd33be04f35dbb6f0fba
|
data/README.md
CHANGED
@@ -1,38 +1,196 @@
|
|
1
|
-
# Shimmer
|
1
|
+
# Shimmer - Because Ruby could be more shiny!
|
2
2
|
|
3
|
-
|
3
|
+
Shimmer is a collection of Rails extensions that bring advanced UI features into your app and make your life easier as a developer.
|
4
4
|
|
5
|
-
|
5
|
+
## Features
|
6
|
+
|
7
|
+
### Static File Serving
|
8
|
+
|
9
|
+
`ActiveStorage` is great, but serving of files, especially behind a CDN, can be complicated to get right. This can be fixed easily:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
# use an image tag
|
13
|
+
image_tag user.avatar, width: 300
|
14
|
+
```
|
15
|
+
|
16
|
+
This extension overrides `image_tag` and also supplies a matching `image_file_url` that automatically resizes your image and creates a static, cacheable url.
|
17
|
+
|
18
|
+
### Modals
|
19
|
+
|
20
|
+
Modals are the designer's best friend, but developers usually hate them for their complexity. Fear no more: Shimmer has you covered.
|
21
|
+
|
22
|
+
```slim
|
23
|
+
a href=modal_path(new_post_path) Create a new Post
|
24
|
+
```
|
25
|
+
|
26
|
+
This will open a modal on click and then asynchronously request the modal content from the controller. Modals can also be controlled via JavaScript via the global `ui` variable:
|
27
|
+
|
28
|
+
```js
|
29
|
+
ui.modal.open({ url: "/posts/new" });
|
30
|
+
ui.modal.close();
|
31
|
+
```
|
32
|
+
|
33
|
+
### Popovers
|
34
|
+
|
35
|
+
When modals are annoying to implement, popovers are even worse. Thankfully, Shimmer comes to the rescue:
|
36
|
+
|
37
|
+
```slim
|
38
|
+
a href=popover_path(new_post_path, placement: :left)
|
39
|
+
```
|
40
|
+
|
41
|
+
This will request `new_post_path` and display it left of the anchor thanks to PopperJS.
|
42
|
+
|
43
|
+
### Remote Navigation
|
44
|
+
|
45
|
+
Remote navigation takes Hotwire to the next level with built-in navigation actions, integrated with modals and popovers.
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
def create
|
49
|
+
@post = current_user.posts.create! post_params
|
50
|
+
ui.navigate_to @post
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
This will automatically close the current modal or popover and navigate via Turbo Drive to the post's url - no redirects necessary.
|
55
|
+
|
56
|
+
The `ui` helper comes with several built-in functions:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
# run any kind of javascript upon request completion
|
60
|
+
ui.run_javascript("alert('hello world')")
|
61
|
+
|
62
|
+
# open or replace a modal's content (dependent on its ID)
|
63
|
+
ui.open_modal(new_post_path, size: :small)
|
64
|
+
|
65
|
+
# close an open modal
|
66
|
+
ui.close_modal
|
67
|
+
|
68
|
+
# same methods also available for popovers
|
69
|
+
ui.open_popover(new_post_path, selector: "#user-profile", placement: :left)
|
70
|
+
ui.close_popover
|
71
|
+
|
72
|
+
# navigate via Turbo Drive
|
73
|
+
ui.navigate_to(@post)
|
74
|
+
|
75
|
+
# manipulate the page's content
|
76
|
+
ui.append(@post, with: "comments/comment", comment: @comment)
|
77
|
+
ui.prepend("#user-profile", with: "users/extra")
|
78
|
+
ui.replace(@post)
|
79
|
+
ui.remove(@post)
|
80
|
+
```
|
81
|
+
|
82
|
+
### Sitemaps
|
83
|
+
|
84
|
+
Want to implement sitemaps, but the ephemeral filesystem of Heroku hates you? Here's a simple way to upload sitemaps:
|
85
|
+
|
86
|
+
- install the sitemap gem and configure the `sitemap.rb` as usual
|
87
|
+
- use the shimmer adapter to automatically upload your sitemap to your configured ActiveStorage adapter
|
88
|
+
- use the shimmer controller to display the sitemap in your app
|
89
|
+
- (optional) tell sidekiq scheduler to regularly update your sitemap
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
# sitemap.rb
|
93
|
+
SitemapGenerator::Sitemap.adapter = Shimmer::SitemapAdapter.new
|
94
|
+
|
95
|
+
# routes.rb
|
96
|
+
get "sitemaps/*path", to: "shimmer/sitemaps#show"
|
97
|
+
|
98
|
+
# sidekiq.yml
|
99
|
+
:schedule:
|
100
|
+
sitemap:
|
101
|
+
cron: '0 0 12 * * * Europe/Berlin' # every day at 16:00, Berlin time
|
102
|
+
class: Shimmer::SitemapJob
|
103
|
+
```
|
104
|
+
|
105
|
+
### Cloudflare Support
|
106
|
+
|
107
|
+
As you might have noticed, Cloudflare SSL will cause some issues with your Rails app if you're not using SSL strict mode (https://github.com/rails/rails/issues/22965). If you can't switch to strict mode, go for the standard flexible mode instead and add this middleware to your stack:
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
# application.rb
|
111
|
+
config.middleware.use Shimmer::CloudflareProxy
|
112
|
+
```
|
113
|
+
|
114
|
+
### Heroku Database Helpers
|
115
|
+
|
116
|
+
Can't reproduce an issue with your local test data and just want the production or staging data on your development machine? Here you go:
|
117
|
+
|
118
|
+
```bash
|
119
|
+
rails db:pull
|
120
|
+
```
|
121
|
+
|
122
|
+
This will drop your local database and pull in the database of your connected Heroku app (make sure you executed `heroku git:remote -a your_app` before to have the git remote). But what about assets you might ask? Easy - assets are pulled from S3 as well via the AWS CLI automatically (make sure your environment variables in Heroku are correctly named as `AWS_REGION`, `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`) and the database is updated to use your local filesystem instead.
|
123
|
+
|
124
|
+
If you don't want the asset support, you can also only pull the database or only the assets:
|
125
|
+
|
126
|
+
```bash
|
127
|
+
rails db:pull_data
|
128
|
+
rails db:pull_assets
|
129
|
+
```
|
130
|
+
|
131
|
+
### Localizable Routes with Browser Locale Support
|
132
|
+
|
133
|
+
To localize a page via urls, this will help you tremendously.
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
# routes.rb
|
137
|
+
Rails.application.routes.draw do
|
138
|
+
scope "/(:locale)", locale: /#{I18n.available_locales.join("|")}/ do
|
139
|
+
get "login", to: "sessions#new"
|
140
|
+
end
|
141
|
+
end
|
142
|
+
```
|
143
|
+
|
144
|
+
From now on you can prefix your routes with a locale like `/de/login` or `/en/login` and `I18n.locale` will automatically be set. If there is no locale in the url (it's optional), this will automatically use the browser's locale.
|
145
|
+
|
146
|
+
You want to redirect from unlocalized paths? Add a before action to your controller:
|
147
|
+
|
148
|
+
```ruby
|
149
|
+
before_action :check_locale
|
150
|
+
```
|
151
|
+
|
152
|
+
Trying to figure out which key a certain translation on the page has? Append `?debug` to the url and `I18n.debug?` will be set - which leads to keys being printed on the page.
|
6
153
|
|
7
154
|
## Installation
|
8
155
|
|
9
156
|
Add this line to your application's Gemfile:
|
10
157
|
|
11
158
|
```ruby
|
12
|
-
gem
|
159
|
+
gem "shimmer"
|
13
160
|
```
|
14
161
|
|
15
162
|
And then execute:
|
16
163
|
|
17
|
-
|
164
|
+
```bash
|
165
|
+
$ bundle install
|
166
|
+
```
|
18
167
|
|
19
|
-
|
168
|
+
Add some configuration to your project:
|
20
169
|
|
21
|
-
|
170
|
+
```ruby
|
171
|
+
# routes.rb
|
22
172
|
|
23
|
-
|
173
|
+
resources :files, only: :show, controller: "shimmer/files"
|
24
174
|
|
25
|
-
|
175
|
+
# application_controller.rb
|
176
|
+
class ApplicationController < ActionController::Base
|
177
|
+
include Shimmer::Localizable
|
178
|
+
include Shimmer::RemoteNavigation
|
179
|
+
end
|
180
|
+
```
|
26
181
|
|
27
|
-
|
182
|
+
```ts
|
183
|
+
// application.ts
|
28
184
|
|
29
|
-
|
185
|
+
import { start } from "@nerdgeschoss/shimmer";
|
186
|
+
import { application } from "controllers/application";
|
30
187
|
|
31
|
-
|
188
|
+
start({ application });
|
189
|
+
```
|
32
190
|
|
33
191
|
## Contributing
|
34
192
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
193
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/nerdgeschoss/shimmer. 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/nerdgeschoss/shimmer/blob/master/CODE_OF_CONDUCT.md).
|
36
194
|
|
37
195
|
## License
|
38
196
|
|
@@ -40,4 +198,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
40
198
|
|
41
199
|
## Code of Conduct
|
42
200
|
|
43
|
-
Everyone interacting in the Shimmer project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
201
|
+
Everyone interacting in the Shimmer project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/nerdgeschoss/shimmer/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/shimmer/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shimmer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jens Ravens
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
11
|
+
date: 2021-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|