shimmer 0.0.5 → 0.0.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 419d4bba740070b286202f099a64f31929b029505bc3411a9db8b922d51e0eec
4
- data.tar.gz: 5f75ac2e0c8ac3fc82335efe2dd8bd98270f9506433bfa0e894369e952fb6aef
3
+ metadata.gz: 166c374942cdbfe22b8a1274633247cb95964439bcd959ca8cdb59a774767f50
4
+ data.tar.gz: 4e64bb6dc30433b6521c6283e5ad9e1232cdadd6b993a45ba4c27999eebb5c36
5
5
  SHA512:
6
- metadata.gz: ec203c95a4fc2088731aa269c0c27577fbd59fa4070d972d6ad066d469b6203b54fb8ffafedb4295d7387e981d6a50a87ca981f8c92c9f5c624d45aed851b906
7
- data.tar.gz: cdae8b03095d4f3c7f38f5ccbe47864ab41ade50bf1e2d45fe3da2e112e2a11e3d733ed73d2b581a833be9d6f5f263795aff008ccfcd5da51d45c52227a560c9
6
+ metadata.gz: 803fcbb251147f224eaa42ce9b5bdca8a2e7d73488e32b7ef01f91abdcff01674b0238b8a0fc0ae2299d69855938a0fe817a9f1b8e1becdfba6cfbc36b8b1595
7
+ data.tar.gz: 545e5378acb4c46a72fa8604f6e881921d65723008e28561aa688d7a1d83729b23bf7f4b1b0ae1d76328fde2cda0a04f4c8176cc167aa632aeee60e5bcfa465f
data/README.md CHANGED
@@ -1,38 +1,196 @@
1
- # Shimmer
1
+ # Shimmer - Because Ruby could be more shiny!
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/shimmer`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Delete this and the text above, and describe your gem
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 'shimmer'
159
+ gem "shimmer"
13
160
  ```
14
161
 
15
162
  And then execute:
16
163
 
17
- $ bundle install
164
+ ```bash
165
+ $ bundle install
166
+ ```
18
167
 
19
- Or install it yourself as:
168
+ Add some configuration to your project:
20
169
 
21
- $ gem install shimmer
170
+ ```ruby
171
+ # routes.rb
22
172
 
23
- ## Usage
173
+ resources :files, only: :show, controller: "shimmer/files"
24
174
 
25
- TODO: Write usage instructions here
175
+ # application_controller.rb
176
+ class ApplicationController < ActionController::Base
177
+ include Shimmer::Localizable
178
+ include Shimmer::RemoteNavigation
179
+ end
180
+ ```
26
181
 
