slacken 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -0
  3. data/README.md +5 -3
  4. data/{sample → examples}/out.txt +0 -0
  5. data/{sample → examples}/source.html +0 -0
  6. data/lib/slacken/document_component.rb +23 -36
  7. data/lib/slacken/dom_container.rb +1 -1
  8. data/lib/slacken/filter.rb +27 -0
  9. data/lib/slacken/filters.rb +19 -0
  10. data/lib/slacken/filters/elim_blanks.rb +41 -0
  11. data/lib/slacken/filters/elim_invalid_links.rb +33 -0
  12. data/lib/slacken/filters/elim_line_breaks.rb +36 -0
  13. data/lib/slacken/filters/extract_img_alt.rb +18 -0
  14. data/lib/slacken/filters/group_indent.rb +28 -0
  15. data/lib/slacken/filters/group_inlines.rb +31 -0
  16. data/lib/slacken/filters/sanitize_headline.rb +46 -0
  17. data/lib/slacken/filters/sanitize_link.rb +48 -0
  18. data/lib/slacken/filters/sanitize_list.rb +57 -0
  19. data/lib/slacken/filters/sanitize_table.rb +44 -0
  20. data/lib/slacken/filters/stringfy_checkbox.rb +26 -0
  21. data/lib/slacken/filters/stringfy_emoji.rb +26 -0
  22. data/lib/slacken/node_type.rb +2 -1
  23. data/lib/slacken/render_element.rb +2 -0
  24. data/lib/slacken/rendering.rb +0 -1
  25. data/lib/slacken/version.rb +1 -1
  26. data/scripts/update_markup_fixture.rb +3 -3
  27. data/spec/slacken/document_component_spec.rb +6 -8
  28. data/spec/slacken/filters/elim_blanks_spec.rb +32 -0
  29. data/spec/slacken/filters/elim_invalid_links_spec.rb +47 -0
  30. data/spec/slacken/filters/elim_line_breaks_spec.rb +39 -0
  31. data/spec/slacken/filters/group_indent_spec.rb +35 -0
  32. data/spec/slacken/filters/group_inlines_spec.rb +31 -0
  33. data/spec/slacken/filters/sanitize_headline_spec.rb +29 -0
  34. data/spec/slacken/filters/sanitize_link_spec.rb +23 -0
  35. data/spec/slacken/filters/sanitize_list_spec.rb +36 -0
  36. data/spec/slacken/filters/sanitize_table_spec.rb +39 -0
  37. data/spec/slacken_spec.rb +3 -0
  38. data/spec/spec_helper.rb +1 -2
  39. metadata +37 -26
  40. data/lib/slacken/document_component/elim_blanks.rb +0 -36
  41. data/lib/slacken/document_component/elim_invalid_links.rb +0 -26
  42. data/lib/slacken/document_component/elim_line_breaks.rb +0 -27
  43. data/lib/slacken/document_component/extract_img_alt.rb +0 -12
  44. data/lib/slacken/document_component/group_indent.rb +0 -27
  45. data/lib/slacken/document_component/group_inlines.rb +0 -26
  46. data/lib/slacken/document_component/sanitize_link_containers.rb +0 -40
  47. data/lib/slacken/document_component/sanitize_special_tag_containers.rb +0 -102
  48. data/lib/slacken/document_component/stringfy_checkbox.rb +0 -20
  49. data/lib/slacken/document_component/stringfy_emoji.rb +0 -20
  50. data/spec/slacken/document_component/elim_blanks_spec.rb +0 -34
  51. data/spec/slacken/document_component/elim_invalid_links_spec.rb +0 -49
  52. data/spec/slacken/document_component/elim_line_breaks_spec.rb +0 -41
  53. data/spec/slacken/document_component/group_indent_spec.rb +0 -37
  54. data/spec/slacken/document_component/group_inlines_spec.rb +0 -33
  55. data/spec/slacken/document_component/sanitize_special_tag_containers_spec.rb +0 -64
