card-mod-content 0.11.2 → 0.12.0
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/escaped_literal.rb +2 -2
- data/lib/card/content/chunk/keep_escaped_literal.rb +2 -2
- data/lib/card/content/chunk/link.rb +74 -62
- data/lib/card/content/chunk/nest.rb +8 -5
- data/lib/card/content/chunk/reference.rb +11 -22
- data/lib/card/content/chunk/uri.rb +119 -114
- data/lib/card/content/chunk/view_stub.rb +0 -4
- data/set/abstract/code_file.rb +0 -1
- data/set/abstract/haml_file.rb +0 -1
- data/set/abstract/lock.rb +1 -0
- data/set/all/chunk.rb +11 -9
- data/set/all/contextual_content.rb +20 -0
- data/set/all/templating.rb +1 -1
- data/set/right/structure.rb +5 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c70d983eed31e1e69a646f97bfd617e414f4fc58f4e12b2e78779f4518911869
|
4
|
+
data.tar.gz: 66fe32d82cd73cb8fbae02ef8e2bf568dad409d79f7430eddbce3d9be9836871
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58e6df74fa73efe4804c8a178da5aa1aca3e53d426b858d1a234510956061d93e3f6eee5194ba8c355006bcc8583447d70ab258d0c354443aa480acc61f4e168
|
7
|
+
data.tar.gz: f912d472dcc0a6e6721f89045c94516510e1ceb47ffa65aacc74a25eb70b1bbef447f9999f19ac91d39cedfdc7044d29e0664c51ff3fca9d3026c178e2d3c96b
|
@@ -9,10 +9,10 @@ class Card
|
|
9
9
|
# and within HTML tags.
|
10
10
|
class EscapedLiteral < Abstract
|
11
11
|
FULL_RE = { "[" => /\A\\\[\[[^\]]*\]\]/,
|
12
|
-
"{" => /\A\\\{\{[
|
12
|
+
"{" => /\A\\\{\{[^}]*\}\}/ }.freeze
|
13
13
|
Card::Content::Chunk.register_class self,
|
14
14
|
prefix_re: '\\\\(?:\\[\\[|\\{\\{)',
|
15
|
-
idx_char:
|
15
|
+
idx_char: "\\"
|
16
16
|
|
17
17
|
def self.full_re prefix
|
18
18
|
FULL_RE[prefix[1, 1]]
|
@@ -8,10 +8,10 @@ class Card
|
|
8
8
|
# the escaping survives the markdown rendering.
|
9
9
|
class KeepEscapedLiteral < Abstract
|
10
10
|
FULL_RE = { "[" => /\A\\\[\[[^\]]*\]\]/,
|
11
|
-
"{" => /\A\\\{\{[
|
11
|
+
"{" => /\A\\\{\{[^}]*\}\}/ }.freeze
|
12
12
|
Card::Content::Chunk.register_class self,
|
13
13
|
prefix_re: '\\\\(?:\\[\\[|\\{\\{)',
|
14
|
-
idx_char:
|
14
|
+
idx_char: "\\"
|
15
15
|
|
16
16
|
def self.full_re prefix
|
17
17
|
FULL_RE[prefix[1, 1]]
|
@@ -1,26 +1,80 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
|
3
3
|
# require File.expand_path("../reference", __FILE__)
|
4
|
-
load File.expand_path("
|
4
|
+
load File.expand_path("reference.rb", __dir__)
|
5
5
|
|
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
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
|
13
|
+
Chunk.register_class self, prefix_re: '\\[\\[',
|
14
|
+
full_re: /\A\[\[([^\]]+)\]\]/,
|
15
|
+
idx_char: "["
|
16
|
+
|
20
17
|
def reference_code
|
21
18
|
CODE
|
22
19
|
end
|
23
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
|
24
78
|
def interpret match, _content
|
25
79
|
target, @link_text = target_and_link_text match[1]
|
26
80
|
|
@@ -35,9 +89,9 @@ class Card
|
|
35
89
|
def target_and_link_text raw_syntax
|
36
90
|
return unless raw_syntax
|
37
91
|
|
38
|
-
if (i = divider_index raw_syntax) # [[A | B]]
|
92
|
+
if (i = divider_index raw_syntax) # if [[A | B]]
|
39
93
|
[raw_syntax[0..(i - 1)], raw_syntax[(i + 1)..-1]] # [A, B]
|
40
|
-
else # [[ A ]]
|
94
|
+
else # else must be [[ A ]]
|
41
95
|
[raw_syntax, nil] # [A, nil]
|
42
96
|
end
|
43
97
|
end
|
@@ -46,78 +100,36 @@ class Card
|
|
46
100
|
# there's probably a better way to do the following.
|
47
101
|
# point is to find the first pipe that's not inside an nest
|
48
102
|
return unless string.index "|"
|
103
|
+
|
49
104
|
string_copy = string.dup
|
50
|
-
string.scan(/\{\{[
|
105
|
+
string.scan(/\{\{[^}]*\}\}/) do |incl|
|
51
106
|
string_copy.gsub! incl, ("x" * incl.length)
|
52
107
|
end
|
53
108
|
string_copy.index "|"
|
54
109
|
end
|
55
110
|
|
56
|
-
#
|
57
|
-
|
58
|
-
link_text ? { title: link_text } : {}
|
59
|
-
end
|
60
|
-
|
111
|
+
# turn a string into a Content object if it looks like it might have more
|
112
|
+
# chunks in it
|
61
113
|
def objectify raw
|
62
114
|
return unless raw
|
115
|
+
|
63
116
|
raw.strip!
|
64
117
|
if raw.match?(/(^|[^\\])\{\{/)
|
65
|
-
|
118
|
+
Content.new raw, format
|
66
119
|
else
|
67
120
|
raw
|
68
121
|
end
|
69
122
|
end
|
70
123
|
|
71
|
-
def render_link view: :link, explicit_link_opts: {}
|
72
|
-
@link_text = render_obj @link_text
|
73
|
-
|
74
|
-
if @explicit_link
|
75
|
-
@explicit_link = render_obj @explicit_link
|
76
|
-
format.link_to_resource @explicit_link, @link_text, explicit_link_opts
|
77
|
-
elsif @name
|
78
|
-
format.with_nest_mode :normal do
|
79
|
-
format.nest referee_name, options.merge(view: view)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def link_target
|
85
|
-
if @explicit_link
|
86
|
-
render_obj @explicit_link
|
87
|
-
elsif @name
|
88
|
-
referee_name
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def process_chunk
|
93
|
-
@process_chunk ||= render_link
|
94
|
-
end
|
95
|
-
|
96
|
-
def inspect
|
97
|
-
"<##{self.class}:e[#{@explicit_link}]n[#{@name}]l[#{@link_text}]" \
|
98
|
-
"p[#{@process_chunk}] txt:#{@text}>"
|
99
|
-
end
|
100
|
-
|
101
|
-
def replace_reference old_name, new_name
|
102
|
-
replace_name_reference old_name, new_name
|
103
|
-
replace_link_text old_name, new_name
|
104
|
-
@text =
|
105
|
-
@link_text.nil? ? "[[#{referee_name}]]" : "[[#{referee_name}|#{@link_text}]]"
|
106
|
-
end
|
107
|
-
|
108
124
|
def replace_link_text old_name, new_name
|
109
|
-
if @link_text.is_a?(
|
110
|
-
@link_text.find_chunks(
|
125
|
+
if @link_text.is_a?(Content)
|
126
|
+
@link_text.find_chunks(:Reference).each do |chunk|
|
111
127
|
chunk.replace_reference old_name, new_name
|
112
128
|
end
|
113
129
|
elsif @link_text.present?
|
114
130
|
@link_text = old_name.to_name.sub_in(@link_text, with: new_name)
|
115
131
|
end
|
116
132
|
end
|
117
|
-
|
118
|
-
def explicit_link?
|
119
|
-
@explicit_link
|
120
|
-
end
|
121
133
|
end
|
122
134
|
end
|
123
135
|
end
|
@@ -8,11 +8,12 @@ class Card
|
|
8
8
|
# Handler for nest chunks: {{example}}
|
9
9
|
class Nest < Reference
|
10
10
|
attr_reader :options
|
11
|
+
|
11
12
|
DEFAULT_OPTION = :view # a value without a key is interpreted as view
|
12
13
|
|
13
14
|
Chunk.register_class(self, prefix_re: '\\{\\{',
|
14
|
-
full_re:
|
15
|
-
idx_char:
|
15
|
+
full_re: /\A\{\{([^{}]*)\}\}/,
|
16
|
+
idx_char: "{")
|
16
17
|
|
17
18
|
def interpret match, _content
|
18
19
|
in_brackets = strip_tags match[1]
|
@@ -27,9 +28,9 @@ class Card
|
|
27
28
|
end
|
28
29
|
|
29
30
|
def strip_tags string
|
30
|
-
#
|
31
|
+
# NOTE: not using ActionView's strip_tags here
|
31
32
|
# because this needs to be super fast.
|
32
|
-
string.gsub(
|
33
|
+
string.gsub(/<[^>]*>/, "")
|
33
34
|
end
|
34
35
|
|
35
36
|
def visible_comment message
|
@@ -83,6 +84,7 @@ class Card
|
|
83
84
|
|
84
85
|
def explicit_view= view
|
85
86
|
return if @options[:view]
|
87
|
+
|
86
88
|
# could check to make sure it's not already the default...
|
87
89
|
if @text.match?(/\|/)
|
88
90
|
@text.sub! "|", "|#{view};"
|
@@ -100,7 +102,7 @@ class Card
|
|
100
102
|
end
|
101
103
|
|
102
104
|
def self.gsub string
|
103
|
-
string.gsub(/\{\{([
|
105
|
+
string.gsub(/\{\{([^}]*)\}\}/) do |_match|
|
104
106
|
yield(Regexp.last_match[1])
|
105
107
|
end
|
106
108
|
end
|
@@ -113,6 +115,7 @@ class Card
|
|
113
115
|
|
114
116
|
def each_option attr_string
|
115
117
|
return if attr_string.blank?
|
118
|
+
|
116
119
|
attr_string.strip.split(";").each do |pair|
|
117
120
|
# key is optional for view option
|
118
121
|
value, key = pair.split(":", 2).reverse
|
@@ -9,26 +9,28 @@ class Card
|
|
9
9
|
|
10
10
|
def referee_name
|
11
11
|
return if name.nil?
|
12
|
-
|
13
|
-
@referee_name
|
12
|
+
|
13
|
+
@referee_name ||= referee_raw_name
|
14
|
+
@referee_name = @referee_name.absolute_name card.name
|
14
15
|
rescue Card::Error::NotFound
|
15
16
|
# do not break on missing id/codename references.
|
16
17
|
end
|
17
18
|
|
18
|
-
def
|
19
|
-
|
20
|
-
ref_card ? ref_card.name : rendered_name.to_name
|
19
|
+
def referee_raw_name
|
20
|
+
Name[render_obj(name)]
|
21
21
|
end
|
22
22
|
|
23
23
|
def referee_card
|
24
24
|
@referee_card ||= referee_name && Card.fetch(referee_name)
|
25
25
|
end
|
26
26
|
|
27
|
+
private
|
28
|
+
|
27
29
|
def replace_name_reference old_name, new_name
|
28
30
|
@referee_card = nil
|
29
31
|
@referee_name = nil
|
30
|
-
if name.is_a?
|
31
|
-
name.find_chunks(
|
32
|
+
if name.is_a? Content
|
33
|
+
name.find_chunks(:Reference).each do |chunk|
|
32
34
|
chunk.replace_reference old_name, new_name
|
33
35
|
end
|
34
36
|
else
|
@@ -37,22 +39,9 @@ class Card
|
|
37
39
|
end
|
38
40
|
|
39
41
|
def render_obj raw
|
40
|
-
|
41
|
-
format.process_content raw
|
42
|
-
else
|
43
|
-
raw
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
42
|
+
return raw unless format && raw.is_a?(Content)
|
48
43
|
|
49
|
-
|
50
|
-
case rendered_name # FIXME: this should be standard fetch option.
|
51
|
-
when /^\~(\d+)$/ # get by id
|
52
|
-
Card.fetch Regexp.last_match(1).to_i
|
53
|
-
when /^\:(\w+)$/ # get by codename
|
54
|
-
Card.fetch Regexp.last_match(1).to_sym
|
55
|
-
end
|
44
|
+
format.process_content raw
|
56
45
|
end
|
57
46
|
end
|
58
47
|
end
|
@@ -19,127 +19,132 @@ require "uri"
|
|
19
19
|
# suffixes.
|
20
20
|
# The generic names are from www.bnoack.com/data/countrycode2.html)
|
21
21
|
# [iso3166]: http://geotags.com/iso3166/
|
22
|
-
|
23
|
-
class
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
last_char = chunk[-1, 1]
|
58
|
-
chunk.gsub!(/(?: )+/, "")
|
22
|
+
class Card
|
23
|
+
class Content
|
24
|
+
module Chunk
|
25
|
+
class Uri < Abstract
|
26
|
+
SCHEMES = %w[irc http https ftp ssh git sftp file ldap ldaps mailto].freeze
|
27
|
+
|
28
|
+
REJECTED_PREFIX_RE = %w{! ": " ' ](}.map { |s| Regexp.escape s } * "|"
|
29
|
+
|
30
|
+
attr_reader :uri, :link_text
|
31
|
+
|
32
|
+
delegate :to, :scheme, :host, :port, :path, :query, :fragment, to: :uri
|
33
|
+
|
34
|
+
Card::Content::Chunk.register_class(
|
35
|
+
self, prefix_re: "(?:(?!#{REJECTED_PREFIX_RE})(?:#{SCHEMES * '|'})\\:)",
|
36
|
+
full_re: /\A#{::URI::DEFAULT_PARSER.make_regexp(SCHEMES)}/,
|
37
|
+
idx_char: ":"
|
38
|
+
)
|
39
|
+
|
40
|
+
class << self
|
41
|
+
def full_match content, prefix
|
42
|
+
prepend_str = if prefix[-1, 1] != ":" && config[:prepend_str]
|
43
|
+
config[:prepend_str]
|
44
|
+
else
|
45
|
+
""
|
46
|
+
end
|
47
|
+
content = prepend_str + content
|
48
|
+
match = super content, prefix
|
49
|
+
[match, prepend_str.length]
|
50
|
+
end
|
51
|
+
|
52
|
+
def context_ok? content, chunk_start
|
53
|
+
preceding_string = content[chunk_start - 2..chunk_start - 1]
|
54
|
+
preceding_string !~ /(?:#{REJECTED_PREFIX_RE})$/
|
55
|
+
end
|
56
|
+
end
|
59
57
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
chunk.
|
64
|
-
|
58
|
+
def interpret match, _content
|
59
|
+
chunk = match[0]
|
60
|
+
last_char = chunk[-1, 1]
|
61
|
+
chunk.gsub!(/(?: )+/, "")
|
62
|
+
|
63
|
+
@trailing_punctuation =
|
64
|
+
if %w[, . ) ! ? :].member?(last_char)
|
65
|
+
@text.chop!
|
66
|
+
chunk.chop!
|
67
|
+
last_char
|
68
|
+
end
|
69
|
+
chunk.sub!(/\.$/, "")
|
70
|
+
|
71
|
+
@link_text = chunk
|
72
|
+
@uri = ::URI.parse(chunk)
|
73
|
+
@process_chunk = process_uri_chunk
|
74
|
+
rescue ::URI::Error => e
|
75
|
+
# warn "rescue parse #{chunk_class}:
|
76
|
+
# '#{m}' #{e.inspect} #{e.backtrace*"\n"}"
|
77
|
+
Rails.logger.warn "rescue parse #{self.class}: #{e.inspect}"
|
65
78
|
end
|
66
|
-
chunk.sub!(/\.$/, "")
|
67
|
-
|
68
|
-
@link_text = chunk
|
69
|
-
@uri = ::URI.parse(chunk)
|
70
|
-
@process_chunk = process_uri_chunk
|
71
|
-
rescue ::URI::Error => e
|
72
|
-
# warn "rescue parse #{chunk_class}:
|
73
|
-
# '#{m}' #{e.inspect} #{e.backtrace*"\n"}"
|
74
|
-
Rails.logger.warn "rescue parse #{self.class}: #{e.inspect}"
|
75
|
-
end
|
76
79
|
|
77
|
-
|
80
|
+
private
|
78
81
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
+
def process_text
|
83
|
+
@link_text
|
84
|
+
end
|
82
85
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
86
|
+
def process_uri_chunk
|
87
|
+
link = format.link_to_resource @link_text, process_text
|
88
|
+
"#{link}#{@trailing_punctuation}"
|
89
|
+
end
|
90
|
+
end
|
88
91
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
92
|
+
# FIXME: DRY, merge these two into one class
|
93
|
+
class EmailUri < Uri
|
94
|
+
PREPEND_STR = "mailto:".freeze
|
95
|
+
EMAIL = '[a-zA-Z\\d](?:[-a-zA-Z\\d.]*[a-zA-Z\\d])?\\@'.freeze
|
96
|
+
|
97
|
+
Card::Content::Chunk.register_class(
|
98
|
+
self, prefix_re: "(?:(?!#{REJECTED_PREFIX_RE})#{EMAIL})\\b",
|
99
|
+
full_re: /\A#{::URI::DEFAULT_PARSER.make_regexp(SCHEMES)}/,
|
100
|
+
prepend_str: PREPEND_STR,
|
101
|
+
idx_char: "@"
|
102
|
+
)
|
103
|
+
|
104
|
+
# removes the prepended string from the unchanged match text
|
105
|
+
def process_text
|
106
|
+
@text = @text.sub(/^mailto:/, "")
|
107
|
+
end
|
108
|
+
end
|
106
109
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
110
|
+
class HostUri < Uri
|
111
|
+
GENERIC = "aero|biz|com|coop|edu|gov|info|int|mil|" \
|
112
|
+
"museum|name|net|org".freeze
|
113
|
+
|
114
|
+
COUNTRY = "ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|az|ba|bb|bd|be|" \
|
115
|
+
"bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cf|cd|cg|" \
|
116
|
+
"ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|" \
|
117
|
+
"ec|ee|eg|eh|er|es|et|fi|fj|fk|fm|fo|fr|fx|ga|gb|gd|ge|gf|gh|" \
|
118
|
+
"gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|" \
|
119
|
+
"il|in|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|" \
|
120
|
+
"kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mk|ml|mm|" \
|
121
|
+
"mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|" \
|
122
|
+
"no|np|nr|nt|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pt|pw|py|" \
|
123
|
+
"qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|" \
|
124
|
+
"st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|" \
|
125
|
+
"tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|" \
|
126
|
+
"za|zm|zr|zw|" \
|
127
|
+
"eu".freeze # made this separate, since it's not technically
|
128
|
+
# a country -efm
|
129
|
+
# These are needed otherwise HOST will match almost anything
|
130
|
+
|
131
|
+
TLDS = "(?:#{GENERIC}|#{COUNTRY})".freeze
|
132
|
+
# TLDS = "(?:#{GENERIC})"
|
133
|
+
|
134
|
+
PREPEND_STR = "http://".freeze
|
135
|
+
HOST = "(?:[a-zA-Z\\d](?:[-a-zA-Z\\d]*[a-zA-Z\\d])?\\.)+#{TLDS}".freeze
|
136
|
+
|
137
|
+
Card::Content::Chunk.register_class(
|
138
|
+
self, prefix_re: "(?:(?!#{REJECTED_PREFIX_RE})#{HOST})\\b",
|
139
|
+
full_re: /\A#{::URI::DEFAULT_PARSER.make_regexp(SCHEMES)}/,
|
140
|
+
prepend_str: PREPEND_STR
|
141
|
+
)
|
142
|
+
|
143
|
+
# removes the prepended string from the unchanged match text
|
144
|
+
def process_text
|
145
|
+
@text = @text.sub(%r{^http://}, "")
|
146
|
+
end
|
147
|
+
end
|
143
148
|
end
|
144
149
|
end
|
145
150
|
end
|
data/set/abstract/code_file.rb
CHANGED
data/set/abstract/haml_file.rb
CHANGED
data/set/abstract/lock.rb
CHANGED
data/set/all/chunk.rb
CHANGED
@@ -1,23 +1,21 @@
|
|
1
|
-
|
2
|
-
def chunks content, type, named=false
|
1
|
+
def chunks content, type=nil, named=false
|
3
2
|
content ||= self.content
|
4
|
-
type ||= Card::Content::Chunk
|
5
3
|
all_chunks = Card::Content.new(content, self).find_chunks type
|
6
4
|
named ? all_chunks.select(&:referee_name) : all_chunks
|
7
5
|
end
|
8
6
|
|
9
7
|
def reference_chunks content=nil, named=true
|
10
|
-
chunks content,
|
8
|
+
chunks content, :Reference, named
|
11
9
|
end
|
12
10
|
|
13
11
|
# named=true rejects commented nests
|
14
12
|
def nest_chunks content=nil, named=true
|
15
|
-
chunks content,
|
13
|
+
chunks content, :Nest, named
|
16
14
|
end
|
17
15
|
|
18
16
|
# named=true rejects external links (since the don't refer to a card name)
|
19
17
|
def link_chunks content=nil, named=false
|
20
|
-
chunks content,
|
18
|
+
chunks content, :Link, named
|
21
19
|
end
|
22
20
|
|
23
21
|
def each_item_name_with_options content=nil
|
@@ -76,6 +74,7 @@ format do
|
|
76
74
|
|
77
75
|
def each_nested_chunk content: nil, fields: false, uniq: true, virtual: true, &block
|
78
76
|
return unless block_given?
|
77
|
+
|
79
78
|
chunks = prepare_nested_chunks content, fields, uniq
|
80
79
|
process_nested_chunks chunks, virtual, &block
|
81
80
|
end
|
@@ -111,14 +110,16 @@ format do
|
|
111
110
|
|
112
111
|
def process_nested_chunk chunk, virtual, &block
|
113
112
|
if chunk.referee_card&.virtual?
|
114
|
-
|
113
|
+
process_virtual_chunk chunk, virtual, &block
|
115
114
|
else
|
116
115
|
yield chunk
|
117
116
|
end
|
118
117
|
end
|
119
118
|
|
120
|
-
def process_virtual_chunk chunk
|
121
|
-
|
119
|
+
def process_virtual_chunk chunk, virtual, &block
|
120
|
+
return if virtual
|
121
|
+
|
122
|
+
subformat(chunk.referee_card).each_nested_field_chunk(&block)
|
122
123
|
end
|
123
124
|
|
124
125
|
def explicit_edit_fields_config
|
@@ -137,6 +138,7 @@ format do
|
|
137
138
|
def normalized_edit_field_mark cardish, options
|
138
139
|
return cardish if cardish.is_a?(Card) ||
|
139
140
|
(options.is_a?(Hash) && options.delete(:absolute))
|
141
|
+
|
140
142
|
card.name.field cardish
|
141
143
|
end
|
142
144
|
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
|
data/set/all/templating.rb
CHANGED
data/set/right/structure.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
include_set Abstract::TemplatedNests
|
2
2
|
|
3
|
+
def item_names args={}
|
4
|
+
item_strings(args).compact.map(&:to_name)
|
5
|
+
end
|
6
|
+
|
3
7
|
format :rss do
|
4
8
|
def raw_feed_items
|
5
9
|
[card]
|
@@ -51,7 +55,7 @@ def structuree_names
|
|
51
55
|
end
|
52
56
|
|
53
57
|
def update_structurees args
|
54
|
-
#
|
58
|
+
# NOTE: that this is not smart about overriding templating rules
|
55
59
|
# for example, if someone were to change the type of a
|
56
60
|
# +*right+*structure rule that was overridden
|
57
61
|
# by a +*type plus right+*structure rule, the override would not be respected.
|
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.
|
4
|
+
version: 0.12.0
|
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-
|
13
|
+
date: 2021-07-05 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.
|
21
|
+
version: 1.102.0
|
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.
|
28
|
+
version: 1.102.0
|
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
|
@@ -77,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
78
|
- !ruby/object:Gem::Version
|
78
79
|
version: '0'
|
79
80
|
requirements: []
|
80
|
-
rubygems_version: 3.
|
81
|
+
rubygems_version: 3.2.15
|
81
82
|
signing_key:
|
82
83
|
specification_version: 4
|
83
84
|
summary: card content handling
|