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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c13ca0ef0fde95144499acc1441c4b15c625e5d1
4
- data.tar.gz: bc66534262bac3c7cf54f3e9809bb78c685e09a3
3
+ metadata.gz: 2422656917f13499ea8ef21312e5a1835e815f29
4
+ data.tar.gz: b01b6da6e54ec58ba79d2a8114367df6a1ad77d9
5
5
  SHA512:
6
- metadata.gz: 94e5e58508c2ddbf613abe2fc1a4f6eecd7858ac82f2ef42ecfe3314c02d074ada6b01871b4f5d238f091b363f4acf87ffba0350b15c7dbd7340f0b39a4b1684
7
- data.tar.gz: 54ae291129545eb406b1c661b9d4c0f303129fc4f12ead0160cf50e6a1b7b8dff9af0bd364e196baa596baaf9b3c81317150c35c4f42012f73689b0a106ea0e8
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.rb/
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
 
@@ -49,11 +49,11 @@ end
49
49
 
50
50
 
51
51
  options = parse_opt()
52
- ec = FrontMatter.new()
52
+ fm = FrontMatter.new()
53
53
 
54
54
  ARGV.each do |f|
55
55
  if File.readable?(f)
56
- content = ec.extract_file(f)
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 = ec.extract(f)
64
+ # comments = fm.extract(f)
65
65
  # rescue IOError => e
66
66
  # puts "Could not write to file"
67
67
  # end
@@ -14,9 +14,9 @@ require 'facets/hash'
14
14
  require 'front_matter/core/array'
15
15
 
16
16
  class FrontMatter
17
- VERSION = '1.0.1'
17
+ VERSION = '1.1.0'
18
18
  attr_accessor :options
19
- def initialize( options={} )
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 => false,
39
- :as_yaml => false
38
+ :unindent => false ,
39
+ :as_yaml => false ,
40
40
  }
41
- @options.merge!(options)
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(infile, filetype=[])
122
- return self.extract_lines(File.readlines(infile).map(&:chomp), filetype)
123
- end
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
- def unindent(lines)
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: front-matter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zhao Cai