mark_maker 0.5.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 76f4840b445542d5b47ffbe2c24cbace45b7bee2
4
- data.tar.gz: 21963a8d8dbbb87fcdd2fcbf1dc753438dedf243
2
+ SHA256:
3
+ metadata.gz: a641fadb4fb218a1e037fcdcbbad94ea9c1f57cae4b983c80ffc2d761f311ee7
4
+ data.tar.gz: 17d05f4b5604756d270d5dd3cc17fff8253ad613432beaf387871fa6082177b5
5
5
  SHA512:
6
- metadata.gz: 6215987f2defe491353b4a2fdb7d67b65836f0d93054f9c7d21e71e4fc9eddc5a94bf7770d9cce31d4916fabcb88c3d1324f8352c4114c831560e9ae901d1a3a
7
- data.tar.gz: ed59aa1746b2e05038cccfbc361ba386fa09dcd724ef5d13e4c870c85b79655be9bc19dd0fad1663f24e2cfed3ca52fd10439d2869e903a5389fd94ec39d2441
6
+ metadata.gz: fbc4f27993d6ec1fb2fd40fe24fb8df2bf25e1d46aec133bd578d6aabbec4437540d043740edabd1d503691398ea7e349f9ac24582ed7d3899bda6b3a083c698
7
+ data.tar.gz: 7bc3cfd8aab4061b8465494733e4eba269a0f4537a718062f124cdff6235910f7aa045be27370241b2139a4c09113e1aa4574661a63d19bf6cc2a41fa1818bf5
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ /.idea/
@@ -1 +1,2 @@
1
- 2.2.1
1
+ 2.6
2
+
@@ -1,3 +1,6 @@
1
1
  language: ruby
2
+ bundler_args: --without dev_tooling
2
3
  rvm:
3
- - 2.2.0
4
+ - ruby-head
5
+ - 2.6.3
6
+ - 2.3.0
@@ -1,3 +1,21 @@
1
+ 0.9.0
2
+ -----
3
+
4
+ - addressing security vulnerability associated with rake
5
+ - dropping support for ruby 1.x versions
6
+ - now calls for bundler 2
7
+
8
+ 0.8.0
9
+ -----
10
+ - added header 4 thru 6 support
11
+ - fixed a bug in the image generation when using a title
12
+ - noted supported ruby versions in the readme, per travis config
13
+
14
+ 0.7.0
15
+ -----
16
+ - added support for images
17
+ - now support ruby 1.9.3, 2.2.4 and 2.3.0
18
+
1
19
  0.3.0
2
20
  -----
3
21
 
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in mark_maker.gemspec
4
4
  gemspec
