mark_maker 0.2.0 → 0.3.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: 1a68f07f8d48fdc287cc5c6f646e84f3a3647bea
4
- data.tar.gz: 8e9a4a968cfbd8ba7b4d6113349cadfa8f4403a1
3
+ metadata.gz: 66fe5512a41c6c304d4156591bec7a359a3a34e3
4
+ data.tar.gz: 3a13cb0564c0331161658693bc0c4a3ec89eb810
5
5
  SHA512:
6
- metadata.gz: c2fd47a0dae3bc3976af88f5474c6a964c8225359138708cc093bfaadf9123336d456ad18475394bced8b3691022dcc5b0c1219ce60356e95b653410862c8c19
7
- data.tar.gz: 2c18d49746a7db186226069519da9a3cf66b482e709e5bd36bfd5e2bd166c3bd81ad5f12c720a9dbdf401e53ce1c27fa79ce418ffd8578490bc7d14b65fabbc7
6
+ metadata.gz: e1bd86c66b71d0cd3b232ea17d9dda5d39207fd64519dfac3878f119d63d9752e8141d2b98369898c5bb57377dc3bd523a9851552638d62d6629dbad05637756
7
+ data.tar.gz: 074857f7001aad4fb85e73f5a3aa5bf6a069bfdcc4aeaac0b5ee6617e0a541cd966847bb130d9664774ef91ebec64b2709354d3a36dee74bd62653683f2d5c03
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ 0.3.0
2
+ -----
3
+
4
+ - added very basic table support
data/README.md CHANGED
@@ -23,7 +23,8 @@ Usage
23
23
 
24
24
  MarkMaker provides line oriented conversion of content to markdown elements. It
25
25
  currently supports first, second and third level headings, links, bullets, numbered
26
- bullets, *emphasis*, **strong** and code markdown. See bin/generate_readme.rb for the code used to generate this
26
+ bullets, *emphasis*, **strong**, code
27
+ and basic table markdown. See bin/generate_readme.rb for the code used to generate this
27
28
  document and a sample of all these markdown generators in action.
28
29
 
29
30
  ### Header Example
@@ -119,6 +120,34 @@ end
119
120
  puts total
