card-mod-content 0.11.4 → 0.11.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e9917d5bafaf177dfb0cf51f5b0e4a03f813ee2d1e06dae87d4544a4bd8c2dbf
4
- data.tar.gz: 62bb2508ff022bdf31fb268577c8277e6fbdc88cf5348fe0c31fd0ab68248e9a
3
+ metadata.gz: 20ef16ab1cd68c60cef87aac784c6e59e693653c1dd83824c41836c779241dbc
4
+ data.tar.gz: af181919b1be08412e2f1a58e114ee1bd5f58fd115d23fd1f4971b8bbe0b2e40
5
5
  SHA512:
6
- metadata.gz: 2f80c399e98d4191f749e3fb1eb6fb9c8eb29f37eb7c80f330ba0e05ab67d1406cd2148459b532ba9ec92b65421d7e7cc1451486eca6e5fe522c99825964a1e8
7
- data.tar.gz: ef15f9bb7f4b9877e53b5fa1217bf903d2f1e56a97e244ca845e8c637854125f88670b6c115d68898a0227d2778aa961339b84f9ff7663e5b69643165b44ba8a
6
+ metadata.gz: e4a460218fb818da58cfc64fdd5bee8ad0a88901833d03fa2a2bb7291386986dbb9acc0130b8f8a1ad9091ef779cd8d22d9f3537003d1ddc3b07a09a1a0c2c50
7
+ data.tar.gz: 6dfa5408e034673b954087356ee7f9c90f2e331c584e7b6761ae559b9571b487267091a4334346d80dc7edb0e13813200387d5108f271dc90b7b84901041f8e4
@@ -9,10 +9,10 @@ class Card
9
9
  # and within HTML tags.
10
10
  class EscapedLiteral < Abstract
11
11
  FULL_RE = { "[" => /\A\\\[\[[^\]]*\]\]/,
12
- "{" => /\A\\\{\{[^\}]*\}\}/ }.freeze
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\\\{\{[^\}]*\}\}/ }.freeze
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,7 +1,7 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
3
  # require File.expand_path("../reference", __FILE__)
4
- load File.expand_path("../reference.rb", __FILE__)
4
+ load File.expand_path("reference.rb", __dir__)
5
5
 
6
6
  class Card
7
7
  class Content
@@ -12,11 +12,12 @@ class Card
12
12
  class Link < Card::Content::Chunk::Reference
13
13
  CODE = "L".freeze # L for "Link"
14
14
  attr_reader :link_text
15
+
15
16
  # Groups: $1, [$2]: [[$1]] or [[$1|$2]] or $3, $4: [$3][$4]
16
17
  Card::Content::Chunk.register_class self,
17
18
  prefix_re: '\\[\\[',
18
- full_re: /\A\[\[([^\]]+)\]\]/,
19
- idx_char: "["
19
+ full_re: /\A\[\[([^\]]+)\]\]/,
20
+ idx_char: "["
20
21
  def reference_code
21
22
  CODE
22
23
  end
@@ -46,8 +47,9 @@ class Card
46
47
  # there's probably a better way to do the following.
47
48
  # point is to find the first pipe that's not inside an nest
48
49
  return unless string.index "|"
50
+
49
51
  string_copy = string.dup
50
- string.scan(/\{\{[^\}]*\}\}/) do |incl|
52
+ string.scan(/\{\{[^}]*\}\}/) do |incl|
51
53
  string_copy.gsub! incl, ("x" * incl.length)
52
54
  end
53
55
  string_copy.index "|"
@@ -60,6 +62,7 @@ class Card
60
62
 
61
63
  def objectify raw
62
64
  return unless raw
65
+
63
66
  raw.strip!
