slackdown 0.1.0 → 0.2.0

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: 0d49f22b8415c9c1a5ec398e77946869bd33c05b
4
- data.tar.gz: 4d5c1138a3c6fc11cfab331da83b9ec6eef5b179
3
+ metadata.gz: 499a5d5c98091cf1fb577d6591bec17e43e53572
4
+ data.tar.gz: 426aa1d4a1b48092407c02dd4455b8fb86bd7add
5
5
  SHA512:
6
- metadata.gz: f532e9fe55ba4de25809ae3d4647ba6bf63b098695adddae8a883ac97dd74f28c1de8bf49bd1d904ebe4d42168eb035bab513a2fb992fee4b140770dcb767586
7
- data.tar.gz: e42f6d301fe0fd57f92ec838ab334c31b03d067ba3967ef9e1cc63e564864f9702f4c192005346ae77f6ff51ea63891847c5ca7dc3aff43bfbac1e5298140053
6
+ metadata.gz: 10543ed1151084a83cab220a941cd47431b84abe8b3a1a23f67d249b9b858ba1aed870686e89fd2c868c82dabd49e3d07c881aadf195eeeb16f087495c83c8bb
7
+ data.tar.gz: 4190b88e6ec41752821920143262048fd59c4459d017b29ae8fc56049e74bb067cd48808268103d566466b54e47a90b153da8c91613773b7028991110857cbea
data/README.md CHANGED
@@ -1,28 +1,26 @@
1
1
  # Slackdown
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/slackdown`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Slackdown converts Markdown to [Slack's simpler markup syntax](https://get.slack.help/hc/en-us/articles/202288908-How-can-I-add-formatting-to-my-messages-).
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ Slackdown implements a converter for [kramdown](https://github.com/gettalong/kramdown).
6
6
 
7
- ## Installation
8
7
 
9
- Add this line to your application's Gemfile:
8
+ ## Usage
10
9
 
11
10
  ```ruby
12
- gem 'slackdown'
13
- ```
14
-
15
- And then execute:
11
+ require "slackdown"
16
12
 
17
- $ bundle
13
+ Slackdown.convert(markdown_text)
14
+ ```
18
15
 
19
- Or install it yourself as:
16
+ If you're familiar with Kramdown, you can also do:
20
17
 
21
- $ gem install slackdown
18
+ ```ruby
19
+ require "kramdown/converter/slack"
22
20
 
23
- ## Usage
21
+ Kramdown::Document.new(markdown_text, options).to_slack
22
+ ```
24
23
 
25
- TODO: Write usage instructions here
26
24
 
27
25
  ## Development
28
26
 
@@ -30,12 +28,12 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
30
28
 
31
29
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
30
 
31
+
33
32
  ## Contributing
34
33
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/slackdown.
34
+ Bug reports and pull requests are welcome on GitHub at https://github.com/houston/slackdown.
36
35
 
37
36
 
38
37
  ## License
39
38
 
