markdown_helper 2.5.0 → 2.5.1
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/Gemfile.lock +1 -1
- data/lib/markdown_helper/markdown_helper.rb +1 -0
- data/lib/markdown_helper/markdown_includer.rb +117 -90
- data/lib/markdown_helper/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a03aca6d8626d52b3ac599739a247fbb454b298ee0fb02187a451982526c8f6
|
4
|
+
data.tar.gz: 4ba9dcaf4796e01953debbb350f308484912b6dd850a50727fba32cd15b13bd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e569e86f5512efeb7cc345388bebcfc0524b08d304b0be154095c9728315fec6b804b58685707b87a6dfd7e6974a5bcc63b6162a31f18be25c288beb86a6bc7
|
7
|
+
data.tar.gz: 130a4b48f210cc5622ccd327273aa1f868ac567f5562662363b0c30cd582a16fbdc3c633a3283f4a03e7a9ecd8350a9f904a848f4dca34ce66e4c203a8d78b7f
|
data/Gemfile.lock
CHANGED
@@ -48,6 +48,7 @@ EOT
|
|
48
48
|
template_path_in_project = MarkdownHelper.path_in_project(template_file_path)
|
49
49
|
output_lines = []
|
50
50
|
yield output_lines
|
51
|
+
output_lines = output_lines.collect { |line| line.chomp }
|
51
52
|
unless pristine
|
52
53
|
output_lines.unshift(MarkdownHelper.comment(" >>>>>> BEGIN GENERATED FILE (#{method}): SOURCE #{template_path_in_project} "))
|
53
54
|
output_lines.push(MarkdownHelper.comment(" <<<<<< END GENERATED FILE (#{method}): SOURCE #{template_path_in_project} "))
|
@@ -9,9 +9,8 @@ class MarkdownIncluder < MarkdownHelper
|
|
9
9
|
@inclusions = []
|
10
10
|
generate_file(:include, template_file_path, markdown_file_path) do |output_lines|
|
11
11
|
Dir.chdir(File.dirname(template_file_path)) do
|
12
|
-
|
13
|
-
|
14
|
-
include_all(template_file_path, markdown_lines, output_lines)
|
12
|
+
page_toc_lines = get_page_toc_lines(template_file_path)
|
13
|
+
include_all(template_file_path, page_toc_lines, is_nested = false, output_lines)
|
15
14
|
end
|
16
15
|
end
|
17
16
|
|
@@ -25,76 +24,45 @@ class MarkdownIncluder < MarkdownHelper
|
|
25
24
|
"<details>\n#{text}</details>"
|
26
25
|
end
|
27
26
|
|
28
|
-
def
|
27
|
+
def gather_markdown(template_file_path)
|
28
|
+
check_template(template_file_path)
|
29
29
|
Dir.chdir(File.dirname(template_file_path)) do
|
30
30
|
markdown_lines = []
|
31
|
-
unless File.readable?(template_file_path)
|
32
|
-
path_in_project = MarkdownHelper.path_in_project(template_file_path )
|
33
|
-
message = [
|
34
|
-
"Could not read template file: #{path_in_project}",
|
35
|
-
MarkdownIncluder.backtrace_inclusions(@inclusions),
|
36
|
-
].join("\n")
|
37
|
-
e = UnreadableTemplateError.new(message)
|
38
|
-
e.set_backtrace([])
|
39
|
-
raise e
|
40
|
-
end
|
41
31
|
template_lines = File.readlines(template_file_path)
|
42
32
|
template_lines.each_with_index do |template_line, i|
|
43
33
|
template_line.chomp!
|
44
34
|
treatment, includee_file_path = *parse_include(template_line)
|
45
|
-
|
46
|
-
markdown_lines.push(template_line)
|
47
|
-
next
|
48
|
-
end
|
49
|
-
if treatment == ':page_toc'
|
35
|
+
unless treatment == ':markdown'
|
50
36
|
markdown_lines.push(template_line)
|
51
37
|
next
|
52
38
|
end
|
53
39
|
inclusion = Inclusion.new(
|
54
|
-
template_file_path,
|
55
|
-
template_line,
|
56
|
-
i,
|
57
|
-
treatment,
|
58
|
-
includee_file_path,
|
59
|
-
@inclusions
|
40
|
+
includer_file_path: template_file_path,
|
41
|
+
include_pragma: template_line,
|
42
|
+
includer_line_number: i,
|
43
|
+
treatment: treatment,
|
44
|
+
cited_includee_file_path: includee_file_path,
|
45
|
+
inclusions: @inclusions
|
60
46
|
)
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
includee_lines = include_markdown(File.absolute_path(includee_file_path))
|
67
|
-
markdown_lines.concat(includee_lines)
|
68
|
-
when ':comment'
|
69
|
-
text = File.read(includee_file_path)
|
70
|
-
markdown_lines.push(MarkdownHelper.comment(text))
|
71
|
-
@inclusions.push(inclusion)
|
72
|
-
when ':pre'
|
73
|
-
text = File.read(includee_file_path)
|
74
|
-
markdown_lines.push(MarkdownIncluder.pre(text))
|
75
|
-
@inclusions.push(inclusion)
|
76
|
-
when ':details'
|
77
|
-
text = File.read(includee_file_path)
|
78
|
-
markdown_lines.push(MarkdownIncluder.details(text))
|
79
|
-
@inclusions.push(inclusion)
|
80
|
-
else
|
81
|
-
markdown_lines.push(template_line)
|
82
|
-
next
|
83
|
-
end
|
47
|
+
check_includee(inclusion)
|
48
|
+
check_circularity(inclusion)
|
49
|
+
@inclusions.push(inclusion)
|
50
|
+
includee_lines = gather_markdown(File.absolute_path(includee_file_path))
|
51
|
+
markdown_lines.concat(includee_lines)
|
84
52
|
@inclusions.pop
|
85
|
-
treatment.sub!(/^:/, '')
|
86
53
|
add_inclusion_comments(treatment, includee_file_path, markdown_lines)
|
87
54
|
end
|
88
55
|
markdown_lines
|
89
56
|
end
|
90
57
|
end
|
91
58
|
|
92
|
-
def
|
59
|
+
def get_page_toc_lines(template_file_path)
|
60
|
+
markdown_lines = gather_markdown(template_file_path)
|
93
61
|
toc_line_index = nil
|
94
62
|
toc_title = nil
|
95
63
|
anchor_counts = Hash.new(0)
|
96
|
-
|
97
|
-
match_data =
|
64
|
+
markdown_lines.each_with_index do |markdown_line, i|
|
65
|
+
match_data = markdown_line.match(INCLUDE_REGEXP)
|
98
66
|
next unless match_data
|
99
67
|
treatment = match_data[1]
|
100
68
|
next unless treatment == ':page_toc'
|
@@ -110,10 +78,10 @@ class MarkdownIncluder < MarkdownHelper
|
|
110
78
|
raise InvalidTocTitleError.new(message)
|
111
79
|
end
|
112
80
|
end
|
113
|
-
return
|
81
|
+
return markdown_lines unless toc_line_index
|
114
82
|
toc_lines = [toc_title]
|
115
83
|
first_heading_level = nil
|
116
|
-
|
84
|
+
markdown_lines.each_with_index do |input_line, i|
|
117
85
|
line = input_line.chomp
|
118
86
|
heading = Heading.parse(line)
|
119
87
|
next unless heading
|
@@ -126,44 +94,103 @@ class MarkdownIncluder < MarkdownHelper
|
|
126
94
|
toc_line = "#{indentation}- #{heading.link(anchor_counts)}"
|
127
95
|
toc_lines.push(toc_line)
|
128
96
|
end
|
129
|
-
|
130
|
-
template_lines.insert(toc_line_index, *toc_lines)
|
131
|
-
template_lines
|
97
|
+
toc_lines
|
132
98
|
end
|
133
99
|
|
134
|
-
def include_all(
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
100
|
+
def include_all(includer_file_path, page_toc_lines, is_nested, output_lines)
|
101
|
+
includer_dir_path = File.dirname(includer_file_path)
|
102
|
+
includer_file_name = File.basename(includer_file_path)
|
103
|
+
Dir.chdir(includer_dir_path) do
|
104
|
+
check_template(includer_file_path)
|
105
|
+
template_lines = File.readlines(includer_file_name)
|
106
|
+
if is_nested
|
107
|
+
add_inclusion_comments(':markdown', includer_file_path, template_lines)
|
140
108
|
end
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
109
|
+
template_lines.each_with_index do |template_line, i|
|
110
|
+
treatment, includee_file_path = *parse_include(template_line)
|
111
|
+
if treatment.nil?
|
112
|
+
output_lines.push(template_line)
|
113
|
+
next
|
114
|
+
end
|
115
|
+
if treatment == ':page_toc'
|
116
|
+
output_lines.concat(page_toc_lines)
|
117
|
+
next
|
118
|
+
end
|
119
|
+
inclusion = Inclusion.new(
|
120
|
+
includer_file_path: includer_file_path,
|
121
|
+
include_pragma: template_line,
|
122
|
+
includer_line_number: i,
|
123
|
+
treatment: treatment,
|
124
|
+
cited_includee_file_path: includee_file_path,
|
125
|
+
inclusions: @inclusions
|
126
|
+
)
|
127
|
+
@inclusions.push(inclusion)
|
128
|
+
check_includee(inclusion)
|
129
|
+
case treatment
|
130
|
+
when ':comment'
|
131
|
+
include_comment(includee_file_path, treatment, inclusion, output_lines)
|
132
|
+
when ':pre'
|
133
|
+
include_pre(includee_file_path, treatment, inclusion, output_lines)
|
134
|
+
when ':details'
|
135
|
+
include_details(includee_file_path, treatment, inclusion, output_lines)
|
136
|
+
when ':markdown'
|
137
|
+
include_all(includee_file_path, page_toc_lines, is_nested = true, output_lines)
|
138
|
+
else
|
139
|
+
include_file(includee_file_path, treatment, inclusion, output_lines)
|
140
|
+
end
|
141
|
+
@inclusions.pop
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def include_comment(includee_file_path, treatment, inclusion, output_lines)
|
147
|
+
text = File.read(includee_file_path)
|
148
|
+
output_lines.push(MarkdownHelper.comment(text))
|
149
|
+
add_inclusion_comments(treatment, includee_file_path, output_lines)
|
150
|
+
end
|
151
|
+
|
152
|
+
def include_pre(includee_file_path, treatment, inclusion, output_lines)
|
153
|
+
text = File.read(includee_file_path)
|
154
|
+
output_lines.push(MarkdownIncluder.pre(text))
|
155
|
+
add_inclusion_comments(treatment, includee_file_path, output_lines)
|
156
|
+
end
|
157
|
+
|
158
|
+
def include_details(includee_file_path, treatment, inclusion, output_lines)
|
159
|
+
text = File.read(includee_file_path)
|
160
|
+
output_lines.push(MarkdownIncluder.details(text))
|
161
|
+
add_inclusion_comments(treatment, includee_file_path, output_lines)
|
162
|
+
end
|
163
|
+
|
164
|
+
def include_file(includee_file_path, treatment, inclusion, output_lines)
|
165
|
+
file_marker = format('```%s```:', File.basename(includee_file_path))
|
166
|
+
begin_backticks = '```'
|
167
|
+
end_backticks = '```'
|
168
|
+
begin_backticks += treatment unless treatment.start_with?(':')
|
169
|
+
includee_lines = File.read(includee_file_path).split("\n")
|
170
|
+
includee_lines.unshift(begin_backticks)
|
171
|
+
includee_lines.unshift(file_marker)
|
172
|
+
includee_lines.push(end_backticks)
|
173
|
+
add_inclusion_comments(treatment, includee_file_path, includee_lines)
|
174
|
+
output_lines.concat(includee_lines)
|
175
|
+
end
|
176
|
+
|
177
|
+
def check_template(template_file_path)
|
178
|
+
unless File.readable?(template_file_path)
|
179
|
+
path_in_project = MarkdownHelper.path_in_project(template_file_path )
|
180
|
+
message = [
|
181
|
+
"Could not read template file: #{path_in_project}",
|
182
|
+
MarkdownIncluder.backtrace_inclusions(@inclusions),
|
183
|
+
].join("\n")
|
184
|
+
e = UnreadableTemplateError.new(message)
|
185
|
+
e.set_backtrace([])
|
186
|
+
raise e
|
161
187
|
end
|
162
188
|
end
|
163
189
|
|
164
190
|
def add_inclusion_comments(treatment, includee_file_path, lines)
|
165
|
-
path_in_project = MarkdownHelper.path_in_project(includee_file_path)
|
166
191
|
unless pristine
|
192
|
+
path_in_project = MarkdownHelper.path_in_project(includee_file_path)
|
193
|
+
treatment = treatment.sub(/^:/, '')
|
167
194
|
comment = format(' >>>>>> BEGIN INCLUDED FILE (%s): SOURCE %s ', treatment, path_in_project)
|
168
195
|
lines.unshift(MarkdownHelper.comment(comment))
|
169
196
|
comment = format(' <<<<<< END INCLUDED FILE (%s): SOURCE %s ', treatment, path_in_project)
|
@@ -267,12 +294,12 @@ class MarkdownIncluder < MarkdownHelper
|
|
267
294
|
:includee_absolute_file_path
|
268
295
|
|
269
296
|
def initialize(
|
270
|
-
includer_file_path
|
271
|
-
include_pragma
|
272
|
-
includer_line_number
|
273
|
-
treatment
|
274
|
-
cited_includee_file_path
|
275
|
-
inclusions
|
297
|
+
includer_file_path:,
|
298
|
+
include_pragma:,
|
299
|
+
includer_line_number:,
|
300
|
+
treatment:,
|
301
|
+
cited_includee_file_path:,
|
302
|
+
inclusions:
|
276
303
|
)
|
277
304
|
self.includer_file_path = includer_file_path
|
278
305
|
self.include_pragma = include_pragma
|
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: 2.5.
|
4
|
+
version: 2.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- burdettelamar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|