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

Commit f67b7a7

Browse files
committed
Remove item index from Ruby side
1 parent 2b8c919 commit f67b7a7

File tree

5 files changed

+9
-24
lines changed

5 files changed

+9
-24
lines changed

lib/task_list.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def summary
2323
@summary ||= TaskList::Summary.new(record.task_list_items)
2424
end
2525

26-
class Item < Struct.new(:index, :checkbox_text, :source)
26+
class Item < Struct.new(:checkbox_text, :source)
2727
Complete = "[x]".freeze # see TaskListFilter
2828
def complete?
2929
checkbox_text == Complete

lib/task_list/filter.rb

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,6 @@ class Filter < HTML::Pipeline::Filter
6262
# Selects first P tag of an LI, if present
6363
ItemParaSelector = ".//p[1]".freeze
6464

65-
attr_accessor :index
66-
67-
def initialize(*)
68-
@index = 0
69-
super
70-
end
71-
72-
# Private: increments and returns the next item index Integer.
73-
def next_index
74-
@index += 1
75-
end
76-
7765
# List of `TaskList::Item` objects that were recognized in the document.
7866
# This is available in the result hash as `:task_list_items`.
7967
#
@@ -82,13 +70,12 @@ def task_list_items
8270
result[:task_list_items] ||= []
8371
end
8472

85-
# Renders the item checkbox in a span including the item index and state.
73+
# Renders the item checkbox in a span including the item state.
8674
#
8775
# Returns an HTML-safe String.
8876
def render_item_checkbox(item)
8977
%(<input type="checkbox"
9078
class="task-list-item-checkbox"
91-
data-item-index="#{item.index}"
9279
#{'checked="checked"' if item.complete?}
9380
disabled="disabled"
9481
/>)
@@ -137,7 +124,7 @@ def filter_list(node)
137124
[li, li.inner_html]
138125
end
139126
if match = (inner.chomp =~ ItemPattern && $1)
140-
item = TaskList::Item.new(next_index, match, inner)
127+
item = TaskList::Item.new(match, inner)
141128
task_list_items << item
142129

143130
add_css_class(li, 'task-list-item')

test/task_list/filter_test.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,9 @@ def test_populates_result_with_task_list_items
5151
incomplete, complete = result[:task_list_items]
5252

5353
assert incomplete
54-
assert_equal 1, incomplete.index
5554
assert !incomplete.complete?
5655

5756
assert complete
58-
assert_equal 2, complete.index
5957
assert complete.complete?
6058
end
6159

test/task_list/summary_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
class TaskList::SummaryTest < Test::Unit::TestCase
66
def setup
7-
@complete = make_item 1, "[x]", "complete"
8-
@incomplete = make_item 2, "[ ]", "incomplete"
7+
@complete = make_item "[x]", "complete"
8+
@incomplete = make_item "[ ]", "incomplete"
99
@items = [@complete, @incomplete]
1010
@summary = make_summary @items
1111
end
@@ -30,8 +30,8 @@ def test_incomplete_count
3030

3131
protected
3232

33-
def make_item(index = 1, checkbox_text = "[ ]", source = "an item!")
34-
TaskList::Item.new(index, checkbox_text, source)
33+
def make_item(checkbox_text = "[ ]", source = "an item!")
34+
TaskList::Item.new(checkbox_text, source)
3535
end
3636

3737
def make_summary(items)

test/task_list_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ def test_has_summary
1616
end
1717

1818
def test_complete_item
19-
item = TaskList::Item.new(1, "[x]", "complete")
19+
item = TaskList::Item.new("[x]", "complete")
2020
assert item.complete?, "expected to be complete"
2121
end
2222

2323
def test_incomplete_item
24-
item = TaskList::Item.new(1, "[ ]", "incomplete")
24+
item = TaskList::Item.new("[ ]", "incomplete")
2525
assert !item.complete?, "expected to be incomplete"
2626
end
2727

0 commit comments

Comments
 (0)