markdown_helper 1.6.1 → 1.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40f6b9b405ab0a09530dc86a3397cd1aeaf05b14
4
- data.tar.gz: 3f6d57289baabeb3528f56550cde10208d2be42c
3
+ metadata.gz: 271b429b2a0016330e36fb2afd2c59c141ffb875
4
+ data.tar.gz: cc509ab4b86e4eeb18a60b5ec435bdf6f840fad1
5
5
  SHA512:
6
- metadata.gz: 39fd4211aa2e807938ecd1e9e7e5c64e309162ddcad2eef087d4762576ac2a344ba6b3f0a85b2ef38ac5d102fc15dd17a2e941400035b444096f0718cfac2cd4
7
- data.tar.gz: ad48c542562adb40e3d7371efbad4c68848777cf1473c62041ee92624cb71ec20ea954f6da462debd5c7a7a3b1230a99d22d3503ec08d01e727b897bee5503e1
6
+ metadata.gz: bdfda83d3fecc8f4f80b0762b28878fa0ef3d4374df8bb10abeb1c7df638b42a97d180bda2388517091220a09bd55c5cd3c2a39da3f73e3d98ced011d4a9ca29
7
+ data.tar.gz: c9acebb1a64ca5f539da782cc451f70e96ef908567770a660e3e60c940714608fa5ae9723861f0fd16b327f444388602ec6f92c8e6ae35304e0042325c2b82d0
data/.gitignore CHANGED
@@ -7,5 +7,5 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
- /test/tmp/
10
+ /test/resolve/tmp/
11
11
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- markdown_helper (1.6.1)
4
+ markdown_helper (1.7.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -41,10 +41,10 @@ You can suppress those comments using the <code>pristine</code> option.
41
41
 
42
42
  ## File Inclusion
43
43
 
44
- <!-- >>>>>> BEGIN RESOLVED IMAGES: INPUT-LINE '![include_icon](images/include.png | width=50)
44
+ <!-- >>>>>> BEGIN RESOLVED IMAGES: INPUT-LINE '![include_icon](../images/include.png | width=50)
45
45
  ' -->
46
46
  <img src="https://raw.githubusercontent.com/BurdetteLamar/markdown_helper/master/images/include.png" alt="include_icon" width="50">
47
- <!-- <<<<<< END RESOLVED IMAGES: INPUT-LINE '![include_icon](images/include.png | width=50)
47
+ <!-- <<<<<< END RESOLVED IMAGES: INPUT-LINE '![include_icon](../images/include.png | width=50)
48
48
  ' -->
49
49
 
50
50
  This markdown helper enables file inclusion in GitHub markdown.
@@ -166,10 +166,10 @@ where:
166
166
 
167
167
  ## Image Path Resolution
168
168
 
169
- <!-- >>>>>> BEGIN RESOLVED IMAGES: INPUT-LINE '![image_icon](images/image.png | width=50)
169
+ <!-- >>>>>> BEGIN RESOLVED IMAGES: INPUT-LINE '![image_icon](../images/image.png | width=50)
170
170
  ' -->
171
171
  <img src="https://raw.githubusercontent.com/BurdetteLamar/markdown_helper/master/images/image.png" alt="image_icon" width="50">
172
- <!-- <<<<<< END RESOLVED IMAGES: INPUT-LINE '![image_icon](images/image.png | width=50)
172
+ <!-- <<<<<< END RESOLVED IMAGES: INPUT-LINE '![image_icon](../images/image.png | width=50)
173
173
  ' -->
174
174
 
175
175
  This markdown helper enables image path resolution in GitHub markdown.
@@ -251,10 +251,10 @@ where:
251
251
 
252
252
  ## Image Attributes
253
253
 
254
- <!-- >>>>>> BEGIN RESOLVED IMAGES: INPUT-LINE '![html_icon](images/html.png | width=50)
254
+ <!-- >>>>>> BEGIN RESOLVED IMAGES: INPUT-LINE '![html_icon](../images/html.png | width=50)
255
255
  ' -->
256
256
  <img src="https://raw.githubusercontent.com/BurdetteLamar/markdown_helper/master/images/html.png" alt="html_icon" width="50">
257
- <!-- <<<<<< END RESOLVED IMAGES: INPUT-LINE '![html_icon](images/html.png | width=50)
257
+ <!-- <<<<<< END RESOLVED IMAGES: INPUT-LINE '![html_icon](../images/html.png | width=50)
258
258
  ' -->
259
259
 
260
260
  This markdown helper enables HTML image attributes in GitHub markdown [image descriptions](https://github.github.com/gfm/#image-description).
@@ -63,14 +63,14 @@ class MarkdownHelper
63
63
  #
64
64
  # The path resolves to:
65
65
  #
66
- # absolute_file_path = File.join(
66
+ # image_path = File.join(
67
67
  # "https://raw.githubusercontent.com/#{repo_user}/#{repo_name}/master",
68
68
  # relative_file_path,
69
69
  # )
70
70
  def resolve(template_file_path, markdown_file_path)
71
71
  # Method :generate_file does the first things, yields the block, does the last things.
72
72
  send(:generate_file, template_file_path, markdown_file_path, __method__) do |input_lines, output_lines|
73
- send(:resolve_images, input_lines, output_lines)
73
+ send(:resolve_images, template_file_path, input_lines, output_lines)
74
74
  end
75
75
  end
76
76
  alias resolve_image_urls resolve
@@ -175,7 +175,7 @@ class MarkdownHelper
175
175
  end
176
176
  end
177
177
 
178
- def resolve_images(input_lines, output_lines)
178
+ def resolve_images(template_file_path, input_lines, output_lines)
179
179
  input_lines.each do |input_line|
180
180
  scan_data = input_line.scan(IMAGE_REGEXP)
181
181
  if scan_data.empty?
@@ -185,7 +185,9 @@ class MarkdownHelper
185
185
  output_lines.push(comment(" >>>>>> BEGIN RESOLVED IMAGES: INPUT-LINE '#{input_line}' ")) unless pristine
186
186
  output_line = input_line
187
187
  scan_data.each do |alt_text, path_and_attributes|
188
- relative_file_path, attributes_s =path_and_attributes.split(/\s?\|\s?/, 2)
188
+ original_image_file_path, attributes_s = path_and_attributes.split(/\s?\|\s?/, 2)
189
+
190
+ # Attributes.
189
191
  attributes = attributes_s ? attributes_s.split(/\s+/) : []
190
192
  formatted_attributes = ['']
191
193
  attributes.each do |attribute|
@@ -193,18 +195,35 @@ class MarkdownHelper
193
195
  formatted_attributes.push(format('%s="%s"', name, value))
194
196
  end
195
197
  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
198
+
199
+ if original_image_file_path.start_with?('http')
200
+ image_path = original_image_file_path
199
201
  else
202
+ git_dir = `git rev-parse --git-dir`.chomp
203
+ if git_dir == '.git'
204
+ git_clone_dir_path = `pwd`.chomp
205
+ else
206
+ git_clone_dir_path = git_dir.chomp
207
+ end
208
+ git_clone_dir_pathname = Pathname.new(git_clone_dir_path.sub(%r|/c/|, 'C:/')).realpath
209
+ git_clone_dir_path = git_clone_dir_pathname.to_s
210
+ absolute_template_file_path = File.absolute_path(template_file_path)
211
+ template_dir_path = File.dirname(absolute_template_file_path)
200
212
  absolute_file_path = File.join(
213
+ template_dir_path,
214
+ original_image_file_path,
215
+ )
216
+ absolute_file_path = Pathname.new(absolute_file_path).cleanpath.to_s
217
+ relative_image_file_path = absolute_file_path.sub(git_clone_dir_path + '/', '')
218
+ repo_user, repo_name = repo_user_and_name
219
+ image_path = File.join(
201
220
  "https://raw.githubusercontent.com/#{repo_user}/#{repo_name}/master",
202
- relative_file_path,
221
+ relative_image_file_path,
203
222
  )
204
223
  end
205
224
  img_element = format(
206
225
  '<img src="%s" alt="%s"%s>',
207
- absolute_file_path,
226
+ image_path,
208
227
  alt_text,
209
228
  formatted_attributes_s,
210
229
  )
@@ -1,3 +1,3 @@
1
1
  class MarkdownHelper
2
- VERSION = '1.6.1'
2
+ VERSION = '1.7.0'
3
3
  end
@@ -35,7 +35,7 @@ You can suppress those comments using the <code>pristine</code> option.
35
35
 
36
36
  ## File Inclusion
37
37
 
38
- ![include_icon](images/include.png | width=50)
38
+ ![include_icon](../images/include.png | width=50)
39
39
 
40
40
  This markdown helper enables file inclusion in GitHub markdown.
41
41
 
@@ -95,7 +95,7 @@ where:
95
95
 
96
96
  ## Image Path Resolution
97
97
 
98
- ![image_icon](images/image.png | width=50)
98
+ ![image_icon](../images/image.png | width=50)
99
99
 
100
100
  This markdown helper enables image path resolution in GitHub markdown.
101
101
 
@@ -133,7 +133,7 @@ where:
133
133
 
134
134
  ## Image Attributes
135
135
 
136
- ![html_icon](images/html.png | width=50)
136
+ ![html_icon](../images/html.png | width=50)
137
137
 
138
138
  This markdown helper enables HTML image attributes in GitHub markdown [image descriptions](https://github.github.com/gfm/#image-description).
139
139
 
@@ -0,0 +1,7 @@
1
+ <!-- >>>>>> BEGIN GENERATED FILE (include): SOURCE includer.md -->
2
+ This file includes the useful text.
3
+
4
+ <!-- >>>>>> BEGIN INCLUDED FILE (verbatim): SOURCE ./reusable_text.md -->
5
+ This is some useful text that can be included in more than one place (actually, in more than one file).
6
+ <!-- <<<<<< END INCLUDED FILE (verbatim): SOURCE ./reusable_text.md -->
7
+ <!-- <<<<<< END GENERATED FILE (include): SOURCE includer.md -->
@@ -1,19 +1,19 @@
1
- ### Reusable Text
1
+ ### Use Case: Reuse Text
2
2
 
3
3
  Use file inclusion to stay DRY (Don't Repeat Yourself).
4
4
 
5
5
  Maintain reusable text in a separate file, then include it wherever it's needed.
6
6
 
7
- #### Separate File
7
+ #### File to Be Included
8
8
 
9
- Here's a file containing some text that can be included in more than one place:
9
+ Here's a file containing some text that can be included:
10
10
 
11
11
  <code>reusable_text.md</code>
12
12
  ```
13
13
  This is some useful text that can be included in more than one place (actually, in more than one file).
14
14
  ```
15
15
 
16
- #### Template File
16
+ #### Includer File
17
17
 
18
18
  Here's a template file that includes it:
19
19
 
@@ -29,16 +29,20 @@ This file includes the useful text.
29
29
  Here's the command to perform the inclusion (```--pristine``` suppresses inclusion comments):
30
30
 
31
31
  ```sh
32
- ruby ../../../bin/include --pristine includer.md included.md
32
+ markdown_helper include includer.md included.md
33
33
  ```
34
34
 
35
- #### Included File
35
+ #### File with Inclusion
36
36
 
37
37
  Here's the finished file with the inclusion:
38
38
 
39
39
  <code>included.md</code>
40
40
  ```
41
+ <!-- >>>>>> BEGIN GENERATED FILE (include): SOURCE includer.md -->
41
42
  This file includes the useful text.
42
43
 
44
+ <!-- >>>>>> BEGIN INCLUDED FILE (verbatim): SOURCE ./reusable_text.md -->
43
45
  This is some useful text that can be included in more than one place (actually, in more than one file).
46
+ <!-- <<<<<< END INCLUDED FILE (verbatim): SOURCE ./reusable_text.md -->
47
+ <!-- <<<<<< END GENERATED FILE (include): SOURCE includer.md -->
44
48
  ```
@@ -1,26 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+
1
3
  reusable_text_file_name = 'reusable_text.md'
2
4
  includer_file_name = 'includer.md'
3
5
  included_file_name = 'included.md'
6
+ use_case_file_name = 'reuse_text.md'
4
7
  template_file_name = 'template.md'
5
- use_case_file_name = 'use_case.md'
6
8
 
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
+ include_command = "markdown_helper include #{includer_file_name} #{included_file_name}"
10
+
11
+ File.write(
12
+ reusable_text_file_name,
13
+ <<EOT
14
+ This is some useful text that can be included in more than one place (actually, in more than one file).
15
+ EOT
16
+ )
17
+
18
+ File.write(
19
+ includer_file_name,
20
+ <<EOT
21
+ This file includes the useful text.
22
+
23
+ @[:verbatim](#{reusable_text_file_name})
24
+ EOT
25
+ )
26
+
27
+ # Example inclusion.
28
+ system(include_command)
9
29
 
10
- template = <<EOT
11
- ### Reusable Text
30
+ File.write(
31
+ template_file_name,
32
+ <<EOT
33
+ ### Use Case: Reuse Text
12
34
 
13
35
  Use file inclusion to stay DRY (Don't Repeat Yourself).
14
36
 
15
37
  Maintain reusable text in a separate file, then include it wherever it's needed.
16
38
 
17
- #### Separate File
39
+ #### File to Be Included
18
40
 
19
- Here's a file containing some text that can be included in more than one place:
41
+ Here's a file containing some text that can be included:
20
42
 
21
43
  @[:code_block](#{reusable_text_file_name})
22
44
 
23
- #### Template File
45
+ #### Includer File
24
46
 
25
47
  Here's a template file that includes it:
26
48
 
@@ -34,34 +56,14 @@ Here's the command to perform the inclusion (```--pristine``` suppresses inclusi
34
56
  #{include_command}
35
57
  ```
36
58
 
37
- #### Included File
59
+ #### File with Inclusion
38
60
 
39
61
  Here's the finished file with the inclusion:
40
62
 
41
63
  @[:code_block](#{included_file_name})
42
64
  EOT
65
+ )
43
66
 
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
+ # Build use case.
68
+ build_command = "markdown_helper include --pristine #{template_file_name} #{use_case_file_name}"
67
69
  system(build_command)
@@ -1,16 +1,16 @@
1
- ### Reusable Text
1
+ ### Use Case: Reuse Text
2
2
 
3
3
  Use file inclusion to stay DRY (Don't Repeat Yourself).
4
4
 
5
5
  Maintain reusable text in a separate file, then include it wherever it's needed.
6
6
 
7
- #### Separate File
7
+ #### File to Be Included
8
8
 
9
- Here's a file containing some text that can be included in more than one place:
9
+ Here's a file containing some text that can be included:
10
10
 
11
11
  @[:code_block](reusable_text.md)
12
12
 
13
- #### Template File
13
+ #### Includer File
14
14
 
15
15
  Here's a template file that includes it:
16
16
 
@@ -21,10 +21,10 @@ Here's a template file that includes it:
21
21
  Here's the command to perform the inclusion (```--pristine``` suppresses inclusion comments):
22
22
 
23
23
  ```sh
24
- ruby ../../../bin/include --pristine includer.md included.md
24
+ markdown_helper include includer.md included.md
25
25
  ```
26
26
 
27
- #### Included File
27
+ #### File with Inclusion
28
28
 
29
29
  Here's the finished file with the inclusion:
30
30
 
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.6.1
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - burdettelamar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-19 00:00:00.000000000 Z
11
+ date: 2018-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -112,16 +112,15 @@ files:
112
112
  - markdown/include_usage.rb
113
113
  - markdown/resolve.md
114
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
115
+ - markdown/use_cases/gemify_images/template.md
116
+ - markdown/use_cases/resize_images/template.md
117
+ - markdown/use_cases/reuse_text/included.md
118
+ - markdown/use_cases/reuse_text/includer.md
119
+ - markdown/use_cases/reuse_text/reusable_text.md
120
+ - markdown/use_cases/reuse_text/reuse_text.md
121
+ - markdown/use_cases/reuse_text/reuse_text.rb
122
+ - markdown/use_cases/reuse_text/template.md
123
+ - markdown/use_cases/verify_examples/template.md
125
124
  - markdown/verbatim_ruby_template.md
126
125
  - markdown_helper.gemspec
127
126
  homepage: https://github.com/BurdetteLamar/markdown_helper
@@ -1,5 +0,0 @@
1
- ### Include Generated Text
2
-
3
- Use the markdown helper to include text that is generated at project "build time."
4
-
5
- Example: Project build runs each executable with option <code>--help</code>, capturing the output into a file. That file can then be included into the markdown pages for the project.
@@ -1,3 +0,0 @@
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).