card-mod-format 0.11.0 → 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/card/path.rb +8 -30
- data/lib/card/path/cast_params.rb +36 -0
- data/set/all/demo.rb +36 -0
- data/set/all/error.rb +6 -13
- data/set/all/rich_html.rb +12 -0
- data/set/type/cardtype.rb +89 -0
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0ec4687a3f1ddc276d8f326e2bb80d2d30138d36c4032cb9e1caf1fa8e92f53
|
4
|
+
data.tar.gz: b21dc49fe93590a7eb083d141f0b92d4e4ffebcbf69175fc10b32a5e36407e01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acc027016400a2ac9f6bfe6e64b14bba11e24fb0779e71215c4bef1685bf21b617c89d8dc7e7879644cf34442a7664f0399779629addd1ac3622d2a6d1c37e79
|
7
|
+
data.tar.gz: 18ecf41a28035e9630d0ec5a3a8f1a7570fa279e4af94e29bf8f11316e04b78b19dbd89a649b25e280bdeb12268b324e4a024f5d3b764b1c37d7b340104fc094
|
data/lib/card/path.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
class Card
|
2
2
|
# Generate standard card paths.
|
3
3
|
class Path
|
4
|
-
|
5
|
-
self.cast_params = { slot: { hide: :array, show: :array, wrap: :array } }.freeze
|
4
|
+
include CastParams
|
6
5
|
|
7
6
|
def initialize card, opts
|
8
7
|
@card = card
|
@@ -60,7 +59,7 @@ class Card
|
|
60
59
|
name = handle_unknown do
|
61
60
|
opts[:mark] ? Card::Name[opts.delete(:mark)] : @card.name
|
62
61
|
end
|
63
|
-
name.
|
62
|
+
(name&.url_key).to_s
|
64
63
|
end
|
65
64
|
|
66
65
|
def markless?
|
@@ -81,40 +80,19 @@ class Card
|
|
81
80
|
query_opts.empty? ? "" : "?#{query_opts.to_param}"
|
82
81
|
end
|
83
82
|
|
84
|
-
# normalizes certain path opts to specified data types
|
85
|
-
def cast_path_hash hash, cast_hash=nil
|
86
|
-
return hash unless hash.is_a? Hash
|
87
|
-
cast_each_path_hash hash, (cast_hash || self.class.cast_params)
|
88
|
-
hash
|
89
|
-
end
|
90
|
-
|
91
|
-
def cast_each_path_hash hash, cast_hash
|
92
|
-
hash.each do |key, value|
|
93
|
-
next unless (cast_to = cast_hash[key])
|
94
|
-
hash[key] = cast_path_value value, cast_to
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def cast_path_value value, cast_to
|
99
|
-
if cast_to.is_a? Hash
|
100
|
-
cast_path_hash value, cast_to
|
101
|
-
else
|
102
|
-
send "cast_path_value_as_#{cast_to}", value
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
def cast_path_value_as_array value
|
107
|
-
Array.wrap value
|
108
|
-
end
|
109
|
-
|
110
83
|
def handle_unknown
|
111
84
|
yield.tap do |name|
|
112
|
-
return name if
|
85
|
+
return name if name.nil? || known_name?(name)
|
86
|
+
|
113
87
|
opts[:card] ||= {}
|
114
88
|
opts[:card][:name] = name
|
115
89
|
end
|
116
90
|
end
|
117
91
|
|
92
|
+
def known_name? name
|
93
|
+
name_specified? || name_standardish?(name) || Card.known?(name)
|
94
|
+
end
|
95
|
+
|
118
96
|
def name_specified?
|
119
97
|
opts.dig :card, :name
|
120
98
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class Card
|
2
|
+
class Path
|
3
|
+
cattr_accessor :cast_params
|
4
|
+
self.cast_params = { slot: { hide: :array, show: :array, wrap: :array } }.freeze
|
5
|
+
|
6
|
+
# normalizes certain path opts to specified data types
|
7
|
+
module CastParams
|
8
|
+
private
|
9
|
+
|
10
|
+
def cast_path_hash hash, cast_hash=nil
|
11
|
+
return hash unless hash.is_a? Hash
|
12
|
+
cast_each_path_hash hash, (cast_hash || self.class.cast_params)
|
13
|
+
hash
|
14
|
+
end
|
15
|
+
|
16
|
+
def cast_each_path_hash hash, cast_hash
|
17
|
+
hash.each do |key, value|
|
18
|
+
next unless (cast_to = cast_hash[key])
|
19
|
+
hash[key] = cast_path_value value, cast_to
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def cast_path_value value, cast_to
|
24
|
+
if cast_to.is_a? Hash
|
25
|
+
cast_path_hash value, cast_to
|
26
|
+
else
|
27
|
+
send "cast_path_value_as_#{cast_to}", value
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def cast_path_value_as_array value
|
32
|
+
Array.wrap value
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/set/all/demo.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
format :html do
|
2
|
+
view :demo do
|
3
|
+
frame do
|
4
|
+
[view_select, wrap_with(:div, view_demo, class: "demo-slot")]
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
view :view_list do
|
9
|
+
%i[bar box info_bar open closed titled labeled content content_panel].map do |v|
|
10
|
+
wrap_with :p, [content_tag(:h3, v), render(v, show: :menu)]
|
11
|
+
end.flatten.join ""
|
12
|
+
end
|
13
|
+
|
14
|
+
def demo_view
|
15
|
+
Env.params[:demo_view] || :core
|
16
|
+
end
|
17
|
+
|
18
|
+
def view_demo
|
19
|
+
wrap(true) do
|
20
|
+
render demo_view
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def view_select
|
25
|
+
card_form :get, success: { view: :demo } do
|
26
|
+
select_tag :demo_view,
|
27
|
+
options_for_select(all_views, demo_view),
|
28
|
+
class: "_submit-on-select"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def all_views
|
33
|
+
Card::Set::Format::AbstractFormat::ViewDefinition
|
34
|
+
.views.slice(*self.class.ancestors).values.map(&:keys).flatten.uniq
|
35
|
+
end
|
36
|
+
end
|
data/set/all/error.rb
CHANGED
@@ -56,24 +56,17 @@ end
|
|
56
56
|
|
57
57
|
format :json do
|
58
58
|
view :errors do
|
59
|
-
|
59
|
+
{
|
60
|
+
error_status: error_status,
|
61
|
+
errors: card.errors.each_with_object({}) { |e, h| h[e.attribute] = e.message }
|
62
|
+
}
|
60
63
|
end
|
61
64
|
|
62
65
|
view :server_error, :errors
|
63
66
|
view :denial, :errors
|
64
67
|
view :not_found, :errors
|
65
|
-
|
66
68
|
view :bad_address do
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
def format_error error
|
71
|
-
{ error_status: error_status, errors: error }
|
72
|
-
end
|
73
|
-
|
74
|
-
def error_list
|
75
|
-
card.errors.each_with_object([]) do |(field, message), list|
|
76
|
-
list << { field: field, message: message }
|
77
|
-
end
|
69
|
+
card.errors.add :address, super()
|
70
|
+
render_error
|
78
71
|
end
|
79
72
|
end
|
data/set/all/rich_html.rb
CHANGED
@@ -1,4 +1,16 @@
|
|
1
1
|
format :html do
|
2
2
|
delegate :class_up, :class_down, :with_class_up, :without_upped_class, :classy,
|
3
3
|
to: :voo
|
4
|
+
|
5
|
+
view :type, unknown: true do
|
6
|
+
link_to_card card.type_card, nil, class: "cardtype"
|
7
|
+
end
|
8
|
+
|
9
|
+
view :type_info do
|
10
|
+
return unless card.type_code != :basic
|
11
|
+
|
12
|
+
wrap_with :span, class: "type-info float-right" do
|
13
|
+
link_to_card card.type_name, nil, class: "navbar-link"
|
14
|
+
end
|
15
|
+
end
|
4
16
|
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
format :html do
|
2
|
+
view :type, unknown: true do
|
3
|
+
link_to_card card.type_card, nil, class: "cardtype"
|
4
|
+
end
|
5
|
+
|
6
|
+
def type_formgroup args={}
|
7
|
+
if card.cards_of_type_exist?
|
8
|
+
wrap_with :div, tr(:cards_exist, cardname: safe_name)
|
9
|
+
else
|
10
|
+
super
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
view :add_link do
|
15
|
+
add_link
|
16
|
+
end
|
17
|
+
|
18
|
+
view :add_button do
|
19
|
+
add_link class: "btn btn-secondary"
|
20
|
+
end
|
21
|
+
|
22
|
+
def add_link opts={}
|
23
|
+
voo.title ||= tr(:add_card, cardname: safe_name)
|
24
|
+
link_to render_title, add_link_opts(opts)
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_link_opts opts
|
28
|
+
modal = opts.delete :modal
|
29
|
+
if modal.nil? || modal
|
30
|
+
modal_link_opts opts.merge(path: add_path(:new_in_modal))
|
31
|
+
else
|
32
|
+
opts.merge path: add_path(:new)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
view :add_url do
|
37
|
+
card_url _render_add_path
|
38
|
+
end
|
39
|
+
|
40
|
+
def add_path view
|
41
|
+
path_args = { mark: card.name }
|
42
|
+
process_voo_params(path_args) if voo.params
|
43
|
+
if view == :new
|
44
|
+
path_args[:action] = :new
|
45
|
+
else
|
46
|
+
path_args[:action] = :type
|
47
|
+
path_args[:view] = view
|
48
|
+
end
|
49
|
+
path path_args
|
50
|
+
end
|
51
|
+
|
52
|
+
# don't cache because it depends on update permission for another card
|
53
|
+
view :configure_link, cache: :never, perms: ->(fmt) { fmt.can_configure? } do
|
54
|
+
configure_link
|
55
|
+
end
|
56
|
+
|
57
|
+
def can_configure?
|
58
|
+
Card.fetch(card, :type, :structure, new: {}).ok? :update
|
59
|
+
end
|
60
|
+
|
61
|
+
view :configure_button, cache: :never,
|
62
|
+
denial: :blank,
|
63
|
+
perms: ->(fmt) { fmt.can_configure? } do
|
64
|
+
configure_link "btn btn-secondary"
|
65
|
+
end
|
66
|
+
|
67
|
+
def configure_link css_class=nil
|
68
|
+
return "" unless Card.fetch(card, :type, :structure, new: {}).ok? :update
|
69
|
+
|
70
|
+
voo.title ||= tr(:configure_card, cardname: safe_name.pluralize)
|
71
|
+
title = _render_title
|
72
|
+
link_to_card card, title,
|
73
|
+
path: { view: :bridge,
|
74
|
+
bridge: { tab: :rules_tab },
|
75
|
+
set: Card::Name[safe_name, :type] },
|
76
|
+
class: css_classes("configure-type-link ml-3", css_class)
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def process_voo_params path_args
|
82
|
+
context = ((@parent&.card) || card).name
|
83
|
+
Rack::Utils.parse_nested_query(voo.params).each do |key, value|
|
84
|
+
value = value.to_name.absolute(context) if value
|
85
|
+
key = key.to_name.absolute(context)
|
86
|
+
path_args[key] = value
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: card-mod-format
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.1
|
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:
|
13
|
+
date: 2021-03-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: card
|
@@ -18,28 +18,28 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - '='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 1.101.
|
21
|
+
version: 1.101.1
|
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.1
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: card-mod-content
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
33
|
- - '='
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: 0.11.
|
35
|
+
version: 0.11.1
|
36
36
|
type: :runtime
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
40
|
- - '='
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: 0.11.
|
42
|
+
version: 0.11.1
|
43
43
|
description: ''
|
44
44
|
email:
|
45
45
|
- info@decko.org
|
@@ -58,10 +58,12 @@ files:
|
|
58
58
|
- lib/card/format/text_format.rb
|
59
59
|
- lib/card/format/xml_format.rb
|
60
60
|
- lib/card/path.rb
|
61
|
+
- lib/card/path/cast_params.rb
|
61
62
|
- set/all/active_card.rb
|
62
63
|
- set/all/base.rb
|
63
64
|
- set/all/css.rb
|
64
65
|
- set/all/csv.rb
|
66
|
+
- set/all/demo.rb
|
65
67
|
- set/all/error.rb
|
66
68
|
- set/all/export.rb
|
67
69
|
- set/all/file.rb
|
@@ -89,6 +91,7 @@ files:
|
|
89
91
|
- set/all/rss.rb
|
90
92
|
- set/all/text.rb
|
91
93
|
- set/self/home.rb
|
94
|
+
- set/type/cardtype.rb
|
92
95
|
- set/type/html.rb
|
93
96
|
- set/type/json.rb
|
94
97
|
- set/type/number.rb
|