card-mod-alias 0.11.5 → 0.11.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 +68 -0
- data/lib/card_controller/aliasing.rb +4 -0
- data/set/all/alias.rb +3 -0
- data/set/all_plus/alias.rb +2 -0
- data/set/type/alias.rb +2 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c574df8634230364ee03616fece0e9223ce632e03cf9c0c8e9a70a73d8fb065e
|
4
|
+
data.tar.gz: 7a44bba4a8219a005dd3febc4b432505809651a319dc5757f9de3161259672fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99c50131bd1fc3268a23d165f34af82cae12d3ac192c8b2ea1ec467ad8904b09663c7f0ed047f0ac1b2f5ce157e36d4b68857ca8b85756df689f2c51ed5b01db
|
7
|
+
data.tar.gz: af0cb63ee5deb619dcdd9df09b6bfed4cb78d189d66708bbbed812620536a15a8cb1761513344066f3357ca34f89d20f08ff5395b963cd4906ff90c7ed9d5f6b
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
<!--
|
2
|
+
# @title README - mod: alias
|
3
|
+
-->
|
4
|
+
|
5
|
+
# Alias Mod
|
6
|
+
Enable Alias cards, which alias one simple card name to another.
|
7
|
+
|
8
|
+
The primary use case for alias cards is for handling redirects, for example after a card
|
9
|
+
has been renamed. Suppose, for example, a card's name is changed from *Former* to
|
10
|
+
*Current*. One can create an Alias card named "Former" with the content "Current". This
|
11
|
+
not only insures that links to /Former will be redirected to /Current, but it also
|
12
|
+
handles all descendants, redirecting /Former+field to /Current+field and /My+Former+Life
|
13
|
+
to /My+Current+Life.
|
14
|
+
|
15
|
+
Alias cards themselves must be simple cards and are not allowed to have children.
|
16
|
+
|
17
|
+
If a request to an alias specifies a view, eg `/Former?view=edit`, then the request
|
18
|
+
will not be redirected and will instead return the view of the Alias card itself.
|
19
|
+
Similarly, transactional requests (create, update, and delete) to the alias card
|
20
|
+
will take effect on the alias, not the target.
|
21
|
+
|
22
|
+
## Cards with codenames
|
23
|
+
|
24
|
+
| codename | default name | purpose |
|
25
|
+
|:--------:|:------------:|:-------:|
|
26
|
+
| :alias | Alias | Cardtype of aliases |
|
27
|
+
|
28
|
+
## Sets with code rules
|
29
|
+
|
30
|
+
### {Card::Set::Type::Alias type: Alias}
|
31
|
+
An alias card's name is the alias's *source*, and its content is its target. So, in the
|
32
|
+
example above, the Alias card would be named *Former* and its content would be *Current*.
|
33
|
+
|
34
|
+
Content is stored as a card id.
|
35
|
+
|
36
|
+
#### Events
|
37
|
+
|
38
|
+
| event name | when | purpose |
|
39
|
+
|:---------:|:------:|:-------:|
|
40
|
+
| validate_alias_source | on save | ensures name is simple and card has no children |
|
41
|
+
| validate_alias_target | on save | ensures target is existing simple card |
|
42
|
+
|
43
|
+
### {Card::Set::All::Alias All}
|
44
|
+
|
45
|
+
#### Events
|
46
|
+
|
47
|
+
| event name | when | purpose |
|
48
|
+
|:---------:|:------:|:-------:|
|
49
|
+
| create_alias_upon_rename | triggered | creates an alias from old name to new one |
|
50
|
+
|
51
|
+
|
52
|
+
#### HtmlFormat
|
53
|
+
Extends `#edit_name_buttons` so that when renaming, user is presented with a checkbox
|
54
|
+
to trigger the creation of an alias
|
55
|
+
|
56
|
+
### {Card::Set::AllPlus::Alias All Plus}
|
57
|
+
Handle aliasing of compound names when at least one name part is an alias.
|
58
|
+
|
59
|
+
#### Events
|
60
|
+
|
61
|
+
| event name | when | purpose |
|
62
|
+
|:---------:|:------:|:-------:|
|
63
|
+
| validate_not_alias | on save | prevents creation of deescendents of aliases |
|
64
|
+
|
65
|
+
## {CardController::Aliasing}
|
66
|
+
Module that enables card controller to handle alias-driven redirects and ensure that
|
67
|
+
transaction requests act upon the correct card (the alias when simple, the target when
|
68
|
+
compound).
|
@@ -7,6 +7,8 @@ class CardController
|
|
7
7
|
hard_redirect target_url
|
8
8
|
end
|
9
9
|
|
10
|
+
# create, read, and update requests take effect on the target card
|
11
|
+
# when aliases are compound (but on the alias card itself when simple).
|
10
12
|
%i[create update delete].each do |action|
|
11
13
|
define_method action do
|
12
14
|
@card = card.target_card if card&.compound? && card&.alias?
|
@@ -16,12 +18,14 @@ class CardController
|
|
16
18
|
|
17
19
|
private
|
18
20
|
|
21
|
+
# url to which aliased requests should be redirected
|
19
22
|
def target_url
|
20
23
|
target_params = params.clone.merge(mark: card.target_name).to_unsafe_h
|
21
24
|
target_params.delete :controller
|
22
25
|
card.target_card.format(:base).path target_params
|
23
26
|
end
|
24
27
|
|
28
|
+
# aliased names are not redirected when a view is specified for a simple alias card
|
25
29
|
def redirect_to_aliased?
|
26
30
|
return false unless card&.alias?
|
27
31
|
|
data/set/all/alias.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
|
+
# triggerable event to auto-add an alias upon renaming a card
|
1
2
|
event :create_alias_upon_rename, :finalize,
|
2
3
|
on: :update, changed: :name, trigger: :required do
|
3
4
|
add_subcard name_before_act, type_code: :alias, content: name
|
4
5
|
end
|
5
6
|
|
7
|
+
# actual aliases override this in narrower sets.
|
6
8
|
def alias?
|
7
9
|
false
|
8
10
|
end
|
9
11
|
|
10
12
|
format :html do
|
13
|
+
# adds checkbox to rename form
|
11
14
|
def edit_name_buttons
|
12
15
|
output [auto_alias_checkbox, super].compact
|
13
16
|
end
|
data/set/all_plus/alias.rb
CHANGED
@@ -2,10 +2,12 @@ event :validate_not_alias, :validate, on: :save do
|
|
2
2
|
errors.add t(:alias_cards_no_children) if alias? && type_code != :alias
|
3
3
|
end
|
4
4
|
|
5
|
+
# a compound name is an alias if any part is an alias
|
5
6
|
def alias?
|
6
7
|
name.parts.any? { |p| Card[p]&.alias? }
|
7
8
|
end
|
8
9
|
|
10
|
+
# reconstructs the name to which a compound name is aliased
|
9
11
|
def target_name
|
10
12
|
Card::Name[
|
11
13
|
name.parts.map do |p|
|
data/set/type/alias.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: card-mod-alias
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ethan McCutchen
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2021-05-
|
13
|
+
date: 2021-05-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: card
|
@@ -18,14 +18,14 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - '='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 1.101.
|
21
|
+
version: 1.101.6
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - '='
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: 1.101.
|
28
|
+
version: 1.101.6
|
29
29
|
description: ''
|
30
30
|
email:
|
31
31
|
- info@decko.org
|
@@ -33,6 +33,7 @@ executables: []
|
|
33
33
|
extensions: []
|
34
34
|
extra_rdoc_files: []
|
35
35
|
files:
|
36
|
+
- README.md
|
36
37
|
- config/initializers/init_aliasing.rb
|
37
38
|
- db/migrate_cards/20210504195646_add_alias_type.rb
|
38
39
|
- lib/card_controller/aliasing.rb
|