40
39
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
-
@@ -0,0 +1,183 @@
1
+ module Kramdown
2
+ module Converter
3
+
4
+ # Converts a Kramdown::Document to Slack.
5
+ # https://api.slack.com/docs/message-formatting
6
+ class Slack < Base
7
+
8
+ def convert(el)
9
+ if el.type == :html_element
10
+ converter = :"convert_html_#{el.value}"
11
+ converter = :convert_html_element unless respond_to? converter
12
+ else
13
+ converter = :"convert_#{el.type}"
14
+ end
15
+ send(converter, el)
16
+ end
17
+
18
+ def inner(el)
19
+ el.children.map { |el| convert(el) }.join
20
+ end
21
+ alias :convert_root :inner
22
+
23
+ def convert_p(el)
24
+ "#{inner(el).strip.gsub(/\n/, " ")}\n\n"
25
+ end
26
+
27
+ def convert_text(el)
28
+ el.value
29
+ end
30
+ alias :convert_abbreviation :convert_text
31
+
32
+ def convert_blank(el)
33
+ ""
34
+ end
35
+ alias :convert_br :convert_blank
36
+ alias :convert_comment :convert_blank
37
+
38
+ def convert_html_br(el)
39
+ "\n"
40
+ end
41
+
42
+ def convert_strong(el)
43
+ "*#{inner(el)}*"
44
+ end
45
+ alias :convert_html_b :convert_strong
46
+ alias :convert_html_strong :convert_strong
47
+
48
+ def convert_em(el)
49
+ "_#{inner(el)}_"
50
+ end
51
+ alias :convert_html_i :convert_em
52
+ alias :convert_html_em :convert_em
53
+
54
+ def convert_del(el)
55
+ "~#{inner(el)}~"
56
+ end
57
+ alias :convert_html_del :convert_del
58
+
59
+ def convert_codespan(el)
60
+ "`#{el.value}`"
61
+ end
62
+ alias :convert_html_code :convert_codespan
63
+
64
+ def convert_blockquote(el)
65
+ "> #{inner(el)}"
66
+ end
67
+
68
+ def convert_codeblock(el)
69
+ "```\n#{el.value}```"
70
+ end
71
+
72
+ def convert_a(el)
73
+ el.attr["href"]
74
+ end
75
+ alias :convert_html_a :convert_a
76
+
77
+ def convert_img(el)
78
+ el.attr["src"]
79
+ end
80
+ alias :convert_html_img :convert_img
81
+
82
+ def convert_ul(el)
83
+ @bullet = UlBulletGenerator.new
84
+ "#{inner(el)}\n"
85
+ end
86
+ alias :convert_html_ul :convert_ul
87
+
88
+ def convert_ol(el)
89
+ @bullet = OlBulletGenerator.new
90
+ "#{inner(el)}\n"
91
+ end
92
+ alias :convert_html_ol :convert_ol
93
+
94
+ def convert_li(el)
95
+ " #{bullet.next} #{inner(el).strip}\n"
96
+ end
97
+ alias :convert_html_li :convert_li
98
+
99
+ def convert_header(el)
100
+ "\n\n#{convert_strong(el)}\n"
101
+ end
102
+ alias :convert_html_h1 :convert_header
103
+ alias :convert_html_h2 :convert_header
104
+ alias :convert_html_h3 :convert_header
105
+ alias :convert_html_h4 :convert_header
106
+ alias :convert_html_h5 :convert_header
107
+ alias :convert_html_h6 :convert_header
108
+
109
+ def convert_hr(el)
110
+ "----------------------------------------------\n\n"
111
+ end
112
+
113
+ def convert_smart_quote(el)
114
+ SMART_QUOTES.fetch(el.value)
115
+ end
116
+
117
+ def convert_typographic_sym(el)
118
+ TYPOGRAPHIC_SYMBOLS.fetch(el.value)
119
+ end
120
+
121
+ def convert_entity(el)
122
+ ENTITIES.fetch(el.options[:original])
123
+ end
124
+
125
+
126
+
127
+ def __convert_todo(el)
128
+ inner(el)
129
+ end
130
+ alias :convert_html_element :__convert_todo
131
+
132
+ # The following are all tags converted by Kramdown::Converter::Html
133
+ alias :convert_dd :__convert_todo
134
+ alias :convert_dl :__convert_todo
135
+ alias :convert_dt :__convert_todo
136
+ alias :convert_footnote :__convert_todo
137
+ alias :convert_math :__convert_todo
138
+ alias :convert_raw :__convert_todo
139
+ alias :convert_table :__convert_todo
140
+ alias :convert_tbody :__convert_todo
141
+ alias :convert_td :__convert_todo
142
+ alias :convert_tfoot :__convert_todo
143
+ alias :convert_thead :__convert_todo
144
+ alias :convert_tr :__convert_todo
145
+ alias :convert_xml_comment :__convert_todo
146
+ alias :convert_xml_pi :__convert_todo
147
+
148
+ private
149
+ attr_reader :bullet
150
+
151
+ class UlBulletGenerator
152
+ def next; "• "; end
153
+ end
154
+
155
+ class OlBulletGenerator
156
+ def initialize; @i = 0; end
157
+ def next; "#{@i += 1}."; end
158
+ end
159
+
160
+ SMART_QUOTES = {
161
+ lsquo: "‘",
162
+ rsquo: "’",
163
+ ldquo: "“",
164
+ rdquo: "”" }.freeze
165
+
166
+ TYPOGRAPHIC_SYMBOLS = {
167
+ mdash: "—",
168
+ ndash: "–",
169
+ hellip: "...",
170
+ laquo_space: "« ",
171
+ raquo_space: " »",
172
+ laquo: "«",
173
+ raquo: "»" }.freeze
174
+
175
+ ENTITIES = {
176
+ "&lt;" => "<",
177
+ "&gt;" => ">",
178
+ "&amp;" => "&",
179
+ "&quot;" => "\"" }.freeze
180
+
181
+ end
182
+ end
183
+ end
data/lib/slackdown.rb CHANGED
@@ -1,5 +1,11 @@
1
1
  require "slackdown/version"
2
+ require "kramdown"
3
+ require "kramdown/converter/slack"
2
4
 
3
5
  module Slackdown
4
- # Your code goes here...
6
+
7
+ def self.convert(markdown, options={})
8
+ Kramdown::Document.new(markdown, options).to_slack
9
+ end
10
+
5
11
  end
@@ -1,3 +1,3 @@
1
1
  module Slackdown
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/slackdown.gemspec CHANGED
@@ -19,7 +19,13 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
+ spec.add_dependency "kramdown", "~> 1.13.2"
23
+
22
24
  spec.add_development_dependency "bundler", "~> 1.11"
23
25
  spec.add_development_dependency "rake", "~> 10.0"
24
26
  spec.add_development_dependency "minitest", "~> 5.0"
27
+ spec.add_development_dependency "minitest-reporters"
28
+ spec.add_development_dependency "minitest-reporters-turn_reporter"
29
+ spec.add_development_dependency "shoulda-context"
30
+ spec.add_development_dependency "pry"
25
31
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slackdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Lail
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-30 00:00:00.000000000 Z
11
+ date: 2017-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: kramdown
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.13.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.13.2
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +66,62 @@ dependencies:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
68
  version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest-reporters
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest-reporters-turn_reporter
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: shoulda-context
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
55
125
  description: A converter for Kramdown that converts GitHub-Flavored Markdown to Slack's
56
126
  simplified Markdown
57
127
  email:
@@ -68,6 +138,7 @@ files:
68
138
  - Rakefile
69
139
  - bin/console
70
140
  - bin/setup
141
+ - lib/kramdown/converter/slack.rb
71
142
  - lib/slackdown.rb
72
143
  - lib/slackdown/version.rb
73
144
  - slackdown.gemspec