Skip to content
This repository was archived by the owner on Nov 1, 2017. It is now read-only.

Commit 88f0135

Browse files
committed
Merge pull request #23 from github/capitalized-completed
Support capitalized completed items
2 parents 480efc2 + 4891454 commit 88f0135

File tree

5 files changed

+30
-5
lines changed

5 files changed

+30
-5
lines changed

app/assets/javascripts/task_lists.coffee

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ complete = "[x]"
105105
escapePattern = (str) ->
106106
str.
107107
replace(/([\[\]])/g, "\\$1"). # escape square brackets
108-
replace(/\s/, "\\s") # match all white space
108+
replace(/\s/, "\\s"). # match all white space
109+
replace("x", "[xX]") # match all cases
109110

110111
incompletePattern = ///
111112
#{escapePattern(incomplete)}

lib/task_list.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ def summary
2424
end
2525

2626
class Item < Struct.new(:checkbox_text, :source)
27-
Complete = "[x]".freeze # see TaskListFilter
27+
Complete = /\[[xX]\]/.freeze # see TaskList::Filter
2828
def complete?
29-
checkbox_text == Complete
29+
checkbox_text =~ Complete
3030
end
3131
end
3232
end

lib/task_list/filter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Filter < HTML::Pipeline::Filter
3535
Complete = "[x]".freeze
3636

3737
IncompletePattern = /\[[[:space:]]\]/.freeze # matches all whitespace
38-
CompletePattern = Regexp.escape(Complete).freeze
38+
CompletePattern = /\[[xX]\]/.freeze # matches any capitalization
3939

4040
# Pattern used to identify all task list items.
4141
# Useful when you need iterate over all items.

test/functional/test_task_lists_behavior.html

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,26 @@
7474
<input type="checkbox" class="task-list-item-checkbox" disabled />
7575
I'm a task list item
7676
</li>
77+
<li class="task-list-item">
78+
<input type="checkbox" class="task-list-item-checkbox" disabled />
79+
with non-breaking space
80+
</li>
81+
<li class="task-list-item">
82+
<input type="checkbox" class="task-list-item-checkbox" disabled checked />
83+
completed, lower
84+
</li>
85+
<li class="task-list-item">
86+
<input type="checkbox" class="task-list-item-checkbox" disabled checked />
87+
completed capitalized
88+
</li>
7789
</ul>
7890
</div>
7991
<form action="/update" method="POST" data-remote data-type="json">
80-
<textarea name="comment[body]" class="js-task-list-field">- [ ] I'm a task list item</textarea>
92+
<textarea name="comment[body]" class="js-task-list-field" cols="40" rows="10">
93+
- [ ] I'm a task list item
94+
- [ ] with non-breaking space
95+
- [x] completed, lower
96+
- [X] completed capitalized</textarea>
8197
</form>
8298
</div>
8399

test/task_list/filter_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ def test_non_breaking_space_between_brackets_in_paras
125125
assert_equal 3, filter(text)[:output].css(@item_selector).size
126126
end
127127

128+
def test_capital_X
129+
text = <<-md
130+
- [x] lower case
131+
- [X] capital
132+
md
133+
assert_equal 2, filter(text)[:output].css("[checked]").size
134+
end
135+
128136
protected
129137

130138
def filter(input, context = @context, result = nil)

0 commit comments

Comments
 (0)