├── var ├── name ├── title ├── version ├── created ├── organization ├── authors ├── summary ├── copyrights ├── repositories ├── requirements ├── resources └── description ├── .reap └── ignore ├── Gemfile ├── lib ├── readme │ ├── version.rb │ └── cli.rb └── readme.rb ├── bin └── readme ├── .gitignore ├── .travis.yml ├── MANIFEST ├── HISTORY.md ├── .test ├── Assembly ├── Reapfile ├── test ├── fixture │ └── README.md └── test_readme.rb ├── .ruby ├── README.md └── .gemspec /var/name: -------------------------------------------------------------------------------- 1 | readme 2 | -------------------------------------------------------------------------------- /var/title: -------------------------------------------------------------------------------- 1 | Readme 2 | -------------------------------------------------------------------------------- /var/version: -------------------------------------------------------------------------------- 1 | 0.1.0 2 | -------------------------------------------------------------------------------- /.reap/ignore: -------------------------------------------------------------------------------- 1 | ../.gitignore -------------------------------------------------------------------------------- /var/created: -------------------------------------------------------------------------------- 1 | 2009-07-22 2 | -------------------------------------------------------------------------------- /var/organization: -------------------------------------------------------------------------------- 1 | rubyworks 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source :rubygems 2 | gemspec 3 | -------------------------------------------------------------------------------- /var/authors: -------------------------------------------------------------------------------- 1 | --- 2 | - Trans 3 | -------------------------------------------------------------------------------- /var/summary: -------------------------------------------------------------------------------- 1 | Extract information from README files. 2 | -------------------------------------------------------------------------------- /var/copyrights: -------------------------------------------------------------------------------- 1 | --- 2 | - (c) 2011 Rubyworks (BSD-2-Clause) 3 | -------------------------------------------------------------------------------- /lib/readme/version.rb: -------------------------------------------------------------------------------- 1 | class Readme 2 | VERSION = '0.1.0' 3 | end 4 | -------------------------------------------------------------------------------- /bin/readme: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'readme' 3 | Readme.cli(*ARGV) 4 | -------------------------------------------------------------------------------- /var/repositories: -------------------------------------------------------------------------------- 1 | --- 2 | upstream: git://github.com/rubyworks/readme.git 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .reap/digest 2 | .yardoc 3 | doc 4 | log 5 | pkg 6 | tmp 7 | web 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | script: "bundle exec rubytest" 3 | rvm: 4 | - 1.8.7 5 | - 1.9.2 6 | - 1.9.3 7 | - rbx-19mode 8 | - jruby-19mode 9 | 10 | -------------------------------------------------------------------------------- /MANIFEST: -------------------------------------------------------------------------------- 1 | #!mast .ruby .yardopts bin info data lib man spec test [A-Z]*.* 2 | .ruby 3 | bin/readme 4 | lib/readme/cli.rb 5 | lib/readme/version.rb 6 | lib/readme.rb 7 | HISTORY.md 8 | README.md 9 | -------------------------------------------------------------------------------- /HISTORY.md: -------------------------------------------------------------------------------- 1 | # Release History 2 | 3 | ## 0.1.0 | 2011-01-01 4 | 5 | First release of Readme project, spun-off from the Ruby POM project. 6 | 7 | Changes: 8 | 9 | * Happy first release day! 10 | 11 | -------------------------------------------------------------------------------- /var/requirements: -------------------------------------------------------------------------------- 1 | --- 2 | - 'detroit (build)' 3 | - 'reap (build)' 4 | - 'mast (test)' 5 | - 'rubytest (test)' 6 | - 'citron (test)' 7 | - 'ae (test)' 8 | - 'simplecov (test)' 9 | 10 | -------------------------------------------------------------------------------- /var/resources: -------------------------------------------------------------------------------- 1 | --- 2 | home: http://rubyworks.github.com/readme 3 | code: http://github.com/rubyworks/readme 4 | bugs: http://github.com/rubyworks/readme/issues 5 | mail: http://groups.google.com/groups/rubyworks-mailinglist 6 | -------------------------------------------------------------------------------- /var/description: -------------------------------------------------------------------------------- 1 | Ever thought perhaps that all the effect in creating a good README, while 2 | great for your end-userss, did't every do you a hill of beans worth of good 3 | when it came to constructing your project's metadata. Well, hang on to your 4 | nerd glasses! Here comes a gem that does just that! 5 | -------------------------------------------------------------------------------- /.test: -------------------------------------------------------------------------------- 1 | require 'citron' 2 | require 'ae' 3 | 4 | # Default test run. 5 | Test.run do |r| 6 | r.files << 'test' 7 | end 8 | 9 | # Generate SimpleCov coverage report. 10 | Test.run :cov do |r| 11 | r.files << 'test' 12 | require 'simplecov' 13 | SimpleCov.start do 14 | coverage_dir 'log/coverage' 15 | add_filter "/test/" 16 | end 17 | end 18 | 19 | -------------------------------------------------------------------------------- /Assembly: -------------------------------------------------------------------------------- 1 | --- 2 | github: 3 | gh_pages: web 4 | 5 | gem: 6 | active: true 7 | 8 | dnote: 9 | title : Source Notes 10 | output : log/notes.html 11 | 12 | yard: 13 | yardopts: true 14 | priority: -1 15 | 16 | #qedoc: 17 | # files : qed/ 18 | # output: doc/QED.rdoc 19 | # title : AE Demonstrandum 20 | 21 | email: 22 | file : ~ 23 | subject : ~ 24 | mailto : 25 | - ruby-talk@ruby-lang.org 26 | - rubyworks-mailinglist@googlegroups.com 27 | 28 | vclog: 29 | output: 30 | - log/history.html 31 | - log/changes.html 32 | 33 | -------------------------------------------------------------------------------- /Reapfile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # @todo move to reap proper 4 | #require 'facets/string/file' 5 | #require 'facets/kernel/ask' # TODO: make sure reap provides this 6 | 7 | # 8 | # TODO: Do things in ruby instead of shelling out! 9 | # 10 | 11 | metadata = YAML.load_file('.ruby') 12 | version = metadata['version'] 13 | 14 | desc 'update manifest file' 15 | task 'manifest' do 16 | system 'mast -u' 17 | end 18 | 19 | desc 'release and tag' 20 | task 'release' do 21 | exit -1 unless system('detroit release') 22 | system "pom news | git tag -a -F - #{version}" 23 | end 24 | 25 | file 'var/*' do 26 | system 'dotruby source var' 27 | end 28 | 29 | #file 'Profile' do 30 | # system 'dotruby source Profile' 31 | #end 32 | 33 | file 'lib/**/*' do 34 | exit -1 unless system('detroit test') 35 | end 36 | 37 | 38 | #require 'facets/functor' 39 | #class String 40 | # def file 41 | # str = self 42 | # Functor.new do |op,*a,&b| 43 | # FileUtils.send(op,str,*a,&b) 44 | # end 45 | # end 46 | #end 47 | -------------------------------------------------------------------------------- /test/fixture/README.md: -------------------------------------------------------------------------------- 1 | # README 2 | 3 | [Home](http://rubyworks.github.com/readme) / 4 | [Work](http://github.com/rubyworks/readme) / 5 | [Mail](http://groups.google.com/groups/rubyworks-mailinglist) 6 | 7 | 8 | ## Description 9 | 10 | Ever thought perhaps that all the effect in creating a good README, while 11 | great for your end-userss, did't every do you a hill of beans worth of good 12 | when it came to constructing your project's metadata. Well, hang on to your 13 | nerd glasses! Here comes a gem that does just that! 14 | 15 | 16 | ## Instruction 17 | 18 | The library is about as easy to use as you can imagine. 19 | 20 | require 'readme' 21 | 22 | readme = Readme.file 23 | 24 | readme.name 25 | readme.description 26 | readme.copyright 27 | 28 | It also come with a command line client to pump out the data into variant 29 | formats, such a YAML, JSON and even Ruby code. 30 | 31 | 32 | ## Copyright 33 | 34 | Copyright (c) 2009 Rubyworks. All rights reserved. 35 | 36 | Readme can be reistributed in accordance with the **BSD-2-Clause** license. 37 | 38 | See COPYING.md file for details. 39 | 40 | -------------------------------------------------------------------------------- /test/test_readme.rb: -------------------------------------------------------------------------------- 1 | require 'readme' 2 | 3 | testcase Readme do 4 | 5 | fixture = File.dirname(__FILE__) + '/fixture' 6 | 7 | setup do 8 | @readme = Readme.file(fixture) 9 | end 10 | 11 | test 'should find readme file' do 12 | assert @readme.file 13 | end 14 | 15 | test 'should have name' do 16 | @readme.name.assert == 'readme' 17 | end 18 | 19 | test 'should have title' do 20 | @readme.title.assert == 'README' 21 | end 22 | 23 | test 'should have description' do 24 | @readme.description.assert.start_with?('Ever thought') 25 | @readme.description.assert.end_with?('does just that!') 26 | end 27 | 28 | test 'should have copyrights' do 29 | @readme.copyright.assert == 'Copyright (c) 2009 Rubyworks. All rights reserved.' 30 | end 31 | 32 | test 'should have home resource' do 33 | @readme.resources['home'].assert == 'http://github.com/rubyworks/readme' 34 | end 35 | 36 | #test 'should have code resource' do 37 | # @readme.resources['code'].assert == 'http://rubyworks.github.com/readme' 38 | #end 39 | 40 | test 'should have mail resource' do 41 | @readme.resources['mail'].assert == 'http://groups.google.com/groups/rubyworks-mailinglist' 42 | end 43 | 44 | end 45 | 46 | -------------------------------------------------------------------------------- /lib/readme/cli.rb: -------------------------------------------------------------------------------- 1 | class Readme 2 | 3 | require 'optparse' 4 | 5 | def self.cli(*argv) 6 | format = nil 7 | name = nil 8 | 9 | OptionParser.new do |opt| 10 | opt.banner = 'Usage: readme [option] [field]' 11 | opt.on('-y', '--yml', '--yaml', 'return in YAML format') do 12 | format = :yaml 13 | end 14 | opt.on('-j', '--json', 'return in JSON format') do 15 | format = :json 16 | end 17 | opt.on('-r', '--ruby', 'return in Ruby code format') do 18 | format = :ruby 19 | end 20 | opt.on_tail('-h', '--help', 'show this help message') do 21 | puts opt 22 | exit 23 | end 24 | end.parse!(argv) 25 | 26 | if argv.first 27 | name = argv.shift 28 | data = Readme.file[name] 29 | else 30 | if format 31 | data = Readme.file.to_h 32 | else 33 | data = Readme.file 34 | end 35 | end 36 | 37 | case format 38 | when :yaml 39 | require 'yaml' 40 | puts data.to_yaml 41 | when :json 42 | require 'json' 43 | puts data.to_json 44 | when :ruby 45 | data = {name => data} if name 46 | data.each do |k,v| 47 | case v 48 | when Hash 49 | puts "#{k} #{v.inspect[1...-1]}" 50 | else 51 | puts "#{k} #{v.inspect}" 52 | end 53 | end 54 | else 55 | puts data #Readme.file.to_s 56 | end 57 | end 58 | 59 | end 60 | -------------------------------------------------------------------------------- /.ruby: -------------------------------------------------------------------------------- 1 | --- 2 | source: 3 | - var 4 | authors: 5 | - name: Trans 6 | email: transfire@gmail.com 7 | copyrights: 8 | - holder: Rubyworks 9 | year: '2011' 10 | license: BSD-2-Clause 11 | replacements: [] 12 | alternatives: [] 13 | requirements: 14 | - name: detroit 15 | groups: 16 | - build 17 | development: true 18 | - name: reap 19 | groups: 20 | - build 21 | development: true 22 | - name: mast 23 | groups: 24 | - test 25 | development: true 26 | - name: rubytest 27 | groups: 28 | - test 29 | development: true 30 | - name: citron 31 | groups: 32 | - test 33 | development: true 34 | - name: ae 35 | groups: 36 | - test 37 | development: true 38 | - name: simplecov 39 | groups: 40 | - test 41 | development: true 42 | dependencies: [] 43 | conflicts: [] 44 | repositories: 45 | - uri: git://github.com/rubyworks/readme.git 46 | scm: git 47 | name: upstream 48 | resources: 49 | home: http://rubyworks.github.com/readme 50 | code: http://github.com/rubyworks/readme 51 | bugs: http://github.com/rubyworks/readme/issues 52 | mail: http://groups.google.com/groups/rubyworks-mailinglist 53 | extra: {} 54 | load_path: 55 | - lib 56 | revision: 0 57 | created: '2009-07-22' 58 | summary: Extract information from README files. 59 | title: Readme 60 | version: 0.1.0 61 | name: readme 62 | description: ! 'Ever thought perhaps that all the effect in creating a good README, 63 | while 64 | 65 | great for your end-userss, did''t every do you a hill of beans worth of good 66 | 67 | when it came to constructing your project''s metadata. Well, hang on to your 68 | 69 | nerd glasses! Here comes a gem that does just that!' 70 | organization: rubyworks 71 | date: '2012-02-08' 72 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # README 2 | 3 | [Website](http://rubyworks.github.com/readme) / 4 | [Development](http://github.com/rubyworks/readme) / 5 | [Issue Tracker](http://github.com/rubyworks/readme/issues) / 6 | [Mailing List](http://groups.google.com/groups/rubyworks-mailinglist) 7 | 8 | [![Build Status](https://secure.travis-ci.org/rubyworks/readme.png)](http://travis-ci.org/rubyworks/readme) 9 | 10 | 11 | ## Description 12 | 13 | Ever thought perhaps that all the effort that went into creating a good README, 14 | while great for your end-users, hadn't ever done you a lick of good 15 | when it came to constructing your project's metadata? Well, hang on to your 16 | nerd glasses! Here comes a gem that does just that! 17 | 18 | Okay, don't get too excited just yet. Though Readme can produce useful results 19 | as is, her heuristics are rather limited at this point. With time and **contribution** 20 | she'll be right fine in the not too distant future. 21 | 22 | 23 | ## Instruction 24 | 25 | The library is about as easy to use as you can imagine. 26 | 27 | require 'readme' 28 | 29 | readme = Readme.file 30 | 31 | readme.name 32 | readme.description 33 | readme.copyright 34 | 35 | It also come with a command line client to pump out the data into variant 36 | formats, such a YAML, JSON and even Ruby code. 37 | 38 | $ readme --yaml 39 | 40 | $ readme description 41 | 42 | See the [API documentation](http:/rubydoc.info/gems/readme) and `readme --help` for more information. 43 | 44 | 45 | ## Copyright 46 | 47 | Copyright (c) 2009 Rubyworks. All rights reserved. 48 | 49 | Readme can be redistributed in accordance with the **BSD-2-Clause** license. 50 | 51 | See COPYING.md file for details. 52 | 53 | -------------------------------------------------------------------------------- /.gemspec: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | require 'yaml' 4 | 5 | module DotRuby 6 | 7 | # 8 | class GemSpec 9 | 10 | # For which revision of .ruby is this gemspec intended? 11 | REVISION = 0 12 | 13 | # 14 | PATTERNS = { 15 | :bin_files => 'bin/*', 16 | :lib_files => 'lib/{**/}*.rb', 17 | :ext_files => 'ext/{**/}extconf.rb', 18 | :doc_files => '*.{txt,rdoc,md,markdown,tt,textile}', 19 | :test_files => '{test/{**/}*_test.rb,spec/{**/}*_spec.rb}' 20 | } 21 | 22 | # 23 | def self.instance 24 | new.to_gemspec 25 | end 26 | 27 | attr :metadata 28 | 29 | attr :manifest 30 | 31 | # 32 | def initialize 33 | @metadata = YAML.load_file('.ruby') 34 | @manifest = Dir.glob('manifest{,.txt}', File::FNM_CASEFOLD).first 35 | 36 | if @metadata['revision'].to_i != REVISION 37 | warn "You have the wrong revision. Trying anyway..." 38 | end 39 | end 40 | 41 | # 42 | def scm 43 | @scm ||= \ 44 | case 45 | when File.directory?('.git') 46 | :git 47 | end 48 | end 49 | 50 | # 51 | def files 52 | @files ||= \ 53 | #glob_files[patterns[:files]] 54 | case 55 | when manifest 56 | File.readlines(manifest). 57 | map{ |line| line.strip }. 58 | reject{ |line| line.empty? || line[0,1] == '#' } 59 | when scm == :git 60 | `git ls-files -z`.split("\0") 61 | else 62 | Dir.glob('{**/}{.*,*}') # TODO: be more specific using standard locations ? 63 | end.select{ |path| File.file?(path) } 64 | end 65 | 66 | # 67 | def glob_files(pattern) 68 | Dir.glob(pattern).select { |path| 69 | File.file?(path) && files.include?(path) 70 | } 71 | end 72 | 73 | # 74 | def patterns 75 | PATTERNS 76 | end 77 | 78 | # 79 | def executables 80 | @executables ||= \ 81 | glob_files(patterns[:bin_files]).map do |path| 82 | File.basename(path) 83 | end 84 | end 85 | 86 | def extensions 87 | @extensions ||= \ 88 | glob_files(patterns[:ext_files]).map do |path| 89 | File.basename(path) 90 | end 91 | end 92 | 93 | # 94 | def name 95 | metadata['name'] || metadata['title'].downcase.gsub(/\W+/,'_') 96 | end 97 | 98 | # 99 | def to_gemspec 100 | Gem::Specification.new do |gemspec| 101 | gemspec.name = name 102 | gemspec.version = metadata['version'] 103 | gemspec.summary = metadata['summary'] 104 | gemspec.description = metadata['description'].to_s.gsub("\n", " ") 105 | 106 | metadata['authors'].each do |author| 107 | gemspec.authors << author['name'] 108 | 109 | if author.has_key?('email') 110 | if gemspec.email 111 | gemspec.email << author['email'] 112 | else 113 | gemspec.email = [author['email']] 114 | end 115 | end 116 | end 117 | 118 | gemspec.licenses = metadata['copyrights'].map{ |c| c['license'] }.compact 119 | 120 | metadata['requirements'].each do |req| 121 | name = req['name'] 122 | version = req['version'] 123 | groups = req['groups'] || [] 124 | 125 | case version 126 | when /^(.*?)\+$/ 127 | version = ">= #{$1}" 128 | when /^(.*?)\-$/ 129 | version = "< #{$1}" 130 | when /^(.*?)\~$/ 131 | version = "~> #{$1}" 132 | end 133 | 134 | if groups.empty? or groups.include?('runtime') 135 | # populate runtime dependencies 136 | if gemspec.respond_to?(:add_runtime_dependency) 137 | gemspec.add_runtime_dependency(name,*version) 138 | else 139 | gemspec.add_dependency(name,*version) 140 | end 141 | else 142 | # populate development dependencies 143 | if gemspec.respond_to?(:add_development_dependency) 144 | gemspec.add_development_dependency(name,*version) 145 | else 146 | gemspec.add_dependency(name,*version) 147 | end 148 | end 149 | end 150 | 151 | # convert external dependencies into a requirements 152 | if metadata['external_dependencies'] 153 | ##gemspec.requirements = [] unless metadata['external_dependencies'].empty? 154 | metadata['external_dependencies'].each do |req| 155 | gemspec.requirements << req.to_s 156 | end 157 | end 158 | 159 | # determine homepage from resources 160 | homepage = metadata['resources'].find{ |key, url| key =~ /^home/ } 161 | gemspec.homepage = homepage.last if homepage 162 | 163 | gemspec.require_paths = metadata['load_path'] || ['lib'] 164 | gemspec.post_install_message = metadata['install_message'] 165 | 166 | # RubyGems specific metadata 167 | gemspec.files = files 168 | gemspec.extensions = extensions 169 | gemspec.executables = executables 170 | 171 | if Gem::VERSION < '1.7.' 172 | gemspec.default_executable = gemspec.executables.first 173 | end 174 | 175 | gemspec.test_files = glob_files(patterns[:test_files]) 176 | 177 | unless gemspec.files.include?('.document') 178 | gemspec.extra_rdoc_files = glob_files(patterns[:doc_files]) 179 | end 180 | end 181 | end 182 | 183 | end #class GemSpec 184 | 185 | end 186 | 187 | DotRuby::GemSpec.instance 188 | -------------------------------------------------------------------------------- /lib/readme.rb: -------------------------------------------------------------------------------- 1 | # Readme is designed to parse a README file applying various hueristics 2 | # in order to descern metadata about a project. 3 | # 4 | # The heuristics are fairly simplistic at this point, but will improve 5 | # with time and contribution. 6 | # 7 | class Readme 8 | 9 | if RUBY_VERSION < '1.9' 10 | require 'readme/version' 11 | require 'readme/cli' 12 | else 13 | require_relative 'readme/version' 14 | require_relative 'readme/cli' 15 | end 16 | 17 | # File glob for matching README file. 18 | FILE_PATTERN = "README{,.*}" 19 | 20 | # 21 | def self.file(path=Dir.pwd) 22 | if File.directory?(path) 23 | path = Dir.glob(File.join(path, FILE_PATTERN), File::FNM_CASEFOLD).first 24 | end 25 | if path 26 | new(File.read(path), path) 27 | else 28 | raise IOError, "no such README -- #{path}" 29 | end 30 | end 31 | 32 | # 33 | def initialize(text, file=nil) 34 | @text = text 35 | @file = file 36 | @data = {} 37 | parse 38 | end 39 | 40 | # 41 | # The ERADME file path, if provided. 42 | # 43 | attr :file 44 | 45 | # 46 | # The README text. 47 | # 48 | attr :text 49 | 50 | # 51 | # Location of README file, if file was provided. 52 | # 53 | # @return [String] Directory of README file 54 | # 55 | def root 56 | File.dirname(file) if file 57 | end 58 | 59 | # 60 | # The full README text. 61 | # 62 | # @return [String] The complete README text. 63 | # 64 | def to_s 65 | text.to_s 66 | end 67 | 68 | # 69 | # Access to underlying parse table. 70 | # 71 | def [](name) 72 | @data[name.to_s] 73 | #return nil unless file 74 | #if respond_to?(name) 75 | # __send__(name) 76 | #else 77 | # nil 78 | #end 79 | end 80 | 81 | # 82 | def name 83 | @data['name'] 84 | end 85 | 86 | # 87 | def title 88 | @data['title'] 89 | end 90 | 91 | # 92 | def description 93 | @data['description'] 94 | end 95 | 96 | # 97 | def license 98 | @data['license'] 99 | end 100 | 101 | # 102 | def copyright 103 | @data['copyright'] 104 | end 105 | 106 | # 107 | def authors 108 | @data['authors'] 109 | end 110 | 111 | # 112 | def resources 113 | @data['resources'] ||= {} 114 | end 115 | 116 | # 117 | def homepage 118 | resources['home'] 119 | end 120 | 121 | # 122 | def wiki 123 | resources['wiki'] 124 | end 125 | 126 | # 127 | def issues 128 | resources['issues'] 129 | end 130 | 131 | # 132 | # Return file extension of README. Even if the file has no extension, 133 | # this method will look at the contents and try to determine it. 134 | # 135 | # @todo Improve type heuristics. 136 | # 137 | # @return [String] Extension type, e.g. `.md`. 138 | # 139 | def extname 140 | ext = File.extname(file) 141 | if ext.empty? 142 | ext = '.rdoc' if /^\=/ =~ text 143 | ext = '.md' if /^\#/ =~ text 144 | end 145 | return ext 146 | end 147 | 148 | # 149 | # Access to a copy of the underlying parse table. 150 | # 151 | # @return [Hash] Copy of the underlying table. 152 | # 153 | def to_h 154 | @data.dup 155 | end 156 | 157 | private 158 | 159 | # 160 | def parse 161 | parse_title 162 | parse_description 163 | parse_license 164 | parse_copyright 165 | parse_resources 166 | end 167 | 168 | # 169 | def parse_title 170 | if md = /^[=#]\s*(.*?)$/m.match(text) 171 | title = md[1].strip 172 | @data['title'] = title 173 | @data['name'] = title.downcase.gsub(/\s+/, '_') 174 | end 175 | end 176 | 177 | # 178 | def parse_description 179 | if md = /[=#]+\s*(DESCRIPTION|ABSTRACT)[:]*(.*?)[=#]/mi.match(text) 180 | @data['description'] = md[2].strip #.sub("\n", ' ') # unfold instead of sub? 181 | else 182 | d = [] 183 | o = false 184 | text.split("\n").each do |line| 185 | if o 186 | if /^(\w|\s*$)/ !~ line 187 | break d 188 | else 189 | d << line 190 | end 191 | else 192 | if /^\w/ =~ line 193 | d << line 194 | o = true 195 | end 196 | end 197 | end 198 | @data['description'] = d.join(' ').strip 199 | end 200 | end 201 | 202 | # 203 | def parse_license 204 | if md = /[=]+\s*(LICENSE)/i.match(text) 205 | section = md.post_match 206 | @data['license'] = ( 207 | case section 208 | when /LGPL/ 209 | "LGPL" 210 | when /GPL/ 211 | "GPL" 212 | when /MIT/ 213 | "MIT" 214 | when /BSD/ 215 | "BSD" 216 | end 217 | ) 218 | end 219 | end 220 | 221 | # 222 | def parse_copyright 223 | md = /Copyright.*?\d+(.*?)$/.match(text) 224 | if md 225 | copyright = md[0] 226 | 227 | authors = md[1].split(/(and|\&|\,)/).map{|a|a.strip} 228 | authors = authors.map{ |a| a.sub(/all rights reserved\.?/i, '').strip.chomp('.') } 229 | 230 | @data['copyright'] = copyright 231 | @data['authors'] = authors 232 | end 233 | end 234 | 235 | # 236 | def parse_resources 237 | @data['resources'] = {} 238 | 239 | scan_for_github 240 | scan_for_google_groups 241 | 242 | text.scan(/(\w+)\:\s*(http:.*?[\w\/])$/) do |m| 243 | @data['resources'][$1] = $2 244 | end 245 | end 246 | 247 | # 248 | # TODO: Improve on github matching. 249 | def scan_for_github 250 | text.scan(/http\:.*?github\.com.*?[">)\s]/) do |m| 251 | case m 252 | when /wiki/ 253 | @data['resources']['wiki'] = m[0...-1] 254 | when /issues/ 255 | @data['resources']['issues'] = m[0...-1] 256 | else 257 | if m[0] =~ /:\/\/github/ 258 | @data['resources']['code'] = m[0...-1] 259 | else 260 | @data['resources']['home'] = m[0...-1] 261 | end 262 | end 263 | end 264 | end 265 | 266 | # 267 | def scan_for_google_groups 268 | if m = /http\:.*?groups\.google\.com.*?[">)\s]/.match(text) 269 | @data['resources']['mail'] = m[0][0...-1] 270 | end 271 | end 272 | 273 | # 274 | # TODO: parse readme into sections of [label, text]. 275 | #def sections 276 | # @sections ||= ( 277 | # secs = text.split(/^(==|##)/) 278 | # secs.map do |sec| 279 | # i = sec.index("\n") 280 | # n = sec[0..i].sub(/^[=#]*/, '') 281 | # t = sec[i+1..-1] 282 | # [n, t] 283 | # end 284 | # ) 285 | #end 286 | end 287 | 288 | --------------------------------------------------------------------------------