mark_maker 0.5.1 → 0.6.0

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
2
  SHA1:
3
- metadata.gz: fd856055ec57459656c6963b82423f55febfe440
4
- data.tar.gz: 355e6e14d071a9d53a9f2fd4333896ab1e0253b7
3
+ metadata.gz: 2a7bac7fc41d83b17b78b5a283583184300401c6
4
+ data.tar.gz: 62d762c6bb495e6e5a33959b7c5690e50fcdd4ef
5
5
  SHA512:
6
- metadata.gz: 95a31758ca8963bebd1080210c333c0ffc7d29767ffeaed3151a7cf92c5cd8bbacaa7788ad359c73efb9db943c735d5e8564eb7ddb2a2cbf47c1d6986203b075
7
- data.tar.gz: 351deb838b05b55f91f1a40991de02e297ed08bbc795a7ffb73cf7d9dad0c74648f26337fb88dcf9cd8a012aa860be5402be3e2906331ae1b136f7053f73f383
6
+ metadata.gz: 38cc8d20ce8e44d3dc5870e0916142046492d8c487e501fe9395c977b202b98d74bf3a36113f821281fbdaaa1e422704cfa328aed355d2f20efdcf2e33f34799
7
+ data.tar.gz: f1677746325c615dafc7bd39352d2a5f7fe63c5c18a608865e8c53d410d9c2883ed19c8f68c6798be453f9bc8c26722a91dd78cc80ac9315986ab067520757c7
data/README.md CHANGED
@@ -56,14 +56,16 @@ bullets, *emphasis*, **strong**, code
56
56
  and basic table markdown. See bin/generate_readme.rb for the code used to generate this
57
57
  document and a sample of all these markdown generators in action.
58
58
 
59
+ Simple markdown generation is handled by extensions to the ruby String class. Headers,
60
+ code, emphasis, and strong are all handled by String methods.
61
+
62
+ Multi line and more complex conversions are handled by a Generator class.
63
+
59
64
  ### Header Example
