motion-html-pipeline 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +379 -0
  3. data/lib/motion-html-pipeline.rb +14 -0
  4. data/lib/motion-html-pipeline/document_fragment.rb +27 -0
  5. data/lib/motion-html-pipeline/pipeline.rb +153 -0
  6. data/lib/motion-html-pipeline/pipeline/absolute_source_filter.rb +45 -0
  7. data/lib/motion-html-pipeline/pipeline/body_content.rb +42 -0
  8. data/lib/motion-html-pipeline/pipeline/disabled/@mention_filter.rb +140 -0
  9. data/lib/motion-html-pipeline/pipeline/disabled/autolink_filter.rb +27 -0
  10. data/lib/motion-html-pipeline/pipeline/disabled/camo_filter.rb +93 -0
  11. data/lib/motion-html-pipeline/pipeline/disabled/email_reply_filter.rb +66 -0
  12. data/lib/motion-html-pipeline/pipeline/disabled/emoji_filter.rb +125 -0
  13. data/lib/motion-html-pipeline/pipeline/disabled/markdown_filter.rb +37 -0
  14. data/lib/motion-html-pipeline/pipeline/disabled/plain_text_input_filter.rb +13 -0
  15. data/lib/motion-html-pipeline/pipeline/disabled/sanitization_filter.rb +137 -0
  16. data/lib/motion-html-pipeline/pipeline/disabled/syntax_highlight_filter.rb +44 -0
  17. data/lib/motion-html-pipeline/pipeline/disabled/toc_filter.rb +67 -0
  18. data/lib/motion-html-pipeline/pipeline/filter.rb +163 -0
  19. data/lib/motion-html-pipeline/pipeline/https_filter.rb +27 -0
  20. data/lib/motion-html-pipeline/pipeline/image_filter.rb +17 -0
  21. data/lib/motion-html-pipeline/pipeline/image_max_width_filter.rb +37 -0
  22. data/lib/motion-html-pipeline/pipeline/text_filter.rb +14 -0
  23. data/lib/motion-html-pipeline/pipeline/version.rb +5 -0
  24. data/spec/motion-html-pipeline/_helpers/mock_instumentation_service.rb +19 -0
  25. data/spec/motion-html-pipeline/pipeline/absolute_source_filter_spec.rb +47 -0
  26. data/spec/motion-html-pipeline/pipeline/disabled/auto_link_filter_spec.rb +33 -0
  27. data/spec/motion-html-pipeline/pipeline/disabled/camo_filter_spec.rb +75 -0
  28. data/spec/motion-html-pipeline/pipeline/disabled/email_reply_filter_spec.rb +64 -0
  29. data/spec/motion-html-pipeline/pipeline/disabled/emoji_filter_spec.rb +92 -0
  30. data/spec/motion-html-pipeline/pipeline/disabled/markdown_filter_spec.rb +112 -0
  31. data/spec/motion-html-pipeline/pipeline/disabled/plain_text_input_filter_spec.rb +20 -0
  32. data/spec/motion-html-pipeline/pipeline/disabled/sanitization_filter_spec.rb +164 -0
  33. data/spec/motion-html-pipeline/pipeline/disabled/syntax_highlighting_filter_spec.rb +59 -0
  34. data/spec/motion-html-pipeline/pipeline/disabled/toc_filter_spec.rb +137 -0
  35. data/spec/motion-html-pipeline/pipeline/https_filter_spec.rb +52 -0
  36. data/spec/motion-html-pipeline/pipeline/image_filter_spec.rb +37 -0
  37. data/spec/motion-html-pipeline/pipeline/image_max_width_filter_spec.rb +57 -0
  38. data/spec/motion-html-pipeline/pipeline_spec.rb +80 -0
  39. data/spec/spec_helper.rb +48 -0
  40. metadata +147 -0
