readminator 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,16 @@
1
+ module Readminator
2
+ def validate(readme)
3
+ errors = []
4
+ blocks = Parsinator.blocks(readme)
5
+ blocks.each do |(line, language, code)|
6
+ validator = Validator.for(language)
7
+ errors << validator.check(code, line)
8
+ end
9
+ errors.compact
10
+ end
11
+ module_function :validate
12
+
13
+ autoload :Parsinator, "readminator/parsinator"
14
+ autoload :Validator, "readminator/validator"
15
+ autoload :VERSION, "readminator/version"
16
+ end
@@ -0,0 +1,12 @@
1
+ module Readminator
2
+ class Parsinator
3
+ def self.blocks(readme)
4
+ blocks = readme.scan(/^``` ?([^\r\n]+)?\r?\n(.+?)\r?\n```\r?$/m)
5
+ lines = readme.split("\n")
6
+ blocks.map do |(language, code)|
7
+ line = code.split("\n", 2).first
8
+ [lines.index(line), language, code]
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ require "readminator/validator/default"
2
+
3
+ module Readminator
4
+ class Validator
5
+ def self.for(language)
6
+ if File.exists?(File.expand_path "../validator/#{language}.rb", __FILE__)
7
+ require "readminator/validator/#{language}"
8
+ Validator.const_get(language.capitalize).new
9
+ else
10
+ Validator::Default.new
11
+ end
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require "open3"
2
+
3
+ module Readminator
4
+ class Validator::Coffeescript
5
+ def check(code, line)
6
+ Open3.popen3("coffee -c -s") do |stdin, stdout, stderr, wait|
7
+ stdin << code
8
+ stdin.close
9
+ exit_status = wait.value
10
+ return { line: line, error: stderr.read.split(/\r|\n/, 2).first, language: "coffeescript" } if exit_status != 0
11
+ end
12
+ nil
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ module Readminator
2
+ class Validator
3
+ class Default
4
+ def check(code, line)
5
+ nil
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ require "open3"
2
+
3
+ module Readminator
4
+ class Validator::Ruby
5
+ def check(code, line)
6
+ Open3.popen3("ruby -c") do |stdin, stdout, stderr, wait|
7
+ stdin << code
8
+ stdin.close
9
+ exit_status = wait.value
10
+ return { line: line, error: stderr.read.chomp, language: "ruby" } if exit_status != 0
11
+ end
12
+ nil
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module Readminator
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: readminator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Bruno Michel
9
+ - Julien Boyer
10
+ - François de Metz
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2011-10-05 00:00:00.000000000 Z
15
+ dependencies: []
16
+ description: Improve your README
17
+ email:
18
+ - bruno.michel@af83.com
19
+ - julien.boyer@af83.com
20
+ - fdemetz@af83.com
21
+ executables: []
22
+ extensions: []
23
+ extra_rdoc_files: []
24
+ files:
25
+ - lib/readminator.rb
26
+ - lib/readminator/parsinator.rb
27
+ - lib/readminator/validator.rb
28
+ - lib/readminator/validator/coffeescript.rb
29
+ - lib/readminator/validator/default.rb
30
+ - lib/readminator/validator/ruby.rb
31
+ - lib/readminator/version.rb
32
+ homepage: https://github.com/af83/readminator
33
+ licenses: []
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 1.8.10
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: Improve your README
56
+ test_files: []