60
- gen = MarkMaker::Generator.new
61
- gen.header1('Let It Begin'')
65
+ 'Let It Begin'.header1
62
66
 
63
67
  Produces
64
68
 
65
- Let It Begin
66
- ============
67
69
 
68
70
  ### Bulleted List Example
69
71
 
@@ -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,11 @@ ensure
25
25
  end
26
26
 
27
27
  gen = MarkMaker::Generator.new
28
- puts gen.header1("MarkMaker")
28
+ puts "MarkMaker".header1
29
29
  puts ""
30
30
  puts "Programatically generate markdown documents."
31
31
  puts ""
32
- puts gen.header2("Intended Use")
32
+ puts "Intended Use".header2
33
33
  puts ""
34
34
  puts "The mark_maker gem provides a set of methods that take text content and"
35
35
  puts "convert it to various markdown elements. The primary use case is simple"
@@ -37,7 +37,7 @@ puts "conversion of something like a JSON document into a markdown document."
37
37
  puts ""
38
38
  puts "The initial development goal is to provide"
39
39
  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') }"
40
+ puts "I mean by basic is that you provide a 'chunk' of content and the mark_maker #{ 'Generator'.code_span }"
41
41
  puts "will return that content in the corresponding markdown format. For grouped content, variable"
42
42
  puts "parameters will be provided on the method call to allow for things like correctly numbered"
43
43
  puts "bullet lists. Each call to the generator is treated as a separate"
@@ -51,61 +51,65 @@ puts "extended capabilities from expanded syntaxes like GitHub flavored markdown
51
51
  puts "generating non-core markdown will be noted in the documentation for that method."
52
52
  puts ""
53
53
  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"
54
+ puts "envisioned that will add a #{ 'Document'.code_span } class that will provide a"
55
55
  puts "more holistic layer of capabilities. For example, the aformentioned reference style"
56
56
  puts "links would be nice. As would the ability to have an arbitrarily long string broken"
57
57
  puts "down into nicely formatted hard break paragraphs. Same goes for nicely indented multi-line"
58
58
  puts "bullets, etc."
59
59
  puts ""
60
- puts gen.header2("Installation")
60
+ puts "Installation".header2
61
61
  puts ""
62
62
  puts "Add this line to your application's Gemfile:"
63
63
  puts ""
64
- puts gen.code("gem 'mark_maker'")
64
+ puts "gem 'mark_maker'".code
65
65
  puts ""
66
66
  puts "And then execute:"
67
67
  puts ""
68
- puts gen.code("$ bundle")
68
+ puts "$ bundle".code
69
69
  puts ""
70
70
  puts "Or install it yourself as:"
71
71
  puts ""
72
- puts gen.code("$ gem install mark_maker")
72
+ puts "$ gem install mark_maker".code
73
73
  puts ""
74
- puts gen.header2("Usage")
74
+ puts "Usage".header2
75
75
  puts ""
76
76
  puts "MarkMaker provides line oriented conversion of content to markdown elements. It"
77
77
  puts "currently supports first, second and third level headings, links, bullets, numbered"
78
- puts "bullets, #{gen.emphasis('emphasis')}, #{gen.strong('strong')}, code"
78
+ puts "bullets, #{'emphasis'.emphasis}, #{'strong'.strong}, code"
79
79
  puts "and basic table markdown. See #{__FILE__} for the code used to generate this"
80
80
  puts "document and a sample of all these markdown generators in action."
81
81
  puts ""
82
- puts gen.header3("Header Example")
82
+ puts "Simple markdown generation is handled by extensions to the ruby String class. Headers,"
83
+ puts "code, emphasis, and strong are all handled by String methods."
84
+ puts ""
85
+ puts "Multi line and more complex conversions are handled by a Generator class."
86
+ puts ""
87
+ puts "Header Example".header3
83
88
  example_header = "Let It Begin"
84
- puts gen.code("gen = MarkMaker::Generator.new")
85
- puts gen.code("gen.header1('#{example_header}'')")
89
+ puts "'#{example_header}'.header1".code
86
90
  puts "\nProduces\n\n"
87
- gen.header1(example_header).lines.map { |l| puts gen.code(l) }
91
+ example_header.header1.lines.map(&:code)
88
92
  puts ""
89
- puts gen.header3("Bulleted List Example")
93
+ puts "Bulleted List Example".header3
90
94
  list_content = ['gold', 'silver', 'bronze']
91
95
  puts ""
92
- puts gen.code("list_content = ['gold', 'silver', 'bronze']")
93
- puts gen.code("gen.bullets(*list_content)")
96
+ puts "list_content = ['gold', 'silver', 'bronze']".code
97
+ puts "gen.bullets(*list_content)".code
94
98
  puts "\nProduces\n\n"
95
99
  puts gen.code_block(*gen.bullets(*list_content))
96
100
  puts ""
97
101
  puts "Or a numbered list with..."
98
102
  puts ""
99
103
  numbered_code = "gen.numbers(*list_content)"
100
- puts gen.code(numbered_code)
104
+ puts numbered_code.code
101
105
  puts ""
102
106
  puts "Produces"
103
107
  puts ""
104
108
  puts gen.code_block(*eval(numbered_code))
105
109
  puts ""
106
- puts gen.header3("Code Examples")
110
+ puts "Code Examples".header3
107
111
  puts ""
108
- puts "Standard markdown code blocks and #{gen.code_span('code span')} are supported, as well as github"
112
+ puts "Standard markdown code blocks and #{'code span'.code_span} are supported, as well as github"
109
113
  puts "flavored markdown fenced code blocks."
110
114
  puts ""
111
115
  sample_block = <<-EOT.lines
@@ -125,7 +129,7 @@ puts ""
125
129
  puts "You can also generate a github flavored markdown fenced code version."
126
130
  fenced_code = "gen.fenced_code_block(*some_code)"
127
131
  puts ""
128
- puts gen.code(fenced_code)
132
+ puts fenced_code.code
129
133
  puts ""
130
134
  puts "Produces"
131
135
  puts ""
@@ -134,7 +138,7 @@ puts ""
134
138
  puts "You can also include a language in a fenced code block."
135
139
  puts ""
136
140
  fenced_code_language = "gen.fenced_code_language('ruby', *some_code)"
137
- puts gen.code(fenced_code_language)
141
+ puts fenced_code_language.code
138
142
  puts ""
139
143
  puts "Produces"
140
144
  puts ""
@@ -144,7 +148,7 @@ puts "Rendering beautifully highlighted code like so, if you are viewing this on
144
148
  puts ""
145
149
  puts eval("#{sample_block.join}\n#{fenced_code_language}")
146
150
  puts ""
147
- puts gen.header3("Table Example")
151
+ puts "Table Example".header3
148
152
  puts ""
149
153
  table_code = <<-EOT
150
154
  header, separator = gen.table_header("Col One", "Col Two", "Col Three")
@@ -185,7 +189,7 @@ puts "Which gives you this stunning HTML table ..."
185
189
  puts ""
186
190
  puts eval(pretty_table_code)
187
191
  puts ""
188
- puts gen.header3("Block Quotes Example")
192
+ puts "Block Quotes Example".header3
189
193
  puts ""
190
194
  block_quote_code = <<-EOT
191
195
  content = <<-QUOTE
@@ -208,7 +212,7 @@ puts "Which looks like this when viewed as HTML..."
208
212
  puts ""
209
213
  puts eval(block_quote_code)
210
214
  puts ""
211
- puts gen.header2("Contributing")
215
+ puts "Contributing".header2
212
216
  puts ""
213
217
  puts gen.numbers(gen.link("Fork it", "https://github.com/sn1de/mark_maker/fork"),
214
218
  "Create your feature branch (`git checkout -b my-new-feature`)",
@@ -216,14 +220,14 @@ puts gen.numbers(gen.link("Fork it", "https://github.com/sn1de/mark_maker/fork")
216
220
  "Push to the branch (`git push origin my-new-feature`)",
217
221
  "Create a new Pull Request")
218
222
  puts ""
219
- puts gen.header2("About This README")
223
+ puts "About This README".header2
220
224
  puts ""
221
225
  puts "This readme document is created using MarkMaker. To modify it, edit the code"
222
226
  puts "in #{__FILE__} and then run the 'readme' rake task to generate and overwrite the"
223
227
  puts "existing README.md"
224
228
  puts ""
225
- puts gen.code("vi #{__FILE__}")
226
- puts gen.code("rake readme")
229
+ puts "vi #{__FILE__}".code
230
+ puts "rake readme".code
227
231
  puts ""
228
232
  puts "I'm calling this Extreme #{gen.link("Readme Driven Development", "http://tom.preston-werner.com/2010/08/23/readme-driven-development.html")}."
229
233
  puts "It's kind of like #{gen.link("Inception", "http://en.wikipedia.org/wiki/Inception")} ;)"
@@ -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,20 @@ 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}"
84
- end
85
-
86
46
  def code_block(*content)
87
- content.map { |c| code(c) }
47
+ content.map(&:code)
88
48
  end
89
49
 
90
50
  # creates a github flavored markdown fenced code block
@@ -102,14 +62,6 @@ module MarkMaker
102
62
  block << FENCE
103
63
  end
104
64
 
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
65
  def table_header(*content)
114
66
  [
115
67
  content.inject("|") { |a, e| a + "#{e}|" },
@@ -200,8 +152,7 @@ module MarkMaker
200
152
  end
201
153
 
202
154
  def column_width(*content)
203
- longest = content.reduce { |a, e| a.length > e.length ? a : e }
204
- longest.length
155
+ content.reduce { |a, e| a.length > e.length ? a : e } .length
205
156
  end
206
157
 
207
158
  def centered_margins(width, content)
@@ -1,4 +1,4 @@
1
1
  # version management
2
2
  module MarkMaker
3
- VERSION = "0.5.1"
3
+ VERSION = "0.6.0"
4
4
  end
@@ -0,0 +1,44 @@
1
+ require 'mark_maker'
2
+
3
+ # adds several basic string to markdown conversion methods
4
+ class String
5
+ def line_for(underscore)
6
+ underscore * size
7
+ end
8
+
9
+ def header1
10
+ "#{self}\n#{line_for('=')}"
11
+ end
12
+
13
+ def header2
14
+ "#{self}\n#{line_for('-')}"
15
+ end
16
+
17
+ def header3
18
+ "### #{self}"
19
+ end
20
+
21
+ def bullet
22
+ " - #{self}"
23
+ end
24
+
25
+ def number(number = 1)
26
+ " #{number}. #{self}"
27
+ end
28
+
29
+ def code
30
+ " #{self}"
31
+ end
32
+
33
+ def code_span
34
+ "#{MarkMaker::CODE_TIC}#{self}#{MarkMaker::CODE_TIC}"
35
+ end
36
+
37
+ def emphasis
38
+ "#{MarkMaker::EMPHASIS}#{self}#{MarkMaker::EMPHASIS}"
39
+ end
40
+
41
+ def strong
42
+ MarkMaker::EMPHASIS * 2 + self + MarkMaker::EMPHASIS * 2
43
+ end
44
+ end
@@ -1,5 +1,6 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
2
  require 'mark_maker'
3
+ require 'mark_maker_string'
3
4
  require 'active_support/core_ext/string'
4
5
  require 'minitest/autorun'
5
6
  require 'minitest/reporters'
@@ -8,38 +8,6 @@ class TestMarkMaker < Minitest::Test
8
8
  refute_nil ::MarkMaker::VERSION
9
9
  end
10
10
 
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
11
  def test_bulleted_list_generation
44
12
  content = ["gold", "silver", "bronze"]
45
13
  gen = MarkMaker::Generator.new
@@ -49,12 +17,6 @@ class TestMarkMaker < Minitest::Test
49
17
  assert_match(/^\s-\s#{c}$/, m)
50
18
  end
51
19
  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
20
 
59
21
  def test_numbered_list_generation
60
22
  content = ["1", "2", "3"]
@@ -74,19 +36,6 @@ class TestMarkMaker < Minitest::Test
74
36
  assert_match(/^\[#{label}\]\(#{url}\)$/, markup)
75
37
  end
76
38
 
77
- def test_code_generation
78
- content = "var = code()"
79
- 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)
88
- end
89
-
90
39
  def test_code_block_generation
91
40
  content = ["a = 1", "b = 2", "c = 3"]
92
41
  gen = MarkMaker::Generator.new
@@ -118,20 +67,6 @@ class TestMarkMaker < Minitest::Test
118
67
  assert(markup.last == MarkMaker::FENCE, "Markup should end with the code fence.")
119
68
  end
120
69
 
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
70
  def test_table_header_generation
136
71
  content = ["Col One", "Col Two", "Col 3"]
137
72
  gen = MarkMaker::Generator.new
@@ -0,0 +1,63 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'minitest_helper'
5
+
6
+ class TestMarkMakerString < 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_bullet_generation
30
+ content = "This is a bullet"
31
+ markup = content.bullet
32
+ assert_match(/^ - #{content}$/, markup)
33
+ end
34
+
35
+ def test_number_generation
36
+ content = "Number this line"
37
+ markup = content.number
38
+ assert_match(/^\s\d\.\s#{content}$/, markup)
39
+ end
40
+
41
+ def test_code_generation
42
+ content = "var = code()"
43
+ markup = content.code
44
+ assert_match(/\s{4}var = code\(\)$/, markup)
45
+ end
46
+
47
+ def test_code_span_generation
48
+ markup = "Some #{'a = b + c'.code_span} here."
49
+ assert_match(/^Some #{MarkMaker::CODE_TIC}a = b \+ c#{MarkMaker::CODE_TIC} here.$/, markup)
50
+ end
51
+
52
+ def test_emphasis_generation
53
+ content = "emphasize this"
54
+ markup = content.emphasis
55
+ assert_match(/^#{Regexp.quote(MarkMaker::EMPHASIS)}#{content}#{Regexp.quote(MarkMaker::EMPHASIS)}$/, markup)
56
+ end
57
+
58
+ def test_strong_generation
59
+ content = "strong stuff"
60
+ markup = content.strong
61
+ assert_match(/^#{Regexp.quote(MarkMaker::EMPHASIS * 2)}#{content}#{Regexp.quote(MarkMaker::EMPHASIS * 2)}$/, markup)
62
+ end
63
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mark_maker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Schneider
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-21 00:00:00.000000000 Z
11
+ date: 2016-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -129,9 +129,11 @@ files:
129
129
  - lib/mark_maker.rb
130
130
  - lib/mark_maker/generator.rb
131
131
  - lib/mark_maker/version.rb
132
+ - lib/mark_maker_string.rb
132
133
  - mark_maker.gemspec
133
134
  - test/minitest_helper.rb
134
135
  - test/test_mark_maker.rb
136
+ - test/test_mark_maker_string.rb
135
137
  homepage: ''
136
138
  licenses:
137
139
  - MIT
@@ -159,3 +161,4 @@ summary: Markdown generator.
159
161
  test_files:
160
162
  - test/minitest_helper.rb
161
163
  - test/test_mark_maker.rb
164
+ - test/test_mark_maker_string.rb