solder 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +46 -6
- data/Rakefile +10 -0
- data/app/controllers/solder/ui_state_controller.rb +14 -2
- data/app/helpers/solder/application_helper.rb +23 -1
- data/lib/generators/solder/initializer/USAGE +8 -0
- data/lib/generators/solder/initializer/USAGE~ +8 -0
- data/lib/generators/solder/initializer/initializer_generator.rb +7 -0
- data/lib/generators/solder/initializer/initializer_generator.rb~ +3 -0
- data/lib/generators/solder/initializer/templates/solder.rb +10 -0
- data/lib/generators/solder/initializer/templates/solder.rb~ +0 -0
- data/lib/generators/solder/stimulus/USAGE +8 -0
- data/lib/generators/solder/stimulus/USAGE~ +8 -0
- data/lib/generators/solder/stimulus/stimulus_generator.rb +7 -0
- data/lib/generators/solder/stimulus/stimulus_generator.rb~ +3 -0
- data/lib/generators/solder/stimulus/templates/solder_controller.js.tt +41 -0
- data/lib/install/install.rb +36 -0
- data/lib/install/install.rb~ +17 -0
- data/lib/install/templates/solder_controller.js.tt +41 -0
- data/lib/solder/engine.rb +33 -2
- data/lib/solder/engine.rb~ +19 -3
- data/lib/solder/version.rb +1 -1
- data/lib/solder/version.rb~ +3 -0
- data/lib/tasks/solder_tasks.rake +6 -4
- metadata +28 -16
- data/app/controllers/solder/ui_state_controller.rb~ +0 -25
- data/app/helpers/solder/application_helper.rb~ +0 -14
- data/config/routes.rb~ +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00c285939bae079a1349a896571e8b315752b813715081d4d29d043a25d0c27a
|
4
|
+
data.tar.gz: '092845396d182c4082c4915a12fd9a9087666557c95cca1cae4a6be1e9078420'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adb71a8e89b6c6730250dd0ba23b5ad0390822ba6d35afd130fd655a37ab6cecbcd45f1c443ece71d8e199a8fce984d6070d8dd0dcab4e6444041f0089e402bf
|
7
|
+
data.tar.gz: ea5f579f47725c9d5f148ca0f1e9dca34e2f98a81b6575595442266b36c3e264577ef96fcff94487dbc3fef0390d7c1c891c8f00b9196023ff796d02cde216dc
|
data/README.md
CHANGED
@@ -1,12 +1,30 @@
|
|
1
1
|
# 🧑🏭 Solder
|
2
|
-
|
2
|
+
Persist and restore ephemeral attributes of HTML elements using the Rails cache store and StimulusJS
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
In short, this plugin will persist UI state changes a user makes on a per-element basis.
|
5
|
+
|
6
|
+
This is useful for
|
7
|
+
- storing the open/closed state of a sidebar, accordion, etc.
|
8
|
+
- storing the state of tree views (e.g. storefront categories),
|
9
|
+
- custom dashboard layouts
|
10
|
+
- etc.
|
11
|
+
|
12
|
+
![A Cyborg Hand Soldering, Steampunk Style](https://user-images.githubusercontent.com/4352208/208506264-db5abac6-7d33-4504-9c0d-2d5f8c26994b.png)
|
13
|
+
|
14
|
+
_Image: [openjourney](https://replicate.com/prompthero/openjourney), prompt: mdjrny-v4 style cyborg soldering a piece of code onto a web application user interface, 8k, steampunk_
|
6
15
|
|
7
|
-
|
16
|
+
## Rationale
|
8
17
|
|
9
|
-
|
18
|
+
Modern server-side rendering techniques like Turbo Frames/Streams, StimulusReflex and others require to persist state on the server to facilitate rerendering without UI discrepancies.
|
19
|
+
|
20
|
+
Typically, you have a few options to achieve this:
|
21
|
+
- ActiveRecord,
|
22
|
+
- the `session`,
|
23
|
+
- [Kredis](https://github.com/rails/kredis)
|
24
|
+
are the most frequent ones. It requires you to invent keys to access the state of UI elements, e.g. `session[:collapsed_categories]` etc.
|
25
|
+
Experience shows that the management of those keys tends to increase complexity.
|
26
|
+
|
27
|
+
Hence, the part that this gem takes care of is the automatic generation and management of those keys.
|
10
28
|
|
11
29
|
## Installation
|
12
30
|
Add this line to your application's Gemfile:
|
@@ -25,6 +43,25 @@ Or install it yourself as:
|
|
25
43
|
$ gem install solder
|
26
44
|
```
|
27
45
|
|
46
|
+
## Usage
|
47
|
+
|
48
|
+
In your view, use the `solder_onto` helper to create a unique key for the element whose attributes you want to track. For example, imagine we have an online store with multiple category-specific landing pages. There's a tree view on it for further filtering items:
|
49
|
+
|
50
|
+
```erb
|
51
|
+
<%= solder_onto([current_user, @category] do %>
|
52
|
+
<details>
|
53
|
+
<summary>Outdoor Equipment</summary>
|
54
|
+
|
55
|
+
<details> ... </details>
|
56
|
+
</details>
|
57
|
+
<% end %>
|
58
|
+
```
|
59
|
+
|
60
|
+
**IMPORTANT**:
|
61
|
+
1. The helper only takes care of the attributes of the **first child** within it. This is because of how [`capture`](https://api.rubyonrails.org/classes/ActionView/Helpers/CaptureHelper.html#method-i-capture) works.
|
62
|
+
2. Think of the first argument to `solder_onto` as something akin to a cache key. You want it to be unique with regard to (almost always) the logged in user, and any other record it is scoped to. In fact, it adheres to the same interface as [`cache`](https://api.rubyonrails.org/classes/ActionView/Helpers/CacheHelper.html#method-i-cache)
|
63
|
+
|
64
|
+
|
28
65
|
## Dependencies
|
29
66
|
|
30
67
|
### Ruby
|
@@ -34,7 +71,10 @@ $ gem install solder
|
|
34
71
|
|
35
72
|
- Stimulus
|
36
73
|
- @rails/request.js
|
37
|
-
|
74
|
+
|
75
|
+
## Persistence
|
76
|
+
|
77
|
+
Uses the active Rails cache store, possibly more adapters to come.
|
38
78
|
|
39
79
|
## Contributing
|
40
80
|
Contribution directions go here.
|
data/Rakefile
CHANGED
@@ -6,3 +6,13 @@ load "rails/tasks/engine.rake"
|
|
6
6
|
load "rails/tasks/statistics.rake"
|
7
7
|
|
8
8
|
require "bundler/gem_tasks"
|
9
|
+
|
10
|
+
require "rake/testtask"
|
11
|
+
|
12
|
+
Rake::TestTask.new(:test) do |t|
|
13
|
+
t.libs << "test"
|
14
|
+
t.pattern = "test/**/*_test.rb"
|
15
|
+
t.verbose = false
|
16
|
+
end
|
17
|
+
|
18
|
+
task default: :test
|
@@ -1,13 +1,17 @@
|
|
1
1
|
module Solder
|
2
2
|
class UiStateController < ApplicationController
|
3
|
+
include ActionView::Helpers::SanitizeHelper
|
4
|
+
|
3
5
|
before_action :set_ui_state, only: :show
|
6
|
+
around_action Solder.config[:around_action]
|
4
7
|
|
5
8
|
def show
|
6
9
|
render json: @ui_state.to_json
|
7
10
|
end
|
8
11
|
|
9
12
|
def update
|
10
|
-
Rails.cache.write "solder/#{
|
13
|
+
Rails.cache.write "solder/#{ui_state_params[:key]}", parsed_attributes
|
14
|
+
records_to_touch.map(&:touch)
|
11
15
|
|
12
16
|
head :ok
|
13
17
|
end
|
@@ -19,7 +23,15 @@ module Solder
|
|
19
23
|
end
|
20
24
|
|
21
25
|
def set_ui_state
|
22
|
-
@ui_state = Rails.cache.read "solder/#{
|
26
|
+
@ui_state = Rails.cache.read "solder/#{ui_state_params[:key]}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def records_to_touch
|
30
|
+
GlobalID::Locator.locate_many_signed parsed_attributes["data-solder-touch"]&.split(":") || []
|
31
|
+
end
|
32
|
+
|
33
|
+
def parsed_attributes
|
34
|
+
JSON.parse(ui_state_params[:attributes]).deep_transform_values { sanitize(_1) }
|
23
35
|
end
|
24
36
|
end
|
25
37
|
end
|
@@ -1,5 +1,27 @@
|
|
1
1
|
module Solder
|
2
2
|
module ApplicationHelper
|
3
|
+
def solder_onto(name, touch: [], attribute_safelist: ["class"], &block)
|
4
|
+
soldered_html = capture(&block).to_s.strip
|
5
|
+
fragment = Nokogiri::HTML.fragment(soldered_html)
|
6
|
+
|
7
|
+
first_fragment_child = fragment.first_element_child
|
8
|
+
|
9
|
+
# rehydrate
|
10
|
+
ui_state = Rails.cache.read "solder/#{solder_key(name)}"
|
11
|
+
|
12
|
+
ui_state&.select { attribute_safelist.include?(_1) }&.each do |attribute_name, value|
|
13
|
+
first_fragment_child[attribute_name] = sanitize(value, tags: [])
|
14
|
+
end
|
15
|
+
|
16
|
+
# add stimulus controller and create unique key
|
17
|
+
first_fragment_child["data-controller"] = "#{first_fragment_child["data-controller"]} solder".strip
|
18
|
+
first_fragment_child["data-solder-key-value"] = solder_key(name)
|
19
|
+
|
20
|
+
first_fragment_child["data-solder-touch"] ||= Array(touch).map(&:to_sgid).map(&:to_s).join(":")
|
21
|
+
|
22
|
+
first_fragment_child.to_html.html_safe
|
23
|
+
end
|
24
|
+
|
3
25
|
def solder_key(name)
|
4
26
|
key = cache_fragment_name(name, skip_digest: true)
|
5
27
|
.flatten
|
@@ -7,7 +29,7 @@ module Solder
|
|
7
29
|
.map(&:cache_key)
|
8
30
|
.join(":")
|
9
31
|
|
10
|
-
key += ":#{caller
|
32
|
+
key += ":#{caller.find { _1 =~ /html/ }}"
|
11
33
|
|
12
34
|
ActiveSupport::Digest.hexdigest(key)
|
13
35
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Solder.configure do |config|
|
2
|
+
# Specify a global around action for Solder's UIStateController
|
3
|
+
# This is useful for any assumptions your app makes, e.g. instance
|
4
|
+
# variables being present, headers being checked, or multitenancy
|
5
|
+
# (see example below)
|
6
|
+
#
|
7
|
+
# config[:around_action] = ->(_controller, action) do
|
8
|
+
# ActsAsTenant.without_tenant { action.call }
|
9
|
+
# end
|
10
|
+
end
|
File without changes
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import { Controller } from '@hotwired/stimulus'
|
2
|
+
import { get, patch } from '@rails/request.js'
|
3
|
+
|
4
|
+
export default class extends Controller {
|
5
|
+
static values = {
|
6
|
+
key: String
|
7
|
+
}
|
8
|
+
|
9
|
+
async connect () {
|
10
|
+
this.mutationObserver = new MutationObserver(this.mutateState.bind(this))
|
11
|
+
|
12
|
+
this.mutationObserver.observe(this.element, { attributes: true })
|
13
|
+
}
|
14
|
+
|
15
|
+
disconnect () {
|
16
|
+
this.mutationObserver?.disconnect()
|
17
|
+
}
|
18
|
+
|
19
|
+
mutateState (mutationList, observer) {
|
20
|
+
mutationList
|
21
|
+
.filter(mutation => mutation.attributeName !== 'data-solder-touch')
|
22
|
+
.forEach(async mutation => {
|
23
|
+
const body = new FormData()
|
24
|
+
|
25
|
+
const attributes = {}
|
26
|
+
this.element
|
27
|
+
.getAttributeNames()
|
28
|
+
.filter(name => name !== 'data-controller')
|
29
|
+
.map(name => {
|
30
|
+
attributes[name] = this.element.getAttribute(name)
|
31
|
+
})
|
32
|
+
|
33
|
+
body.append('key', this.keyValue)
|
34
|
+
body.append('attributes', JSON.stringify(attributes))
|
35
|
+
|
36
|
+
await patch('/solder/ui_state/update', {
|
37
|
+
body
|
38
|
+
})
|
39
|
+
})
|
40
|
+
}
|
41
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# install @rails/request.js
|
2
|
+
if Rails.root.join("config/importmap.rb").exist?
|
3
|
+
say "Pin @rails/request.js"
|
4
|
+
append_to_file "config/importmap.rb", %(pin "@rails/request.js", preload: true\n)
|
5
|
+
else
|
6
|
+
say "Install @rails/request.js"
|
7
|
+
run "yarn add @rails/request.js"
|
8
|
+
end
|
9
|
+
|
10
|
+
gemfile = Rails.root.join("Gemfile").read
|
11
|
+
|
12
|
+
# install stimulus-rails, if not already present
|
13
|
+
if !gemfile.include? "stimulus-rails"
|
14
|
+
gem "stimulus-rails"
|
15
|
+
rails_command "stimulus:install"
|
16
|
+
say "✅ stimulus-rails has been installed"
|
17
|
+
else
|
18
|
+
say "⏩ stimulus-rails is already installed. Skipping."
|
19
|
+
end
|
20
|
+
|
21
|
+
# copy stimulus controller template
|
22
|
+
generate "solder:stimulus"
|
23
|
+
|
24
|
+
# turn on development caching
|
25
|
+
if Rails.root.join("tmp", "caching-dev.txt").exist?
|
26
|
+
say "⏩ Already caching in development. Skipping."
|
27
|
+
else
|
28
|
+
system "rails dev:cache"
|
29
|
+
say "✅ Enabled caching in development"
|
30
|
+
end
|
31
|
+
|
32
|
+
# mount engine
|
33
|
+
route 'mount Solder::Engine, at: "/solder"'
|
34
|
+
|
35
|
+
# copy initializer template
|
36
|
+
generate "solder:initializer" if yes?("Do you want to install the solder initializer template?")
|
@@ -0,0 +1,17 @@
|
|
1
|
+
if Rails.root.join("config/importmap.rb").exist?
|
2
|
+
say "Pin @rails/request.js"
|
3
|
+
append_to_file "config/importmap.rb", %(pin "@rails/request.js", preload: true\n)
|
4
|
+
else
|
5
|
+
say "Install @rails/request.js"
|
6
|
+
run "yarn add @rails/request.js"
|
7
|
+
end
|
8
|
+
|
9
|
+
# if stimulus isn't present
|
10
|
+
# bundle add stimulus-rails
|
11
|
+
# bin/rails stimulus:install
|
12
|
+
gemfile = Rails.root.join("Gemfile").read
|
13
|
+
binding.irb
|
14
|
+
|
15
|
+
say "Installing Stimulus"
|
16
|
+
gem "stimulus-rails"
|
17
|
+
rails_command "stimulus:install"
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import { Controller } from '@hotwired/stimulus'
|
2
|
+
import { get, patch } from '@rails/request.js'
|
3
|
+
|
4
|
+
export default class extends Controller {
|
5
|
+
static values = {
|
6
|
+
key: String
|
7
|
+
}
|
8
|
+
|
9
|
+
async connect () {
|
10
|
+
this.mutationObserver = new MutationObserver(this.mutateState.bind(this))
|
11
|
+
|
12
|
+
this.mutationObserver.observe(this.element, { attributes: true })
|
13
|
+
}
|
14
|
+
|
15
|
+
disconnect () {
|
16
|
+
this.mutationObserver?.disconnect()
|
17
|
+
}
|
18
|
+
|
19
|
+
mutateState (mutationList, observer) {
|
20
|
+
mutationList
|
21
|
+
.filter(mutation => mutation.attributeName !== 'data-solder-touch')
|
22
|
+
.forEach(async mutation => {
|
23
|
+
const body = new FormData()
|
24
|
+
|
25
|
+
const attributes = {}
|
26
|
+
this.element
|
27
|
+
.getAttributeNames()
|
28
|
+
.filter(name => name !== 'data-controller')
|
29
|
+
.map(name => {
|
30
|
+
attributes[name] = this.element.getAttribute(name)
|
31
|
+
})
|
32
|
+
|
33
|
+
body.append('key', this.keyValue)
|
34
|
+
body.append('attributes', JSON.stringify(attributes))
|
35
|
+
|
36
|
+
await patch('/solder/ui_state/update', {
|
37
|
+
body
|
38
|
+
})
|
39
|
+
})
|
40
|
+
}
|
41
|
+
}
|
data/lib/solder/engine.rb
CHANGED
@@ -1,8 +1,24 @@
|
|
1
1
|
module Solder
|
2
|
+
class << self
|
3
|
+
def config
|
4
|
+
Rails.application.config.solder
|
5
|
+
end
|
6
|
+
|
7
|
+
def configure
|
8
|
+
yield config
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
2
12
|
class Engine < ::Rails::Engine
|
3
13
|
isolate_namespace Solder
|
4
14
|
|
15
|
+
config.solder = ActiveSupport::OrderedOptions.new
|
16
|
+
config.solder[:around_action] = ->(_controller, action) { action.call }
|
17
|
+
|
5
18
|
initializer "solder.check_caching" do |app|
|
19
|
+
next if called_by_installer?
|
20
|
+
next if called_by_generator?
|
21
|
+
|
6
22
|
unless app.config.action_controller.perform_caching && app.config.cache_store != :null_store
|
7
23
|
puts <<~WARN
|
8
24
|
🧑🏭 Solder uses the Rails cache store to provide UI state persistence. Therefore, please make sure caching is enabled in your environment.
|
@@ -15,8 +31,23 @@ module Solder
|
|
15
31
|
end
|
16
32
|
end
|
17
33
|
|
18
|
-
|
19
|
-
|
34
|
+
initializer "solder.helpers" do
|
35
|
+
ActiveSupport.on_load(:action_controller_base) do
|
36
|
+
include Solder::ApplicationHelper
|
37
|
+
helper Solder::Engine.helpers
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def called_by_installer?
|
44
|
+
Rake.application.top_level_tasks.include? "app:template"
|
45
|
+
rescue
|
46
|
+
false
|
47
|
+
end
|
48
|
+
|
49
|
+
def called_by_generator?
|
50
|
+
ARGV.any? { _1.include? "solder:" }
|
20
51
|
end
|
21
52
|
end
|
22
53
|
end
|
data/lib/solder/engine.rb~
CHANGED
@@ -1,15 +1,31 @@
|
|
1
1
|
module Solder
|
2
|
+
def self.config
|
3
|
+
Rails.application.config.solder
|
4
|
+
end
|
5
|
+
|
2
6
|
class Engine < ::Rails::Engine
|
3
7
|
isolate_namespace Solder
|
4
8
|
|
5
|
-
|
6
|
-
|
9
|
+
config.solder = ActiveSupport::OrderedOptions.new
|
10
|
+
config.solder[:around_action] = ->(_controller, action) { action.call }
|
11
|
+
|
12
|
+
initializer "solder.check_caching" do |app|
|
13
|
+
unless app.config.action_controller.perform_caching && app.config.cache_store != :null_store
|
7
14
|
puts <<~WARN
|
8
|
-
|
15
|
+
🧑🏭 Solder uses the Rails cache store to provide UI state persistence. Therefore, please make sure caching is enabled in your environment.
|
9
16
|
|
10
17
|
To enable caching in development, run:
|
11
18
|
rails dev:cache
|
12
19
|
WARN
|
20
|
+
|
21
|
+
exit false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
initializer "solder.helpers" do
|
26
|
+
ActiveSupport.on_load(:action_controller_base) do
|
27
|
+
include Solder::ApplicationHelper
|
28
|
+
helper Solder::Engine.helpers
|
13
29
|
end
|
14
30
|
end
|
15
31
|
end
|
data/lib/solder/version.rb
CHANGED
data/lib/tasks/solder_tasks.rake
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
#
|
1
|
+
namespace :solder do
|
2
|
+
desc "Install Solder into the app"
|
3
|
+
task :install do
|
4
|
+
system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../install/install.rb", __dir__)}"
|
5
|
+
end
|
6
|
+
end
|
metadata
CHANGED
@@ -1,57 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julian Rubisch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: nokogiri
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rails
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 7.0.4
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 7.0.4
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: mocha
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
48
|
-
type: :
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: solargraph-rails
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -107,19 +107,31 @@ files:
|
|
107
107
|
- app/assets/stylesheets/solder/application.css
|
108
108
|
- app/controllers/solder/application_controller.rb
|
109
109
|
- app/controllers/solder/ui_state_controller.rb
|
110
|
-
- app/controllers/solder/ui_state_controller.rb~
|
111
110
|
- app/helpers/solder/application_helper.rb
|
112
|
-
- app/helpers/solder/application_helper.rb~
|
113
111
|
- app/jobs/solder/application_job.rb
|
114
112
|
- app/mailers/solder/application_mailer.rb
|
115
113
|
- app/models/solder/application_record.rb
|
116
114
|
- app/views/layouts/solder/application.html.erb
|
117
115
|
- config/routes.rb
|
118
|
-
-
|
116
|
+
- lib/generators/solder/initializer/USAGE
|
117
|
+
- lib/generators/solder/initializer/USAGE~
|
118
|
+
- lib/generators/solder/initializer/initializer_generator.rb
|
119
|
+
- lib/generators/solder/initializer/initializer_generator.rb~
|
120
|
+
- lib/generators/solder/initializer/templates/solder.rb
|
121
|
+
- lib/generators/solder/initializer/templates/solder.rb~
|
122
|
+
- lib/generators/solder/stimulus/USAGE
|
123
|
+
- lib/generators/solder/stimulus/USAGE~
|
124
|
+
- lib/generators/solder/stimulus/stimulus_generator.rb
|
125
|
+
- lib/generators/solder/stimulus/stimulus_generator.rb~
|
126
|
+
- lib/generators/solder/stimulus/templates/solder_controller.js.tt
|
127
|
+
- lib/install/install.rb
|
128
|
+
- lib/install/install.rb~
|
129
|
+
- lib/install/templates/solder_controller.js.tt
|
119
130
|
- lib/solder.rb
|
120
131
|
- lib/solder/engine.rb
|
121
132
|
- lib/solder/engine.rb~
|
122
133
|
- lib/solder/version.rb
|
134
|
+
- lib/solder/version.rb~
|
123
135
|
- lib/tasks/solder_tasks.rake
|
124
136
|
homepage: https://github.com/julianrubisch/solder
|
125
137
|
licenses: []
|
@@ -141,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
153
|
- !ruby/object:Gem::Version
|
142
154
|
version: '0'
|
143
155
|
requirements: []
|
144
|
-
rubygems_version: 3.3.
|
156
|
+
rubygems_version: 3.3.22
|
145
157
|
signing_key:
|
146
158
|
specification_version: 4
|
147
159
|
summary: Simplistic UI State Management for Rails Apps using Hotwire and Caching
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module Solder
|
2
|
-
class UiStateController < ApplicationController
|
3
|
-
before_action :set_ui_state
|
4
|
-
|
5
|
-
def show
|
6
|
-
render json: @ui_state.value
|
7
|
-
end
|
8
|
-
|
9
|
-
def update
|
10
|
-
@ui_state.value = JSON.parse(params[:attributes])
|
11
|
-
|
12
|
-
head :ok
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def ui_state_params
|
18
|
-
params.permit(:attributes, :key)
|
19
|
-
end
|
20
|
-
|
21
|
-
def set_ui_state
|
22
|
-
@ui_state = Kredis.json params[:key]
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module Solder
|
2
|
-
module ApplicationHelper
|
3
|
-
def solder_key(name)
|
4
|
-
key = cache_fragment_name(name, skip_digest: true)
|
5
|
-
.flatten
|
6
|
-
.compact
|
7
|
-
.map(&:cache_key)
|
8
|
-
.join(":")
|
9
|
-
key += ":#{caller(1..1).first}"
|
10
|
-
|
11
|
-
ActiveSupport::Digest.hexdigest(key)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
data/config/routes.rb~
DELETED