markdown_helper 1.5.1 → 1.6.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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/README.md +38 -33
  4. data/Rakefile +5 -5
  5. data/bin/_include +49 -0
  6. data/bin/_resolve +48 -0
  7. data/bin/include +3 -11
  8. data/bin/markdown_helper +37 -0
  9. data/bin/resolve +13 -8
  10. data/bin/usage/include.txt +1 -1
  11. data/bin/usage/resolve.txt +2 -1
  12. data/lib/markdown_helper.rb +96 -63
  13. data/lib/markdown_helper/version.rb +1 -1
  14. data/{readme_files → markdown}/README.template.md +5 -2
  15. data/{readme_files → markdown}/code_block_ruby_template.md +0 -0
  16. data/{readme_files → markdown}/highlight_ruby_template.md +0 -0
  17. data/markdown/highlighted_ruby.md +12 -0
  18. data/{readme_files → markdown}/include.md +0 -0
  19. data/{readme_files → markdown}/include.rb +0 -0
  20. data/{readme_files → markdown}/include_usage.rb +0 -0
  21. data/{readme_files → markdown}/resolve.md +0 -0
  22. data/{readme_files → markdown}/resolve_usage.rb +0 -0
  23. data/{readme_files → markdown}/use_cases/evergreen_examples.md +0 -0
  24. data/{readme_files → markdown}/use_cases/generated_text.md +0 -0
  25. data/{readme_files → markdown}/use_cases/image_attributes.md +0 -0
  26. data/markdown/use_cases/reusable_text/build.rb +67 -0
  27. data/markdown/use_cases/reusable_text/included.md +3 -0
  28. data/markdown/use_cases/reusable_text/includer.md +3 -0
  29. data/markdown/use_cases/reusable_text/reusable_text.md +1 -0
  30. data/markdown/use_cases/reusable_text/template.md +31 -0
  31. data/markdown/use_cases/reusable_text/use_case.md +44 -0
  32. data/{readme_files → markdown}/use_cases/rubygem_images.md +0 -0
  33. data/{readme_files → markdown}/verbatim_ruby_template.md +0 -0
  34. data/markdown_helper.gemspec +2 -3
  35. metadata +28 -19
  36. data/readme_files/highlighted_ruby.md +0 -12
  37. data/readme_files/use_cases/reusable_text.md +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38e7b32f5f6e0b8b46878e5ef5586d2f94852c60
4
- data.tar.gz: efefe056e97327bc5dafd225774e52ce81955a03
3
+ metadata.gz: b7bd60eb7a1f8efbccafc0efda8eb504d344e7c1
4
+ data.tar.gz: c1a3ff13373ee40259f46e3769c300a3ca8c7f4b
5
5
  SHA512:
