slacken 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a8fc3d24b062a5e3aba15a9db41a869fc831631b
4
- data.tar.gz: 0b20ca1fd0b5a57693be55d43a5b1cd7ae46dcfa
3
+ metadata.gz: eff0971741bcd8f34f1a50df9351cd804e485620
4
+ data.tar.gz: 42b10defb2d8676b9f50bf516208562391c054c6
5
5
  SHA512:
6
- metadata.gz: 523fb090a808213aafbd64900dd83f4c7cf13050030fa2de77b0f27e6e0f109199d6b2bd7cb1793992351ae43c0ed8761a6312968b69e154b5cc4015ff8b1ffe
7
- data.tar.gz: 182d9d64e2dc63da8b0eeb2a6aa92fe56c18b3db222fe3ec5a4fdcca423d7a8ccde6964f5986f433bd29da46a7282b39575669bb14a8b6feeac80270b46bb1cc
6
+ metadata.gz: 6dd32be590dbfb6f46c29d0499c858f4274e56c1fdd623f6ee202ebce8c17d59632c1dc7fa3979257bbf1aeb85a51f791bbeb195447e16a8a5ffafaed3b468bd
7
+ data.tar.gz: d5a47134c8b6bea5e35f5fb97dc9c4b6892e6edd5a0da1f186486e6bfa2facf7eda4f0c620e4cebdeea44cc22590c4096db3b68e8e712faa299c44c6ddf83cb9
@@ -9,6 +9,7 @@ module Slacken
9
9
  NORMALIZE_FILTERS = [
10
10
  Filters::StringfyEmoji,
11
11
  Filters::StringfyCheckbox,
12
+ Filters::ReplaceUnsupportedImgs,
12
13
  Filters::ExtractImgAlt,
13
14
  Filters::ElimInvalidLinks,
14
15
  Filters::SanitizeHeadline,
@@ -68,5 +69,13 @@ module Slacken
68
69
  RenderElement.new(type, children.map(&:produce_element), attrs)
69
70
  end
70
71
  end
72
+
73
+ def ==(other)
74
+ other.instance_of?(self.class) &&
75
+ type.name == other.type.name &&
76
+ attrs == other.attrs &&
77
+ marks == other.marks &&
78
+ children == other.children
79
+ end
71
80
  end
72
81
  end
@@ -11,6 +11,7 @@ require 'slacken/filters/elim_line_breaks'
11
11
  require 'slacken/filters/extract_img_alt'
12
12
  require 'slacken/filters/group_inlines'
13
13
  require 'slacken/filters/group_indent'
14
+ require 'slacken/filters/replace_unsupported_imgs'
14
15
  require 'slacken/filters/sanitize_headline'
15
16
  require 'slacken/filters/sanitize_link'
16
17
  require 'slacken/filters/sanitize_list'
@@ -0,0 +1,23 @@
1
+ module Slacken::Filters
2
+ # Public: Replace unsupported images by placeholder.
3
+ class ReplaceUnsupportedImgs < Slacken::Filter
4
+ def call(component)
5
+ if img_with_data_uri?(component)
6
+ component.class.new(
7
+ :text, [], content: '&lt;img src="data:..."&gt;'
8
+ )
9
+ else
10
+ component.derive(
11
+ component.children.map(&method(:call)),
12
+ )
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def img_with_data_uri?(component)
19
+ component.type.member_of?(:img) &&
20
+ (component.attrs[:src] || '') =~ /^data:/i
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module Slacken
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Slacken::Filters::ReplaceUnsupportedImgs, dsl: true do
4
+ describe '#call' do
5
+ subject { described_class.new.call(component) }
6
+
7
+ context 'when a supported img is given' do
8
+ let(:component) do
9
+ c(:img, src: 'http://example.com/example.png')
10
+ end
11
+
12
+ it { is_expected.to eq component }
13
+ end
14
+
15
+ context 'when an unsupported img is given' do
16
+ let(:component) do
17
+ c(:img, src: 'data:image/png;base64,ZXhhbXBsZQo=')
18
+ end
19
+
20
+ let(:placeholder) do
21
+ text('&lt;img src="data:..."&gt;')
22
+ end
23
+
24
+ it { is_expected.to eq placeholder }
25
+ end
26
+
27
+ context 'when a given component is not an img' do
28
+ let(:component) do
29
+ text('text')
30
+ end
31
+
32
+ it { is_expected.to eq component }
33
+ end
34
+ end
35
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slacken
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomoya Chiba
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-10-18 00:00:00.000000000 Z
12
+ date: 2018-06-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -151,6 +151,7 @@ files:
151
151
  - lib/slacken/filters/extract_img_alt.rb
152
152
  - lib/slacken/filters/group_indent.rb
153
153
  - lib/slacken/filters/group_inlines.rb
154
+ - lib/slacken/filters/replace_unsupported_imgs.rb
154
155
  - lib/slacken/filters/sanitize_headline.rb
155
156
  - lib/slacken/filters/sanitize_link.rb
156
157
  - lib/slacken/filters/sanitize_list.rb
@@ -174,6 +175,7 @@ files:
174
175
  - spec/slacken/filters/elim_line_breaks_spec.rb
175
176
  - spec/slacken/filters/group_indent_spec.rb
176
177
  - spec/slacken/filters/group_inlines_spec.rb
178
+ - spec/slacken/filters/replace_unsupported_imgs_spec.rb
177
179
  - spec/slacken/filters/sanitize_headline_spec.rb
178
180
  - spec/slacken/filters/sanitize_link_spec.rb
179
181
  - spec/slacken/filters/sanitize_list_spec.rb
@@ -200,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
202
  version: '0'
201
203
  requirements: []
202
204
  rubyforge_project:
203
- rubygems_version: 2.5.1
205
+ rubygems_version: 2.6.11
204
206
  signing_key:
205
207
  specification_version: 4
206
208
  summary: Translate HTML sources to markup texts for slack
@@ -214,6 +216,7 @@ test_files:
214
216
  - spec/slacken/filters/elim_line_breaks_spec.rb
215
217
  - spec/slacken/filters/group_indent_spec.rb
216
218
  - spec/slacken/filters/group_inlines_spec.rb
219
+ - spec/slacken/filters/replace_unsupported_imgs_spec.rb
217
220
  - spec/slacken/filters/sanitize_headline_spec.rb
218
221
  - spec/slacken/filters/sanitize_link_spec.rb
219
222
  - spec/slacken/filters/sanitize_list_spec.rb