card-mod-content 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/lib/card/content/chunk/link.rb +68 -59
- data/set/all/contextual_content.rb +20 -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: f2291c460c993a049e0a2f34017937f1e3277da3772b417a6b66fcea70cbfc18
|
4
|
+
data.tar.gz: c417b2ef2edba1ca4d68358a11e54774f5efd6074b19a2e75531207864083dda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 808f4ab388779bb84ddb82290aaf2aaf86c554e66d77716baf45b4da5a812aa60845ebf0f277fbd19b3db34059aaac8d935e1a845aaf3b0bb0f8c4d5e4c000c5
|
7
|
+
data.tar.gz: d22f792f974626167e3f76e6b5c24e5cf2782b7ddfd364e7b9c585cf4186a09d4e0b3b9928d08a42fa9cd79629644196caeaec0720842c9f4c7a7c5d28c52787
|
@@ -6,22 +6,75 @@ load File.expand_path("reference.rb", __dir__)
|
|
6
6
|
class Card
|
7
7
|
class Content
|
8
8
|
module Chunk
|
9
|
-
|
10
|
-
# autoload :Reference , "reference"
|
11
|
-
|
12
|
-
class Link < Card::Content::Chunk::Reference
|
9
|
+
class Link < Reference
|
13
10
|
CODE = "L".freeze # L for "Link"
|
14
11
|
attr_reader :link_text
|
15
12
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
idx_char: "["
|
13
|
+
Chunk.register_class self, prefix_re: '\\[\\[',
|
14
|
+
full_re: /\A\[\[([^\]]+)\]\]/,
|
15
|
+
idx_char: "["
|
16
|
+
|
21
17
|
def reference_code
|
22
18
|
CODE
|
23
19
|
end
|
24
20
|
|
21
|
+
def process_chunk
|
22
|
+
@process_chunk ||= render_link
|
23
|
+
end
|
24
|
+
|
25
|
+
def inspect
|
26
|
+
"<##{self.class}:e[#{@explicit_link}]n[#{@name}]l[#{@link_text}]" \
|
27
|
+
"p[#{@process_chunk}] txt:#{@text}>"
|
28
|
+
end
|
29
|
+
|
30
|
+
# view options
|
31
|
+
def options
|
32
|
+
link_text ? { title: link_text } : {}
|
33
|
+
end
|
34
|
+
|
35
|
+
def replace_reference old_name, new_name
|
36
|
+
replace_name_reference old_name, new_name
|
37
|
+
replace_link_text old_name, new_name
|
38
|
+
link_text_syntax = "|#{@link_text}" if @link_text.present?
|
39
|
+
@text = "[[#{referee_name}#{link_text_syntax}]]"
|
40
|
+
end
|
41
|
+
|
42
|
+
def explicit_link?
|
43
|
+
@explicit_link
|
44
|
+
end
|
45
|
+
|
46
|
+
def render_link view: :link, explicit_link_opts: {}
|
47
|
+
@link_text = render_obj @link_text
|
48
|
+
|
49
|
+
if @explicit_link
|
50
|
+
render_explicit_link explicit_link_opts
|
51
|
+
elsif @name
|
52
|
+
render_name_link view
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def link_target
|
57
|
+
if @explicit_link
|
58
|
+
render_obj @explicit_link
|
59
|
+
elsif @name
|
60
|
+
referee_name
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def render_explicit_link explicit_link_opts
|
67
|
+
@explicit_link = render_obj @explicit_link
|
68
|
+
format.link_to_resource @explicit_link, @link_text, explicit_link_opts
|
69
|
+
end
|
70
|
+
|
71
|
+
def render_name_link view
|
72
|
+
format.with_nest_mode :normal do
|
73
|
+
format.nest referee_name, options.merge(view: view)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# interpret a chunk matching
|
25
78
|
def interpret match, _content
|
26
79
|
target, @link_text = target_and_link_text match[1]
|
27
80
|
|
@@ -36,9 +89,9 @@ class Card
|
|
36
89
|
def target_and_link_text raw_syntax
|
37
90
|
return unless raw_syntax
|
38
91
|
|
39
|
-
if (i = divider_index raw_syntax) # [[A | B]]
|
92
|
+
if (i = divider_index raw_syntax) # if [[A | B]]
|
40
93
|
[raw_syntax[0..(i - 1)], raw_syntax[(i + 1)..-1]] # [A, B]
|
41
|
-
else # [[ A ]]
|
94
|
+
else # else must be [[ A ]]
|
42
95
|
[raw_syntax, nil] # [A, nil]
|
43
96
|
end
|
44
97
|
end
|
@@ -55,61 +108,21 @@ class Card
|
|
55
108
|
string_copy.index "|"
|
56
109
|
end
|
57
110
|
|
58
|
-
#
|
59
|
-
|
60
|
-
link_text ? { title: link_text } : {}
|
61
|
-
end
|
62
|
-
|
111
|
+
# turn a string into a Content object if it looks like it might have more
|
112
|
+
# chunks in it
|
63
113
|
def objectify raw
|
64
114
|
return unless raw
|
65
115
|
|
66
116
|
raw.strip!
|
67
117
|
if raw.match?(/(^|[^\\])\{\{/)
|
68
|
-
|
118
|
+
Content.new raw, format
|
69
119
|
else
|
70
120
|
raw
|
71
121
|
end
|
72
122
|
end
|
73
123
|
|
74
|
-
def render_link view: :link, explicit_link_opts: {}
|
75
|
-
@link_text = render_obj @link_text
|
76
|
-
|
77
|
-
if @explicit_link
|
78
|
-
@explicit_link = render_obj @explicit_link
|
79
|
-
format.link_to_resource @explicit_link, @link_text, explicit_link_opts
|
80
|
-
elsif @name
|
81
|
-
format.with_nest_mode :normal do
|
82
|
-
format.nest referee_name, options.merge(view: view)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def link_target
|
88
|
-
if @explicit_link
|
89
|
-
render_obj @explicit_link
|
90
|
-
elsif @name
|
91
|
-
referee_name
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
def process_chunk
|
96
|
-
@process_chunk ||= render_link
|
97
|
-
end
|
98
|
-
|
99
|
-
def inspect
|
100
|
-
"<##{self.class}:e[#{@explicit_link}]n[#{@name}]l[#{@link_text}]" \
|
101
|
-
"p[#{@process_chunk}] txt:#{@text}>"
|
102
|
-
end
|
103
|
-
|
104
|
-
def replace_reference old_name, new_name
|
105
|
-
replace_name_reference old_name, new_name
|
106
|
-
replace_link_text old_name, new_name
|
107
|
-
@text =
|
108
|
-
@link_text.nil? ? "[[#{referee_name}]]" : "[[#{referee_name}|#{@link_text}]]"
|
109
|
-
end
|
110
|
-
|
111
124
|
def replace_link_text old_name, new_name
|
112
|
-
if @link_text.is_a?(
|
125
|
+
if @link_text.is_a?(Content)
|
113
126
|
@link_text.find_chunks(:Reference).each do |chunk|
|
114
127
|
chunk.replace_reference old_name, new_name
|
115
128
|
end
|
@@ -117,10 +130,6 @@ class Card
|
|
117
130
|
@link_text = old_name.to_name.sub_in(@link_text, with: new_name)
|
118
131
|
end
|
119
132
|
end
|
120
|
-
|
121
|
-
def explicit_link?
|
122
|
-
@explicit_link
|
123
|
-
end
|
124
133
|
end
|
125
134
|
end
|
126
135
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
def context_card
|
2
|
+
@context_card || self
|
3
|
+
end
|
4
|
+
|
5
|
+
def with_context context_card
|
6
|
+
old_context = @context_card
|
7
|
+
@context_card = context_card if context_card
|
8
|
+
yield
|
9
|
+
ensure
|
10
|
+
@context_card = old_context
|
11
|
+
end
|
12
|
+
|
13
|
+
format do
|
14
|
+
delegate :context_card, :with_context, to: :card
|
15
|
+
|
16
|
+
def contextual_content context_card, options={}
|
17
|
+
view = options.delete(:view) || :core
|
18
|
+
with_context(context_card) { render! view, options }
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: card-mod-content
|
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
|
@@ -47,6 +47,7 @@ files:
|
|
47
47
|
- set/abstract/templated_nests.rb
|
48
48
|
- set/abstract/vendor_code_file.rb
|
49
49
|
- set/all/chunk.rb
|
50
|
+
- set/all/contextual_content.rb
|
50
51
|
- set/all/templating.rb
|
51
52
|
- set/right/default.rb
|
52
53
|
- set/right/structure.rb
|