md_inc 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- md_inc (0.2.2)
4
+ md_inc (0.2.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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 straight forwark: Just require
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 incldue files" do |dir|
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='', re1=nil, re2=nil)
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
- ["```#{language}"] + lines + ["```"]
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
@@ -1,3 +1,3 @@
1
1
  module MdInc
2
- VERSION = "0.2.6"
2
+ VERSION = "0.2.7"
3
3
  end
data/spec/new_commands.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # This is an example of what you need to do to
2
2
  # Add a new command to MdInc: Just add a new
3
- # module level method to the Vacuum::Commands
3
+ # module level method to the MdInc::Commands
4
4
  # module and off you go.
5
5
  module MdInc
6
6
  module Commands
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.6
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 00:00:00.000000000Z
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.