front-matter 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c13ca0ef0fde95144499acc1441c4b15c625e5d1
4
+ data.tar.gz: bc66534262bac3c7cf54f3e9809bb78c685e09a3
5
+ SHA512:
6
+ metadata.gz: 94e5e58508c2ddbf613abe2fc1a4f6eecd7858ac82f2ef42ecfe3314c02d074ada6b01871b4f5d238f091b363f4acf87ffba0350b15c7dbd7340f0b39a4b1684
7
+ data.tar.gz: 54ae291129545eb406b1c661b9d4c0f303129fc4f12ead0160cf50e6a1b7b8dff9af0bd364e196baa596baaf9b3c81317150c35c4f42012f73689b0a106ea0e8
File without changes
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # -*- ruby -*-
2
+
3
+ source "https://rubygems.org/"
4
+
5
+ gemspec
6
+
7
+
8
+ # vim: syntax=ruby
@@ -0,0 +1,77 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ front-matter (1.0.1.20130414202700)
5
+ facets (>= 2.9.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ awesome_print (1.1.0)
11
+ coderay (1.0.9)
12
+ diff-lcs (1.2.3)
13
+ facets (2.9.3)
14
+ formatador (0.2.4)
15
+ growl (1.0.3)
16
+ guard (1.7.0)
17
+ formatador (>= 0.2.4)
18
+ listen (>= 0.6.0)
19
+ lumberjack (>= 1.0.2)
20
+ pry (>= 0.9.10)
21
+ thor (>= 0.14.6)
22
+ guard-bundler (1.0.0)
23
+ bundler (~> 1.0)
24
+ guard (~> 1.1)
25
+ guard-rspec (2.5.3)
26
+ guard (>= 1.1)
27
+ rspec (~> 2.11)
28
+ hoe (3.5.3)
29
+ rake (>= 0.8, < 11.0)
30
+ hoe-gemspec (1.0.0)
31
+ hoe (>= 2.2.0)
32
+ hoe-git (1.5.0)
33
+ hoe (>= 2.2.0)
34
+ hoe-version (1.2.0)
35
+ json (1.7.7)
36
+ listen (0.7.3)
37
+ lumberjack (1.0.3)
38
+ method_source (0.8.1)
39
+ pry (0.9.12)
40
+ coderay (~> 1.0.5)
41
+ method_source (~> 0.8)
42
+ slop (~> 3.4)
43
+ rake (10.0.4)
44
+ rb-fsevent (0.9.3)
45
+ rdoc (4.0.1)
46
+ json (~> 1.4)
47
+ rspec (2.13.0)
48
+ rspec-core (~> 2.13.0)
49
+ rspec-expectations (~> 2.13.0)
50
+ rspec-mocks (~> 2.13.0)
51
+ rspec-core (2.13.1)
52
+ rspec-expectations (2.13.0)
53
+ diff-lcs (>= 1.1.3, < 2.0)
54
+ rspec-mocks (2.13.1)
55
+ slop (3.4.4)
56
+ terminal-notifier-guard (1.5.3)
57
+ thor (0.18.1)
58
+
59
+ PLATFORMS
60
+ ruby
61
+
62
+ DEPENDENCIES
63
+ awesome_print (>= 1.1.0)
64
+ front-matter!
65
+ growl
66
+ guard (~> 1.7.0)
67
+ guard-bundler
68
+ guard-rspec
69
+ hoe
70
+ hoe-gemspec
71
+ hoe-git
72
+ hoe-version
73
+ rake (>= 10.0.0)
74
+ rb-fsevent (~> 0.9)
75
+ rdoc (~> 4.0)
76
+ rspec (>= 2.13)
77
+ terminal-notifier-guard
@@ -0,0 +1,29 @@
1
+
2
+ require 'guard/bundler'
3
+ require 'guard/rspec'
4
+
5
+ notification :growl
6
+ # notification :terminal_notifier
7
+
8
+ group :frontend do
9
+ guard 'bundler' do
10
+ watch('Gemfile')
11
+ # Uncomment next line if Gemfile contain `gemspec' command
12
+ # watch(/^.+\.gemspec/)
13
+ end
14
+ end
15
+
16
+ group :backend do
17
+
18
+ guard 'rspec', :rvm => ['2.0.0'], :notification => true do
19
+
20
+ watch(%r{^spec/.+_spec\.rb$})
21
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
22
+ watch('spec/spec_helper.rb') { "spec" }
23
+ end
24
+
25
+ end
26
+
27
+
28
+
29
+
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2012-08-25
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
@@ -0,0 +1,14 @@
1
+ .gemtest
2
+ Gemfile
3
+ Gemfile.lock
4
+ Guardfile
5
+ History.txt
6
+ Manifest.txt
7
+ README.md
8
+ Rakefile
9
+ bin/front_matter
10
+ front-matter.gemspec
11
+ lib/front_matter.rb
12
+ lib/front_matter/core/array.rb
13
+ spec/front_matter_spec.rb
14
+ spec/spec_helper.rb
@@ -0,0 +1,113 @@
1
+ # Front Matter
2
+
3
+ * home :: http://zhaocai.github.com/front-matter.rb/
4
+ * rdoc :: http://rubydoc.info/gems/front-matter.rb/
5
+ * code :: https://github.com/zhaocai/front-matter.rb
6
+ * bugs :: https://github.com/zhaocai/front-matter.rb/issues
7
+
8
+ ## DESCRIPTION:
9
+
10
+ This gem extracts embeded info (yaml front matters, for example ) in source code
11
+ comments with predefined format:
12
+
13
+ 1. the leading comment string can be different based on the language.
14
+ 2. the leading column of yaml docs must be aligned to be converted to yaml.
15
+
16
+ ### Format 1
17
+
18
+ # ---
19
+ # Gem : front_matter
20
+ # Author : Zhao Cai
21
+ # Email : caizhaoff@gmail.com
22
+ # Tag : [ ruby, yaml, comment ]
23
+ # ---
24
+
25
+ ### Format 2
26
+
27
+ # ============= = ============================================================
28
+ # Gem : front_matter
29
+ # Author : Zhao Cai
30
+ # Email : caizhaoff@gmail.com
31
+ # Homepage : https://github.com/zhaocai/
32
+ # Tag : [ ruby, yaml, comment ]
33
+ # ============= = ============================================================
34
+
35
+ OR
36
+
37
+ # ------------- - ------------------------------------------------------------
38
+ # Gem : front_matter
39
+ # Author : Zhao Cai
40
+ # Email : caizhaoff@gmail.com
41
+ # Homepage : https://github.com/zhaocai/
42
+ # Tag : [ ruby, yaml, comment ]
43
+ # ------------- - ------------------------------------------------------------
44
+
45
+
46
+
47
+ ## SYNOPSIS:
48
+
49
+ ```ruby
50
+ require 'front_matter'
51
+ require 'awesome_print'
52
+ require "yaml"
53
+
54
+ fm = FrontMatter.new(:unindent => true, :as_yaml => true)
55
+ file = "README.md"
56
+
57
+
58
+ ap YAML.load(fm.extract_file(file)[:valid][0])
59
+
60
+ # {
61
+ # "Gem" => "front_matter",
62
+ # "Author" => "Zhao Cai",
63
+ # "Email" => "caizhaoff@gmail.com",
64
+ # "Homepage" => "https://github.com/zhaocai/",
65
+ # "Tag" => [
66
+ # "ruby",
67
+ # "yaml",
68
+ # "comment"
69
+ # ]
70
+ # }
71
+
72
+
73
+ ```
74
+
75
+ ## INSTALL:
76
+
77
+ `gem install front-matter`
78
+
79
+
80
+
81
+ ## DEVELOPERS:
82
+
83
+ After checking out the source, run:
84
+
85
+ $ rake newb
86
+
87
+ This task will install any missing dependencies, run the tests/specs,
88
+ and generate the RDoc.
89
+
90
+ ## LICENSE:
91
+
92
+ (The MIT License)
93
+
94
+ Copyright (c) 2012, Zhao Cai
95
+
96
+ Permission is hereby granted, free of charge, to any person obtaining
97
+ a copy of this software and associated documentation files (the
98
+ 'Software'), to deal in the Software without restriction, including
99
+ without limitation the rights to use, copy, modify, merge, publish,
100
+ distribute, sublicense, and/or sell copies of the Software, and to
101
+ permit persons to whom the Software is furnished to do so, subject to
102
+ the following conditions:
103
+
104
+ The above copyright notice and this permission notice shall be
105
+ included in all copies or substantial portions of the Software.
106
+
107
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
108
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
109
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
110
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
111
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
112
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
113
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ Hoe.plugin :gemspec
7
+ Hoe.plugin :git
8
+ Hoe.plugin :version
9
+
10
+ Hoe.spec 'front-matter' do
11
+
12
+ developer('Zhao Cai', 'caizhaoff@gmail.com')
13
+
14
+ license 'GPL-3'
15
+
16
+ extra_deps << ['facets', '>= 2.9.0']
17
+
18
+
19
+
20
+ extra_dev_deps << ['rspec', '>= 2.13']
21
+ extra_dev_deps << ['rake', '>= 10.0.0']
22
+ extra_dev_deps << ['hoe'] << ['hoe-gemspec'] << ['hoe-git'] << ['hoe-version']
23
+ extra_dev_deps << ['awesome_print', '>= 1.1.0']
24
+ extra_dev_deps << ['guard', '~> 1.7.0'] << ['guard-rspec'] << ['guard-bundler']
25
+ extra_dev_deps << ['terminal-notifier-guard'] << ['growl'] << ['rb-fsevent', '~> 0.9']
26
+
27
+ end
28
+
29
+ %w{major minor patch}.each { |v|
30
+ desc "Bump #{v.capitalize} Version"
31
+ task "bump:#{v}", [:message] => ["version:bump:#{v}"] do |t, args|
32
+ m = args[:message] ? args[:message] : "Bump version to #{ENV["VERSION"]}"
33
+ sh "git commit -am '#{m}'"
34
+ end
35
+ }
36
+
37
+ # vim: syntax=ruby
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ require "front_matter"
4
+ require 'optparse'
5
+ require 'awesome_print'
6
+
7
+ def parse_opt()
8
+ options = {}
9
+
10
+ # optparse definition
11
+ optparse = OptionParser.new do |opts|
12
+ opts.on('-t', '--to FOLDER', 'save to FOLDER [required]') do |d|
13
+ if Dir.exist?(d)
14
+ options[:to] = File.expand_path(d)
15
+ else
16
+ puts "Invalid Option: #{d} should be an existing folder!"
17
+ puts opts
18
+ exit
19
+ end
20
+ end
21
+
22
+ opts.on('-h', '--help', 'Help Message') do
23
+ puts opts
24
+ exit
25
+ end
26
+ end
27
+
28
+ # parse and check mandatory options
29
+ begin
30
+ optparse.parse!
31
+ mandatory = []
32
+ missing = mandatory.select{ |param| options[param].nil? }
33
+ if not missing.empty?
34
+ puts "Missing options: #{missing.join(', ')}"
35
+ puts optparse
36
+ exit
37
+ end
38
+ rescue OptionParser::InvalidOption, OptionParser::MissingArgument
39
+ puts $!.to_s
40
+ puts optparse
41
+ exit
42
+ end
43
+
44
+ return options
45
+ end
46
+
47
+
48
+
49
+
50
+
51
+ options = parse_opt()
52
+ ec = FrontMatter.new()
53
+
54
+ ARGV.each do |f|
55
+ if File.readable?(f)
56
+ content = ec.extract_file(f)
57
+ ap content
58
+ else
59
+ puts "File: #{f} is not readable!"
60
+ end
61
+ end
62
+
63
+ # begin
64
+ # comments = ec.extract(f)
65
+ # rescue IOError => e
66
+ # puts "Could not write to file"
67
+ # end
68
+ # comments.each { |k, v|
69
+ # File.open(options[:to] + '/' + k, "w") do |file|
70
+ # file.puts v
71
+ # end
72
+ # }
73
+
@@ -0,0 +1,77 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "front-matter"
5
+ s.version = "1.0.1.20130414202700"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Zhao Cai"]
9
+ s.date = "2013-04-15"
10
+ s.description = "extract embeded info (yaml, for example ) in source code comments with\npredefined format.\n\n1. the leading comment string can be different based on the language.\n2. the leading column of yaml docs must be aligned"
11
+ s.email = ["caizhaoff@gmail.com"]
12
+ s.executables = ["front_matter"]
13
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
14
+ s.files = ["Gemfile", "Gemfile.lock", "History.txt", "Manifest.txt", "README.txt", "Rakefile", "bin/front_matter", "front-matter.gemspec", "lib/front_matter.rb", "spec/front_matter_spec.rb", "spec/spec_helper.rb", "test/test_front_matter.rb", ".gemtest"]
15
+ s.homepage = "https://github.com/zhaocai/extrComment"
16
+ s.licenses = ["GPL-3"]
17
+ s.rdoc_options = ["--main", "README.txt"]
18
+ s.require_paths = ["lib"]
19
+ s.rubyforge_project = "front-matter"
20
+ s.rubygems_version = "2.0.3"
21
+ s.summary = "extract embeded info (yaml, for example ) in source code comments with predefined format"
22
+ s.test_files = ["test/test_front_matter.rb"]
23
+
24
+ if s.respond_to? :specification_version then
25
+ s.specification_version = 4
26
+
27
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
28
+ s.add_runtime_dependency(%q<facets>, [">= 2.9.0"])
29
+ s.add_development_dependency(%q<rdoc>, ["~> 4.0"])
30
+ s.add_development_dependency(%q<rspec>, [">= 2.13"])
31
+ s.add_development_dependency(%q<rake>, [">= 10.0.0"])
32
+ s.add_development_dependency(%q<hoe>, [">= 0"])
33
+ s.add_development_dependency(%q<hoe-gemspec>, [">= 0"])
34
+ s.add_development_dependency(%q<hoe-git>, [">= 0"])
35
+ s.add_development_dependency(%q<hoe-version>, [">= 0"])
36
+ s.add_development_dependency(%q<awesome_print>, [">= 1.1.0"])
37
+ s.add_development_dependency(%q<guard>, ["~> 1.7.0"])
38
+ s.add_development_dependency(%q<guard-rspec>, [">= 0"])
39
+ s.add_development_dependency(%q<guard-bundler>, [">= 0"])
40
+ s.add_development_dependency(%q<terminal-notifier-guard>, [">= 0"])
41
+ s.add_development_dependency(%q<growl>, [">= 0"])
42
+ s.add_development_dependency(%q<rb-fsevent>, ["~> 0.9"])
43
+ else
44
+ s.add_dependency(%q<facets>, [">= 2.9.0"])
45
+ s.add_dependency(%q<rdoc>, ["~> 4.0"])
46
+ s.add_dependency(%q<rspec>, [">= 2.13"])
47
+ s.add_dependency(%q<rake>, [">= 10.0.0"])
48
+ s.add_dependency(%q<hoe>, [">= 0"])
49
+ s.add_dependency(%q<hoe-gemspec>, [">= 0"])
50
+ s.add_dependency(%q<hoe-git>, [">= 0"])
51
+ s.add_dependency(%q<hoe-version>, [">= 0"])
52
+ s.add_dependency(%q<awesome_print>, [">= 1.1.0"])
53
+ s.add_dependency(%q<guard>, ["~> 1.7.0"])
54
+ s.add_dependency(%q<guard-rspec>, [">= 0"])
55
+ s.add_dependency(%q<guard-bundler>, [">= 0"])
56
+ s.add_dependency(%q<terminal-notifier-guard>, [">= 0"])
57
+ s.add_dependency(%q<growl>, [">= 0"])
58
+ s.add_dependency(%q<rb-fsevent>, ["~> 0.9"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<facets>, [">= 2.9.0"])
62
+ s.add_dependency(%q<rdoc>, ["~> 4.0"])
63
+ s.add_dependency(%q<rspec>, [">= 2.13"])
64
+ s.add_dependency(%q<rake>, [">= 10.0.0"])
65
+ s.add_dependency(%q<hoe>, [">= 0"])
66
+ s.add_dependency(%q<hoe-gemspec>, [">= 0"])
67
+ s.add_dependency(%q<hoe-git>, [">= 0"])
68
+ s.add_dependency(%q<hoe-version>, [">= 0"])
69
+ s.add_dependency(%q<awesome_print>, [">= 1.1.0"])
70
+ s.add_dependency(%q<guard>, ["~> 1.7.0"])
71
+ s.add_dependency(%q<guard-rspec>, [">= 0"])
72
+ s.add_dependency(%q<guard-bundler>, [">= 0"])
73
+ s.add_dependency(%q<terminal-notifier-guard>, [">= 0"])
74
+ s.add_dependency(%q<growl>, [">= 0"])
75
+ s.add_dependency(%q<rb-fsevent>, ["~> 0.9"])
76
+ end
77
+ end
@@ -0,0 +1,138 @@
1
+ #!/usr/bin/env ruby
2
+ # =============== ============================================================
3
+ # Desc : extract (YAML) front matter from source code
4
+ # Author : Zhao Cai <caizhaoff@gmail.com>
5
+ # HomePage : https://github.com/zhaocai/front_matter.rb
6
+ # Date Created : Sat 25 Aug 2012 01:36:13 AM EDT
7
+ # Last Modified : Sun 14 Apr 2013 08:05:00 PM EDT
8
+ # Tag : [ ruby, YAML, comment, extract ]
9
+ # Copyright : (c) 2012 by Zhao Cai,
10
+ # Released under current GPL license.
11
+ # =============== ============================================================
12
+
13
+ require 'facets/hash'
14
+ require 'front_matter/core/array'
15
+
16
+ class FrontMatter
17
+ VERSION = '1.0.1'
18
+ attr_accessor :options
19
+ def initialize( options={} )
20
+ comment_marker = %r{(?<comment> ^\s* \W{1,2} )}x
21
+ @options = {
22
+ :patterns => {
23
+ :header => {
24
+ :comment_marker => comment_marker,
25
+ :filetype => %r{.*},
26
+ :start => %r{#{comment_marker} (?<start> \s* [-=]{3,} .* [-=]{3,}$) }x ,
27
+ :content => %r{#{comment_marker} (?<content> .* $) }x ,
28
+ :end => %r{#{comment_marker} (?<end> \s* [-=]{3,} .* [-=]{3,}$) }x ,
29
+ },
30
+ :yaml => {
31
+ :comment_marker => comment_marker,
32
+ :filetype => %r{.*},
33
+ :start => %r{#{comment_marker} (?<start> \s* -{3} $) }x ,
34
+ :content => %r{#{comment_marker} (?<content> .* $) }x ,
35
+ :end => %r{#{comment_marker} (?<end> \s* -{3} $) }x ,
36
+ },
37
+ },
38
+ :unindent => false,
39
+ :as_yaml => false
40
+ }
41
+ @options.merge!(options)
42
+ end
43
+
44
+ def extract_lines(lines, filetype=[])
45
+ content={}
46
+ unless filetype.empty?
47
+ patterns = @options[:patterns].select { |kind, pattern|
48
+ filetype.any { |ft| pattern[:filetype].match(ft)}
49
+ }
50
+ else
51
+ patterns = @options[:patterns]
52
+ end
53
+
54
+ patterns.each { |kind, pattern|
55
+ content[kind] = []
56
+ in_comment = false
57
+ in_content = {
58
+ :valid => [],
59
+ :invalid => [],
60
+ :unbound => [],
61
+ }
62
+
63
+ lines.each { |line|
64
+ if ! in_comment
65
+ case line
66
+ when pattern[:start]
67
+ in_comment = true
68
+ next
69
+ end
70
+ else
71
+ if pattern[:end] =~ line
72
+ in_comment = false
73
+ content[kind].push(in_content)
74
+ next
75
+ end
76
+
77
+ m = pattern[:content].match(line)
78
+ begin
79
+ in_content[:valid].push(m[:content])
80
+ rescue IndexError,NoMethodError
81
+ in_content[:invalid].push(line)
82
+ end
83
+ end
84
+ }
85
+
86
+ # fail to match ending
87
+ if in_comment
88
+ in_content[:unbound] = in_content[:valid]
89
+ in_content[:valid] = []
90
+ content[kind].push(in_content)
91
+ end
92
+ }
93
+
94
+ results = {
95
+ :valid => [],
96
+ :invalid => [],
97
+ :unbound => [],
98
+ }
99
+
100
+ content.each_pair { |kind, v|
101
+ v.each { |c| c.each_pair { |status, content|
102
+ results[status].push(content) unless content.empty? }
103
+ }
104
+ }
105
+ results.delete_if {|status, result| result.empty?}
106
+
107
+ if @options[:unindent]
108
+ results.traverse! { |k,v|
109
+ [k, v.map {|i| i.unindent }]
110
+ }
111
+ end
112
+
113
+ if @options[:as_yaml]
114
+ results.traverse! { |k,v|
115
+ [k, v.map {|i| "---\n#{i.join("\n")}"}]
116
+ }
117
+ end
118
+ results
119
+ end
120
+
121
+ def extract_file(infile, filetype=[])
122
+ return self.extract_lines(File.readlines(infile).map(&:chomp), filetype)
123
+ end
124
+
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}}/, '')}
128
+ end
129
+
130
+ end
131
+
132
+ # ---
133
+ # a : "b"
134
+ # c : d
135
+ # ---
136
+
137
+
138
+
@@ -0,0 +1,8 @@
1
+ class Array
2
+ def unindent
3
+ indent = select {|line| !line.strip.empty? }.map {|line| line.index(/[^\s]/) }.compact.min || 0
4
+ map {|line| line.gsub(/^[[:blank:]]{#{indent}}/, '')}
5
+ end
6
+
7
+ end
8
+
@@ -0,0 +1,176 @@
1
+ require "spec_helper"
2
+ require "yaml"
3
+ describe "Front_Matter" do
4
+ before :all do
5
+ Dir.chdir("test/")
6
+ end
7
+
8
+
9
+ context "Extraction" do
10
+ before :all do
11
+ @fm = FrontMatter.new
12
+ end
13
+
14
+ it "should extract yaml front matter" do
15
+ code = %Q{
16
+ # ---
17
+ # FileName : extract_sh
18
+ # Desc : extract shell functions from shell script
19
+ # Author : Zhao Cai <caizhaoff@gmail.com>
20
+ # ---
21
+ #
22
+ }.unindent
23
+
24
+ valid_content = [
25
+ " FileName : extract_sh" ,
26
+ " Desc : extract shell functions from shell script" ,
27
+ " Author : Zhao Cai <caizhaoff@gmail.com>"
28
+ ]
29
+ content = @fm.extract_lines(code.split("\n").map(&:chomp))
30
+
31
+ content[:valid][0].should == valid_content
32
+
33
+ end
34
+
35
+ it "should extract header front matter" do
36
+ code = %Q{
37
+ # --------------- ------------------------------------------------------------
38
+ # FileName : extract_sh
39
+ # Desc : extract shell functions from shell script
40
+ # Author : Zhao Cai <caizhaoff@gmail.com>
41
+ # --------------- ------------------------------------------------------------
42
+ }.unindent
43
+
44
+ valid_content = [
45
+ " FileName : extract_sh" ,
46
+ " Desc : extract shell functions from shell script" ,
47
+ " Author : Zhao Cai <caizhaoff@gmail.com>"
48
+ ]
49
+ content = @fm.extract_lines(code.split("\n").map(&:chomp))
50
+
51
+ content[:valid][0].should == valid_content
52
+
53
+ end
54
+
55
+ it "should properly extract yaml front matter when there is no ending" do
56
+ code = %Q{
57
+ # ---
58
+ # FileName : extract_sh
59
+ # Desc : extract shell functions from shell script
60
+ # Author : Zhao Cai <caizhaoff@gmail.com>
61
+
62
+ abc
63
+ }.unindent
64
+
65
+ valid_content = [
66
+ " FileName : extract_sh" ,
67
+ " Desc : extract shell functions from shell script" ,
68
+ " Author : Zhao Cai <caizhaoff@gmail.com>",
69
+ ]
70
+ content = @fm.extract_lines(code.split("\n").map(&:chomp))
71
+
72
+ content[:unbound][0].should == valid_content
73
+ end
74
+ end
75
+
76
+
77
+
78
+ context "Unindent" do
79
+ before :all do
80
+ @fm = FrontMatter.new(:unindent => true)
81
+ end
82
+
83
+ it "should extract yaml front matter" do
84
+ code = %Q{
85
+ # ---
86
+ # FileName : extract_sh
87
+ # Desc : extract shell functions from shell script
88
+ # Author : Zhao Cai <caizhaoff@gmail.com>
89
+ # ---
90
+ #
91
+ }.unindent
92
+
93
+ valid_content = [
94
+ "FileName : extract_sh" ,
95
+ "Desc : extract shell functions from shell script" ,
96
+ "Author : Zhao Cai <caizhaoff@gmail.com>"
97
+ ]
98
+ content = @fm.extract_lines(code.split("\n").map(&:chomp))
99
+
100
+ content[:valid][0].should == valid_content
101
+
102
+ end
103
+
104
+ it "should extract header front matter" do
105
+ code = %Q{
106
+ # --------------- ------------------------------------------------------------
107
+ # FileName : extract_sh
108
+ # Desc : extract shell functions from shell script
109
+ # Author : Zhao Cai <caizhaoff@gmail.com>
110
+ # --------------- ------------------------------------------------------------
111
+ }.unindent
112
+
113
+ valid_content = [
114
+ "FileName : extract_sh" ,
115
+ "Desc : extract shell functions from shell script" ,
116
+ "Author : Zhao Cai <caizhaoff@gmail.com>"
117
+ ]
118
+ content = @fm.extract_lines(code.split("\n").map(&:chomp))
119
+
120
+ content[:valid][0].should == valid_content
121
+
122
+ end
123
+
124
+ it "should properly extract yaml front matter when there is no ending" do
125
+ code = %Q{
126
+ # ---
127
+ # FileName : extract_sh
128
+ # Desc : extract shell functions from shell script
129
+ # Author : Zhao Cai <caizhaoff@gmail.com>
130
+
131
+ abc
132
+ }.unindent
133
+
134
+ valid_content = [
135
+ "FileName : extract_sh" ,
136
+ "Desc : extract shell functions from shell script" ,
137
+ "Author : Zhao Cai <caizhaoff@gmail.com>",
138
+ ]
139
+ content = @fm.extract_lines(code.split("\n").map(&:chomp))
140
+
141
+ content[:unbound][0].should == valid_content
142
+ end
143
+ end
144
+
145
+ context "YAML" do
146
+ before :all do
147
+ @fm = FrontMatter.new(:unindent => true, :as_yaml => true)
148
+ end
149
+
150
+ it "should extract and convert to valid yaml" do
151
+ code = %Q{
152
+ # ---
153
+ # FileName : extract_sh
154
+ # Desc : extract shell functions from shell script
155
+ # Author : Zhao Cai <caizhaoff@gmail.com>
156
+ # ---
157
+ #
158
+ }.unindent
159
+
160
+ valid_yaml = YAML.load([
161
+ "---",
162
+ "FileName : extract_sh" ,
163
+ "Desc : extract shell functions from shell script" ,
164
+ "Author : Zhao Cai <caizhaoff@gmail.com>"
165
+ ].join("\n"))
166
+ content = @fm.extract_lines(code.split("\n"))
167
+
168
+ YAML.load(content[:valid][0]).should == valid_yaml
169
+
170
+ end
171
+
172
+ end
173
+ end
174
+
175
+
176
+
@@ -0,0 +1,18 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
2
+
3
+ require "rspec"
4
+
5
+ require 'facets/string'
6
+ require "front_matter"
7
+
8
+ RSpec.configure do |c|
9
+ c.color_enabled = true
10
+
11
+ # Use color not only in STDOUT but also in pagers and files
12
+ c.tty = true
13
+
14
+ c.formatter = :documentation # :progress, :html, :textmate
15
+
16
+ c.mock_with :rspec
17
+ end
18
+
metadata ADDED
@@ -0,0 +1,279 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: front-matter
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Zhao Cai
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: facets
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.9.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.9.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '4.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '2.13'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '2.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 10.0.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: 10.0.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: hoe
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: hoe-gemspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: hoe-git
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: hoe-version
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: awesome_print
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: 1.1.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: 1.1.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: guard
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ~>
144
+ - !ruby/object:Gem::Version
145
+ version: 1.7.0
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ~>
151
+ - !ruby/object:Gem::Version
152
+ version: 1.7.0
153
+ - !ruby/object:Gem::Dependency
154
+ name: guard-rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: guard-bundler
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: terminal-notifier-guard
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - '>='
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - '>='
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: growl
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - '>='
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - '>='
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: rb-fsevent
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ~>
214
+ - !ruby/object:Gem::Version
215
+ version: '0.9'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ~>
221
+ - !ruby/object:Gem::Version
222
+ version: '0.9'
223
+ description: |-
224
+ This gem extracts embeded info (yaml front matters, for example ) in source code
225
+ comments with predefined format:
226
+
227
+ 1. the leading comment string can be different based on the language.
228
+ 2. the leading column of yaml docs must be aligned to be converted to yaml.
229
+ email:
230
+ - caizhaoff@gmail.com
231
+ executables:
232
+ - front_matter
233
+ extensions: []
234
+ extra_rdoc_files:
235
+ - History.txt
236
+ - Manifest.txt
237
+ files:
238
+ - .gemtest
239
+ - Gemfile
240
+ - Gemfile.lock
241
+ - Guardfile
242
+ - History.txt
243
+ - Manifest.txt
244
+ - README.md
245
+ - Rakefile
246
+ - bin/front_matter
247
+ - front-matter.gemspec
248
+ - lib/front_matter.rb
249
+ - lib/front_matter/core/array.rb
250
+ - spec/front_matter_spec.rb
251
+ - spec/spec_helper.rb
252
+ homepage: http://zhaocai.github.com/front-matter.rb/
253
+ licenses:
254
+ - GPL-3
255
+ metadata: {}
256
+ post_install_message:
257
+ rdoc_options:
258
+ - --main
259
+ - README.md
260
+ require_paths:
261
+ - lib
262
+ required_ruby_version: !ruby/object:Gem::Requirement
263
+ requirements:
264
+ - - '>='
265
+ - !ruby/object:Gem::Version
266
+ version: '0'
267
+ required_rubygems_version: !ruby/object:Gem::Requirement
268
+ requirements:
269
+ - - '>='
270
+ - !ruby/object:Gem::Version
271
+ version: '0'
272
+ requirements: []
273
+ rubyforge_project: front-matter
274
+ rubygems_version: 2.0.3
275
+ signing_key:
276
+ specification_version: 4
277
+ summary: 'This gem extracts embeded info (yaml front matters, for example ) in source
278
+ code comments with predefined format: 1'
279
+ test_files: []