@@ -1,20 +0,0 @@
1
- class Slacken::DocumentComponent
2
- module StringfyCheckbox
3
- # Private: Reject blank elements
4
- def stringfy_checkbox
5
- if type.member_of?(:input) && attrs[:type] == 'checkbox'
6
- self.class.new(:checkbox, [], checked: attrs[:checked])
7
- else
8
- derive(children.map(&:stringfy_checkbox))
9
- end
10
- end
11
-
12
- def checkbox_stringfied?
13
- if type.member_of?(:input) && attrs[:type] == 'checkbox'
14
- false
15
- else
16
- children.all?(&:checkbox_stringfied?)
17
- end
18
- end
19
- end
20
- end
@@ -1,20 +0,0 @@
1
- class Slacken::DocumentComponent
2
- module StringfyEmoji
3
- # Private: Reject blank elements
4
- def stringfy_emoji
5
- if type.member_of?(:img) && attrs[:class].include?('emoji')
6
- self.class.new(:emoji, [], content: attrs[:alt])
7
- else
8
- derive(children.map(&:stringfy_emoji))
9
- end
10
- end
11
-
12
- def emoji_stringfied?
13
- if type.member_of?(:img) && attrs[:class].include?('emoji')
14
- false
15
- else
16
- children.all?(&:emoji_stringfied?)
17
- end
18
- end
19
- end
20
- end
@@ -1,34 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class Slacken::DocumentComponent
4
- describe ElimBlanks, dsl: true do
5
- describe '#has_no_blanks?' do
6
- subject { component.has_no_blanks? }
7
-
8
- context 'when a component obviously having no blanks is given' do
9
- let(:component) do
10
- c(:div, text('hello world!'))
11
- end
12
-
13
- it { is_expected.to be_truthy }
14
- end
15
-
16
- context 'when a component with blank children is given' do
17
- let(:component) do
18
- c(:div, text(''), c(:div), c(:span))
19
- end
20
-
21
- it { is_expected.to be_falsey }
22
- end
23
-
24
- context 'when a component with a img is given' do
25
- let(:component) do
26
- c(:div, c(:img))
27
- end
28
-
29
- it { is_expected.to be_truthy }
30
- end
31
-
32
- end
33
- end
34
- end
@@ -1,49 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class Slacken::DocumentComponent
4
- describe ElimInvalidLinks, dsl: true do
5
- describe '#has_no_invalid_links?' do
6
- subject { component.has_no_invalid_links? }
7
-
8
- context 'when a http link is given' do
9
- let(:component) do
10
- c(:a, { href: 'http://example.com' })
11
- end
12
-
13
- it { is_expected.to be_truthy }
14
- end
15
-
16
- context 'when a https link is given' do
17
- let(:component) do
18
- c(:a, { href: 'https://example.com' })
19
- end
20
-
21
- it { is_expected.to be_truthy }
22
- end
23
-
24
- context "when a disallowed link containing 'http://' is given" do
25
- let(:component) do
26
- c(:a, { href: '#hogefugahttp://' })
27
- end
28
-
29
- it { is_expected.to be_falsey }
30
- end
31
-
32
- context 'when a disallowed link is given' do
33
- let(:component) do
34
- c(:a, { href: '#hogehoge' })
35
- end
36
-
37
- it { is_expected.to be_falsey }
38
- end
39
-
40
- context 'when a disallowed link occurs as a component\'s children' do
41
- let(:component) do
42
- c(:div, c(:span, c(:a, { href: '#hogehoge' })))
43
- end
44
-
45
- it { is_expected.to be_falsey }
46
- end
47
- end
48
- end
49
- end
@@ -1,41 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class Slacken::DocumentComponent
4
- describe ElimLineBreaks, dsl: true do
5
- describe '#has_no_line_breaks?' do
6
- subject { component.has_no_line_breaks? }
7
-
8
- context 'when no linebreaks occur' do
9
- let(:component) do
10
- c(:div, c(:h1, text('yo!')), c(:wrapper, text('hello world!'), text('another')))
11
- end
12
-
13
- it { is_expected.to be_truthy }
14
- end
15
-
16
- context 'when a linebreak occurs in a inline component' do
17
- let(:component) do
18
- c(:div, c(:h1, text('yo!')), c(:wrapper, text('hello world!'), text("another\n")))
19
- end
20
-
21
- it { is_expected.to be_falsey }
22
- end
23
-
24
- context 'when a linebreak occurs in a block component' do
25
- let(:component) do
26
- c(:div, c(:h1, text("yo\n!")), c(:wrapper, text('hello world!'), text("another")))
27
- end
28
-
29
- it { is_expected.to be_falsey }
30
- end
31
-
32
- context 'when a linebreak occurs in a pre tag' do
33
- let(:component) do
34
- c(:div, c(:pre, text("yo\n!")), c(:wrapper, text('hello world!'), text("another")))
35
- end
36
-
37
- it { is_expected.to be_truthy }
38
- end
39
- end
40
- end
41
- end
@@ -1,37 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class Slacken::DocumentComponent
4
- describe GroupIndent, dsl: true do
5
- describe '#indent_grouped?' do
6
- subject { component.indent_grouped? }
7
-
8
- context 'when a indented list component is given' do
9
- let(:component) do
10
- c(:ul,
11
- c(:li,
12
- text('List Heading'),
13
- c(:indent,
14
- text('List Content1'),
15
- c(:span, text('List Content2'), text('List Content3'))
16
- )))
17
- end
18
-
19
- it { is_expected.to be_truthy }
20
- end
21
-
22
- context 'when a indented list where child component is not indented is given' do
23
- let(:component) do
24
- c(:ul,
25
- c(:li,
26
- text('List Heading'),
27
- c(:span,
28
- text('List Content1'),
29
- c(:span, text('List Content2'), text('List Content3'))
30
- )))
31
- end
32
-
33
- it { is_expected.to be_falsey }
34
- end
35
- end
36
- end
37
- end
@@ -1,33 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class Slacken::DocumentComponent
4
- describe GroupInlines, dsl: true do
5
- describe '#inlines_grouped?' do
6
- subject { component.inlines_grouped? }
7
-
8
- context 'when a grouped component is given' do
9
- let(:component) do
10
- c(:div, c(:wrapper, text('hello world!'), text('another')))
11
- end
12
-
13
- it { is_expected.to be_truthy }
14
- end
15
-
16
- context 'when a component whose inline components are exposed is given' do
17
- let(:component) do
18
- c(:div, text(''), c(:div), c(:span))
19
- end
20
-
21
- it { is_expected.to be_falsey }
22
- end
23
-
24
- context 'when a component with only block components is given' do
25
- let(:component) do
26
- c(:div, c(:div), c(:img), c(:p, c(:h1)))
27
- end
28
-
29
- it { is_expected.to be_truthy }
30
- end
31
- end
32
- end
33
- end
@@ -1,64 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class Slacken::DocumentComponent
4
- describe SanitizeSpecialTagContainers, dsl: true do
5
- describe '#sanitized?' do
6
- subject { component.sanitized? }
7
-
8
- context 'when a header occurs in a list' do
9
- let(:component) do
10
- c(:ul,
11
- c(:li,
12
- text('header'),
13
- c(:indent,
14
- c(:h1, text('hoge')))))
15
- end
16
-
17
- it { is_expected.to be_falsey }
18
- end
19
-
20
- context 'when a list occurs in another list' do
21
- let(:component) do
22
- c(:ul,
23
- c(:li,
24
- text('header'),
25
- c(:indent,
26
- c(:dl,
27
- c(:li,
28
- text('header2'),
29
- c(:indent,
30
- text('fuga')))))))
31
- end
32
-
33
- it { is_expected.to be_truthy }
34
- end
35
-
36
- context 'when a code occurs in a header' do
37
- let(:component) do
38
- c(:h3,
39
- text('A Ruby Code is Given: '),
40
- c(:span,
41
- c(:code, text("puts('hello, world!')"))))
42
- end
43
-
44
- it { is_expected.to be_falsey }
45
- end
46
-
47
- context 'when a pre tag occurs in a table' do
48
- let(:component) do
49
- c(:table,
50
- c(:thead,
51
- c(:tr,
52
- c(:th, text('Header1')),
53
- c(:th, text('Header2')))),
54
- c(:tbody,
55
- c(:tr,
56
- c(:td, text('Content1')),
57
- c(:td, c(:pre, (text('Content2')))))))
58
- end
59
-
60
- it { is_expected.to be_falsey }
61
- end
62
- end
63
- end
64
- end