slacken 0.1.3 → 0.1.4

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: 748574f85629230126187b4628430c5d8831f491
4
- data.tar.gz: 8dfea56b37ed82aac7597ce7fd33fe3ed87b98dc
3
+ metadata.gz: 2833570db817e35c80edc5c2ec84657903c82a64
4
+ data.tar.gz: 3aa4ed03460af012db8137f15bc321df3426e1da
5
5
  SHA512:
6
- metadata.gz: 4fbccd9ac94194719631dff4cef4d5ed07fecad897b6b55169162a0bb828c5d3b3ab1947595eb223f74d0c8283f4ed91f36ec9f1cca2a42dd7b6b489b9059f60
7
- data.tar.gz: c5f1cf5dca2d0c5fb4cc24055a02a94101e3b46d8ed76652ab0c9605594a0ae1cccf1d95041cef1cc74bc5175291e209ef23bfd4c3dd28716442aa5edec0ad3f
6
+ metadata.gz: 52f1fc76598107f24e40e19aa76efe0fc8caa71ab87b552d6a70db3acbfc275fbd5b056d0add4fe7cd7f08b73aa31cddfc7f440aeb520272b183d7541314a9f9
7
+ data.tar.gz: 7d4884483a55ea08247ce1f586dfd0699ef10179c89f71aeba6e7ac1005f98944a0d6d87da9aaae31d6418a2cd7e55a3dd0ab415ac26470ca6af9dfbfddb3930
data/README.md CHANGED
@@ -7,7 +7,7 @@ Official description of Slack message formatting is [here](https://api.slack.com
7
7
 
8
8
  ## Examples
9
9
 
10
- Sample input source and output texts are in `examples/`.
10
+ The following code translates [a html source](https://github.com/increments/slacken/blob/master/examples/source.html) to [a markup text](https://github.com/increments/slacken/blob/master/examples/out.txt) for Slack
11
11
 
12
12
  ```
13
13
  > require 'slacken'
@@ -15,7 +15,7 @@ Sample input source and output texts are in `examples/`.
15
15
  # *Slacken*
16
16
  #
17
17
  # This gem translates a html source into *a markup text for Slack*.
18
- # <http://qiita.com|Qiita> uses this gem to decorate notification messages to Slack :trollface:.
18
+ # <https://teams.qiita.com|Qiita:Team> uses this gem to decorate notification messages to Slack :trollface:.
19
19
  #
20
20
  # *Examples*
21
21
  #
@@ -32,7 +32,7 @@ Sample input source and output texts are in `examples/`.
32
32
  # *Citation*
33
33
  #
34
34
  # > Qiita is a technical information sharing site for programmers.
35
- # > Kobito is an application for technical information recording.
35
+ # > Kobito is an application for technical information recording.
36
36
  #
37
37
  # *Source Code*
38
38
  #
@@ -43,12 +43,12 @@ Sample input source and output texts are in `examples/`.
43
43
  # end
44
44
  # ```
45
45
  #
46
+ # -----------
47
+ #
46
48
  # *Image*
47
49
  #
48
50
  # This is a Qiita logo.
49
51
  #
50
- # -----------
51
- #
52
52
  # <http://cdn.qiita.com/assets/siteid-reverse-1949e989f9d8b2f6fad65a57292b2b01.png|Qiita logo>
53
53
  ```
54
54
 
@@ -1,7 +1,7 @@
1
1
  *Slacken*
2
2
 
3
3
  This gem translates a html source into *a markup text for Slack*.
4
- <http://qiita.com|Qiita> uses this gem to decorate notification messages to Slack :trollface:.
4
+ <https://teams.qiita.com|Qiita:Team> uses this gem to decorate notification messages to Slack :trollface:.
5
5
 
6
6
  *Examples*
7
7
 
@@ -18,7 +18,7 @@ This gem translates a html source into *a markup text for Slack*.
18
18
  *Citation*
19
19
 
20
20
  > Qiita is a technical information sharing site for programmers.
21
- > Kobito is an application for technical information recording.
21
+ > Kobito is an application for technical information recording.
22
22
 
23
23
  *Source Code*
24
24
 
@@ -29,10 +29,10 @@ This gem translates a html source into *a markup text for Slack*.
29
29
  end
30
30
  ```
31
31
 
32
+ -----------
33
+
32
34
  *Image*
33
35
 
34
36
  This is a Qiita logo.
35
37
 
36
- -----------
37
-
38
38
  <http://cdn.qiita.com/assets/siteid-reverse-1949e989f9d8b2f6fad65a57292b2b01.png|Qiita logo>
@@ -2,7 +2,7 @@
2
2
  <h1>Slacken</h1>
3
3
 
4
4
  <p>This gem translates a html source into <strong>a markup text for Slack</strong>.<br>
5
- <a href="http://qiita.com">Qiita</a> uses this gem to decorate notification messages to Slack <img class="emoji" title=":trollface:" alt=":trollface:" src="https://cdn.qiita.com/emoji/trollface.png" height="20" width="20" align="absmiddle">.</p>
5
+ <a href="https://teams.qiita.com">Qiita:Team</a> uses this gem to decorate notification messages to Slack <img class="emoji" title=":trollface:" alt=":trollface:" src="https://cdn.qiita.com/emoji/trollface.png" height="20" width="20" align="absmiddle">.</p>
6
6
 
7
7
  <h2>Examples</h2>
8
8
 
@@ -46,10 +46,10 @@ Kobito is an application for technical information recording.</p>
46
46
  <span class="k">end</span>
47
47
  </pre></div></div>
48
48
 
49
+ <hr>
50
+
49
51
  <h3>Image</h3>
50
52
 
51
53
  <p>This is a Qiita logo.</p>
52
54
 
53
- <hr>
54
-
55
55
  <p><img src="http://cdn.qiita.com/assets/siteid-reverse-1949e989f9d8b2f6fad65a57292b2b01.png" alt="Qiita logo"></p>
@@ -32,7 +32,7 @@ module Slacken::Filters
32
32
  false
33
33
  when :text, :emoji
34
34
  content = component.attrs[:content]
35
- content.nil? || !content.match(/\A\s*\Z/).nil?
35
+ content.nil? || !content.match(/\A\n*\Z/).nil?
36
36
  else
37
37
  component.children.empty? || component.children.all?(&method(:blank?))
38
38
  end
@@ -1,10 +1,23 @@
1
1
  module Slacken
2
+ # Internal: Contain classes calculating proper spacing to serialize RenderElement.
3
+ #
4
+ # TODO: The class and module names are vague.
5
+ # Give better names to these class and module.
2
6
  module Rendering
3
7
  def self.decorate(str)
4
8
  DecorationWrapper.new(str)
5
9
  end
6
10
 
7
- # Private: A wrapper of string to concat node strings of a document tree.
11
+ # These StringWrapper and DecorationWrapper is to calculate spacing of
12
+ # each RenderElement's string representation.
13
+ #
14
+ # Most formatting expression in Slack messages should have distances from neighbor strings.
15
+ # For example, Slack does not make the following text `*should-be-bold*` bold.
16
+ #
17
+ # previous-string-*should-be-bold*-next-string
18
+ #
19
+
20
+ # Internal: A string which may adjoin previous and next strings.
8
21
  class StringWrapper
9
22
  def self.wrap(str)
10
23
  str.kind_of?(StringWrapper) ? str : new(str)
@@ -18,18 +31,18 @@ module Slacken
18
31
  @str.to_s
19
32
  end
20
33
 
21
- # Public: Append another string to self.
34
+ # Internal: Append another string to self.
22
35
  def append(other)
23
36
  other.concat_head(self)
24
37
  end
25
38
 
26
- # Private: prepend another string to self.
39
+ # Internal: prepend another string to self.
27
40
  def concat_head(other)
28
41
  StringWrapper.new(other.to_s + to_s)
29
42
  end
30
43
  end
31
44
 
32
- # Private: A wrapper to space before and after the given string.
45
+ # Internal: A string which should put distances from previous and next strings.
33
46
  class DecorationWrapper < StringWrapper
34
47
 
35
48
  # Public: Append another string to self.
@@ -59,7 +72,25 @@ module Slacken
59
72
  end
60
73
  end
61
74
 
62
- # Public: an intermediate object to stringfy RenderElements.
75
+ # These classes represents gruop of strings and they concat their strings with
76
+ # their own separator.
77
+ # They also works with StringWrapper and DecorationWrapper to avoid
78
+ # bad or unnecessary spacing.
79
+ #
80
+ # For example, Slack does not make the following text `* should-be-bold *` bold
81
+ # because there are spaces after the first asterisk and before the last asterisk.
82
+ #
83
+ # * should-be-bold *
84
+ #
85
+ # Besides, for such the formatting expressions, it is unnecessary to put space on
86
+ # the beginning of each new line. Unnecessary spacing does not look good.
87
+ #
88
+ # This is the first line.
89
+ # *This* is the second line.
90
+ # This is the third line.
91
+ #
92
+
93
+ # Internal: an intermediate object to stringfy RenderElements.
63
94
  class RenderingGroup
64
95
  attr_reader :children
65
96
  def initialize(children)
@@ -70,6 +101,7 @@ module Slacken
70
101
  fail NotImplementedError
71
102
  end
72
103
 
104
+ # Internal: Return Array of Strings, where there are separators between each string.
73
105
  def to_a
74
106
  extracted_children = children.map { |c| c.respond_to?(:to_a) ? c.to_a : c }
75
107
  extracted_children.zip(Array.new(children.length, separator)).flatten[0..-2]
@@ -1,3 +1,3 @@
1
1
  module Slacken
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -319,11 +319,11 @@ describe Slacken do
319
319
  end
320
320
  end
321
321
 
322
- context 'when a is given' do
323
- let(:source) { '<p><a href="http://qiita.com">qiita</a></p>' }
322
+ context 'when space-separated links are given' do
323
+ let(:source) { '<p><a href="/alice">@alice</a> <a href="/bob">@bob</a></p>' }
324
324
 
325
- it 'converts to link notation' do
326
- should eq "<http://qiita.com|qiita>"
325
+ it 'preserves the space' do
326
+ should eq "@alice @bob"
327
327
  end
328
328
  end
329
329
 
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.3
4
+ version: 0.1.4
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: 2015-08-17 00:00:00.000000000 Z
12
+ date: 2016-09-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -200,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
200
  version: '0'
201
201
  requirements: []
202
202
  rubyforge_project:
203
- rubygems_version: 2.2.2
203
+ rubygems_version: 2.4.5.1
204
204
  signing_key:
205
205
  specification_version: 4
206
206
  summary: Translate HTML sources to markup texts for slack