front-matter 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/bin/front_matter +3 -3
- data/lib/front_matter.rb +10 -16
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2422656917f13499ea8ef21312e5a1835e815f29
|
4
|
+
data.tar.gz: b01b6da6e54ec58ba79d2a8114367df6a1ad77d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 233c2ecaed2c4a9c19221f22e8758cdce8d3d8666466b19511e369931d0a5be74b22e0f6f6897a36b1c9c565e837b919d633df8ffc0e412f37edb97310869a31
|
7
|
+
data.tar.gz: 38896323b13143c5a676008d2f1f96b62268deb12a2f5afe1ba6393f04dcbd16fd03f75e36062b88540b8a6e550e5c69d300b27bd1a3749abd1c347dfaa14481
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Front Matter
|
2
2
|
|
3
3
|
* home :: http://zhaocai.github.com/front-matter.rb/
|
4
|
-
* rdoc :: http://rubydoc.info/gems/front-matter
|
4
|
+
* rdoc :: http://rubydoc.info/gems/front-matter/
|
5
5
|
* code :: https://github.com/zhaocai/front-matter.rb
|
6
6
|
* bugs :: https://github.com/zhaocai/front-matter.rb/issues
|
7
7
|
|
data/bin/front_matter
CHANGED
@@ -49,11 +49,11 @@ end
|
|
49
49
|
|
50
50
|
|
51
51
|
options = parse_opt()
|
52
|
-
|
52
|
+
fm = FrontMatter.new()
|
53
53
|
|
54
54
|
ARGV.each do |f|
|
55
55
|
if File.readable?(f)
|
56
|
-
content =
|
56
|
+
content = fm.extract_file(f)
|
57
57
|
ap content
|
58
58
|
else
|
59
59
|
puts "File: #{f} is not readable!"
|
@@ -61,7 +61,7 @@ ARGV.each do |f|
|
|
61
61
|
end
|
62
62
|
|
63
63
|
# begin
|
64
|
-
# comments =
|
64
|
+
# comments = fm.extract(f)
|
65
65
|
# rescue IOError => e
|
66
66
|
# puts "Could not write to file"
|
67
67
|
# end
|
data/lib/front_matter.rb
CHANGED
@@ -14,9 +14,9 @@ require 'facets/hash'
|
|
14
14
|
require 'front_matter/core/array'
|
15
15
|
|
16
16
|
class FrontMatter
|
17
|
-
VERSION = '1.0
|
17
|
+
VERSION = '1.1.0'
|
18
18
|
attr_accessor :options
|
19
|
-
def initialize(
|
19
|
+
def initialize( opts={} )
|
20
20
|
comment_marker = %r{(?<comment> ^\s* \W{1,2} )}x
|
21
21
|
@options = {
|
22
22
|
:patterns => {
|
@@ -35,10 +35,10 @@ class FrontMatter
|
|
35
35
|
:end => %r{#{comment_marker} (?<end> \s* -{3} $) }x ,
|
36
36
|
},
|
37
37
|
},
|
38
|
-
:unindent
|
39
|
-
:as_yaml
|
38
|
+
:unindent => false ,
|
39
|
+
:as_yaml => false ,
|
40
40
|
}
|
41
|
-
@options.merge!(
|
41
|
+
@options.merge!(opts)
|
42
42
|
end
|
43
43
|
|
44
44
|
def extract_lines(lines, filetype=[])
|
@@ -118,21 +118,15 @@ class FrontMatter
|
|
118
118
|
results
|
119
119
|
end
|
120
120
|
|
121
|
-
def extract_file(
|
122
|
-
|
123
|
-
|
121
|
+
def extract_file(path, opts={})
|
122
|
+
filetype = opts[:filetype] ? opts[:filetype] : []
|
123
|
+
firstline = opts[:firstline] ? opts[:firstline] : 0
|
124
|
+
lastline = opts[:lastline] ? opts[:lastline] : -1
|
124
125
|
|
125
|
-
|
126
|
-
indent = lines.select {|line| !line.strip.empty? }.map {|line| line.index(/[^\s]/) }.compact.min || 0
|
127
|
-
lines.map {|line| line.gsub(/^[[:blank:]]{#{indent}}/, '')}
|
126
|
+
return extract_lines(File.readlines(path)[firstline..lastline].map(&:chomp), filetype)
|
128
127
|
end
|
129
128
|
|
130
129
|
end
|
131
130
|
|
132
|
-
# ---
|
133
|
-
# a : "b"
|
134
|
-
# c : d
|
135
|
-
# ---
|
136
|
-
|
137
131
|
|
138
132
|
|