64
67
  if raw.match?(/(^|[^\\])\{\{/)
65
68
  Card::Content.new raw, format
@@ -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: /\A\{\{([^\{\}]*)\}\}/,
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
- # note: not using ActionView's strip_tags here
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(/\{\{([^\}]*)\}\}/) do |_match|
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,6 +9,7 @@ class Card
9
9
 
10
10
  def referee_name
11
11
  return if name.nil?
12
+
12
13
  @referee_name ||= referee_raw_name
13
14
  @referee_name = @referee_name.absolute_name card.name
14
15
  rescue Card::Error::NotFound
@@ -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
- module Card::Content::Chunk
23
- class Uri < Abstract
24
- SCHEMES = %w[irc http https ftp ssh git sftp file ldap ldaps mailto].freeze
25
-
26
- REJECTED_PREFIX_RE = %w{! ": " ' ](}.map { |s| Regexp.escape s } * "|"
27
-
28
- attr_reader :uri, :link_text
29
- delegate :to, :scheme, :host, :port, :path, :query, :fragment, to: :uri
30
-
31
- Card::Content::Chunk.register_class(
32
- self, prefix_re: "(?:(?!#{REJECTED_PREFIX_RE})(?:#{SCHEMES * '|'})\\:)",
33
- full_re: /\A#{::URI.regexp(SCHEMES)}/,
34
- idx_char: ":"
35
- )
36
-
37
- class << self
38
- def full_match content, prefix
39
- prepend_str = if prefix[-1, 1] != ":" && config[:prepend_str]
40
- config[:prepend_str]
41
- else
42
- ""
43
- end
44
- content = prepend_str + content
45
- match = super content, prefix
46
- [match, prepend_str.length]
47
- end
48
-
49
- def context_ok? content, chunk_start
50
- preceding_string = content[chunk_start - 2..chunk_start - 1]
51
- preceding_string !~ /(?:#{REJECTED_PREFIX_RE})$/
52
- end
53
- end
54
-
55
- def interpret match, _content
56
- chunk = match[0]
57
- last_char = chunk[-1, 1]
58
- chunk.gsub!(/(?:&nbsp;)+/, "")
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
- @trailing_punctuation =
61
- if %w[, . ) ! ? :].member?(last_char)
62
- @text.chop!
63
- chunk.chop!
64
- last_char
58
+ def interpret match, _content
59
+ chunk = match[0]
60
+ last_char = chunk[-1, 1]
61
+ chunk.gsub!(/(?:&nbsp;)+/, "")
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
- private
80
+ private
78
81
 
79
- def process_text
80
- @link_text
81
- end
82
+ def process_text
83
+ @link_text
84
+ end
82
85
 
83
- def process_uri_chunk
84
- link = format.link_to_resource @link_text, process_text
85
- "#{link}#{@trailing_punctuation}"
86
- end
87
- end
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
- # FIXME: DRY, merge these two into one class
90
- class EmailUri < Uri
91
- PREPEND_STR = "mailto:".freeze
92
- EMAIL = '[a-zA-Z\\d](?:[-a-zA-Z\\d.]*[a-zA-Z\\d])?\\@'.freeze
93
-
94
- Card::Content::Chunk.register_class(
95
- self, prefix_re: "(?:(?!#{REJECTED_PREFIX_RE})#{EMAIL})\\b",
96
- full_re: /\A#{::URI.regexp(SCHEMES)}/,
97
- prepend_str: PREPEND_STR,
98
- idx_char: "@"
99
- )
100
-
101
- # removes the prepended string from the unchanged match text
102
- def process_text
103
- @text = @text.sub(/^mailto:/, "")
104
- end
105
- end
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
- class HostUri < Uri
108
- GENERIC = "aero|biz|com|coop|edu|gov|info|int|mil|" \
109
- "museum|name|net|org".freeze
110
-
111
- COUNTRY = "ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|az|ba|bb|bd|be|" \
112
- "bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cf|cd|cg|" \
113
- "ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|" \
114
- "ec|ee|eg|eh|er|es|et|fi|fj|fk|fm|fo|fr|fx|ga|gb|gd|ge|gf|gh|" \
115
- "gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|" \
116
- "il|in|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|" \
117
- "kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mk|ml|mm|" \
118
- "mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|" \
119
- "no|np|nr|nt|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pt|pw|py|" \
120
- "qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|" \
121
- "st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|" \
122
- "tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|" \
123
- "za|zm|zr|zw|" \
124
- "eu".freeze # made this separate, since it's not technically
125
- # a country -efm
126
- # These are needed otherwise HOST will match almost anything
127
-
128
- TLDS = "(?:#{GENERIC}|#{COUNTRY})".freeze
129
- # TLDS = "(?:#{GENERIC})"
130
-
131
- PREPEND_STR = "http://".freeze
132
- HOST = "(?:[a-zA-Z\\d](?:[-a-zA-Z\\d]*[a-zA-Z\\d])?\\.)+#{TLDS}".freeze
133
-
134
- Card::Content::Chunk.register_class(
135
- self, prefix_re: "(?:(?!#{REJECTED_PREFIX_RE})#{HOST})\\b",
136
- full_re: /\A#{::URI.regexp(SCHEMES)}/,
137
- prepend_str: PREPEND_STR
138
- )
139
-
140
- # removes the prepended string from the unchanged match text
141
- def process_text
142
- @text = @text.sub(%r{^http://}, "")
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
@@ -9,10 +9,6 @@ class Card
9
9
  idx_char: "("
10
10
  )
11
11
 
12
- def initialize text, content
13
- super
14
- end
15
-
16
12
  def interpret match, _content
17
13
  @stub_hash = initial_stub_hash match[1]
18
14
  interpret_hash_values
@@ -1,5 +1,4 @@
1
1
  class << self
2
-
3
2
  def included host_class
4
3
  track_mod_name host_class, caller
5
4
  end
@@ -1,4 +1,3 @@
1
-
2
1
  def self.included host_class
3
2
  host_class.mattr_accessor :template_path
4
3
  host_class.extend Card::Set::Format::HamlPaths
data/set/abstract/lock.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  def lock
2
2
  was_already_locked = locked?
3
3
  return if was_already_locked
4
+
4
5
  Auth.as_bot do
5
6
  lock!
6
7
  yield
data/set/all/chunk.rb CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  def chunks content, type=nil, named=false
3
2
  content ||= self.content
4
3
  all_chunks = Card::Content.new(content, self).find_chunks type
@@ -75,6 +74,7 @@ format do
75
74
 
76
75
  def each_nested_chunk content: nil, fields: false, uniq: true, virtual: true, &block
77
76
  return unless block_given?
77
+
78
78
  chunks = prepare_nested_chunks content, fields, uniq
79
79
  process_nested_chunks chunks, virtual, &block
80
80
  end
@@ -116,8 +116,8 @@ format do
116
116
  end
117
117
  end
118
118
 
119
- def process_virtual_chunk chunk
120
- subformat(chunk.referee_card).each_nested_field_chunk { |sub_chunk| yield sub_chunk }
119
+ def process_virtual_chunk chunk, &block
120
+ subformat(chunk.referee_card).each_nested_field_chunk(&block)
121
121
  end
122
122
 
123
123
  def explicit_edit_fields_config
@@ -136,6 +136,7 @@ format do
136
136
  def normalized_edit_field_mark cardish, options
137
137
  return cardish if cardish.is_a?(Card) ||
138
138
  (options.is_a?(Hash) && options.delete(:absolute))
139
+
139
140
  card.name.field cardish
140
141
  end
141
142
  end
@@ -1,4 +1,3 @@
1
-
2
1
  def is_template?
3
2
  return @is_template unless @is_template.nil?
4
3
 
@@ -46,6 +45,7 @@ end
46
45
 
47
46
  def assign_type_to? structure
48
47
  return if type_id == structure.type_id
48
+
49
49
  structure.assigns_type?
50
50
  end
51
51
 
@@ -55,7 +55,7 @@ def structuree_names
55
55
  end
56
56
 
57
57
  def update_structurees args
58
- # note that this is not smart about overriding templating rules
58
+ # NOTE: that this is not smart about overriding templating rules
59
59
  # for example, if someone were to change the type of a
60
60
  # +*right+*structure rule that was overridden
61
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.11.4
4
+ version: 0.11.5
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-05 00:00:00.000000000 Z
13
+ date: 2021-05-10 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.4
21
+ version: 1.101.5
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.4
28
+ version: 1.101.5
29
29
  description: ''
30
30
  email:
31
31
  - info@decko.org