27
- ## Development
182
+ ```ts
183
+ // application.ts
28
184
 
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
185
+ import { start } from "@nerdgeschoss/shimmer";
186
+ import { application } from "controllers/application";
30
187
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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/[USERNAME]/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/[USERNAME]/shimmer/blob/master/CODE_OF_CONDUCT.md).
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/[USERNAME]/shimmer/blob/master/CODE_OF_CONDUCT.md).
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).
@@ -3,14 +3,17 @@
3
3
  namespace :db do
4
4
  desc "Downloads the app database from heroku to local db"
5
5
  task pull_data: :environment do
6
- config = ActiveRecord::Base.connection_db_config.config
7
- # binding.pry
6
+ config = if Rails.version.to_f >= 7
7
+ ActiveRecord::Base.connection_db_config.configuration_hash.with_indifferent_access
8
+ else
9
+ ActiveRecord::Base.connection_db_config.config
10
+ end
8
11
  ENV["DISABLE_DATABASE_ENVIRONMENT_CHECK"] = "1"
9
12
  Rake::Task["db:drop"].invoke
10
13
  ENV["PGUSER"] = config["username"]
11
14
  ENV["PGHOST"] = config["host"]
12
15
  ENV["PGPORT"] = config["port"].to_s
13
- sh "heroku pg:pull DATABASE_URL #{config["database"]} --app thefetishtraveller"
16
+ sh "heroku pg:pull DATABASE_URL #{config["database"]}"
14
17
  sh "rails db:environment:set"
15
18
  sh "RAILS_ENV=test rails db:create"
16
19
  end
@@ -29,31 +29,32 @@ module Shimmer
29
29
  def url_locale
30
30
  params[:locale]
31
31
  end
32
- end
33
- end
34
- end
35
-
36
- module I18n
37
- UNTRANSLATED_SCOPES = ["number", "transliterate", "date", "datetime", "errors", "helpers", "support", "time", "faker"].map { |k| "#{k}." }
38
-
39
- thread_mattr_accessor :debug
40
32
 
41
- class << self
42
- alias_method :old_translate, :translate
43
- def translate(key, options = {})
44
- key = key.to_s.downcase
45
- untranslated = UNTRANSLATED_SCOPES.any? { |e| key.include? e }
46
- key_name = [options[:scope], key].flatten.compact.join(".")
47
- option_names = options.except(:count, :default, :raise, :scope).map { |k, v| "#{k}=#{v}" }.join(", ")
48
- return "#{key_name} #{option_names}" if I18n.debug && !untranslated
49
-
50
- options.reverse_merge!(default: old_translate(key, **options.merge(locale: :de))) if untranslated
51
- old_translate(key, **options)
52
- end
53
- alias_method :t, :translate
54
-
55
- def debug?
56
- debug
33
+ I18n.class_eval do
34
+ next if defined? debug
35
+
36
+ thread_mattr_accessor :debug
37
+
38
+ class << self
39
+ alias_method :old_translate, :translate
40
+ def translate(key, options = {})
41
+ untranslated_scopes = ["number", "transliterate", "date", "datetime", "errors", "helpers", "support", "time", "faker"].map { |k| "#{k}." }
42
+ key = key.to_s.downcase
43
+ untranslated = untranslated_scopes.any? { |e| key.include? e }
44
+ key_name = [options[:scope], key].flatten.compact.join(".")
45
+ option_names = options.except(:count, :default, :raise, :scope).map { |k, v| "#{k}=#{v}" }.join(", ")
46
+ return "#{key_name} #{option_names}" if I18n.debug && !untranslated
47
+
48
+ options.reverse_merge!(default: old_translate(key, **options.merge(locale: :de))) if untranslated
49
+ old_translate(key, **options)
50
+ end
51
+ alias_method :t, :translate
52
+
53
+ def debug?
54
+ debug
55
+ end
56
+ end
57
+ end
57
58
  end
58
59
  end
59
60
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Shimmer
4
- VERSION = "0.0.5"
4
+ VERSION = "0.0.9"
5
5
  end
data/src/modal.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { loaded, createElement, nextFrame, getHTML } from "./util";
1
+ import { createElement, nextFrame, getHTML } from "./util";
2
2
 
3
3
  export interface ModalOptions {
4
4
  id?: string;
@@ -11,7 +11,7 @@ export class ModalPresenter {
11
11
  private modals: Record<string, Modal> = {};
12
12
 
13
13
  constructor() {
14
- loaded.then(this.prepareBlind);
14
+ document.addEventListener("turbo:load", this.prepareBlind);
15
15
  }
16
16
 
17
17
  async open(options: ModalOptions): Promise<void> {
@@ -38,9 +38,9 @@ export class ModalPresenter {
38
38
  document.body.classList.toggle("modal-open", open);
39
39
  }
40
40
 
41
- private async prepareBlind(): Promise<void> {
41
+ private prepareBlind: () => void = () => {
42
42
  createElement(document.body, "modal-blind");
43
- }
43
+ };
44
44
  }
45
45
 
46
46
  export class Modal {
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.5
4
+ version: 0.0.9
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-22 00:00:00.000000000 Z
11
+ date: 2022-01-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: