md_inc 0.2.6 → 0.2.7
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.
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/bin/md_inc +2 -2
- data/lib/md_inc/md_inc_commands.rb +24 -4
- data/lib/md_inc/version.rb +1 -1
- data/spec/new_commands.rb +1 -1
- metadata +2 -2
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -21,7 +21,7 @@ Or install it yourself as:
|
|
21
21
|
MdInc is a simple text inclusion filter intended for use
|
22
22
|
with markdown and similar text formatting utilities.
|
23
23
|
MdInc provides simple 'include this other file' kind
|
24
|
-
of processing. Using MdInc is
|
24
|
+
of processing. Using MdInc is straightforward: Just require
|
25
25
|
it in and use the process method:
|
26
26
|
|
27
27
|
require 'md_inc'
|
data/bin/md_inc
CHANGED
@@ -19,15 +19,15 @@ op = OptionParser.new do |op|
|
|
19
19
|
$: << dir
|
20
20
|
end
|
21
21
|
|
22
|
-
op.on '-d dir', '--dir dir', "Set the default dir for pulling
|
22
|
+
op.on '-d dir', '--dir dir', "Set the default dir for pulling include files" do |dir|
|
23
23
|
base_dir = dir
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
op.parse!
|
28
28
|
|
29
|
+
MdInc::Commands::root(base_dir) unless base_dir.nil?
|
29
30
|
tp = MdInc::TextProcessor.new
|
30
|
-
tp.base_dir = base_dir if base_dir
|
31
31
|
|
32
32
|
if ARGV.empty?
|
33
33
|
puts tp.process_stream(STDIN)
|
@@ -20,16 +20,20 @@ module MdInc
|
|
20
20
|
lines.map &:rstrip!
|
21
21
|
end
|
22
22
|
|
23
|
-
def code_inc(path, language=
|
23
|
+
def code_inc(path, language=nil, re1=nil, re2=nil)
|
24
24
|
if re1
|
25
|
-
code(language, between(re1, re2, inc(path)))
|
25
|
+
code(language, normalize_indent(between(re1, re2, inc(path))))
|
26
26
|
else
|
27
|
-
code(language, inc(path))
|
27
|
+
code(language, normalize_indent(inc(path)))
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
def code(language, lines)
|
32
|
-
|
32
|
+
unless language.nil?
|
33
|
+
["```#{language}"] + lines + ["```"]
|
34
|
+
else
|
35
|
+
lines.map {|l| l.rstrip.prepend(' ')}
|
36
|
+
end
|
33
37
|
end
|
34
38
|
|
35
39
|
def between(re1, re2, lines)
|
@@ -55,6 +59,22 @@ module MdInc
|
|
55
59
|
end
|
56
60
|
output
|
57
61
|
end
|
62
|
+
|
63
|
+
def normalize_indent(lines)
|
64
|
+
min_indent = min_indent(lines)
|
65
|
+
lines.map {|l| l[min_indent..-1]}
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def min_indent(lines)
|
71
|
+
indents = lines.map {|l| indent_depth(l)}
|
72
|
+
indents.min
|
73
|
+
end
|
74
|
+
|
75
|
+
def indent_depth(s)
|
76
|
+
/^ */.match(s).end(0)
|
77
|
+
end
|
58
78
|
end
|
59
79
|
end
|
60
80
|
end
|
data/lib/md_inc/version.rb
CHANGED
data/spec/new_commands.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: md_inc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-13 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: MdInc is a simple text inclusion utility (it sucks in files) intended
|
15
15
|
for use with markdown and similar utilities.
|