mark_maker 0.2.0 → 0.3.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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +30 -1
- data/bin/generate_readme.rb +125 -93
- data/lib/mark_maker/generator.rb +11 -0
- data/lib/mark_maker/version.rb +2 -1
- data/lib/mark_maker.rb +2 -0
- data/test/test_mark_maker.rb +15 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66fe5512a41c6c304d4156591bec7a359a3a34e3
|
4
|
+
data.tar.gz: 3a13cb0564c0331161658693bc0c4a3ec89eb810
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1bd86c66b71d0cd3b232ea17d9dda5d39207fd64519dfac3878f119d63d9752e8141d2b98369898c5bb57377dc3bd523a9851552638d62d6629dbad05637756
|
7
|
+
data.tar.gz: 074857f7001aad4fb85e73f5a3aa5bf6a069bfdcc4aeaac0b5ee6617e0a541cd966847bb130d9664774ef91ebec64b2709354d3a36dee74bd62653683f2d5c03
|
data/CHANGELOG.md
ADDED
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
|
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
|
|
data/bin/generate_readme.rb
CHANGED
@@ -14,62 +14,72 @@
|
|
14
14
|
# examples. So here goes ... extreme readme driven development!
|
15
15
|
|
16
16
|
require 'mark_maker'
|
17
|
-
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
49
|
-
gen.header1(example_header).lines.map { |l|
|
50
|
-
|
51
|
-
|
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
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
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
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
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
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
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
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
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
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
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")} ;)"
|
data/lib/mark_maker/generator.rb
CHANGED
@@ -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
|
data/lib/mark_maker/version.rb
CHANGED
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
|
data/test/test_mark_maker.rb
CHANGED
@@ -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.
|
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-
|
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
|