markdown_helper 1.8.0 → 1.9.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 (97) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +5 -5
  3. data/CODE_OF_CONDUCT.md +74 -74
  4. data/Gemfile.lock +2 -1
  5. data/LICENSE.txt +21 -21
  6. data/README.md +60 -47
  7. data/Rakefile +16 -13
  8. data/bin/_include +0 -1
  9. data/bin/_resolve +0 -1
  10. data/bin/markdown_helper +3 -0
  11. data/bin/setup +8 -8
  12. data/lib/markdown_helper.rb +329 -97
  13. data/lib/markdown_helper/version.rb +1 -1
  14. data/markdown/{README.template.md → readme/README.template.md} +25 -12
  15. data/markdown/{code_block_ruby_template.md → readme/code_block_ruby_template.md} +0 -0
  16. data/markdown/{highlight_ruby_template.md → readme/highlight_ruby_template.md} +0 -0
  17. data/markdown/readme/highlighted_ruby.md +12 -0
  18. data/markdown/{include.md → readme/include.md} +0 -0
  19. data/markdown/{include.rb → readme/include.rb} +0 -0
  20. data/markdown/{include_usage.rb → readme/include_usage.rb} +0 -0
  21. data/markdown/{resolve.md → readme/resolve.md} +0 -0
  22. data/markdown/{resolve_usage.rb → readme/resolve_usage.rb} +0 -0
  23. data/markdown/{verbatim_ruby_template.md → readme/verbatim_ruby_template.md} +0 -0
  24. data/markdown/use_cases/Rakefile +53 -23
  25. data/markdown/use_cases/include/diagnose_circular_includes/diagnose_circular_includes.err +26 -0
  26. data/markdown/use_cases/include/diagnose_circular_includes/diagnose_circular_includes.rb +65 -0
  27. data/markdown/use_cases/include/diagnose_circular_includes/include.rb +5 -0
  28. data/markdown/use_cases/include/diagnose_circular_includes/includer.md +1 -0
  29. data/markdown/use_cases/include/diagnose_circular_includes/includer_0.md +1 -0
  30. data/markdown/use_cases/include/diagnose_circular_includes/includer_1.md +1 -0
  31. data/markdown/use_cases/include/diagnose_circular_includes/includer_2.md +1 -0
  32. data/markdown/use_cases/include/diagnose_circular_includes/use_case.md +98 -0
  33. data/markdown/use_cases/include/diagnose_circular_includes/use_case_template.md +27 -0
  34. data/markdown/use_cases/include/diagnose_missing_includee/diagnose_missing_includee.err +26 -0
  35. data/markdown/use_cases/include/diagnose_missing_includee/diagnose_missing_includee.rb +67 -0
  36. data/markdown/use_cases/include/diagnose_missing_includee/include.rb +5 -0
  37. data/markdown/use_cases/include/diagnose_missing_includee/included.md +1 -0
  38. data/markdown/use_cases/include/diagnose_missing_includee/includer.md +1 -0
  39. data/markdown/use_cases/include/diagnose_missing_includee/includer_0.md +1 -0
  40. data/markdown/use_cases/include/diagnose_missing_includee/includer_1.md +1 -0
  41. data/markdown/use_cases/include/diagnose_missing_includee/includer_2.md +1 -0
  42. data/markdown/use_cases/include/diagnose_missing_includee/use_case.md +100 -0
  43. data/markdown/use_cases/include/diagnose_missing_includee/use_case_template.md +29 -0
  44. data/markdown/use_cases/include/include.rb +5 -0
  45. data/markdown/use_cases/include/include_code_block/hello.rb +8 -0
  46. data/markdown/use_cases/include/include_code_block/include_code_block.rb +79 -0
  47. data/markdown/use_cases/include/include_code_block/included.md +14 -0
  48. data/markdown/use_cases/include/include_code_block/includer.md +4 -0
  49. data/markdown/use_cases/include/include_code_block/use_case.md +108 -0
  50. data/markdown/use_cases/include/include_code_block/use_case_template.md +33 -0
  51. data/markdown/use_cases/include/include_generated_text/include_generated_text.rb +38 -0
  52. data/markdown/use_cases/include/include_generated_text/use_case.md +18 -0
  53. data/markdown/use_cases/include/include_generated_text/use_case_template.md +18 -0
  54. data/markdown/use_cases/include/include_highlighted_code/hello.rb +8 -0
  55. data/markdown/use_cases/include/include_highlighted_code/include_highlighted_code.rb +83 -0
  56. data/markdown/use_cases/include/include_highlighted_code/included.md +14 -0
  57. data/markdown/use_cases/include/include_highlighted_code/includer.md +4 -0
  58. data/markdown/use_cases/include/include_highlighted_code/use_case.md +110 -0
  59. data/markdown/use_cases/include/include_highlighted_code/use_case_template.md +35 -0
  60. data/markdown/use_cases/include/include_markdown/include_markdown.rb +81 -0
  61. data/markdown/use_cases/include/include_markdown/included.md +13 -0
  62. data/markdown/use_cases/include/include_markdown/includer.md +4 -0
  63. data/markdown/use_cases/include/include_markdown/markdown.md +10 -0
  64. data/markdown/use_cases/include/include_markdown/use_case.md +106 -0
  65. data/markdown/use_cases/include/include_markdown/use_case_template.md +33 -0
  66. data/markdown/use_cases/include/include_use_case.rb +110 -0
  67. data/markdown/use_cases/include/include_with_added_comments/include_with_added_comments.rb +43 -60
  68. data/markdown/use_cases/include/include_with_added_comments/included.md +2 -2
  69. data/markdown/use_cases/include/include_with_added_comments/use_case.md +56 -0
  70. data/markdown/use_cases/include/include_with_added_comments/{template.md → use_case_template.md} +20 -1
  71. data/markdown/use_cases/include/interface.md +25 -0
  72. data/markdown/use_cases/include/nest_inclusions/included.md +5 -0
  73. data/markdown/use_cases/include/nest_inclusions/includee.md +3 -0
  74. data/markdown/use_cases/include/nest_inclusions/includer.md +3 -0
  75. data/markdown/use_cases/include/nest_inclusions/nest_inclusions.rb +61 -0
  76. data/markdown/use_cases/include/nest_inclusions/nested_includee.md +1 -0
  77. data/markdown/use_cases/include/nest_inclusions/use_case.md +74 -0
  78. data/markdown/use_cases/include/nest_inclusions/use_case_template.md +23 -0
  79. data/markdown/use_cases/include/reuse_text/include.rb +5 -0
  80. data/markdown/use_cases/include/reuse_text/included.md +2 -5
  81. data/markdown/use_cases/include/reuse_text/includee.md +1 -0
  82. data/markdown/use_cases/include/reuse_text/includer.md +2 -5
  83. data/markdown/use_cases/include/reuse_text/reuse_text.rb +24 -77
  84. data/markdown/use_cases/include/reuse_text/use_case.md +69 -0
  85. data/markdown/use_cases/include/reuse_text/use_case_template.md +23 -0
  86. data/markdown/use_cases/resolve/gemify_images/gemify_images.rb +58 -29
  87. data/markdown/use_cases/resolve/gemify_images/template.md +4 -0
  88. data/markdown/use_cases/use_case.rb +45 -0
  89. data/markdown/use_cases/use_cases.md +9 -2
  90. data/markdown_helper.gemspec +1 -1
  91. metadata +70 -19
  92. data/markdown/highlighted_ruby.md +0 -12
  93. data/markdown/use_cases/include/include_generated_text/build.rb +0 -46
  94. data/markdown/use_cases/include/include_with_added_comments/include_with_added_comments.md +0 -37
  95. data/markdown/use_cases/include/reuse_text/reusable_text.md +0 -1
  96. data/markdown/use_cases/include/reuse_text/reuse_text.md +0 -54
  97. data/markdown/use_cases/include/reuse_text/template.md +0 -33