6
- metadata.gz: 62891f62df9f8a0a68f1cd865335057285e9a9b1cd28d7ff0d153fdb05e679bb61accec96ec626f6dfc450843e8bc3f6f0fbc7b3b38d09d3de9e7488a2c88e9c
7
- data.tar.gz: 588635b8668e9757edcb0d1eaa11364c640763471b3d943410a2a650344f7168d152fd2f9cd6752c494ee57c57405702153f7b57f4da1e1fcec28781144f20ee
6
+ metadata.gz: e301810ed4eb380b8b5edf4effee8ff17c2acfaf25c49e0e9468068bc983dccb6ebfbc661fe0048a919795ef7866adbd7731814534175135ab01e8a01cf29105
7
+ data.tar.gz: a6e5f17c0aa9788df2ec2c64f9536590dae2dc49e7701a6e60dc8bab8022084afbce6c3189e08014424c0e0f89e35501aaec6123054f3356f2f658dd4e4868a0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- markdown_helper (1.5.1)
4
+ markdown_helper (1.6.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,16 +1,19 @@
1
- <!-- >>>>>> BEGIN GENERATED FILE (include): SOURCE readme_files/temp_resolved.md -->
2
- <!-- >>>>>> BEGIN GENERATED FILE (resolve): SOURCE readme_files/README.template.md -->
1
+ <!-- >>>>>> BEGIN GENERATED FILE (include): SOURCE markdown/temp_resolved.md -->
2
+ <!-- >>>>>> BEGIN GENERATED FILE (resolve): SOURCE markdown/README.template.md -->
3
3
  # Markdown Helper
4
4
 
5
- <!-- >>>>>> BEGIN RESOLVED IMAGES: INPUT-LINE '![Gem Version](https://badge.fury.io/rb/markdown_helper.svg)
5
+ <!-- >>>>>> BEGIN RESOLVED IMAGES: INPUT-LINE '![Gem Version](https://badge.fury.io/rb/markdown_helper.svg) [Visit gem markdown_helper](https://rubygems.org/gems/markdown_helper)
6
6
  ' -->
7
- <img src="https://badge.fury.io/rb/markdown_helper.svg" alt="Gem Version">
8
- <!-- <<<<<< END RESOLVED IMAGES: INPUT-LINE '![Gem Version](https://badge.fury.io/rb/markdown_helper.svg)
7
+ <img src="https://badge.fury.io/rb/markdown_helper.svg" alt="Gem Version"> [Visit gem markdown_helper](https://rubygems.org/gems/markdown_helper)
8
+ <!-- <<<<<< END RESOLVED IMAGES: INPUT-LINE '![Gem Version](https://badge.fury.io/rb/markdown_helper.svg) [Visit gem markdown_helper](https://rubygems.org/gems/markdown_helper)
9
9
  ' -->
10
10
 
11
11
  ## What's New?
12
12
 
13
- Nested file inclusion is now supported, which means that an included file can include more files. This applies only to a file included verbatim, not to a file included as a code block or as a markdown comment.
13
+ Command-line interface is now supported:
14
+
15
+ * ```markdown_helper include [options] template_file_path markdown_file_path```
16
+ * ```markdown_helper resolve [options] template_file_path markdown_file_path```
14
17
 
15
18
  ## What's This?
16
19
 
@@ -54,7 +57,7 @@ Use the markdown helper to merge external files into a markdown (</code>.md</cod
54
57
 
55
58
  #### Highlighted Code Block
56
59
 
57
- <!-- >>>>>> BEGIN INCLUDED FILE (ruby): SOURCE readme_files/include.rb -->
60
+ <!-- >>>>>> BEGIN INCLUDED FILE (ruby): SOURCE markdown/include.rb -->
58
61
  <code>include.rb</code>
59
62
  ```ruby
60
63
  class RubyCode
@@ -63,11 +66,11 @@ class RubyCode
63
66
  end
64
67
  end
65
68
  ```
66
- <!-- <<<<<< END INCLUDED FILE (ruby): SOURCE readme_files/include.rb -->
69
+ <!-- <<<<<< END INCLUDED FILE (ruby): SOURCE markdown/include.rb -->
67
70
 
68
71
  #### Plain Code Block
69
72
 
70
- <!-- >>>>>> BEGIN INCLUDED FILE (code_block): SOURCE readme_files/include.rb -->
73
+ <!-- >>>>>> BEGIN INCLUDED FILE (code_block): SOURCE markdown/include.rb -->
71
74
  <code>include.rb</code>
72
75
  ```
73
76
  class RubyCode
@@ -76,7 +79,7 @@ class RubyCode
76
79
  end
77
80
  end
78
81
  ```
79
- <!-- <<<<<< END INCLUDED FILE (code_block): SOURCE readme_files/include.rb -->
82
+ <!-- <<<<<< END INCLUDED FILE (code_block): SOURCE markdown/include.rb -->
80
83
 
81
84
  [Note: In the gem documentation, RubyDoc.info chooses to highlight this code block regardless. Go figure.]
82
85
 
@@ -94,11 +97,11 @@ The verbatim text is itself scanned for nested includes.
94
97
 
95
98
  #### CLI
96
99
 
97
- <!-- >>>>>> BEGIN INCLUDED FILE (code_block): SOURCE readme_files/../bin/usage/include.txt -->
100
+ <!-- >>>>>> BEGIN INCLUDED FILE (code_block): SOURCE markdown/../bin/usage/include.txt -->
98
101
  <code>include.txt</code>
99
102
  ```
100
103
 
101
- Usage: include [options] template_file_path markdown_file_page
104
+ Usage: markdown_helper include [options] template_file_path markdown_file_path
102
105
  --pristine No comments added
103
106
  --help Display help
104
107
 
@@ -112,11 +115,11 @@ Usage: include [options] template_file_path markdown_file_page
112
115
  * Both file types are .md.
113
116
  * The template file contains file inclusion descriptions.
114
117
  ```
115
- <!-- <<<<<< END INCLUDED FILE (code_block): SOURCE readme_files/../bin/usage/include.txt -->
118
+ <!-- <<<<<< END INCLUDED FILE (code_block): SOURCE markdown/../bin/usage/include.txt -->
116
119
 
117
120
  #### API
118
121
 
119
- <!-- >>>>>> BEGIN INCLUDED FILE (ruby): SOURCE readme_files/include_usage.rb -->
122
+ <!-- >>>>>> BEGIN INCLUDED FILE (ruby): SOURCE markdown/include_usage.rb -->
120
123
  <code>include_usage.rb</code>
121
124
  ```ruby
122
125
  require 'markdown_helper'
@@ -132,7 +135,7 @@ markdown_helper.include(template_file_path, markdown_file_path)
132
135
  markdown_helper = MarkdownHelper.new(:pristine => true)
133
136
  markdown_helper.include(template_file_path, markdown_file_path)
134
137
  ```
135
- <!-- <<<<<< END INCLUDED FILE (ruby): SOURCE readme_files/include_usage.rb -->
138
+ <!-- <<<<<< END INCLUDED FILE (ruby): SOURCE markdown/include_usage.rb -->
136
139
 
137
140
  #### Include Descriptions
138
141
 
@@ -150,7 +153,7 @@ where:
150
153
 
151
154
  ##### Example Include Descriptions
152
155
 
153
- <!-- >>>>>> BEGIN INCLUDED FILE (code_block): SOURCE readme_files/include.md -->
156
+ <!-- >>>>>> BEGIN INCLUDED FILE (code_block): SOURCE markdown/include.md -->
154
157
  <code>include.md</code>
155
158
  ```code_block
156
159
  @[ruby](my_ruby.rb)
@@ -159,7 +162,7 @@ where:
159
162
 
160
163
  @[:verbatim](my_markdown.md)
161
164
  ```
162
- <!-- <<<<<< END INCLUDED FILE (code_block): SOURCE readme_files/include.md -->
165
+ <!-- <<<<<< END INCLUDED FILE (code_block): SOURCE markdown/include.md -->
163
166
 
164
167
  ## Image Path Resolution
165
168
 
@@ -181,10 +184,11 @@ This matters because when markdown becomes part of a Ruby gem, its images will h
181
184
 
182
185
  #### CLI
183
186
 
184
- <!-- >>>>>> BEGIN INCLUDED FILE (code_block): SOURCE readme_files/../bin/usage/resolve.txt -->
187
+ <!-- >>>>>> BEGIN INCLUDED FILE (code_block): SOURCE markdown/../bin/usage/resolve.txt -->
185
188
  <code>resolve.txt</code>
186
189
  ```
187
- Usage: bin/resolve [options] template_file_path markdown_file_page
190
+
191
+ Usage: markdown_helper resolve [options] template_file_path markdown_file_path
188
192
  --pristine No comments added
189
193
  --help Display help
190
194
 
@@ -198,11 +202,11 @@ Usage: bin/resolve [options] template_file_path markdown_file_page
198
202
  * Both file types are .md.
199
203
  * The template file contains image descriptions.
200
204
  ```
201
- <!-- <<<<<< END INCLUDED FILE (code_block): SOURCE readme_files/../bin/usage/resolve.txt -->
205
+ <!-- <<<<<< END INCLUDED FILE (code_block): SOURCE markdown/../bin/usage/resolve.txt -->
202
206
 
203
207
  #### API
204
208
 
205
- <!-- >>>>>> BEGIN INCLUDED FILE (ruby): SOURCE readme_files/resolve_usage.rb -->
209
+ <!-- >>>>>> BEGIN INCLUDED FILE (ruby): SOURCE markdown/resolve_usage.rb -->
206
210
  <code>resolve_usage.rb</code>
207
211
  ```ruby
208
212
  require 'markdown_helper'
@@ -218,7 +222,7 @@ markdown_helper.resolve(template_file_path, markdown_file_path)
218
222
  markdown_helper = MarkdownHelper.new(:pristine => true)
219
223
  markdown_helper.resolve(template_file_path, markdown_file_path)
220
224
  ```
221
- <!-- <<<<<< END INCLUDED FILE (ruby): SOURCE readme_files/resolve_usage.rb -->
225
+ <!-- <<<<<< END INCLUDED FILE (ruby): SOURCE markdown/resolve_usage.rb -->
222
226
 
223
227
  #### Image Descriptions
224
228
 
@@ -234,7 +238,7 @@ where:
234
238
 
235
239
  ##### Example Image Descriptions
236
240
 
237
- <!-- >>>>>> BEGIN INCLUDED FILE (code_block): SOURCE readme_files/resolve.md -->
241
+ <!-- >>>>>> BEGIN INCLUDED FILE (code_block): SOURCE markdown/resolve.md -->
238
242
  <code>resolve.md</code>
239
243
  ```code_block
240
244
  ![my_alt](image/image.png)
@@ -243,7 +247,7 @@ where:
243
247
 
244
248
  ![my_alt](image/image.png| width=50 height=50)
245
249
  ```
246
- <!-- <<<<<< END INCLUDED FILE (code_block): SOURCE readme_files/resolve.md -->
250
+ <!-- <<<<<< END INCLUDED FILE (code_block): SOURCE markdown/resolve.md -->
247
251
 
248
252
  ## Image Attributes
249
253
 
@@ -263,10 +267,11 @@ Use the markdown helper to add image attributes in a markdown (</code>.md</code>
263
267
 
264
268
  #### CLI
265
269
 
266
- <!-- >>>>>> BEGIN INCLUDED FILE (code_block): SOURCE readme_files/../bin/usage/resolve.txt -->
270
+ <!-- >>>>>> BEGIN INCLUDED FILE (code_block): SOURCE markdown/../bin/usage/resolve.txt -->
267
271
  <code>resolve.txt</code>
268
272
  ```
269
- Usage: bin/resolve [options] template_file_path markdown_file_page
273
+
274
+ Usage: markdown_helper resolve [options] template_file_path markdown_file_path
270
275
  --pristine No comments added
271
276
  --help Display help
272
277
 
@@ -280,11 +285,11 @@ Usage: bin/resolve [options] template_file_path markdown_file_page
280
285
  * Both file types are .md.
281
286
  * The template file contains image descriptions.
282
287
  ```
283
- <!-- <<<<<< END INCLUDED FILE (code_block): SOURCE readme_files/../bin/usage/resolve.txt -->
288
+ <!-- <<<<<< END INCLUDED FILE (code_block): SOURCE markdown/../bin/usage/resolve.txt -->
284
289
 
285
290
  #### API
286
291
 
287
- <!-- >>>>>> BEGIN INCLUDED FILE (ruby): SOURCE readme_files/resolve_usage.rb -->
292
+ <!-- >>>>>> BEGIN INCLUDED FILE (ruby): SOURCE markdown/resolve_usage.rb -->
288
293
  <code>resolve_usage.rb</code>
289
294
  ```ruby
290
295
  require 'markdown_helper'
@@ -300,7 +305,7 @@ markdown_helper.resolve(template_file_path, markdown_file_path)
300
305
  markdown_helper = MarkdownHelper.new(:pristine => true)
301
306
  markdown_helper.resolve(template_file_path, markdown_file_path)
302
307
  ```
303
- <!-- <<<<<< END INCLUDED FILE (ruby): SOURCE readme_files/resolve_usage.rb -->
308
+ <!-- <<<<<< END INCLUDED FILE (ruby): SOURCE markdown/resolve_usage.rb -->
304
309
 
305
310
  #### Image Descriptions
306
311
 
@@ -316,7 +321,7 @@ where:
316
321
 
317
322
  ##### Example Image Descriptions
318
323
 
319
- <!-- >>>>>> BEGIN INCLUDED FILE (code_block): SOURCE readme_files/resolve.md -->
324
+ <!-- >>>>>> BEGIN INCLUDED FILE (code_block): SOURCE markdown/resolve.md -->
320
325
  <code>resolve.md</code>
321
326
  ```code_block
322
327
  ![my_alt](image/image.png)
@@ -325,7 +330,7 @@ where:
325
330
 
326
331
  ![my_alt](image/image.png| width=50 height=50)
327
332
  ```
328
- <!-- <<<<<< END INCLUDED FILE (code_block): SOURCE readme_files/resolve.md -->
333
+ <!-- <<<<<< END INCLUDED FILE (code_block): SOURCE markdown/resolve.md -->
329
334
 
330
335
  ## What Should Be Next?
331
336
 
@@ -338,5 +343,5 @@ I have opened some enhancement Issues in the GitHub [markdown_helper](https://gi
338
343
  * [Pagination](https://github.com/BurdetteLamar/markdown_helper/issues/40): series of markdown pages connected by prev/next navigation links.
339
344
 
340
345
  Feel free to comment on any of these, or to add more Issues (enhancement or otherwise).
341
- <!-- <<<<<< END GENERATED FILE (resolve): SOURCE readme_files/README.template.md -->
342
- <!-- <<<<<< END GENERATED FILE (include): SOURCE readme_files/temp_resolved.md -->
346
+ <!-- <<<<<< END GENERATED FILE (resolve): SOURCE markdown/README.template.md -->
347
+ <!-- <<<<<< END GENERATED FILE (include): SOURCE markdown/temp_resolved.md -->
data/Rakefile CHANGED
@@ -14,14 +14,14 @@ namespace :build do
14
14
  Rake::Task['build:usages'].invoke
15
15
  require_relative 'lib/markdown_helper'
16
16
  markdown_helper = MarkdownHelper.new
17
- template_file_path = 'readme_files/highlight_ruby_template.md'
18
- markdown_file_path = 'readme_files/highlighted_ruby.md'
17
+ template_file_path = 'markdown/highlight_ruby_template.md'
18
+ markdown_file_path = 'markdown/highlighted_ruby.md'
19
19
  markdown_helper.include(template_file_path, markdown_file_path)
20
20
  # Do the resolve before the include, so that the included text is not also resolved.
21
21
  # This protects example code from being also resolved, thus damaging the example code.
22
22
  # Temp file must be in the same directory as its source (it becomes the source).
23
- temp_file_path = 'readme_files/temp_resolved.md'
24
- markdown_helper.resolve('readme_files/README.template.md', temp_file_path)
23
+ temp_file_path = 'markdown/temp_resolved.md'
24
+ markdown_helper.resolve('markdown/README.template.md', temp_file_path)
25
25
  readme_file_path = 'README.md'
26
26
  markdown_helper.include(temp_file_path, readme_file_path)
27
27
  File.delete(temp_file_path)
@@ -33,7 +33,7 @@ namespace :build do
33
33
  include
34
34
  resolve
35
35
  /.each do |executable_name|
36
- usage_text = `ruby bin/#{executable_name} --help`
36
+ usage_text = `ruby bin/_#{executable_name} --help`
37
37
  usage_file_path = "bin/usage/#{executable_name}.txt"
38
38
  File.open(usage_file_path, 'w') do |file|
39
39
  file.puts(usage_text)
data/bin/_include ADDED
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+
5
+ require 'markdown_helper'
6
+
7
+ options = {:pristine => false}
8
+
9
+ # Save opts for use below.
10
+ opts = nil
11
+ parser = OptionParser.new do |_opts|
12
+ opts = _opts
13
+ _opts.banner = "Usage: markdown_helper include [options] template_file_path markdown_file_path"
14
+ _opts.on('--pristine', 'No comments added') do |_|
15
+ options[:pristine] = true
16
+ end
17
+ _opts.on('--help', 'Display help') do
18
+ usage(_opts)
19
+ end
20
+ end
21
+
22
+ def usage(opts)
23
+ puts ''
24
+ puts opts
25
+ puts <<-EOT
26
+
27
+ where
28
+
29
+ * template_file_path is the path to an existing file.
30
+ * markdown_file_path is the path to a file to be created.
31
+
32
+ Typically:
33
+
34
+ * Both file types are .md.
35
+ * The template file contains file inclusion descriptions.
36
+ EOT
37
+ exit
38
+ end
39
+
40
+ parser.parse!
41
+
42
+ template_file_path, markdown_file_path = ARGV
43
+
44
+ usage(opts) unless ARGV.size == 2
45
+ usage(opts) unless File.readable?(template_file_path)
46
+ usage(opts) unless File.writable?(File.dirname(markdown_file_path))
47
+
48
+ MarkdownHelper.new(options).include(template_file_path, markdown_file_path)
49
+
data/bin/_resolve ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+
5
+ require 'markdown_helper'
6
+
7
+ options = {:pristine => false}
8
+
9
+ # Save opts for use below.
10
+ opts = nil
11
+ parser = OptionParser.new do |_opts|
12
+ opts = _opts
13
+ _opts.banner = "Usage: markdown_helper resolve [options] template_file_path markdown_file_path"
14
+ _opts.on('--pristine', 'No comments added') do |_|
15
+ options[:pristine] = true
16
+ end
17
+ _opts.on('--help', 'Display help') do
18
+ usage(_opts)
19
+ end
20
+ end
21
+
22
+ def usage(opts)
23
+ puts ''
24
+ puts opts
25
+ puts <<-EOT
26
+
27
+ where
28
+
29
+ * template_file_path is the path to an existing file.
30
+ * markdown_file_path is the path to a file to be created.
31
+
32
+ Typically:
33
+
34
+ * Both file types are .md.
35
+ * The template file contains image descriptions.
36
+ EOT
37
+ exit
38
+ end
39
+
40
+ parser.parse!
41
+
42
+ template_file_path, markdown_file_path = ARGV
43
+
44
+ usage(opts) unless ARGV.size == 2
45
+ usage(opts) unless File.readable?(template_file_path)
46
+ usage(opts) unless File.writable?(File.dirname(markdown_file_path))
47
+
48
+ MarkdownHelper.new(options).resolve(template_file_path, markdown_file_path)
data/bin/include CHANGED
@@ -10,7 +10,7 @@ options = {:pristine => false}
10
10
  opts = nil
11
11
  parser = OptionParser.new do |_opts|
12
12
  opts = _opts
13
- _opts.banner = "Usage: #{File.basename(__FILE__)} [options] template_file_path markdown_file_page"
13
+ _opts.banner = "Usage: #{File.basename(__FILE__)} [options] template_file_path markdown_file_path"
14
14
  _opts.on('--pristine', 'No comments added') do |_|
15
15
  options[:pristine] = true
16
16
  end
@@ -45,14 +45,6 @@ usage(opts) unless ARGV.size == 2
45
45
  usage(opts) unless File.readable?(template_file_path)
46
46
  usage(opts) unless File.writable?(File.dirname(markdown_file_path))
47
47
 
48
- # This code, outside of a class, had interference from Module#include.
49
- # So now it's in a class.
50
- class AvoidModule
51
- def initialize(template_file_path, markdown_file_path, options)
52
- markdown_helper = MarkdownHelper.new(options)
53
- markdown_helper.include(template_file_path, markdown_file_path)
54
- end
55
- end
56
-
57
- AvoidModule.new(template_file_path, markdown_file_path, options)
48
+ warn('This include is deprecated. Please use command "markdown_helper include".')
49
+ MarkdownHelper.new(options).include(template_file_path, markdown_file_path)
58
50
 
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'markdown_helper'
4
+
5
+ # Each command foo has a corresponding Ruby executable _foo.
6
+ def command_keywords
7
+ dir_path = File.dirname(__FILE__)
8
+ dirs = Dir.entries(dir_path)
9
+ command_file_names = dirs.select{ |x| x.start_with?('_')}
10
+ command_file_names.collect {|x| x.sub(/^_/, '')}
11
+ end
12
+
13
+
14
+ def usage
15
+ puts <<-EOT
16
+ Usage: markdown_helper command [options] [args]
17
+
18
+ where
19
+
20
+ * Command is one of #{command_keywords.inspect}.
21
+
22
+ EOT
23
+ exit
24
+ end
25
+
26
+ command_keyword = ARGV[0]
27
+ unless command_keywords.include?(command_keyword)
28
+ usage
29
+ end
30
+
31
+ bindir = File.dirname(__FILE__)
32
+ bin_file_path = File.absolute_path(File.join(
33
+ bindir,
34
+ '_' + command_keyword,
35
+ ))
36
+ command = "ruby #{bin_file_path}"
37
+ system(command)
data/bin/resolve CHANGED
@@ -6,17 +6,21 @@ require 'markdown_helper'
6
6
 
7
7
  options = {:pristine => false}
8
8
 
9
- parser = OptionParser.new do|opts|
10
- opts.banner = "Usage: #{__FILE__} [options] template_file_path markdown_file_page"
11
- opts.on('--pristine', 'No comments added') do |_|
9
+ # Save opts for use below.
10
+ opts = nil
11
+ parser = OptionParser.new do |_opts|
12
+ opts = _opts
13
+ _opts.banner = "Usage: #{File.basename(__FILE__)} [options] template_file_path markdown_file_path"
14
+ _opts.on('--pristine', 'No comments added') do |_|
12
15
  options[:pristine] = true
13
16
  end
14
- opts.on('--help', 'Display help') do
15
- usage(opts)
17
+ _opts.on('--help', 'Display help') do
18
+ usage(_opts)
16
19
  end
17
20
  end
18
21
 
19
22
  def usage(opts)
23
+ puts ''
20
24
  puts opts
21
25
  puts <<-EOT
22
26
 
@@ -37,8 +41,9 @@ parser.parse!
37
41
 
38
42
  template_file_path, markdown_file_path = ARGV
39
43
 
40
- usage(options) unless ARGV.size == 2
41
- usage(options) unless File.readable?(template_file_path)
42
- usage(options) unless File.writable?(File.dirname(markdown_file_path))
44
+ usage(opts) unless ARGV.size == 2
45
+ usage(opts) unless File.readable?(template_file_path)
46
+ usage(opts) unless File.writable?(File.dirname(markdown_file_path))
43
47
 
48
+ warn('This resolve is deprecated. Please use command "markdown_helper resolve".')
44
49
  MarkdownHelper.new(options).resolve(template_file_path, markdown_file_path)
@@ -1,5 +1,5 @@
1
1
 
2
- Usage: include [options] template_file_path markdown_file_page
2
+ Usage: markdown_helper include [options] template_file_path markdown_file_path
3
3
  --pristine No comments added
4
4
  --help Display help
5
5
 
@@ -1,4 +1,5 @@
1
- Usage: bin/resolve [options] template_file_path markdown_file_page
1
+
2
+ Usage: markdown_helper resolve [options] template_file_path markdown_file_path
2
3
  --pristine No comments added
3
4
  --help Display help
4
5
 
@@ -42,7 +42,7 @@ class MarkdownHelper
42
42
  # @[:verbatim](foo.md)
43
43
  def include(template_file_path, markdown_file_path)
44
44
  send(:generate_file, template_file_path, markdown_file_path, __method__) do |input_lines, output_lines|
45
- send(:include_files, template_file_path, input_lines, output_lines, paths = [], realpaths = [])
45
+ send(:include_files, template_file_path, input_lines, output_lines, verbatim_inclusions = {})
46
46
  end
47
47
  end
48
48
 
@@ -106,31 +106,17 @@ class MarkdownHelper
106
106
  output
107
107
  end
108
108
 
109
- def include_files(template_file_path, input_lines, output_lines, paths, realpaths)
110
- realpath = Pathname.new(template_file_path).realpath
111
- i = realpaths.index(realpath)
112
- if i
113
- old_path = paths[i]
114
- new_path = template_file_path
115
- realpath = realpaths[i]
116
- message = <<EOT
117
- Includes are circular:
118
- Old path: #{old_path}
119
- New path: #{new_path}
120
- Real path: #{realpath}
121
- EOT
122
- raise RuntimeError.new(message)
123
- end
124
- paths.push(template_file_path)
125
- realpaths.push(realpath)
109
+ def include_files(includer_file_path, input_lines, output_lines, verbatim_inclusions)
126
110
 
127
- input_lines.each do |input_line|
111
+ input_lines.each_with_index do |input_line, line_index|
128
112
  match_data = input_line.match(INCLUDE_REGEXP)
129
113
  unless match_data
130
114
  output_lines.push(input_line)
131
115
  next
132
116
  end
133
- treatment = case match_data[1]
117
+ treatment = match_data[1]
118
+ relative_included_file_path = match_data[2]
119
+ treatment = case treatment
134
120
  when ':code_block'
135
121
  :code_block
136
122
  when ':verbatim'
@@ -138,28 +124,46 @@ EOT
138
124
  when ':comment'
139
125
  :comment
140
126
  else
141
- match_data[1]
127
+ treatment
142
128
  end
143
- relative_file_path = match_data[2]
144
- include_file_path = File.join(
145
- File.dirname(template_file_path),
146
- relative_file_path,
129
+ new_inclusion = Inclusion.new(
130
+ includer_file_path,
131
+ includer_line_number = line_index + 1,
132
+ relative_included_file_path
147
133
  )
148
- output_lines.push(comment(" >>>>>> BEGIN INCLUDED FILE (#{treatment}): SOURCE #{include_file_path} ")) unless pristine
149
- include_lines = File.readlines(include_file_path)
134
+ included_real_path = new_inclusion.included_real_path
135
+ if treatment == :verbatim
136
+ previously_included = verbatim_inclusions.include?(new_inclusion.included_real_path)
137
+ if previously_included
138
+ backtrace = verbatim_inclusions.values.push(new_inclusion)
139
+ message_lines = ['Includes are circular:']
140
+ backtrace.each_with_index do |inclusion, i|
141
+ message_lines.push(" Level #{i}:")
142
+ message_lines.push(" Includer: #{inclusion.includer_file_path}:#{inclusion.includer_line_number}")
143
+ message_lines.push(" Relative file path: #{inclusion.relative_included_file_path}")
144
+ message_lines.push(" Included file path: #{inclusion.included_file_path}")
145
+ message_lines.push(" Real file_path: #{inclusion.included_real_path}")
146
+ end
147
+ message = message_lines.join("\n")
148
+ raise RuntimeError.new(message)
149
+ end
150
+ verbatim_inclusions[included_real_path] = new_inclusion
151
+ end
152
+ output_lines.push(comment(" >>>>>> BEGIN INCLUDED FILE (#{treatment}): SOURCE #{new_inclusion.included_file_path} ")) unless pristine
153
+ include_lines = File.readlines(new_inclusion.included_file_path)
150
154
  unless include_lines.last.match("\n")
151
- message = "Warning: Included file has no trailing newline: #{include_file_path}"
155
+ message = "Warning: Included file has no trailing newline: #{relative_included_file_path}"
152
156
  warn(message)
153
157
  end
154
158
  case treatment
155
159
  when :verbatim
156
160
  # Pass through unadorned, but honor any nested includes.
157
- include_files(include_file_path, include_lines, output_lines, paths, realpaths)
161
+ include_files(new_inclusion.included_file_path, include_lines, output_lines, verbatim_inclusions)
158
162
  when :comment
159
163
  output_lines.push(comment(include_lines.join('')))
160
164
  else
161
165
  # Use the file name as a label.
162
- file_name_line = format("<code>%s</code>\n", File.basename(include_file_path))
166
+ file_name_line = format("<code>%s</code>\n", File.basename(relative_included_file_path))
163
167
  output_lines.push(file_name_line)
164
168
  # Put into code block.
165
169
  language = treatment == :code_block ? '' : treatment
@@ -167,48 +171,77 @@ EOT
167
171
  output_lines.push(*include_lines)
168
172
  output_lines.push("```\n")
169
173
  end
170
- output_lines.push(comment(" <<<<<< END INCLUDED FILE (#{treatment}): SOURCE #{include_file_path} ")) unless pristine
174
+ output_lines.push(comment(" <<<<<< END INCLUDED FILE (#{treatment}): SOURCE #{new_inclusion.included_file_path} ")) unless pristine
171
175
  end
172
176
  end
173
177
 
174
178
  def resolve_images(input_lines, output_lines)
175
- input_lines.each do |input_line|
176
- scan_data = input_line.scan(IMAGE_REGEXP)
177
- if scan_data.empty?
178
- output_lines.push(input_line)
179
- next
180
- end
181
- output_lines.push(comment(" >>>>>> BEGIN RESOLVED IMAGES: INPUT-LINE '#{input_line}' ")) unless pristine
182
- output_line = input_line
183
- scan_data.each do |alt_text, path_and_attributes|
184
- relative_file_path, attributes_s =path_and_attributes.split(/\s?\|\s?/, 2)
185
- attributes = attributes_s ? attributes_s.split(/\s+/) : []
186
- formatted_attributes = ['']
187
- attributes.each do |attribute|
188
- name, value = attribute.split('=', 2)
189
- formatted_attributes.push(format('%s="%s"', name, value))
179
+ input_lines.each do |input_line|
180
+ scan_data = input_line.scan(IMAGE_REGEXP)
181
+ if scan_data.empty?
182
+ output_lines.push(input_line)
183
+ next
190
184
  end
191
- formatted_attributes_s = formatted_attributes.join(' ')
192
- repo_user, repo_name = repo_user_and_name
193
- if relative_file_path.start_with?('http')
194
- absolute_file_path = relative_file_path
195
- else
196
- absolute_file_path = File.join(
197
- "https://raw.githubusercontent.com/#{repo_user}/#{repo_name}/master",
198
- relative_file_path,
185
+ output_lines.push(comment(" >>>>>> BEGIN RESOLVED IMAGES: INPUT-LINE '#{input_line}' ")) unless pristine
186
+ output_line = input_line
187
+ scan_data.each do |alt_text, path_and_attributes|
188
+ relative_file_path, attributes_s =path_and_attributes.split(/\s?\|\s?/, 2)
189
+ attributes = attributes_s ? attributes_s.split(/\s+/) : []
190
+ formatted_attributes = ['']
191
+ attributes.each do |attribute|
192
+ name, value = attribute.split('=', 2)
193
+ formatted_attributes.push(format('%s="%s"', name, value))
194
+ end
195
+ formatted_attributes_s = formatted_attributes.join(' ')
196
+ repo_user, repo_name = repo_user_and_name
197
+ if relative_file_path.start_with?('http')
198
+ absolute_file_path = relative_file_path
199
+ else
200
+ absolute_file_path = File.join(
201
+ "https://raw.githubusercontent.com/#{repo_user}/#{repo_name}/master",
202
+ relative_file_path,
203
+ )
204
+ end
205
+ img_element = format(
206
+ '<img src="%s" alt="%s"%s>',
207
+ absolute_file_path,
208
+ alt_text,
209
+ formatted_attributes_s,
199
210
  )
211
+ output_line = output_line.sub(IMAGE_REGEXP, img_element)
200
212
  end
201
- img_element = format(
202
- '<img src="%s" alt="%s"%s>',
203
- absolute_file_path,
204
- alt_text,
205
- formatted_attributes_s,
206
- )
207
- output_line = output_line.sub(IMAGE_REGEXP, img_element)
213
+ output_lines.push(output_line)
214
+ output_lines.push(comment(" <<<<<< END RESOLVED IMAGES: INPUT-LINE '#{input_line}' ")) unless pristine
208
215
  end
209
- output_lines.push(output_line)
210
- output_lines.push(comment(" <<<<<< END RESOLVED IMAGES: INPUT-LINE '#{input_line}' ")) unless pristine
216
+
211
217
  end
218
+
219
+ class Inclusion
220
+
221
+ attr_accessor \
222
+ :includer_file_path,
223
+ :includer_line_number,
224
+ :relative_included_file_path,
225
+ :included_file_path,
226
+ :included_real_path
227
+
228
+ def initialize(
229
+ includer_file_path,
230
+ includer_line_number,
231
+ relative_included_file_path
232
+ )
233
+ included_file_path = File.join(
234
+ File.dirname(includer_file_path),
235
+ relative_included_file_path,
236
+ )
237
+ self.includer_file_path = includer_file_path
238
+ self.includer_line_number = includer_line_number
239
+ self.relative_included_file_path = relative_included_file_path
240
+ self.included_file_path = included_file_path
241
+ self.included_real_path = Pathname.new(included_file_path).realpath.to_s
242
+ end
243
+
212
244
  end
213
245
 
214
246
  end
247
+
@@ -1,3 +1,3 @@
1
1
  class MarkdownHelper
2
- VERSION = '1.5.1'
2
+ VERSION = '1.6.0'
3
3
  end
@@ -1,10 +1,13 @@
1
1
  # Markdown Helper
2
2
 
3
- ![Gem Version](https://badge.fury.io/rb/markdown_helper.svg)
3
+ ![Gem Version](https://badge.fury.io/rb/markdown_helper.svg) [Visit gem markdown_helper](https://rubygems.org/gems/markdown_helper)
4
4
 
5
5
  ## What's New?
6
6
 
7
- Nested file inclusion is now supported, which means that an included file can include more files. This applies only to a file included verbatim, not to a file included as a code block or as a markdown comment.
7
+ Command-line interface is now supported:
8
+
9
+ * ```markdown_helper include [options] template_file_path markdown_file_path```
10
+ * ```markdown_helper resolve [options] template_file_path markdown_file_path```
8
11
 
9
12
  ## What's This?
10
13
 
@@ -0,0 +1,12 @@
1
+ <!-- >>>>>> BEGIN GENERATED FILE (include): SOURCE markdown/highlight_ruby_template.md -->
2
+ <!-- >>>>>> BEGIN INCLUDED FILE (ruby): SOURCE markdown/include.rb -->
3
+ <code>include.rb</code>
4
+ ```ruby
5
+ class RubyCode
6
+ def initialize
7
+ raise RuntimeError.new('I am only an example!')
8
+ end
9
+ end
10
+ ```
11
+ <!-- <<<<<< END INCLUDED FILE (ruby): SOURCE markdown/include.rb -->
12
+ <!-- <<<<<< END GENERATED FILE (include): SOURCE markdown/highlight_ruby_template.md -->
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,67 @@
1
+ reusable_text_file_name = 'reusable_text.md'
2
+ includer_file_name = 'includer.md'
3
+ included_file_name = 'included.md'
4
+ template_file_name = 'template.md'
5
+ use_case_file_name = 'use_case.md'
6
+
7
+ include_command = "ruby ../../../bin/include --pristine #{includer_file_name} #{included_file_name}"
8
+ build_command = "ruby ../../../bin/include --pristine #{template_file_name} #{use_case_file_name}"
9
+
10
+ template = <<EOT
11
+ ### Reusable Text
12
+
13
+ Use file inclusion to stay DRY (Don't Repeat Yourself).
14
+
15
+ Maintain reusable text in a separate file, then include it wherever it's needed.
16
+
17
+ #### Separate File
18
+
19
+ Here's a file containing some text that can be included in more than one place:
20
+
21
+ @[:code_block](#{reusable_text_file_name})
22
+
23
+ #### Template File
24
+
25
+ Here's a template file that includes it:
26
+
27
+ @[:code_block](#{includer_file_name})
28
+
29
+ #### Command
30
+
31
+ Here's the command to perform the inclusion (```--pristine``` suppresses inclusion comments):
32
+
33
+ ```sh
34
+ #{include_command}
35
+ ```
36
+
37
+ #### Included File
38
+
39
+ Here's the finished file with the inclusion:
40
+
41
+ @[:code_block](#{included_file_name})
42
+ EOT
43
+
44
+ reusable_text = <<EOT
45
+ This is some useful text that can be included in more than one place (actually, in more than one file).
46
+ EOT
47
+
48
+ includer = <<EOT
49
+ This file includes the useful text.
50
+
51
+ @[:verbatim](#{reusable_text_file_name})
52
+ EOT
53
+
54
+ # Write markdown files.
55
+ {
56
+ template_file_name => template,
57
+ reusable_text_file_name => reusable_text,
58
+ includer_file_name => includer,
59
+ }.each_pair do |file_name, text|
60
+ File.write(file_name, text)
61
+ end
62
+
63
+ # Perform the inclusion.
64
+ system(include_command)
65
+
66
+ # Build the use case.
67
+ system(build_command)
@@ -0,0 +1,3 @@
1
+ This file includes the useful text.
2
+
3
+ This is some useful text that can be included in more than one place (actually, in more than one file).
@@ -0,0 +1,3 @@
1
+ This file includes the useful text.
2
+
3
+ @[:verbatim](reusable_text.md)
@@ -0,0 +1 @@
1
+ This is some useful text that can be included in more than one place (actually, in more than one file).
@@ -0,0 +1,31 @@
1
+ ### Reusable Text
2
+
3
+ Use file inclusion to stay DRY (Don't Repeat Yourself).
4
+
5
+ Maintain reusable text in a separate file, then include it wherever it's needed.
6
+
7
+ #### Separate File
8
+
9
+ Here's a file containing some text that can be included in more than one place:
10
+
11
+ @[:code_block](reusable_text.md)
12
+
13
+ #### Template File
14
+
15
+ Here's a template file that includes it:
16
+
17
+ @[:code_block](includer.md)
18
+
19
+ #### Command
20
+
21
+ Here's the command to perform the inclusion (```--pristine``` suppresses inclusion comments):
22
+
23
+ ```sh
24
+ ruby ../../../bin/include --pristine includer.md included.md
25
+ ```
26
+
27
+ #### Included File
28
+
29
+ Here's the finished file with the inclusion:
30
+
31
+ @[:code_block](included.md)
@@ -0,0 +1,44 @@
1
+ ### Reusable Text
2
+
3
+ Use file inclusion to stay DRY (Don't Repeat Yourself).
4
+
5
+ Maintain reusable text in a separate file, then include it wherever it's needed.
6
+
7
+ #### Separate File
8
+
9
+ Here's a file containing some text that can be included in more than one place:
10
+
11
+ <code>reusable_text.md</code>
12
+ ```
13
+ This is some useful text that can be included in more than one place (actually, in more than one file).
14
+ ```
15
+
16
+ #### Template File
17
+
18
+ Here's a template file that includes it:
19
+
20
+ <code>includer.md</code>
21
+ ```
22
+ This file includes the useful text.
23
+
24
+ @[:verbatim](reusable_text.md)
25
+ ```
26
+
27
+ #### Command
28
+
29
+ Here's the command to perform the inclusion (```--pristine``` suppresses inclusion comments):
30
+
31
+ ```sh
32
+ ruby ../../../bin/include --pristine includer.md included.md
33
+ ```
34
+
35
+ #### Included File
36
+
37
+ Here's the finished file with the inclusion:
38
+
39
+ <code>included.md</code>
40
+ ```
41
+ This file includes the useful text.
42
+
43
+ This is some useful text that can be included in more than one place (actually, in more than one file).
44
+ ```
@@ -8,7 +8,6 @@ Gem::Specification.new do |spec|
8
8
  spec.version = MarkdownHelper::VERSION
9
9
  spec.authors = ['burdettelamar']
10
10
  spec.email = ['BurdetteLamar@Yahoo.com']
11
-
12
11
  spec.summary = 'Class to help with GitHub markdown.'
13
12
  spec.description = <<-EOT
14
13
  Class to help with GitHub markdown:
@@ -33,8 +32,8 @@ EOT
33
32
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
34
33
  f.match(%r{^(test|spec|features)/})
35
34
  end
36
- spec.bindir = 'exe'
37
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.bindir = 'bin'
36
+ spec.executables = ['markdown_helper']
38
37
  spec.require_paths = ['lib']
39
38
 
40
39
  spec.add_development_dependency 'bundler', '~> 1.14'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdown_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - burdettelamar
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-08 00:00:00.000000000 Z
11
+ date: 2018-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -74,7 +74,8 @@ description: |
74
74
  * Image attributes
75
75
  email:
76
76
  - BurdetteLamar@Yahoo.com
77
- executables: []
77
+ executables:
78
+ - markdown_helper
78
79
  extensions: []
79
80
  extra_rdoc_files: []
80
81
  files:
@@ -88,8 +89,11 @@ files:
88
89
  - README.md
89
90
  - Rakefile
90
91
  - _config.yml
92
+ - bin/_include
93
+ - bin/_resolve
91
94
  - bin/console
92
95
  - bin/include
96
+ - bin/markdown_helper
93
97
  - bin/resolve
94
98
  - bin/setup
95
99
  - bin/usage/include.txt
@@ -99,22 +103,27 @@ files:
99
103
  - images/include.png
100
104
  - lib/markdown_helper.rb
101
105
  - lib/markdown_helper/version.rb
106
+ - markdown/README.template.md
107
+ - markdown/code_block_ruby_template.md
108
+ - markdown/highlight_ruby_template.md
109
+ - markdown/highlighted_ruby.md
110
+ - markdown/include.md
111
+ - markdown/include.rb
112
+ - markdown/include_usage.rb
113
+ - markdown/resolve.md
114
+ - markdown/resolve_usage.rb
115
+ - markdown/use_cases/evergreen_examples.md
116
+ - markdown/use_cases/generated_text.md
117
+ - markdown/use_cases/image_attributes.md
118
+ - markdown/use_cases/reusable_text/build.rb
119
+ - markdown/use_cases/reusable_text/included.md
120
+ - markdown/use_cases/reusable_text/includer.md
121
+ - markdown/use_cases/reusable_text/reusable_text.md
122
+ - markdown/use_cases/reusable_text/template.md
123
+ - markdown/use_cases/reusable_text/use_case.md
124
+ - markdown/use_cases/rubygem_images.md
125
+ - markdown/verbatim_ruby_template.md
102
126
  - markdown_helper.gemspec
103
- - readme_files/README.template.md
104
- - readme_files/code_block_ruby_template.md
105
- - readme_files/highlight_ruby_template.md
106
- - readme_files/highlighted_ruby.md
107
- - readme_files/include.md
108
- - readme_files/include.rb
109
- - readme_files/include_usage.rb
110
- - readme_files/resolve.md
111
- - readme_files/resolve_usage.rb
112
- - readme_files/use_cases/evergreen_examples.md
113
- - readme_files/use_cases/generated_text.md
114
- - readme_files/use_cases/image_attributes.md
115
- - readme_files/use_cases/reusable_text.md
116
- - readme_files/use_cases/rubygem_images.md
117
- - readme_files/verbatim_ruby_template.md
118
127
  homepage: https://github.com/BurdetteLamar/markdown_helper
119
128
  licenses:
120
129
  - MIT
@@ -1,12 +0,0 @@
1
- <!-- >>>>>> BEGIN GENERATED FILE (include): SOURCE readme_files/highlight_ruby_template.md -->
2
- <!-- >>>>>> BEGIN INCLUDED FILE (ruby): SOURCE readme_files/include.rb -->
3
- <code>include.rb</code>
4
- ```ruby
5
- class RubyCode
6
- def initialize
7
- raise RuntimeError.new('I am only an example!')
8
- end
9
- end
10
- ```
11
- <!-- <<<<<< END INCLUDED FILE (ruby): SOURCE readme_files/include.rb -->
12
- <!-- <<<<<< END GENERATED FILE (include): SOURCE readme_files/highlight_ruby_template.md -->
@@ -1,7 +0,0 @@
1
- ### Reusable Text
2
-
3
- Use the markdown helper to stay DRY (Don't Repeat Yourself).
4
-
5
- Text that will be needed in more than one place in the documentation can be maintained in a separate file, then included wherever it's needed.
6
-
7
- Note that the included text may itself be markdown, which can be included verbatim, or it may be code or other example data, which can be included into a code block.