5
+
6
+ group :dev_tooling do
7
+ gem 'rubocop'
8
+ end
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ ![MarkMaker build status](https://travis-ci.org/sn1de/mark_maker.svg?branch=master "Build Status")
2
+
1
3
  MarkMaker
2
4
  =========
3
5
 
@@ -56,14 +58,48 @@ bullets, *emphasis*, **strong**, code
56
58
  and basic table markdown. See bin/generate_readme.rb for the code used to generate this
57
59
  document and a sample of all these markdown generators in action.
58
60
 
61
+ Simple markdown generation is handled by extensions to the ruby String class. Headers,
62
+ code, emphasis, and strong are all handled by String methods.
63
+
64
+ Multi line and more complex conversions are handled by a Generator class.
65
+
59
66
  ### Header Example
60
- gen = MarkMaker::Generator.new
61
- gen.header1('Let It Begin'')
62
67
 
63
- Produces
68
+ The following ruby code ...
69
+
70
+ ```ruby
71
+ h = "Let It Begin"
72
+ puts h.header1
73
+ puts h.header2
74
+ puts h.header3
75
+ puts h.header4
76
+ puts h.header5
77
+ puts h.header6
78
+ ```
79
+
80
+ Results in this generated markdown ...
81
+ ```
82
+ Let It Begin
83
+ ============
84
+ Let It Begin
85
+ ------------
86
+ ### Let It Begin
87
+ #### Let It Begin
88
+ ##### Let It Begin
89
+ ###### Let It Begin
90
+ ```
91
+
92
+ Ultimately looking something like this (if your are viewing this on github or through some other markdown viewing method) ...
93
+
94
+ Let It Begin
95
+ ============
96
+ Let It Begin
97
+ ------------
98
+ ### Let It Begin
99
+ #### Let It Begin
100
+ ##### Let It Begin
101
+ ###### Let It Begin
64
102
 
65
- Let It Begin
66
- ============
67
103
 
68
104
  ### Bulleted List Example
69
105
 
@@ -151,14 +187,16 @@ puts total
151
187
 
152
188
  ### Table Example
153
189
 
154
- header, separator = gen.table_header("Col One", "Col Two", "Col Three")
155
- puts header
156
- puts separator
157
- puts gen.table_row("First", "A", "$3.99")
158
- puts gen.table_row("Second", "BC", "$14.00")
159
- puts gen.table_row("Third", "DEFGH", "$1,034.50")
190
+ ```ruby
191
+ header, separator = gen.table_header("Col One", "Col Two", "Col Three")
192
+ puts header
193
+ puts separator
194
+ puts gen.table_row("First", "A", "$3.99")
195
+ puts gen.table_row("Second", "BC", "$14.00")
196
+ puts gen.table_row("Third", "DEFGH", "$1,034.50")
197
+ ```
160
198
 
161
- Produces this terribly ugly markdown ...
199
+ Produces this terribly ugly markdown (but standby, there is a better way below) ...
162
200
 
163
201
  ```
164
202
  |Col One|Col Two|Col Three|
@@ -204,8 +242,7 @@ content = <<-QUOTE
204
242
  If you want to quote, you'll get a quote.
205
243
  Warning, it will just quote line by line, not break it up nicely.
206
244
  QUOTE
207
- puts gen.block_quote(*content.split("
208
- "))
245
+ puts gen.block_quote(*content.lines)
209
246
  ```
210
247
 
211
248
  Produces the markdown ...
@@ -243,3 +280,27 @@ existing README.md
243
280
 
244
281
  I'm calling this Extreme [Readme Driven Development](http://tom.preston-werner.com/2010/08/23/readme-driven-development.html).
245
282
  It's kind of like [Inception](http://en.wikipedia.org/wiki/Inception) ;)
283
+
284
+ Supported Ruby Versions
285
+ -----------------------
286
+
287
+ The following ruby versions are explicitly supported (see .travis.yml)
288
+
289
+ - 2.3.0
290
+ - 2.2.4
291
+ - 1.9.3
292
+ - ruby-head
293
+
294
+ Release Process
295
+ ---------------
296
+
297
+ Document release changes in `CHANGELOG.md`
298
+
299
+ Increment the VERSION number in `lib/mark_maker/version.rb`
300
+
301
+ Run `rake release` which will:
302
+
303
+ - build the gem into the `pkg/` director
304
+ - create a git tag for the version
305
+ - push to github
306
+ - push the packaged gem to rubygems
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'bundler/gem_tasks'
2
2
  require 'rake/testtask'
3
- require 'rubocop/rake_task'
3
+ require 'rubocop/rake_task' unless ENV['CI'] == 'true'
4
4
 
5
5
  Rake::TestTask.new(:test) do |t|
6
6
  t.libs << "test"
@@ -13,12 +13,13 @@ task :console do
13
13
  exec "irb -r mark_maker -I ./lib"
14
14
  end
15
15
 
16
- RuboCop::RakeTask.new(:rubocop) do |task|
17
- task.patterns = ['lib/**/*.rb']
16
+ if ENV['CI'] != 'true'
17
+ RuboCop::RakeTask.new(:rubocop) do |task|
18
+ task.patterns = ['lib/**/*.rb']
19
+ end
18
20
  end
19
21
 
20
22
  desc "generate the readme file for the project programatically using MarkMaker"
21
23
  task :readme do
22
24
  exec "ruby -Ilib bin/generate_readme.rb > README.md"
23
25
  end
24
-
@@ -11,7 +11,7 @@
11
11
  # would be a good way to eat my own dogfood and provide
12
12
  # a solid example.
13
13
  #
14
- # examples. So here goes ... extreme readme driven development!
14
+ # So here goes ... extreme readme driven development!
15
15
 
16
16
  require 'mark_maker'
17
17
 
@@ -25,11 +25,13 @@ ensure
25
25
  end
26
26
 
27
27
  gen = MarkMaker::Generator.new
28
- puts gen.header1("MarkMaker")
28
+ puts gen.image("MarkMaker build status", "https://travis-ci.org/sn1de/mark_maker.svg?branch=master", "Build Status")
29
+ puts ""
30
+ puts "MarkMaker".header1
29
31
  puts ""
30
32
  puts "Programatically generate markdown documents."
31
33
  puts ""
32
- puts gen.header2("Intended Use")
34
+ puts "Intended Use".header2
33
35
  puts ""
34
36
  puts "The mark_maker gem provides a set of methods that take text content and"
35
37
  puts "convert it to various markdown elements. The primary use case is simple"
@@ -37,7 +39,7 @@ puts "conversion of something like a JSON document into a markdown document."
37
39
  puts ""
38
40
  puts "The initial development goal is to provide"
39
41
  puts "support for all of the markdown supported operations, at least in their basic form. What"
40
- puts "I mean by basic is that you provide a 'chunk' of content and the mark_maker #{ gen.code_span('Generator') }"
42
+ puts "I mean by basic is that you provide a 'chunk' of content and the mark_maker #{ 'Generator'.code_span }"
41
43
  puts "will return that content in the corresponding markdown format. For grouped content, variable"
42
44
  puts "parameters will be provided on the method call to allow for things like correctly numbered"
43
45
  puts "bullet lists. Each call to the generator is treated as a separate"
@@ -51,64 +53,85 @@ puts "extended capabilities from expanded syntaxes like GitHub flavored markdown
51
53
  puts "generating non-core markdown will be noted in the documentation for that method."
52
54
  puts ""
53
55
  puts "If all goes well, and it appears anyone is using this gem, then a 2.0 release is"
54
- puts "envisioned that will add a #{ gen.code_span('Document') } class that will provide a"
56
+ puts "envisioned that will add a #{ 'Document'.code_span } class that will provide a"
55
57
  puts "more holistic layer of capabilities. For example, the aformentioned reference style"
56
58
  puts "links would be nice. As would the ability to have an arbitrarily long string broken"
57
59
  puts "down into nicely formatted hard break paragraphs. Same goes for nicely indented multi-line"
58
60
  puts "bullets, etc."
59
61
  puts ""
60
- puts gen.header2("Installation")
62
+ puts "Installation".header2
61
63
  puts ""
62
64
  puts "Add this line to your application's Gemfile:"
63
65
  puts ""
64
- puts gen.code("gem 'mark_maker'")
66
+ puts "gem 'mark_maker'".code
65
67
  puts ""
66
68
  puts "And then execute:"
67
69
  puts ""
68
- puts gen.code("$ bundle")
70
+ puts "$ bundle".code
69
71
  puts ""
70
72
  puts "Or install it yourself as:"
71
73
  puts ""
72
- puts gen.code("$ gem install mark_maker")
74
+ puts "$ gem install mark_maker".code
73
75
  puts ""
74
- puts gen.header2("Usage")
76
+ puts "Usage".header2
75
77
  puts ""
76
78
  puts "MarkMaker provides line oriented conversion of content to markdown elements. It"
77
79
  puts "currently supports first, second and third level headings, links, bullets, numbered"
78
- puts "bullets, #{gen.emphasis('emphasis')}, #{gen.strong('strong')}, code"
80
+ puts "bullets, #{'emphasis'.emphasis}, #{'strong'.strong}, code"
79
81
  puts "and basic table markdown. See #{__FILE__} for the code used to generate this"
80
82
  puts "document and a sample of all these markdown generators in action."
81
83
  puts ""
82
- puts gen.header3("Header Example")
83
- example_header = "Let It Begin"
84
- puts gen.code("gen = MarkMaker::Generator.new")
85
- puts gen.code("gen.header1('#{example_header}'')")
86
- puts "\nProduces\n\n"
87
- gen.header1(example_header).lines.map { |l| puts gen.code(l) }
84
+ puts "Simple markdown generation is handled by extensions to the ruby String class. Headers,"
85
+ puts "code, emphasis, and strong are all handled by String methods."
86
+ puts ""
87
+ puts "Multi line and more complex conversions are handled by a Generator class."
88
+ puts ""
89
+ puts "Header Example".header3
90
+ puts ""
91
+ puts "The following ruby code ..."
92
+ puts ""
93
+ header_code = <<-EOT
94
+ h = "Let It Begin"
95
+ puts h.header1
96
+ puts h.header2
97
+ puts h.header3
98
+ puts h.header4
99
+ puts h.header5
100
+ puts h.header6
101
+ EOT
102
+ puts gen.fenced_code_language('ruby', *header_code.lines)
103
+ puts ""
104
+ puts "Results in this generated markdown ..."
105
+ header_markdown = capture_stdout do
106
+ eval(header_code)
107
+ end
108
+ puts gen.fenced_code_block(*header_markdown.string.lines)
109
+ puts "\nUltimately looking something like this (if your are viewing this on github or through some other markdown viewing method) ...\n\n"
110
+ puts eval(header_code)
88
111
  puts ""
89
- puts gen.header3("Bulleted List Example")
112
+ puts "Bulleted List Example".header3
90
113
  list_content = ['gold', 'silver', 'bronze']
91
114
  puts ""
92
- puts gen.code("list_content = ['gold', 'silver', 'bronze']")
93
- puts gen.code("gen.bullets(*list_content)")
115
+ puts "list_content = ['gold', 'silver', 'bronze']".code
116
+ puts "gen.bullets(*list_content)".code
94
117
  puts "\nProduces\n\n"
95
118
  puts gen.code_block(*gen.bullets(*list_content))
96
119
  puts ""
97
120
  puts "Or a numbered list with..."
98
121
  puts ""
99
122
  numbered_code = "gen.numbers(*list_content)"
100
- puts gen.code(numbered_code)
123
+ puts numbered_code.code
101
124
  puts ""
102
125
  puts "Produces"
103
126
  puts ""
104
127
  puts gen.code_block(*eval(numbered_code))
105
128
  puts ""
106
- puts gen.header3("Code Examples")
129
+ puts "Code Examples".header3
107
130
  puts ""
108
- puts "Standard markdown code blocks and #{gen.code_span('code span')} are supported, as well as github"
131
+ puts "Standard markdown code blocks and #{'code span'.code_span} are supported, as well as github"
109
132
  puts "flavored markdown fenced code blocks."
110
133
  puts ""
111
- sample_block = <<-EOT.split("\n")
134
+ sample_block = <<-EOT.lines.to_a
112
135
  some_code = [ "# add it up",
113
136
  "total = [1, 2, 3, 4].inject do |sum, i|",
114
137
  " sum += i",
@@ -125,7 +148,7 @@ puts ""
125
148
  puts "You can also generate a github flavored markdown fenced code version."
126
149
  fenced_code = "gen.fenced_code_block(*some_code)"
127
150
  puts ""
128
- puts gen.code(fenced_code)
151
+ puts fenced_code.code
129
152
  puts ""
130
153
  puts "Produces"
131
154
  puts ""
@@ -134,7 +157,7 @@ puts ""
134
157
  puts "You can also include a language in a fenced code block."
135
158
  puts ""
136
159
  fenced_code_language = "gen.fenced_code_language('ruby', *some_code)"
137
- puts gen.code(fenced_code_language)
160
+ puts fenced_code_language.code
138
161
  puts ""
139
162
  puts "Produces"
140
163
  puts ""
@@ -144,7 +167,7 @@ puts "Rendering beautifully highlighted code like so, if you are viewing this on
144
167
  puts ""
145
168
  puts eval("#{sample_block.join}\n#{fenced_code_language}")
146
169
  puts ""
147
- puts gen.header3("Table Example")
170
+ puts "Table Example".header3
148
171
  puts ""
149
172
  table_code = <<-EOT
150
173
  header, separator = gen.table_header("Col One", "Col Two", "Col Three")
@@ -154,14 +177,14 @@ table_code = <<-EOT
154
177
  puts gen.table_row("Second", "BC", "$14.00")
155
178
  puts gen.table_row("Third", "DEFGH", "$1,034.50")
156
179
  EOT
157
- puts gen.code_block(*table_code.split("\n"))
180
+ puts gen.fenced_code_language('ruby', *table_code.lines)
158
181
  puts ""
159
- puts "Produces this terribly ugly markdown ..."
182
+ puts "Produces this terribly ugly markdown (but standby, there is a better way below) ..."
160
183
  puts ""
161
184
  table_markdown = capture_stdout do
162
185
  eval(table_code)
163
186
  end
164
- puts gen.fenced_code_block(*table_markdown.string.split("\n"))
187
+ puts gen.fenced_code_block(*table_markdown.string.lines)
165
188
  puts ""
166
189
  puts "Or, you can pass all the rows in at once like so ..."
167
190
  puts ""
@@ -175,40 +198,40 @@ pretty_table_code = <<-EOT
175
198
  ]
176
199
  puts gen.table(*table_data)
177
200
  EOT
178
- puts gen.fenced_code_language('ruby', *pretty_table_code.split("\n"))
201
+ puts gen.fenced_code_language('ruby', *pretty_table_code.lines)
179
202
  puts "And get nicely justified markdown like this ..."
180
203
  pretty_table_markdown = capture_stdout do
181
204
  eval(pretty_table_code)
182
205
  end
183
- puts gen.fenced_code_block(*pretty_table_markdown.string.split("\n"))
206
+ puts gen.fenced_code_block(*pretty_table_markdown.string.lines)
184
207
  puts "Which gives you this stunning HTML table ..."
185
208
  puts ""
186
209
  puts eval(pretty_table_code)
187
210
  puts ""
188
- puts gen.header3("Block Quotes Example")
211
+ puts "Block Quotes Example".header3
189
212
  puts ""
190
213
  block_quote_code = <<-EOT
191
214
  content = <<-QUOTE
192
215
  If you want to quote, you'll get a quote.
193
216
  Warning, it will just quote line by line, not break it up nicely.
194
217
  QUOTE
195
- puts gen.block_quote(*content.split("\n"))
218
+ puts gen.block_quote(*content.lines)
196
219
  EOT
197
- puts gen.fenced_code_block(*block_quote_code.split("\n"))
220
+ puts gen.fenced_code_block(*block_quote_code.lines)
198
221
  puts ""
199
222
  puts "Produces the markdown ..."
200
223
  puts ""
201
224
  block_quote_markdown = capture_stdout do
202
225
  eval(block_quote_code)
203
226
  end
204
- puts gen.fenced_code_block(*block_quote_markdown.string.split("\n"))
227
+ puts gen.fenced_code_block(*block_quote_markdown.string.lines)
205
228
  puts ""
206
229
  puts ""
207
230
  puts "Which looks like this when viewed as HTML..."
208
231
  puts ""
209
232
  puts eval(block_quote_code)
210
233
  puts ""
211
- puts gen.header2("Contributing")
234
+ puts "Contributing".header2
212
235
  puts ""
213
236
  puts gen.numbers(gen.link("Fork it", "https://github.com/sn1de/mark_maker/fork"),
214
237
  "Create your feature branch (`git checkout -b my-new-feature`)",
@@ -216,14 +239,34 @@ puts gen.numbers(gen.link("Fork it", "https://github.com/sn1de/mark_maker/fork")
216
239
  "Push to the branch (`git push origin my-new-feature`)",
217
240
  "Create a new Pull Request")
218
241
  puts ""
219
- puts gen.header2("About This README")
242
+ puts "About This README".header2
220
243
  puts ""
221
244
  puts "This readme document is created using MarkMaker. To modify it, edit the code"
222
245
  puts "in #{__FILE__} and then run the 'readme' rake task to generate and overwrite the"
223
246
  puts "existing README.md"
224
247
  puts ""
225
- puts gen.code("vi #{__FILE__}")
226
- puts gen.code("rake readme")
248
+ puts "vi #{__FILE__}".code
249
+ puts "rake readme".code
227
250
  puts ""
228
251
  puts "I'm calling this Extreme #{gen.link("Readme Driven Development", "http://tom.preston-werner.com/2010/08/23/readme-driven-development.html")}."
229
252
  puts "It's kind of like #{gen.link("Inception", "http://en.wikipedia.org/wiki/Inception")} ;)"
253
+ puts ""
254
+ puts "Supported Ruby Versions".header2
255
+ puts ""
256
+ puts "The following ruby versions are explicitly supported (see .travis.yml)"
257
+ puts ""
258
+ puts gen.bullets("2.3.0", "2.2.4", "1.9.3", "ruby-head")
259
+ puts ""
260
+ puts "Release Process".header2
261
+ puts ""
262
+ puts "Document release changes in `CHANGELOG.md`"
263
+ puts ""
264
+ puts "Increment the VERSION number in `lib/mark_maker/version.rb`"
265
+ puts ""
266
+ puts "Run `rake release` which will:"
267
+ puts ""
268
+ puts gen.bullets("build the gem into the `pkg/` director",
269
+ "create a git tag for the version",
270
+ "push to github",
271
+ "push the packaged gem to rubygems")
272
+
@@ -1,20 +1,9 @@
1
+ require 'mark_maker_string'
2
+
1
3
  module MarkMaker
2
4
  # Generator is the workhorse of the MarkMaker utility. It provides
3
5
  # line by line generation of markdown output.
4
6
  class Generator
5
- def line_for(underscore, content)
6
- underscore * content.size
7
- end
8
-
9
- def line_for_left
10
- end
11
-
12
- def line_for_right
13
- end
14
-
15
- def line_for_center
16
- end
17
-
18
7
  # Justification indicators are a bit of a special case, because the way
19
8
  # they actually work is the colon's proximity to the vertical | bars marking
20
9
  # the table cells. This means that the center justification indicator, for
@@ -42,49 +31,24 @@ module MarkMaker
42
31
  justification?(c) ? '-' : fill
43
32
  end
44
33
 
45
- def header1(title)
46
- "#{title}\n#{line_for('=', title)}"
47
- end
48
-
49
- def header2(title)
50
- "#{title}\n#{line_for('-', title)}"
51
- end
52
-
53
- def header3(title)
54
- "### #{title}"
55
- end
56
-
57
- def bullet(content)
58
- " - #{content}"
59
- end
60
-
61
34
  def bullets(*content)
62
- content.map { |li| bullet(li) }
63
- end
64
-
65
- def number(content, number = 1)
66
- " #{number}. #{content}"
35
+ content.map(&:bullet)
67
36
  end
68
37
 
69
38
  def numbers(*content)
70
- current_number = 0
71
- content.map { |li| number(li, current_number += 1) }
39
+ content.each.with_index(1).map { |l, i| l.number(i) }
72
40
  end
73
41
 
74
42
  def link(label, url)
75
43
  "[#{label}](#{url})"
76
44
  end
77
45
 
78
- def code(content)
79
- " #{content}"
80
- end
81
-
82
- def code_span(content)
83
- "#{CODE_TIC}#{content}#{CODE_TIC}"
46
+ def image(alt, path, title = "")
47
+ %Q(![#{alt}](#{path} "#{title}"))
84
48
  end
85
49
 
86
50
  def code_block(*content)
87
- content.map { |c| code(c) }
51
+ content.map(&:code)
88
52
  end
89
53
 
90
54
  # creates a github flavored markdown fenced code block
@@ -102,14 +66,6 @@ module MarkMaker
102
66
  block << FENCE
103
67
  end
104
68
 
105
- def emphasis(content)
106
- "#{EMPHASIS}#{content}#{EMPHASIS}"
107
- end
108
-
109
- def strong(content)
110
- EMPHASIS * 2 + content + EMPHASIS * 2
111
- end
112
-
113
69
  def table_header(*content)
114
70
  [
115
71
  content.inject("|") { |a, e| a + "#{e}|" },
@@ -189,19 +145,18 @@ module MarkMaker
189
145
  end
190
146
  end
191
147
 
148
+ # split the cell in two and then add the fill character
149
+ # to the end of the first half of the cell to reach the
150
+ # justified width
192
151
  def fill_justify(fill, *content)
193
152
  width = column_width(*content)
194
153
  content.map do |c|
195
- # split the cell in two and then add the fill character
196
- # to the end of the first half of the cell to reach the
197
- # justified width
198
154
  c.insert(c.length / 2, fill * (width - c.length))
199
155
  end
200
156
  end
201
157
 
202
158
  def column_width(*content)
203
- longest = content.reduce { |a, e| a.length > e.length ? a : e }
204
- longest.length
159
+ content.reduce { |a, e| a.length > e.length ? a : e } .length
205
160
  end
206
161
 
207
162
  def centered_margins(width, content)
@@ -1,4 +1,4 @@
1
1
  # version management
2
2
  module MarkMaker
3
- VERSION = "0.5.0"
3
+ VERSION = "0.9.1"
4
4
  end
@@ -0,0 +1,55 @@
1
+
2
+ # adds several basic string to markdown conversion methods
3
+ class String
4
+ def line_for(underscore)
5
+ underscore * size
6
+ end
7
+
8
+ def header1
9
+ "#{self}\n#{line_for('=')}"
10
+ end
11
+
12
+ def header2
13
+ "#{self}\n#{line_for('-')}"
14
+ end
15
+
16
+ def header3
17
+ "### #{self}"
18
+ end
19
+
20
+ def header4
21
+ "#### #{self}"
22
+ end
23
+
24
+ def header5
25
+ "##### #{self}"
26
+ end
27
+
28
+ def header6
29
+ "###### #{self}"
30
+ end
31
+
32
+ def bullet
33
+ " - #{self}"
34
+ end
35
+
36
+ def number(number = 1)
37
+ " #{number}. #{self}"
38
+ end
39
+
40
+ def code
41
+ " #{self}"
42
+ end
43
+
44
+ def code_span
45
+ "#{MarkMaker::CODE_TIC}#{self}#{MarkMaker::CODE_TIC}"
46
+ end
47
+
48
+ def emphasis
49
+ "#{MarkMaker::EMPHASIS}#{self}#{MarkMaker::EMPHASIS}"
50
+ end
51
+
52
+ def strong
53
+ MarkMaker::EMPHASIS * 2 + self + MarkMaker::EMPHASIS * 2
54
+ end
55
+ end
@@ -12,17 +12,18 @@ Gem::Specification.new do |spec|
12
12
  spec.description = %q{Programatically generate markdown documents.}
13
13
  spec.homepage = ""
14
14
  spec.license = "MIT"
15
+ spec.required_ruby_version = '>= 1.9.3'
15
16
 
16
17
  spec.files = `git ls-files -z`.split("\x0")
17
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
20
  spec.require_paths = ["lib"]
20
21
 
21
- spec.add_development_dependency "bundler", "~> 1.7"
22
- spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "bundler", ">= 2"
23
+ spec.add_development_dependency "rake", ">= 12.3.3"
23
24
  spec.add_development_dependency "minitest"
24
25
  spec.add_development_dependency "pry"
25
- spec.add_development_dependency "rubocop"
26
- spec.add_development_dependency "activesupport"
26
+ spec.add_development_dependency "unindent"
27
27
  spec.add_development_dependency "simplecov"
28
+ spec.add_development_dependency "minitest-reporters", '~> 1.1', '>= 1.1.8'
28
29
  end
@@ -1,4 +1,6 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
2
  require 'mark_maker'
3
- require 'active_support/core_ext/string'
3
+ require 'mark_maker_string'
4
4
  require 'minitest/autorun'
5
+ require 'minitest/reporters'
6
+ Minitest::Reporters.use! Minitest::Reporters::DefaultReporter.new
@@ -0,0 +1,47 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'minitest_helper'
5
+
6
+ class TestHeaders < Minitest::Test
7
+ def test_header1_generation
8
+ title = "abc123"
9
+ markup = title.header1
10
+ assert_match(/^={#{title.size}}$/, markup)
11
+ assert_match(/^#{title}$/, markup)
12
+ assert_match(/^#{title}\n={#{title.size}}$/, markup)
13
+ end
14
+
15
+ def test_header2_generation
16
+ title = "abc123"
17
+ markup = title.header2
18
+ assert_match(/^-{#{title.size}}$/, markup)
19
+ assert_match(/^#{title}$/, markup)
20
+ assert_match(/^#{title}\n-{#{title.size}}$/, markup)
21
+ end
22
+
23
+ def test_header3_generation
24
+ title = "abc123"
25
+ markup = title.header3
26
+ assert_match(/###\s#{title}/, markup)
27
+ end
28
+
29
+ def test_header4_generation
30
+ title = "abc123"
31
+ markup = title.header4
32
+ assert_match(/####\s#{title}/, markup)
33
+ end
34
+
35
+ def test_header5_generation
36
+ title = "abc123"
37
+ markup = title.header5
38
+ assert_match(/#####\s#{title}/, markup)
39
+ end
40
+
41
+ def test_header6_generation
42
+ title = "abc123"
43
+ markup = title.header6
44
+ assert_match(/######\s#{title}/, markup)
45
+ end
46
+
47
+ end
@@ -1,3 +1,4 @@
1
+ require 'unindent'
1
2
  require 'simplecov'
2
3
  SimpleCov.start
3
4
 
@@ -8,38 +9,6 @@ class TestMarkMaker < Minitest::Test
8
9
  refute_nil ::MarkMaker::VERSION
9
10
  end
10
11
 
11
- def test_header1_generation
12
- title = "abc123"
13
- gen = MarkMaker::Generator.new
14
- markup = gen.header1(title)
15
- assert_match(/^={#{title.size}}$/, markup)
16
- assert_match(/^#{title}$/, markup)
17
- assert_match(/^#{title}\n={#{title.size}}$/, markup)
18
- end
19
-
20
- def test_header2_generation
21
- title = "abc123"
22
- gen = MarkMaker::Generator.new
23
- markup = gen.header2(title)
24
- assert_match(/^-{#{title.size}}$/, markup)
25
- assert_match(/^#{title}$/, markup)
26
- assert_match(/^#{title}\n-{#{title.size}}$/, markup)
27
- end
28
-
29
- def test_header3_generation
30
- title = "abc123"
31
- gen = MarkMaker::Generator.new
32
- markup = gen.header3(title)
33
- assert_match(/###\s#{title}/, markup)
34
- end
35
-
36
- def test_bullet_generation
37
- content = "This is a bullet"
38
- gen = MarkMaker::Generator.new
39
- markup = gen.bullet(content)
40
- assert_match(/^ - #{content}$/, markup)
41
- end
42
-
43
12
  def test_bulleted_list_generation
44
13
  content = ["gold", "silver", "bronze"]
45
14
  gen = MarkMaker::Generator.new
@@ -49,12 +18,6 @@ class TestMarkMaker < Minitest::Test
49
18
  assert_match(/^\s-\s#{c}$/, m)
50
19
  end
51
20
  end
52
- def test_number_generation
53
- content = "Number this line"
54
- gen = MarkMaker::Generator.new
55
- markup = gen.number(content)
56
- assert_match(/^\s\d\.\s#{content}$/, markup)
57
- end
58
21
 
59
22
  def test_numbered_list_generation
60
23
  content = ["1", "2", "3"]
@@ -74,17 +37,13 @@ class TestMarkMaker < Minitest::Test
74
37
  assert_match(/^\[#{label}\]\(#{url}\)$/, markup)
75
38
  end
76
39
 
77
- def test_code_generation
78
- content = "var = code()"
40
+ def test_image_generation
41
+ path = "https://travis-ci.org/sn1de/mark_maker.svg?branch=master"
42
+ alt = "Mark Maker build status from Travis continuous integration"
43
+ title = "Build Status"
79
44
  gen = MarkMaker::Generator.new
80
- markup = gen.code(content)
81
- assert_match(/\s{4}var = code\(\)$/, markup)
82
- end
83
-
84
- def test_code_span_generation
85
- gen = MarkMaker::Generator.new
86
- markup = "Some #{gen.code_span('a = b + c')} here."
87
- assert_match(/^Some #{MarkMaker::CODE_TIC}a = b \+ c#{MarkMaker::CODE_TIC} here.$/, markup)
45
+ markup = gen.image(alt, path, title)
46
+ assert_match(/^!\[#{Regexp.quote(alt)}\]\(#{Regexp.quote(path)}\s"#{Regexp.quote(title)}"\)/, markup)
88
47
  end
89
48
 
90
49
  def test_code_block_generation
@@ -118,20 +77,6 @@ class TestMarkMaker < Minitest::Test
118
77
  assert(markup.last == MarkMaker::FENCE, "Markup should end with the code fence.")
119
78
  end
120
79
 
121
- def test_emphasis_generation
122
- content = "emphasize this"
123
- gen = MarkMaker::Generator.new
124
- markup = gen.emphasis(content)
125
- assert_match(/^#{Regexp.quote(MarkMaker::EMPHASIS)}#{content}#{Regexp.quote(MarkMaker::EMPHASIS)}$/, markup)
126
- end
127
-
128
- def test_strong_generation
129
- content = "strong stuff"
130
- gen = MarkMaker::Generator.new
131
- markup = gen.strong(content)
132
- assert_match(/^#{Regexp.quote(MarkMaker::EMPHASIS * 2)}#{content}#{Regexp.quote(MarkMaker::EMPHASIS * 2)}$/, markup)
133
- end
134
-
135
80
  def test_table_header_generation
136
81
  content = ["Col One", "Col Two", "Col 3"]
137
82
  gen = MarkMaker::Generator.new
@@ -160,22 +105,26 @@ class TestMarkMaker < Minitest::Test
160
105
  # usage of a heredoc as a test method
161
106
 
162
107
  def test_heredoc_method
163
- desired_output = <<-EOS.strip_heredoc
164
- This should contain no intents.
108
+ desired_output = <<-EOS.unindent
109
+ This should contain no indents.
165
110
 
166
111
  It should be 3 lines long.
167
112
  EOS
168
- test_output = "This should contain no intents.\n\nIt should be 3 lines long.\n"
113
+ test_output = "This should contain no indents.\n\nIt should be 3 lines long.\n"
169
114
  assert_equal(desired_output, test_output, "Output must exactly match.")
170
115
  end
171
116
 
117
+ def test_join
118
+ assert_equal("abc", ["a", "b", "c"].join)
119
+ end
120
+
172
121
  def test_column_width
173
122
  gen = MarkMaker::Generator.new
174
123
  assert_equal(5, gen.column_width("One", "Two", "12345", "Four"))
175
124
  end
176
125
 
177
126
  def test_pretty_table_generation
178
- pretty_table = <<-EOS.strip_heredoc
127
+ pretty_table = <<-EOS.unindent
179
128
  |Col One|Col Two|Col Three|
180
129
  |:------|:-----:|--------:|
181
130
  |First | A | $3.99|
@@ -215,12 +164,6 @@ class TestMarkMaker < Minitest::Test
215
164
  assert_equal(test_justified, gen_justified)
216
165
  end
217
166
 
218
- def test_column_width
219
- gen = MarkMaker::Generator.new
220
- width = gen.column_width("a", "bbb", "ccccc", "dd")
221
- assert_equal(5, width)
222
- end
223
-
224
167
  def test_centered_margins
225
168
  gen = MarkMaker::Generator.new
226
169
  left, right = gen.centered_margins(5, "cc")
@@ -305,7 +248,7 @@ class TestMarkMaker < Minitest::Test
305
248
  # end
306
249
 
307
250
  # def test_right_justify_table_column
308
- # right_justified = <<-EOS.strip_heredoc
251
+ # right_justified = <<-EOS.unindent
309
252
  # | Justified|
310
253
  # |----------:|
311
254
  # | a|
@@ -319,7 +262,7 @@ class TestMarkMaker < Minitest::Test
319
262
 
320
263
 
321
264
  # def test_pretty_table_justified_generation
322
- # pretty_table = <<-EOS.strip_heredoc
265
+ # pretty_table = <<-EOS.unindent
323
266
  # |Col One|Col Two|Col Three |Data Sized |
324
267
  # |-------|-------|----------|-------------|
325
268
  # |First | A | $3.99|xxxxxxxxxxxxx|
@@ -0,0 +1,41 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'minitest_helper'
5
+
6
+ class TestMarkMakerString < Minitest::Test
7
+ def test_bullet_generation
8
+ content = "This is a bullet"
9
+ markup = content.bullet
10
+ assert_match(/^ - #{content}$/, markup)
11
+ end
12
+
13
+ def test_number_generation
14
+ content = "Number this line"
15
+ markup = content.number
16
+ assert_match(/^\s\d\.\s#{content}$/, markup)
17
+ end
18
+
19
+ def test_code_generation
20
+ content = "var = code()"
21
+ markup = content.code
22
+ assert_match(/\s{4}var = code\(\)$/, markup)
23
+ end
24
+
25
+ def test_code_span_generation
26
+ markup = "Some #{'a = b + c'.code_span} here."
27
+ assert_match(/^Some #{MarkMaker::CODE_TIC}a = b \+ c#{MarkMaker::CODE_TIC} here.$/, markup)
28
+ end
29
+
30
+ def test_emphasis_generation
31
+ content = "emphasize this"
32
+ markup = content.emphasis
33
+ assert_match(/^#{Regexp.quote(MarkMaker::EMPHASIS)}#{content}#{Regexp.quote(MarkMaker::EMPHASIS)}$/, markup)
34
+ end
35
+
36
+ def test_strong_generation
37
+ content = "strong stuff"
38
+ markup = content.strong
39
+ assert_match(/^#{Regexp.quote(MarkMaker::EMPHASIS * 2)}#{content}#{Regexp.quote(MarkMaker::EMPHASIS * 2)}$/, markup)
40
+ end
41
+ end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mark_maker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Schneider
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-12 00:00:00.000000000 Z
11
+ date: 2020-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.7'
19
+ version: '2'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.7'
26
+ version: '2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: 12.3.3
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: 12.3.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rubocop
70
+ name: unindent
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: activesupport
84
+ name: simplecov
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -95,19 +95,25 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: simplecov
98
+ name: minitest-reporters
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.1'
101
104
  - - ">="
102
105
  - !ruby/object:Gem::Version
103
- version: '0'
106
+ version: 1.1.8
104
107
  type: :development
105
108
  prerelease: false
106
109
  version_requirements: !ruby/object:Gem::Requirement
107
110
  requirements:
111
+ - - "~>"
112
+ - !ruby/object:Gem::Version
113
+ version: '1.1'
108
114
  - - ">="
109
115
  - !ruby/object:Gem::Version
110
- version: '0'
116
+ version: 1.1.8
111
117
  description: Programatically generate markdown documents.
112
118
  email:
113
119
  - brad.schneider@me.com
@@ -129,9 +135,12 @@ files:
129
135
  - lib/mark_maker.rb
130
136
  - lib/mark_maker/generator.rb
131
137
  - lib/mark_maker/version.rb
138
+ - lib/mark_maker_string.rb
132
139
  - mark_maker.gemspec
133
140
  - test/minitest_helper.rb
141
+ - test/test_headers.rb
134
142
  - test/test_mark_maker.rb
143
+ - test/test_mark_maker_string.rb
135
144
  homepage: ''
136
145
  licenses:
137
146
  - MIT
@@ -144,18 +153,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
153
  requirements:
145
154
  - - ">="
146
155
  - !ruby/object:Gem::Version
147
- version: '0'
156
+ version: 1.9.3
148
157
  required_rubygems_version: !ruby/object:Gem::Requirement
149
158
  requirements:
150
159
  - - ">="
151
160
  - !ruby/object:Gem::Version
152
161
  version: '0'
153
162
  requirements: []
154
- rubyforge_project:
155
- rubygems_version: 2.4.6
163
+ rubygems_version: 3.0.6
156
164
  signing_key:
157
165
  specification_version: 4
158
166
  summary: Markdown generator.
159
167
  test_files:
160
168
  - test/minitest_helper.rb
169
+ - test/test_headers.rb
161
170
  - test/test_mark_maker.rb
171
+ - test/test_mark_maker_string.rb