120
121
  ```
121
122
 
123
+ ### Table Example
124
+
125
+ header, separator = gen.table_header("Col One", "Col Two", "Col Three")
126
+ puts header
127
+ puts separator
128
+ puts gen.table_row("First", "A", "$3.99")
129
+ puts gen.table_row("Second", "B", "$14.00")
130
+ puts gen.table_row("Third", "C", "$1,034.50")
131
+
132
+ Produces this terribly ugly markdown ...
133
+
134
+ ```
135
+ |Col One|Col Two|Col Three|
136
+ |-------|-------|---------|
137
+ |First|A|$3.99|
138
+ |Second|B|$14.00|
139
+ |Third|C|$1,034.50|
140
+ ```
141
+
142
+ Which gives you this stunning HTML table ...
143
+
144
+ |Col One|Col Two|Col Three|
145
+ |-------|-------|---------|
146
+ |First|A|$3.99|
147
+ |Second|B|$14.00|
148
+ |Third|C|$1,034.50|
149
+
150
+
122
151
  Contributing
123
152
  ------------
124
153
 
@@ -14,62 +14,72 @@
14
14
  # examples. So here goes ... extreme readme driven development!
15
15
 
16
16
  require 'mark_maker'
17
- doc = []
17
+
18
+ def capture_stdout
19
+ out = StringIO.new
20
+ $stdout = out
21
+ yield
22
+ return out
23
+ ensure
24
+ $stdout = STDOUT
25
+ end
26
+
18
27
  gen = MarkMaker::Generator.new
19
- doc << gen.header1("MarkMaker")
20
- doc << ""
21
- doc << "Programatically generate markdown documents."
22
- doc << ""
23
- doc << gen.header2("Installation")
24
- doc << ""
25
- doc << "Add this line to your application's Gemfile:"
26
- doc << ""
27
- doc << gen.code("gem 'mark_maker'")
28
- doc << ""
29
- doc << "And then execute:"
30
- doc << ""
31
- doc << gen.code("$ bundle")
32
- doc << ""
33
- doc << "Or install it yourself as:"
34
- doc << ""
35
- doc << gen.code("$ gem install mark_maker")
36
- doc << ""
37
- doc << gen.header2("Usage")
38
- doc << ""
39
- doc << "MarkMaker provides line oriented conversion of content to markdown elements. It"
40
- doc << "currently supports first, second and third level headings, links, bullets, numbered"
41
- doc << "bullets, #{gen.emphasis('emphasis')}, #{gen.strong('strong')} and code markdown. See #{__FILE__} for the code used to generate this"
42
- doc << "document and a sample of all these markdown generators in action."
43
- doc << ""
44
- doc << gen.header3("Header Example")
28
+ puts gen.header1("MarkMaker")
29
+ puts ""
30
+ puts "Programatically generate markdown documents."
31
+ puts ""
32
+ puts gen.header2("Installation")
33
+ puts ""
34
+ puts "Add this line to your application's Gemfile:"
35
+ puts ""
36
+ puts gen.code("gem 'mark_maker'")
37
+ puts ""
38
+ puts "And then execute:"
39
+ puts ""
40
+ puts gen.code("$ bundle")
41
+ puts ""
42
+ puts "Or install it yourself as:"
43
+ puts ""
44
+ puts gen.code("$ gem install mark_maker")
45
+ puts ""
46
+ puts gen.header2("Usage")
47
+ puts ""
48
+ puts "MarkMaker provides line oriented conversion of content to markdown elements. It"
49
+ puts "currently supports first, second and third level headings, links, bullets, numbered"
50
+ puts "bullets, #{gen.emphasis('emphasis')}, #{gen.strong('strong')}, code"
51
+ puts "and basic table markdown. See #{__FILE__} for the code used to generate this"
52
+ puts "document and a sample of all these markdown generators in action."
53
+ puts ""
54
+ puts gen.header3("Header Example")
45
55
  example_header = "Let It Begin"
46
- doc << gen.code("gen = MarkMaker::Generator.new")
47
- doc << gen.code("gen.header1('#{example_header}'')")
48
- doc << "\nProduces\n\n"
49
- gen.header1(example_header).lines.map { |l| doc << gen.code(l) }
50
- doc << ""
51
- doc << gen.header3("Bulleted List Example")
56
+ puts gen.code("gen = MarkMaker::Generator.new")
57
+ puts gen.code("gen.header1('#{example_header}'')")
58
+ puts "\nProduces\n\n"
59
+ gen.header1(example_header).lines.map { |l| puts gen.code(l) }
60
+ puts ""
61
+ puts gen.header3("Bulleted List Example")
52
62
  list_content = ['gold', 'silver', 'bronze']
53
- doc << ""
54
- doc << gen.code("list_content = ['gold', 'silver', 'bronze']")
55
- doc << gen.code("gen.bullets(*list_content)")
56
- doc << "\nProduces\n\n"
57
- doc << gen.code_block(*gen.bullets(*list_content))
58
- doc << ""
59
- doc << "Or a numbered list with..."
60
- doc << ""
63
+ puts ""
64
+ puts gen.code("list_content = ['gold', 'silver', 'bronze']")
65
+ puts gen.code("gen.bullets(*list_content)")
66
+ puts "\nProduces\n\n"
67
+ puts gen.code_block(*gen.bullets(*list_content))
68
+ puts ""
69
+ puts "Or a numbered list with..."
70
+ puts ""
61
71
  numbered_code = "gen.numbers(*list_content)"
62
- doc << gen.code(numbered_code)
63
- doc << ""
64
- doc << "Produces"
65
- doc << ""
66
- doc << gen.code_block(*eval(numbered_code))
67
- doc << ""
68
- doc << gen.header3("Code Examples")
69
- doc << ""
70
- doc << "Standard markdown code blocks and embedding are supported, as well as github"
71
- doc << "flavored markdown fenced code blocks."
72
- doc << ""
72
+ puts gen.code(numbered_code)
73
+ puts ""
74
+ puts "Produces"
75
+ puts ""
76
+ puts gen.code_block(*eval(numbered_code))
77
+ puts ""
78
+ puts gen.header3("Code Examples")
79
+ puts ""
80
+ puts "Standard markdown code blocks and embedding are supported, as well as github"
81
+ puts "flavored markdown fenced code blocks."
82
+ puts ""
73
83
  sample_block = <<-EOT.split("\n")
74
84
  some_code = [ "# add it up",
75
85
  "total = [1, 2, 3, 4].inject do |sum, i|",
@@ -79,50 +89,72 @@ some_code = [ "# add it up",
79
89
  "puts total" ]
80
90
  EOT
81
91
  execution_block = "gen.code_block(*some_code)"
82
- doc << gen.code_block(*sample_block, execution_block)
83
- doc << ""
84
- doc << "Produces\n\n"
85
- doc << gen.code_block(*gen.code_block(*eval(sample_block.join)))
86
- doc << ""
87
- doc << "You can also generate a github flavored markdown fenced code version."
92
+ puts gen.code_block(*sample_block, execution_block)
93
+ puts ""
94
+ puts "Produces\n\n"
95
+ puts gen.code_block(*gen.code_block(*eval(sample_block.join)))
96
+ puts ""
97
+ puts "You can also generate a github flavored markdown fenced code version."
88
98
  fenced_code = "gen.fenced_code_block(*some_code)"
89
- doc << ""
90
- doc << gen.code(fenced_code)
91
- doc << ""
92
- doc << "Produces"
93
- doc << ""
94
- doc << gen.code_block(*eval("#{sample_block.join}\n#{fenced_code}\n"))
95
- doc << ""
96
- doc << "You can also include a language in a fenced code block."
97
- doc << ""
99
+ puts ""
100
+ puts gen.code(fenced_code)
101
+ puts ""
102
+ puts "Produces"
103
+ puts ""
104
+ puts gen.code_block(*eval("#{sample_block.join}\n#{fenced_code}\n"))
105
+ puts ""
106
+ puts "You can also include a language in a fenced code block."
107
+ puts ""
98
108
  fenced_code_language = "gen.fenced_code_language('ruby', *some_code)"
99
- doc << gen.code(fenced_code_language)
100
- doc << ""
101
- doc << "Produces"
102
- doc << ""
103
- doc << gen.code_block(*eval("#{sample_block.join}\n#{fenced_code_language}"))
104
- doc << ""
105
- doc << "Rendering beautifully highlighted code like so, if you are viewing this on github."
106
- doc << ""
107
- doc << eval("#{sample_block.join}\n#{fenced_code_language}")
108
- doc << ""
109
- doc << gen.header2("Contributing")
110
- doc << ""
111
- doc << gen.numbers(gen.link("Fork it", "https://github.com/sn1de/mark_maker/fork"),
109
+ puts gen.code(fenced_code_language)
110
+ puts ""
111
+ puts "Produces"
112
+ puts ""
113
+ puts gen.code_block(*eval("#{sample_block.join}\n#{fenced_code_language}"))
114
+ puts ""
115
+ puts "Rendering beautifully highlighted code like so, if you are viewing this on github."
116
+ puts ""
117
+ puts eval("#{sample_block.join}\n#{fenced_code_language}")
118
+ puts ""
119
+ puts gen.header3("Table Example")
120
+ puts ""
121
+ table_code = <<-EOT
122
+ header, separator = gen.table_header("Col One", "Col Two", "Col Three")
123
+ puts header
124
+ puts separator
125
+ puts gen.table_row("First", "A", "$3.99")
126
+ puts gen.table_row("Second", "B", "$14.00")
127
+ puts gen.table_row("Third", "C", "$1,034.50")
128
+ EOT
129
+ puts gen.code_block(*table_code.split("\n"))
130
+ puts ""
131
+ puts "Produces this terribly ugly markdown ..."
132
+ puts ""
133
+ table_markdown = capture_stdout do
134
+ eval(table_code)
135
+ end
136
+ puts gen.fenced_code_block(*table_markdown.string.split("\n"))
137
+ puts ""
138
+ puts "Which gives you this stunning HTML table ..."
139
+ puts ""
140
+ puts eval(table_code)
141
+ puts ""
142
+ puts gen.header2("Contributing")
143
+ puts ""
144
+ puts gen.numbers(gen.link("Fork it", "https://github.com/sn1de/mark_maker/fork"),
112
145
  "Create your feature branch (`git checkout -b my-new-feature`)",
113
146
  "Commit your changes (`git commit -am 'Add some feature'`)",
114
147
  "Push to the branch (`git push origin my-new-feature`)",
115
148
  "Create a new Pull Request")
116
- doc << ""
117
- doc << gen.header2("About This README")
118
- doc << ""
119
- doc << "This readme document is created using MarkMaker. To modify it, edit the code"
120
- doc << "in #{__FILE__} and then run the 'readme' rake task to generate and overwrite the"
121
- doc << "existing README.md"
122
- doc << ""
123
- doc << gen.code("vi #{__FILE__}")
124
- doc << gen.code("rake readme")
125
- doc << ""
126
- doc << "I'm calling this Extreme #{gen.link("Readme Driven Development", "http://tom.preston-werner.com/2010/08/23/readme-driven-development.html")}."
127
- doc << "It's kind of like #{gen.link("Inception", "http://en.wikipedia.org/wiki/Inception")} ;)"
128
- puts doc
149
+ puts ""
150
+ puts gen.header2("About This README")
151
+ puts ""
152
+ puts "This readme document is created using MarkMaker. To modify it, edit the code"
153
+ puts "in #{__FILE__} and then run the 'readme' rake task to generate and overwrite the"
154
+ puts "existing README.md"
155
+ puts ""
156
+ puts gen.code("vi #{__FILE__}")
157
+ puts gen.code("rake readme")
158
+ puts ""
159
+ puts "I'm calling this Extreme #{gen.link("Readme Driven Development", "http://tom.preston-werner.com/2010/08/23/readme-driven-development.html")}."
160
+ puts "It's kind of like #{gen.link("Inception", "http://en.wikipedia.org/wiki/Inception")} ;)"
@@ -69,5 +69,16 @@ module MarkMaker
69
69
  def strong(content)
70
70
  EMPHASIS * 2 + content + EMPHASIS * 2
71
71
  end
72
+
73
+ def table_header(*content)
74
+ [
75
+ content.inject("|") { |a, e| a + "#{e}|" },
76
+ content.inject("|") { |a, e| a + "-" * e.size + "|" }
77
+ ]
78
+ end
79
+
80
+ def table_row(*content)
81
+ content.inject("|") { |a, e| a << e << "|" }
82
+ end
72
83
  end
73
84
  end
@@ -1,3 +1,4 @@
1
+ # version management
1
2
  module MarkMaker
2
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
3
4
  end
data/lib/mark_maker.rb CHANGED
@@ -1,10 +1,12 @@
1
1
  require "mark_maker/version"
2
2
  require "mark_maker/generator"
3
3
 
4
+ # rubocop:disable Lint/HandleExceptions
4
5
  begin
5
6
  require "pry"
6
7
  rescue LoadError
7
8
  end
9
+ # rubocop:enable Lint/HandleExceptions
8
10
 
9
11
  # MarkMaker is a markdown generation capability. It is intended to be
10
12
  # very straightforward, non-tricky and easy to expand upon going
@@ -122,5 +122,20 @@ class TestMarkMaker < Minitest::Test
122
122
  markup = gen.strong(content)
123
123
  assert_match(/^#{Regexp.quote(MarkMaker::EMPHASIS * 2)}#{content}#{Regexp.quote(MarkMaker::EMPHASIS * 2)}$/, markup)
124
124
  end
125
+
126
+ def test_table_header_generation
127
+ content = ["Col One", "Col Two", "Col 3"]
128
+ gen = MarkMaker::Generator.new
129
+ line1, line2 = gen.table_header(*content)
130
+ assert_match(/^\|#{Regexp.quote(content[0])}\|#{Regexp.quote(content[1])}\|#{Regexp.quote(content[2])}\|$/, line1)
131
+ assert_match(/^\|-{#{content[0].size}}\|-{#{content[1].size}}\|-{#{content[2].size}}\|$/, line2)
132
+ end
133
+
134
+ def test_table_row_generation
135
+ content = ["A", "Two", "$3.99"]
136
+ gen = MarkMaker::Generator.new
137
+ row = gen.table_row(*content)
138
+ assert_match(/^\|#{Regexp.quote(content[0])}\|#{Regexp.quote(content[1])}\|#{Regexp.quote(content[2])}\|$/, row)
139
+ end
125
140
  end
126
141
 
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.2.0
4
+ version: 0.3.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: 2015-03-25 00:00:00.000000000 Z
11
+ date: 2015-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -91,6 +91,7 @@ files:
91
91
  - ".gitignore"
92
92
  - ".rubocop.yml"
93
93
  - ".travis.yml"
94
+ - CHANGELOG.md
94
95
  - Gemfile
95
96
  - LICENSE.txt
96
97
  - README.md