@@ -0,0 +1,52 @@
1
+ describe 'MotionHTMLPipeline::Pipeline::HttpsFilter' do
2
+ HttpsFilter = MotionHTMLPipeline::Pipeline::HttpsFilter
3
+
4
+ def filter(html)
5
+ HttpsFilter.to_html(html, @options)
6
+ end
7
+
8
+ before do
9
+ @options = { base_url: 'http://github.com' }
10
+ end
11
+
12
+ it 'test_http' do
13
+ expect(%(<a href="https://github.com">github.com</a>))
14
+ .to eq filter(%(<a href="http://github.com">github.com</a>))
15
+ end
16
+
17
+ it 'test_https' do
18
+ expect(%(<a href="https://github.com">github.com</a>))
19
+ .to eq filter(%(<a href="https://github.com">github.com</a>))
20
+ end
21
+
22
+ it 'test_subdomain' do
23
+ expect(%(<a href="http://help.github.com">github.com</a>))
24
+ .to eq filter(%(<a href="http://help.github.com">github.com</a>))
25
+ end
26
+
27
+ it 'test_other' do
28
+ expect(%(<a href="http://github.io">github.io</a>))
29
+ .to eq filter(%(<a href="http://github.io">github.io</a>))
30
+ end
31
+
32
+ it 'test_uses_http_url_over_base_url' do
33
+ @options = { http_url: 'http://github.com', base_url: 'https://github.com' }
34
+
35
+ expect(%(<a href="https://github.com">github.com</a>))
36
+ .to eq filter(%(<a href="http://github.com">github.com</a>))
37
+ end
38
+
39
+ it 'test_only_http_url' do
40
+ @options = { http_url: 'http://github.com' }
41
+
42
+ expect(%(<a href="https://github.com">github.com</a>))
43
+ .to eq filter(%(<a href="http://github.com">github.com</a>))
44
+ end
45
+
46
+ it 'test_validates_http_url' do
47
+ @options.clear
48
+
49
+ expect{ filter('') }
50
+ .to raise_error(ArgumentError, 'MotionHTMLPipeline::Pipeline::HttpsFilter: :http_url')
51
+ end
52
+ end
@@ -0,0 +1,37 @@
1
+ describe 'MotionHTMLPipeline::Pipeline::ImageFilterTest' do
2
+ ImageFilter = MotionHTMLPipeline::Pipeline::ImageFilter
3
+
4
+ def filter(html)
5
+ ImageFilter.to_html(html)
6
+ end
7
+
8
+ it 'test_jpg' do
9
+ expect(%(<img src="http://example.com/test.jpg" alt=""/>))
10
+ .to eq filter(%(http://example.com/test.jpg))
11
+ end
12
+
13
+ it 'test_jpeg' do
14
+ expect(%(<img src="http://example.com/test.jpeg" alt=""/>))
15
+ .to eq filter(%(http://example.com/test.jpeg))
16
+ end
17
+
18
+ it 'test_bmp' do
19
+ expect(%(<img src="http://example.com/test.bmp" alt=""/>))
20
+ .to eq filter(%(http://example.com/test.bmp))
21
+ end
22
+
23
+ it 'test_gif' do
24
+ expect(%(<img src="http://example.com/test.gif" alt=""/>))
25
+ .to eq filter(%(http://example.com/test.gif))
26
+ end
27
+
28
+ it 'test_png' do
29
+ expect(%(<img src="http://example.com/test.png" alt=""/>))
30
+ .to eq filter(%(http://example.com/test.png))
31
+ end
32
+
33
+ it 'test_https_url' do
34
+ expect(%(<img src="https://example.com/test.png" alt=""/>))
35
+ .to eq filter(%(https://example.com/test.png))
36
+ end
37
+ end
@@ -0,0 +1,57 @@
1
+ describe 'MotionHTMLPipeline::Pipeline::ImageMaxWidthFilterTest' do
2
+ def filter(html)
3
+ MotionHTMLPipeline::Pipeline::ImageMaxWidthFilter.call(html)
4
+ end
5
+
6
+ def parse(html)
7
+ MotionHTMLPipeline::DocumentFragment.parse(html)
8
+ end
9
+
10
+ it 'test_rewrites_image_style_tags' do
11
+ body = "<p>Screenshot: <img src='screenshot.png'></p>"
12
+ doc = parse(body)
13
+
14
+ res = filter(doc)
15
+
16
+ expect('<p>Screenshot: <a href="screenshot.png" target="_blank"><img src="screenshot.png" style="max-width:100%;"></a></p>')
17
+ .to eq res.to_html
18
+ end
19
+
20
+ it 'test_leaves_existing_image_style_tags_alone' do
21
+ body = "<p><img src='screenshot.png' style='width:100px;'></p>"
22
+ doc = parse(body)
23
+
24
+ res = filter(doc)
25
+
26
+ expect('<p><img src="screenshot.png" style="width:100px;"></p>')
27
+ .to eq res.to_html
28
+ end
29
+
30
+ it 'test_links_to_image' do
31
+ body = "<p>Screenshot: <img src='screenshot.png'></p>"
32
+ doc = parse(body)
33
+
34
+ res = filter(doc)
35
+
36
+ expect('<p>Screenshot: <a href="screenshot.png" target="_blank"><img src="screenshot.png" style="max-width:100%;"></a></p>')
37
+ .to eq res.to_html
38
+ end
39
+
40
+ it 'test_doesnt_link_to_image_when_already_linked' do
41
+ body = "<p>Screenshot: <a href='blah.png'><img src='screenshot.png'></a></p>"
42
+ doc = parse(body)
43
+
44
+ res = filter(doc)
45
+
46
+ expect('<p>Screenshot: <a href="blah.png"><img src="screenshot.png" style="max-width:100%;"></a></p>')
47
+ .to eq res.to_html
48
+ end
49
+
50
+ it 'test_doesnt_screw_up_inlined_images' do
51
+ body = "<p>Screenshot <img src='screenshot.png'>, yes, this is a <b>screenshot</b> indeed.</p>"
52
+ doc = parse(body)
53
+
54
+ expect('<p>Screenshot <a href="screenshot.png" target="_blank"><img src="screenshot.png" style="max-width:100%;"></a>, yes, this is a <b>screenshot</b> indeed.</p>')
55
+ .to eq filter(doc).to_html
56
+ end
57
+ end
@@ -0,0 +1,80 @@
1
+ describe 'MotionHTMLPipeline::PipelineTest' do
2
+ Pipeline = MotionHTMLPipeline::Pipeline
3
+
4
+ class TestFilter
5
+ def self.call(input, _context, _result)
6
+ input.reverse
7
+ end
8
+ end
9
+
10
+ before do
11
+ @context = {}
12
+ @result_class = Hash
13
+ @pipeline = Pipeline.new [TestFilter], @context, @result_class
14
+ end
15
+
16
+ it 'works' do
17
+ expect(true).to be_true
18
+ end
19
+
20
+ it 'test_filter_instrumentation' do
21
+ service = MockedInstrumentationService.new
22
+ events = service.subscribe 'call_filter.html_pipeline'
23
+ @pipeline.instrumentation_service = service
24
+ filter(body = 'hello')
25
+ event, payload, res = events.pop
26
+
27
+ expect(event).not_to be_nil
28
+ expect('call_filter.html_pipeline').to eq event
29
+ expect(TestFilter.name).to eq payload[:filter]
30
+ expect(@pipeline.class.name).to eq payload[:pipeline]
31
+ expect(body.reverse).to eq payload[:result][:output]
32
+ end
33
+
34
+ it 'test_pipeline_instrumentation' do
35
+ service = MockedInstrumentationService.new
36
+ events = service.subscribe 'call_pipeline.html_pipeline'
37
+ @pipeline.instrumentation_service = service
38
+ filter(body = 'hello')
39
+ event, payload, res = events.pop
40
+
41
+ expect(event).not_to be_nil
42
+ expect('call_pipeline.html_pipeline').to eq event
43
+ expect(@pipeline.filters.map(&:name)).to eq payload[:filters]
44
+ expect(@pipeline.class.name).to eq payload[:pipeline]
45
+ expect(body.reverse).to eq payload[:result][:output]
46
+ end
47
+
48
+ it 'test_default_instrumentation_service' do
49
+ service = 'default'
50
+ Pipeline.default_instrumentation_service = service
51
+ pipeline = Pipeline.new [], @context, @result_class
52
+
53
+ expect(service).to eq pipeline.instrumentation_service
54
+
55
+ Pipeline.default_instrumentation_service = nil
56
+ end
57
+
58
+ it 'test_setup_instrumentation' do
59
+ expect(@pipeline.instrumentation_service).to be_nil
60
+
61
+ service = MockedInstrumentationService.new
62
+ events = service.subscribe 'call_pipeline.html_pipeline'
63
+ @pipeline.setup_instrumentation name = 'foo', service
64
+
65
+ expect(service).to eq @pipeline.instrumentation_service
66
+ expect(name).to eq @pipeline.instrumentation_name
67
+
68
+ filter(body = 'foo')
69
+
70
+ event, payload, res = events.pop
71
+
72
+ expect(event).not_to be_nil
73
+ expect(name).to eq payload[:pipeline]
74
+ expect(body.reverse).to eq payload[:result][:output]
75
+ end
76
+
77
+ def filter(input)
78
+ @pipeline.call(input)
79
+ end
80
+ end
@@ -0,0 +1,48 @@
1
+ # Add following abilities
2
+ #
3
+ # rake spec filter="name of spec" # To filter by spec name
4
+ # rake spec files=foo_spec filter="name of spec"
5
+ # rake spec filter_context="this doesn't work yet" # To filter by context name (doesn't work until MacBacon implements it)
6
+ # rake spec hide_backtraces=yes # Hide backtraces
7
+
8
+
9
+ # From http://chen.do/blog/2013/06/03/running-individual-specs-with-rubymotion/
10
+ #------------------------------------------------------------------------------
11
+ def silence_warnings(&block)
12
+ warn_level = $VERBOSE
13
+ $VERBOSE = nil
14
+ begin
15
+ result = block.call
16
+ ensure
17
+ $VERBOSE = warn_level
18
+ end
19
+ result
20
+ end
21
+
22
+ silence_warnings do
23
+ module Bacon
24
+ if ENV['filter']
25
+ $stderr.puts "Filtering specs that match: #{ENV['filter']}"
26
+ RestrictName = Regexp.new(ENV['filter'])
27
+ end
28
+
29
+ if ENV['filter_context']
30
+ $stderr.puts "Filtering contexts that match: #{ENV['filter_context']}"
31
+ RestrictContext = Regexp.new(ENV['filter_context'])
32
+ end
33
+
34
+ Backtraces = false if ENV['hide_backtraces']
35
+ end
36
+ end
37
+
38
+ #------------------------------------------------------------------------------
39
+ # TODO total hack - without this, the `bacon-expect` gem doesn't get used, and
40
+ # on iOS I get errors like
41
+ # *** Terminating app due to uncaught exception 'NameError', reason: '.../bacon-expect/lib/bacon-expect/matchers/eql.rb:2:in `<main>: uninitialized constant BaconExpect::Matcher::SingleMethod (NameError)
42
+ # and on macOS it only show up as `*nil description*`
43
+ module BaconExpect
44
+ module Matcher
45
+ class SingleMethod
46
+ end
47
+ end
48
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: motion-html-pipeline
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Tomayko
8
+ - Jerry Cheung
9
+ - Garen J. Torikian
10
+ - Brett Walker
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2019-07-07 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: motion-cocoapods
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ - !ruby/object:Gem::Dependency
45
+ name: motion-expect
46
+ requirement: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - "~>"
49
+ - !ruby/object:Gem::Version
50
+ version: '2.0'
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '2.0'
58
+ description: GitHub HTML processing filters and utilities (RubyMotion version)
59
+ email:
60
+ - ryan@github.com
61
+ - jerry@github.com
62
+ - gjtorikian@gmail.com
63
+ - github@digitalmoksha.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - README.md
69
+ - lib/motion-html-pipeline.rb
70
+ - lib/motion-html-pipeline/document_fragment.rb
71
+ - lib/motion-html-pipeline/pipeline.rb
72
+ - lib/motion-html-pipeline/pipeline/absolute_source_filter.rb
73
+ - lib/motion-html-pipeline/pipeline/body_content.rb
74
+ - lib/motion-html-pipeline/pipeline/disabled/@mention_filter.rb
75
+ - lib/motion-html-pipeline/pipeline/disabled/autolink_filter.rb
76
+ - lib/motion-html-pipeline/pipeline/disabled/camo_filter.rb
77
+ - lib/motion-html-pipeline/pipeline/disabled/email_reply_filter.rb
78
+ - lib/motion-html-pipeline/pipeline/disabled/emoji_filter.rb
79
+ - lib/motion-html-pipeline/pipeline/disabled/markdown_filter.rb
80
+ - lib/motion-html-pipeline/pipeline/disabled/plain_text_input_filter.rb
81
+ - lib/motion-html-pipeline/pipeline/disabled/sanitization_filter.rb
82
+ - lib/motion-html-pipeline/pipeline/disabled/syntax_highlight_filter.rb
83
+ - lib/motion-html-pipeline/pipeline/disabled/toc_filter.rb
84
+ - lib/motion-html-pipeline/pipeline/filter.rb
85
+ - lib/motion-html-pipeline/pipeline/https_filter.rb
86
+ - lib/motion-html-pipeline/pipeline/image_filter.rb
87
+ - lib/motion-html-pipeline/pipeline/image_max_width_filter.rb
88
+ - lib/motion-html-pipeline/pipeline/text_filter.rb
89
+ - lib/motion-html-pipeline/pipeline/version.rb
90
+ - spec/motion-html-pipeline/_helpers/mock_instumentation_service.rb
91
+ - spec/motion-html-pipeline/pipeline/absolute_source_filter_spec.rb
92
+ - spec/motion-html-pipeline/pipeline/disabled/auto_link_filter_spec.rb
93
+ - spec/motion-html-pipeline/pipeline/disabled/camo_filter_spec.rb
94
+ - spec/motion-html-pipeline/pipeline/disabled/email_reply_filter_spec.rb
95
+ - spec/motion-html-pipeline/pipeline/disabled/emoji_filter_spec.rb
96
+ - spec/motion-html-pipeline/pipeline/disabled/markdown_filter_spec.rb
97
+ - spec/motion-html-pipeline/pipeline/disabled/plain_text_input_filter_spec.rb
98
+ - spec/motion-html-pipeline/pipeline/disabled/sanitization_filter_spec.rb
99
+ - spec/motion-html-pipeline/pipeline/disabled/syntax_highlighting_filter_spec.rb
100
+ - spec/motion-html-pipeline/pipeline/disabled/toc_filter_spec.rb
101
+ - spec/motion-html-pipeline/pipeline/https_filter_spec.rb
102
+ - spec/motion-html-pipeline/pipeline/image_filter_spec.rb
103
+ - spec/motion-html-pipeline/pipeline/image_max_width_filter_spec.rb
104
+ - spec/motion-html-pipeline/pipeline_spec.rb
105
+ - spec/spec_helper.rb
106
+ homepage: https://github.com/digitalmoksha/motion-html-pipeline
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.7.6
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Helpers for processing content through a chain of filters (RubyMotion version,
130
+ ported from https://github.com/jch/html-pipeline)
131
+ test_files:
132
+ - spec/spec_helper.rb
133
+ - spec/motion-html-pipeline/pipeline/image_max_width_filter_spec.rb
134
+ - spec/motion-html-pipeline/pipeline/image_filter_spec.rb
135
+ - spec/motion-html-pipeline/pipeline/absolute_source_filter_spec.rb
136
+ - spec/motion-html-pipeline/pipeline/https_filter_spec.rb
137
+ - spec/motion-html-pipeline/pipeline/disabled/camo_filter_spec.rb
138
+ - spec/motion-html-pipeline/pipeline/disabled/emoji_filter_spec.rb
139
+ - spec/motion-html-pipeline/pipeline/disabled/email_reply_filter_spec.rb
140
+ - spec/motion-html-pipeline/pipeline/disabled/toc_filter_spec.rb
141
+ - spec/motion-html-pipeline/pipeline/disabled/sanitization_filter_spec.rb
142
+ - spec/motion-html-pipeline/pipeline/disabled/syntax_highlighting_filter_spec.rb
143
+ - spec/motion-html-pipeline/pipeline/disabled/markdown_filter_spec.rb
144
+ - spec/motion-html-pipeline/pipeline/disabled/auto_link_filter_spec.rb
145
+ - spec/motion-html-pipeline/pipeline/disabled/plain_text_input_filter_spec.rb
146
+ - spec/motion-html-pipeline/_helpers/mock_instumentation_service.rb
147
+ - spec/motion-html-pipeline/pipeline_spec.rb