deckar01-task_list 2.3.3 → 3.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 25b1e9330f205a0fdcd27bffcd57709c3b13d45d6554075dc66472d71230421a
4
- data.tar.gz: 575a135f17373ec21748d76cd96cd7143a2846aae8667b8fba7a0d2c10a4312f
3
+ metadata.gz: '058afd74f87d80538ead4fff4993788d7f71b1152112edd07115e0554029050c'
4
+ data.tar.gz: 12daa5aca83f2a05ca08f6937b5f7c438ac7a93e6acce53346189fcf25c6814e
5
5
  SHA512:
6
- metadata.gz: 6bef865f56600783b7c5da763891fec1fdd2de59152af2f698c481ff936859f60d7a5b5ce3756a90021d82dea1e50894f362701384606c8e4a9ef8ebbd62e739
7
- data.tar.gz: 72cc545b970a28c4fe2b03b2fe271c9ad7304b5a3880305a8aed1f458e7cd67141c73e7f7d3829044bfd6d128cb61c9350b451ccc9af817dec7284e657bb98b1
6
+ metadata.gz: 7578ca24199c41c957baab771a76f2f7d605bf9d128ff461fffa618700aca615d29c5128b4ffb2b40b251fc7bbf5ed19ec49dd9b44a87b654dd6a15fc78f433d
7
+ data.tar.gz: bc47cc0071775b370fc3a26e232d6121c4aff312579c9879c428437d1af8b46d14dfdb4bd9e22378d9cbcb363bd513e72c21590bb545e0f5c12af588de1131e6
data/bower.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deckar01-task_list",
3
- "version": "2.0.1",
3
+ "version": "3.0.0",
4
4
  "description": "Markdown TaskList components",
5
5
  "homepage": "https://gitlab.com/deckar01/task_list",