@@ -0,0 +1,13 @@
1
+ This file includes the markdown file.
2
+
3
+ This fiie, to be included, is markdown.
4
+
5
+ ### This is a level-three title.
6
+
7
+ Here's a [link](http://yahoo.com).
8
+
9
+ This is an unordered list:
10
+ * One.
11
+ * Two.
12
+ * Three.
13
+
@@ -0,0 +1,4 @@
1
+ This file includes the markdown file.
2
+
3
+ @[:markdown](markdown.md)
4
+
@@ -0,0 +1,10 @@
1
+ This fiie, to be included, is markdown.
2
+
3
+ ### This is a level-three title.
4
+
5
+ Here's a [link](http://yahoo.com).
6
+
7
+ This is an unordered list:
8
+ * One.
9
+ * Two.
10
+ * Three.
@@ -0,0 +1,106 @@
1
+ ### Include Markdown
2
+
3
+ Use file inclusion to include markdown. The whole page, includer and includee, will be rendered when it's pushed to GitHub.
4
+
5
+ #### File to Be Included
6
+
7
+ Here's a file containing markdown to be included:
8
+
9
+ ```markdown.md```:
10
+ ```markdown
11
+ This fiie, to be included, is markdown.
12
+
13
+ ### This is a level-three title.
14
+
15
+ Here's a [link](http://yahoo.com).
16
+
17
+ This is an unordered list:
18
+ * One.
19
+ * Two.
20
+ * Three.
21
+ ```
22
+
23
+ #### Includer File
24
+
25
+ Here's a template file that includes it:
26
+
27
+ ```includer.md```:
28
+ ```markdown
29
+ This file includes the markdown file.
30
+
31
+ @[:markdown](markdown.md)
32
+
33
+ ```
34
+
35
+ The treatment token ```:markdown``` specifies that the included text is to be treated as markdown.
36
+
37
+ #### CLI
38
+
39
+ You can use the command-line interface to perform the inclusion.
40
+
41
+ ##### Command
42
+
43
+ ```sh
44
+ markdown_helper include --pristine includer.md included.md
45
+ ```
46
+
47
+ (Option ```--pristine``` suppresses comment insertion.)
48
+
49
+ #### API
50
+
51
+ You can use the API to perform the inclusion.
52
+
53
+ ##### Ruby Code
54
+
55
+ ```include.rb```:
56
+ ```ruby
57
+ require 'markdown_helper'
58
+
59
+ # Option :pristine suppresses comment insertion.
60
+ markdown_helper = MarkdownHelper.new(:pristine => true)
61
+ markdown_helper.include('includer.md', 'included.md')
62
+ ```
63
+
64
+ ##### Command
65
+
66
+ ```sh
67
+ ruby include.rb
68
+ ```
69
+
70
+ #### File with Inclusion
71
+
72
+ Here's the finished file with the inclusion:
73
+
74
+ ```included.md```:
75
+ ```markdown
76
+ This file includes the markdown file.
77
+
78
+ This fiie, to be included, is markdown.
79
+
80
+ ### This is a level-three title.
81
+
82
+ Here's a [link](http://yahoo.com).
83
+
84
+ This is an unordered list:
85
+ * One.
86
+ * Two.
87
+ * Three.
88
+
89
+ ```
90
+
91
+ And here's the finished markdown, as rendered on this page:
92
+
93
+ ---
94
+
95
+ This fiie, to be included, is markdown.
96
+
97
+ ### This is a level-three title.
98
+
99
+ Here's a [link](http://yahoo.com).
100
+
101
+ This is an unordered list:
102
+ * One.
103
+ * Two.
104
+ * Three.
105
+
106
+ ---
@@ -0,0 +1,33 @@
1
+ ### Include Markdown
2
+
3
+ Use file inclusion to include markdown. The whole page, includer and includee, will be rendered when it's pushed to GitHub.
4
+
5
+ #### File to Be Included
6
+
7
+ Here's a file containing markdown to be included:
8
+
9
+ @[markdown](markdown.md)
10
+
11
+ #### Includer File
12
+
13
+ Here's a template file that includes it:
14
+
15
+ @[markdown](includer.md)
16
+
17
+ The treatment token ```:markdown``` specifies that the included text is to be treated as markdown.
18
+
19
+ @[:markdown](../interface.md)
20
+
21
+ #### File with Inclusion
22
+
23
+ Here's the finished file with the inclusion:
24
+
25
+ @[markdown](included.md)
26
+
27
+ And here's the finished markdown, as rendered on this page:
28
+
29
+ ---
30
+
31
+ @[:markdown](markdown.md)
32
+
33
+ ---
@@ -0,0 +1,110 @@
1
+ require_relative '../use_case'
2
+
3
+ class IncludeUseCase < UseCase
4
+
5
+ attr_accessor :use_case_dir_name
6
+
7
+ INCLUDE_DIR_PATH = File.dirname(__FILE__)
8
+
9
+ INCLUDEE_FILE_NAME = 'includee.md'
10
+ INCLUDER_FILE_NAME = 'includer.md'
11
+ INCLUDED_FILE_NAME = 'included.md'
12
+
13
+ RUBY_FILE_NAME = 'include.rb'
14
+ RUBY_COMMAND = "ruby #{RUBY_FILE_NAME}"
15
+
16
+ INCLUDE_COMMAND = IncludeUseCase.construct_include_command(INCLUDER_FILE_NAME, INCLUDED_FILE_NAME, pristine = true)
17
+
18
+ BUILD_COMMAND = IncludeUseCase.construct_include_command(TEMPLATE_FILE_NAME, USE_CASE_FILE_NAME, pristine = true)
19
+
20
+ def initialize(use_case_dir_name)
21
+
22
+ super
23
+
24
+ commands_to_execute.push(RUBY_COMMAND) if File.exist?(RUBY_FILE_NAME)
25
+ commands_to_execute.push(BUILD_COMMAND) if File.exist?(TEMPLATE_FILE_NAME)
26
+
27
+ self.use_case_dir_name = use_case_dir_name
28
+
29
+
30
+ end
31
+
32
+ def use_case_dir_path
33
+ File.join(File.absolute_path(File.dirname(__FILE__)), use_case_dir_name)
34
+ end
35
+
36
+ def write_includee_file
37
+ File.write(
38
+ INCLUDEE_FILE_NAME,
39
+ <<EOT
40
+ Text in includee file.
41
+ EOT
42
+ )
43
+ end
44
+
45
+ def write_includer_file
46
+ File.write(
47
+ INCLUDER_FILE_NAME,
48
+ <<EOT
49
+ Text in includer file.
50
+
51
+ @[:markdown](#{INCLUDEE_FILE_NAME})
52
+
53
+ EOT
54
+ )
55
+ end
56
+
57
+ def write_ruby_file(pristine)
58
+ args = pristine ? '(:pristine => true)' : ''
59
+ File.write(
60
+ RUBY_FILE_NAME,
61
+ <<EOT
62
+ require 'markdown_helper'
63
+
64
+ # Option :pristine suppresses comment insertion.
65
+ markdown_helper = MarkdownHelper.new#{args}
66
+ markdown_helper.include('#{INCLUDER_FILE_NAME}', '#{INCLUDED_FILE_NAME}')
67
+ EOT
68
+ )
69
+ end
70
+
71
+ def self.write_interface_file
72
+ interface_file_path = File.join(
73
+ INCLUDE_DIR_PATH,
74
+ 'interface.md',
75
+ )
76
+ File.open(interface_file_path, 'w') do |interface_file|
77
+ interface_file.puts(<<EOT
78
+ #### CLI
79
+
80
+ You can use the command-line interface to perform the inclusion.
81
+
82
+ ##### Command
83
+
84
+ ```sh
85
+ #{INCLUDE_COMMAND}
86
+ ```
87
+
88
+ @[:markdown](../pristine.md)
89
+
90
+ #### API
91
+
92
+ You can use the API to perform the inclusion.
93
+
94
+ ##### Ruby Code
95
+
96
+ @[ruby](#{RUBY_FILE_NAME})
97
+
98
+ ##### Command
99
+
100
+ ```sh
101
+ #{RUBY_COMMAND}
102
+ ```
103
+ EOT
104
+ )
105
+ end
106
+
107
+ end
108
+
109
+ end
110
+
@@ -1,57 +1,18 @@
1
- #!/usr/bin/env ruby
2
-
3
- use_case_dir_path = File.absolute_path(File.dirname(__FILE__))
4
-
5
- includee_file_name = 'includee.md'
6
- includee_file_path = File.join(
7
- use_case_dir_path,
8
- includee_file_name,
9
- )
10
-
11
- includer_file_name = 'includer.md'
12
- includer_file_path = File.join(
13
- use_case_dir_path,
14
- includer_file_name,
15
- )
16
-
17
- included_file_name = 'included.md'
18
-
19
- use_case_file_name = 'include_with_added_comments.md'
20
- use_case_file_path = File.join(
21
- use_case_dir_path,
22
- use_case_file_name,
23
- )
24
-
25
- template_file_name = 'template.md'
26
- template_file_path = File.join(
27
- use_case_dir_path,
28
- template_file_name,
29
- )
30
-
31
- include_command = "markdown_helper include #{includer_file_name} #{included_file_name}"
32
-
33
- File.write(
34
- includee_file_path,
35
- <<EOT
36
- Text to be included.
37
- EOT
38
- )
1
+ require_relative '../include_use_case'
39
2
 
40
- File.write(
41
- includer_file_path,
42
- <<EOT
43
- @[:markdown](#{includee_file_name})
44
- EOT
45
- )
3
+ class IncludeWithAddedComments < IncludeUseCase
46
4
 
47
- # Example inclusion.
48
- Dir.chdir(use_case_dir_path) do
49
- system(include_command)
50
- end
5
+ def self.build
6
+
7
+ use_case_name = File.basename(__FILE__, '.rb')
8
+ use_case = self.new(use_case_name)
9
+
10
+ include_command = IncludeUseCase.construct_include_command(INCLUDER_FILE_NAME, INCLUDED_FILE_NAME, pristine = false)
11
+ use_case.commands_to_execute.push(include_command)
51
12
 
52
- File.write(
53
- template_file_path,
54
- <<EOT
13
+ use_case.files_to_write.store(
14
+ TEMPLATE_FILE_NAME,
15
+ <<EOT
55
16
  ### Include with Added Comments
56
17
 
57
18
  By default (that is, without option ```--pristine```) file inclusion adds comments that:
@@ -61,24 +22,46 @@ By default (that is, without option ```--pristine```) file inclusion adds commen
61
22
 
62
23
  #### Includee File
63
24
 
64
- @[markdown](#{includee_file_name})
25
+ @[markdown](#{INCLUDEE_FILE_NAME})
65
26
 
66
27
  #### Includer File
67
28
 
68
- @[markdown](#{includer_file_name})
29
+ @[markdown](#{INCLUDER_FILE_NAME})
69
30
 
70
- #### Inclusion Command
31
+ #### CLI
32
+
33
+ You can use the command-line interface to perform the inclusion.
34
+
35
+ ##### Command
71
36
 
72
37
  ```sh
73
- #{include_command}
38
+ markdown_helper include #{INCLUDER_FILE_NAME} #{INCLUDED_FILE_NAME}
39
+ ```
40
+
41
+ #### API
42
+
43
+ You can use the API to perform the inclusion.
44
+
45
+ ##### Ruby Code
46
+
47
+ ```ruby
48
+ require 'markdown_helper'
49
+
50
+ markdown_helper = MarkdownHelper.new
51
+ markdown_helper.include(#{INCLUDER_FILE_NAME}, #{INCLUDED_FILE_NAME})
74
52
  ```
75
53
 
76
54
  #### File with Inclusion and Added Comments
77
55
 
78
- @[markdown](#{included_file_name})
56
+ @[markdown](#{INCLUDED_FILE_NAME})
57
+
58
+ The file path for the included file is relative to the .git directory.
79
59
  EOT
80
- )
81
60
 
82
- # Build use case.
83
- build_command = "markdown_helper include --pristine #{template_file_path} #{use_case_file_path}"
84
- system(build_command)
61
+ )
62
+
63
+ use_case.build
64
+
65
+ end
66
+
67
+ end
@@ -1,5 +1,5 @@
1
1
  <!-- >>>>>> BEGIN GENERATED FILE (include): SOURCE includer.md -->
2
- <!-- >>>>>> BEGIN INCLUDED FILE (markdown): SOURCE ./includee.md -->
2
+ <!-- >>>>>> BEGIN INCLUDED FILE (markdown): SOURCE markdown/use_cases/include/include_with_added_comments/includee.md -->
3
3
  Text to be included.
4
- <!-- <<<<<< END INCLUDED FILE (markdown): SOURCE ./includee.md -->
4
+ <!-- <<<<<< END INCLUDED FILE (markdown): SOURCE markdown/use_cases/include/include_with_added_comments/includee.md -->
5
5
  <!-- <<<<<< END GENERATED FILE (include): SOURCE includer.md -->
@@ -0,0 +1,56 @@
1
+ ### Include with Added Comments
2
+
3
+ By default (that is, without option ```--pristine```) file inclusion adds comments that:
4
+
5
+ * Identify the includer file.
6
+ * Identify each includee file.
7
+
8
+ #### Includee File
9
+
10
+ ```includee.md```:
11
+ ```markdown
12
+ Text to be included.
13
+ ```
14
+
15
+ #### Includer File
16
+
17
+ ```includer.md```:
18
+ ```markdown
19
+ @[:markdown](includee.md)
20
+ ```
21
+
22
+ #### CLI
23
+
24
+ You can use the command-line interface to perform the inclusion.
25
+
26
+ ##### Command
27
+
28
+ ```sh
29
+ markdown_helper include includer.md included.md
30
+ ```
31
+
32
+ #### API
33
+
34
+ You can use the API to perform the inclusion.
35
+
36
+ ##### Ruby Code
37
+
38
+ ```ruby
39
+ require 'markdown_helper'
40
+
41
+ markdown_helper = MarkdownHelper.new
42
+ markdown_helper.include(includer.md, included.md)
43
+ ```
44
+
45
+ #### File with Inclusion and Added Comments
46
+
47
+ ```included.md```:
48
+ ```markdown
49
+ <!-- >>>>>> BEGIN GENERATED FILE (include): SOURCE includer.md -->
50
+ <!-- >>>>>> BEGIN INCLUDED FILE (markdown): SOURCE markdown/use_cases/include/include_with_added_comments/includee.md -->
51
+ Text to be included.
52
+ <!-- <<<<<< END INCLUDED FILE (markdown): SOURCE markdown/use_cases/include/include_with_added_comments/includee.md -->
53
+ <!-- <<<<<< END GENERATED FILE (include): SOURCE includer.md -->
54
+ ```
55
+
56
+ The file path for the included file is relative to the .git directory.