6
6
  "devDependencies": {
@@ -37,35 +37,20 @@ class TaskList
37
37
  IncompletePattern = /\[[[:space:]]\]/.freeze # matches all whitespace
38
38
  CompletePattern = /\[[xX]\]/.freeze # matches any capitalization
39
39
 
40
+ # All valid checkbox patterns.
41
+ # Useful for overriding ItemPattern wih custom formats.
42
+ CheckboxPatterns = /#{CompletePattern}|#{IncompletePattern}/
43
+
40
44
  # Pattern used to identify all task list items.
41
45
  # Useful when you need iterate over all items.
42
46
  ItemPattern = /
43
47
  ^
44
48
  (?:\s*[-+*]|(?:\d+\.))? # optional list prefix
45
49
  \s* # optional whitespace prefix
46
- ( # checkbox
47
- #{CompletePattern}|
48
- #{IncompletePattern}
49
- )
50
+ (#{CheckboxPatterns}) # checkbox
50
51
  (?=\s) # followed by whitespace
51
52
  /x
52
53
 
53
- ListItemSelector = ".//li[task_list_item(.)]".freeze
54
-
55
- class XPathSelectorFunction
56
- def self.task_list_item(nodes)
57
- nodes.select { |li| Filter::item_container(li).inner_html =~ ItemPattern }
58
- end
59
- end
60
-
61
- # Selects first P tag of an LI, if present
62
- ItemParaSelector = "./p[1]".freeze
63
-
64
- # The the node directly containing the checkbox text
65
- def self.item_container(li)
66
- li.xpath(ItemParaSelector)[0] || li
67
- end
68
-
69
54
  # List of `TaskList::Item` objects that were recognized in the document.
70
55
  # This is available in the result hash as `:task_list_items`.
71
56
  #
@@ -74,18 +59,24 @@ class TaskList
74
59
  result[:task_list_items] ||= []
75
60
  end
76
61
 
62
+ # Computes attributes for the item input.
63
+ #
64
+ # Returns an String of HTML attributes.
65
+ def checkbox_attributes(item)
66
+ 'checked="checked"' if item.complete?
67
+ end
68
+
77
69
  # Renders the item checkbox in a span including the item state.
78
70
  #
79
71
  # Returns an HTML-safe String.
80
72
  def render_item_checkbox(item)
81
73
  %(<input type="checkbox"
82
74
  class="task-list-item-checkbox"
83
- #{'checked="checked"' if item.complete?}
75
+ #{checkbox_attributes(item)}
84
76
  disabled="disabled"
85
77
  />)
86
78
  end
87
79
 
88
- # Deprecated: Removed in v3
89
80
  # Public: Marks up the task list item checkbox with metadata and behavior.
90
81
  #
91
82
  # NOTE: produces a string that, when assigned to a Node's `inner_html`,
@@ -101,16 +92,6 @@ class TaskList
101
92
  item.source.sub(ItemPattern, render_item_checkbox(item)), 'utf-8'
102
93
  end
103
94
 
104
- # Deprecated: Removed in v3
105
- # Public: Select all task list items within `container`.
106
- #
107
- # Returns an Array of Nokogiri::XML::Element objects for ordered and
108
- # unordered lists. The container can either be the entire document (as
109
- # returned by `#doc`) or an Element object.
110
- def list_items(container)
111
- container.xpath(ListItemSelector, XPathSelectorFunction)
112
- end
113
-
114
95
  # Filters the source for task list items.
115
96
  #
116
97
  # Each item is wrapped in HTML to identify, style, and layer
@@ -120,16 +101,15 @@ class TaskList
120
101
  #
121
102
  # Returns nothing.
122
103
  def filter!
123
- list_items(doc).reverse.each do |li|
124
- outer = self.class.item_container(li)
125
- inner = outer.inner_html
126
- checkbox = inner.match(ItemPattern).captures[0]
127
- item = TaskList::Item.new(checkbox, inner)
128
- # prepend because we're iterating in reverse
104
+ doc.xpath(".//li").reverse.each do |li|
105
+ container = li.xpath("./p[1]")[0] || li
106
+ next if not container.inner_html =~ ItemPattern
107
+
108
+ item = TaskList::Item.new($1, container.inner_html)
129
109
  task_list_items.unshift item
110
+ container.inner_html = render_task_list_item(item)
130
111
  li.parent.add_class('task-list')
131
112
  li.add_class('task-list-item')
132
- outer.inner_html = render_task_list_item(item)
133
113
  end
134
114
  end
135
115
 
@@ -137,15 +117,5 @@ class TaskList
137
117
  filter!
138
118
  doc
139
119
  end
140
-
141
- # Deprecated: Removed in v3
142
- # Private: adds a CSS class name to a node, respecting existing class
143
- # names.
144
- def add_css_class(node, *new_class_names)
145
- class_names = (node['class'] || '').split(' ')
146
- return if new_class_names.all? { |klass| class_names.include?(klass) }
147
- class_names.concat(new_class_names)
148
- node['class'] = class_names.uniq.join(' ')
149
- end
150
120
  end
151
121
  end
@@ -1,3 +1,3 @@
1
1
  class TaskList
2
- VERSION = [2, 3, 3].join('.')
2
+ VERSION = [3, 0, 'alpha1'].join('.')
3
3
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deckar01-task_list",
3
- "version": "2.3.3",
3
+ "version": "3.0.0",
4
4
  "description": "Markdown TaskList components",
5
5
  "main": "dist/task_list.js",
6
6
  "directories": {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deckar01-task_list
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.3
4
+ version: 3.0.alpha1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared Deckard
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-09-08 00:00:00.000000000 Z
12
+ date: 2023-09-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: html-pipeline
@@ -180,9 +180,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
180
180
  version: 2.0.0
181
181
  required_rubygems_version: !ruby/object:Gem::Requirement
182
182
  requirements:
183
- - - ">="
183
+ - - ">"
184
184
  - !ruby/object:Gem::Version
185
- version: '0'
185
+ version: 1.3.1
186
186
  requirements: []
187
187
  rubygems_version: 3.4.18
188
188
  signing_key: