From 702477ca28d3139d33d64153615e4112bd1f78d1 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Wed, 26 Feb 2014 19:50:16 +0100 Subject: [PATCH] Basic project layout. --- .yardopts | 13 ++++++++ Gemfile | 3 ++ Gemfile.lock | 44 +++++++++++++++++++++++++ MANIFEST | 0 Rakefile | 24 ++++++++++++++ checksum/.gitkeep | 0 doc/.gitkeep | 0 doc/DCO.md | 26 +++++++++++++++ doc/changelog.md | 2 ++ doc/css/.gitkeep | 0 doc/css/common.css | 69 +++++++++++++++++++++++++++++++++++++++ lib/oga.rb | 1 + lib/oga/version.rb | 3 ++ oga.gemspec | 27 +++++++++++++++ spec/spec_helper.rb | 13 ++++++++ spec/support/parsing.rb | 14 ++++++++ spec/support/simplecov.rb | 12 +++++++ task/build.rake | 4 +++ task/checksum.rake | 13 ++++++++ task/generate.rake | 5 +++ task/lexer.rake | 8 +++++ task/manifest.rake | 9 +++++ task/parser.rake | 8 +++++ task/tag.rake | 6 ++++ task/test.rake | 4 +++ 25 files changed, 308 insertions(+) create mode 100644 .yardopts create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 MANIFEST create mode 100644 Rakefile create mode 100644 checksum/.gitkeep create mode 100644 doc/.gitkeep create mode 100644 doc/DCO.md create mode 100644 doc/changelog.md create mode 100644 doc/css/.gitkeep create mode 100644 doc/css/common.css create mode 100644 lib/oga.rb create mode 100644 lib/oga/version.rb create mode 100644 oga.gemspec create mode 100644 spec/spec_helper.rb create mode 100644 spec/support/parsing.rb create mode 100644 spec/support/simplecov.rb create mode 100644 task/build.rake create mode 100644 task/checksum.rake create mode 100644 task/generate.rake create mode 100644 task/lexer.rake create mode 100644 task/manifest.rake create mode 100644 task/parser.rake create mode 100644 task/tag.rake create mode 100644 task/test.rake diff --git a/.yardopts b/.yardopts new file mode 100644 index 0000000..64faf91 --- /dev/null +++ b/.yardopts @@ -0,0 +1,13 @@ +./lib/oga/**/*.rb ./lib/oga.rb +-m markdown +-M kramdown +-o yardoc +-r ./README.md +--private +--protected +--asset ./doc/css/common.css:css/common.css +--verbose +- +./doc/*.md +LICENSE +CONTRIBUTING.md diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..fa75df1 --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source 'https://rubygems.org' + +gemspec diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..dd2451a --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,44 @@ +PATH + remote: . + specs: + oga (0.0.1) + ast + racc + +GEM + remote: https://rubygems.org/ + specs: + ast (1.1.0) + cliver (0.3.2) + diff-lcs (1.2.5) + docile (1.1.3) + kramdown (1.3.2) + multi_json (1.8.4) + racc (1.4.11) + rake (10.1.1) + rspec (2.14.1) + rspec-core (~> 2.14.0) + rspec-expectations (~> 2.14.0) + rspec-mocks (~> 2.14.0) + rspec-core (2.14.7) + rspec-expectations (2.14.5) + diff-lcs (>= 1.1.3, < 2.0) + rspec-mocks (2.14.6) + simplecov (0.8.2) + docile (~> 1.1.0) + multi_json + simplecov-html (~> 0.8.0) + simplecov-html (0.8.0) + yard (0.8.7.3) + +PLATFORMS + ruby + +DEPENDENCIES + cliver + kramdown + oga! + rake + rspec + simplecov + yard diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..e69de29 diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..dad27a3 --- /dev/null +++ b/Rakefile @@ -0,0 +1,24 @@ +require 'bundler/gem_tasks' +require 'digest/sha2' +require 'rake/clean' +require 'cliver' + +GEMSPEC = Gem::Specification.load('oga.gemspec') + +LEXER_INPUT = 'lib/oga/lexer.rl' +LEXER_OUTPUT = 'lib/oga/lexer.rb' + +#PARSER_INPUT = 'lib/oga/parser.y' +#PARSER_OUTPUT = 'lib/oga/parser.rb' + +GENERATED_FILES = ['coverage', 'yardoc', LEXER_OUTPUT] + +GENERATED_FILES.each do |file| + CLEAN << file if File.exist?(file) +end + +Dir['./task/*.rake'].each do |task| + import(task) +end + +task :default => :test diff --git a/checksum/.gitkeep b/checksum/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/doc/.gitkeep b/doc/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/doc/DCO.md b/doc/DCO.md new file mode 100644 index 0000000..8733e43 --- /dev/null +++ b/doc/DCO.md @@ -0,0 +1,26 @@ +# @title DCO +# Developer's Certificate of Origin 1.0 + +By making a contribution to this project, I certify that: + +1. The contribution was created in whole or in part by me and I + have the right to submit it under the open source license + indicated in the file LICENSE; or + +2. The contribution is based upon previous work that, to the best + of my knowledge, is covered under an appropriate open source + license and I have the right under that license to submit that + work with modifications, whether created in whole or in part + by me, under the same open source license (unless I am + permitted to submit under a different license), as indicated + in the file LICENSE; or + +3. The contribution was provided directly to me by some other + person who certified (1), (2) or (3) and I have not modified + it. + +4. I understand and agree that this project and the contribution + are public and that a record of the contribution (including all + personal information I submit with it, including my sign-off) is + maintained indefinitely and may be redistributed consistent with + this project or the open source license(s) involved. diff --git a/doc/changelog.md b/doc/changelog.md new file mode 100644 index 0000000..36e6c66 --- /dev/null +++ b/doc/changelog.md @@ -0,0 +1,2 @@ +# @title Changelog +# Changelog diff --git a/doc/css/.gitkeep b/doc/css/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/doc/css/common.css b/doc/css/common.css new file mode 100644 index 0000000..57afcc4 --- /dev/null +++ b/doc/css/common.css @@ -0,0 +1,69 @@ +body +{ + font-size: 14px; + line-height: 1.6; + margin: 0 auto; + max-width: 960px; +} + +p code +{ + background: #f2f2f2; + padding-left: 3px; + padding-right: 3px; +} + +pre.code +{ + font-size: 13px; + line-height: 1.4; + overflow: auto; +} + +/** + * YARD uses generic table styles, using a special class means those tables + * don't get messed up. + */ +.table +{ + border: 1px solid #ccc; + border-right: none; + border-collapse: separate; + border-spacing: 0; + text-align: left; +} + +.table.full +{ + width: 100%; +} + + .table .field_name + { + min-width: 160px; + } + + .table thead tr th.no_sort:first-child + { + width: 25px; + } + + .table thead tr th, .table tbody tr td + { + border-bottom: 1px solid #ccc; + border-right: 1px solid #ccc; + min-width: 20px; + padding: 8px 5px; + text-align: left; + vertical-align: top; + } + + .table tbody tr:last-child td + { + border-bottom: none; + } + + .table tr:nth-child(odd) td + { + background: #f9f9f9; + } diff --git a/lib/oga.rb b/lib/oga.rb new file mode 100644 index 0000000..132b7a1 --- /dev/null +++ b/lib/oga.rb @@ -0,0 +1 @@ +require 'ast' diff --git a/lib/oga/version.rb b/lib/oga/version.rb new file mode 100644 index 0000000..f29a20f --- /dev/null +++ b/lib/oga/version.rb @@ -0,0 +1,3 @@ +module Oga + VERSION = '0.0.1' +end # Oga diff --git a/oga.gemspec b/oga.gemspec new file mode 100644 index 0000000..2e940d2 --- /dev/null +++ b/oga.gemspec @@ -0,0 +1,27 @@ +require File.expand_path('../lib/oga/version', __FILE__) + +Gem::Specification.new do |s| + s.name = 'oga' + s.version = Oga::VERSION + s.authors = ['Yorick Peterse'] + s.email = 'yorickpeterse@gmail.com' + s.summary = 'A pure Ruby HTML/XML parser.' + s.homepage = 'https://github.com/yorickpeterse/oga/' + s.description = s.summary + s.license = 'MIT' + + s.files = File.read(File.expand_path('../MANIFEST', __FILE__)).split("\n") + + s.has_rdoc = 'yard' + s.required_ruby_version = '>= 1.9.3' + + s.add_dependency 'racc' + s.add_dependency 'ast' + + s.add_development_dependency 'cliver' + s.add_development_dependency 'rake' + s.add_development_dependency 'rspec' + s.add_development_dependency 'yard' + s.add_development_dependency 'simplecov' + s.add_development_dependency 'kramdown' +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..ef1c8d4 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,13 @@ +require 'rspec' + +if ENV['COVERAGE'] + require_relative 'support/simplecov' +end + +require_relative '../lib/oga' +require_relative 'support/parsing' + +RSpec.configure do |config| + config.color = true + config.include Oga::ParsingHelpers +end diff --git a/spec/support/parsing.rb b/spec/support/parsing.rb new file mode 100644 index 0000000..81db60a --- /dev/null +++ b/spec/support/parsing.rb @@ -0,0 +1,14 @@ +module Oga + module ParsingHelpers + ## + # Builds an AST node. + # + # @param [Symbol] type + # @param [Array] cihldren + # @return [Oga::AST::Node] + # + def s(type, *children) + return Oga::AST::Node.new(type, children) + end + end # ParsingHelpers +end # Oga diff --git a/spec/support/simplecov.rb b/spec/support/simplecov.rb new file mode 100644 index 0000000..26038c0 --- /dev/null +++ b/spec/support/simplecov.rb @@ -0,0 +1,12 @@ +require 'simplecov' + +SimpleCov.configure do + root File.expand_path('../../../', __FILE__) + command_name 'rspec' + project_name 'oga' + + add_filter 'spec' + add_filter 'lib/oga/version' +end + +SimpleCov.start diff --git a/task/build.rake b/task/build.rake new file mode 100644 index 0000000..a2f79b5 --- /dev/null +++ b/task/build.rake @@ -0,0 +1,4 @@ +desc 'Builds a new Gem and its checksum' +task :signed_build => [:build] do + Rake::Task['checksum'].invoke +end diff --git a/task/checksum.rake b/task/checksum.rake new file mode 100644 index 0000000..19235a5 --- /dev/null +++ b/task/checksum.rake @@ -0,0 +1,13 @@ +desc 'Creates a SHA512 checksum of the current version' +task :checksum do + checksums = File.expand_path('../../checksum', __FILE__) + name = "#{GEMSPEC.name}-#{GEMSPEC.version}.gem" + path = File.join(File.expand_path('../../pkg', __FILE__), name) + + checksum_name = File.basename(path) + '.sha512' + checksum = Digest::SHA512.new.hexdigest(File.read(path)) + + File.open(File.join(checksums, checksum_name), 'w') do |handle| + handle.write(checksum) + end +end diff --git a/task/generate.rake b/task/generate.rake new file mode 100644 index 0000000..ab6ede3 --- /dev/null +++ b/task/generate.rake @@ -0,0 +1,5 @@ +desc 'Generates auto-generated files' +task :generate => [:lexer, :parser] + +desc 'Regenerates auto-generated files' +task :regenerate => [:clean, :generate] diff --git a/task/lexer.rake b/task/lexer.rake new file mode 100644 index 0000000..1832fa6 --- /dev/null +++ b/task/lexer.rake @@ -0,0 +1,8 @@ +rule '.rb' => '.rl' do |task| + Cliver.assert('ragel', '~> 6.8') + + sh "ragel -F1 -R #{task.source} -o #{task.name}" +end + +desc 'Generates the lexer' +task :lexer => [LEXER_OUTPUT] diff --git a/task/manifest.rake b/task/manifest.rake new file mode 100644 index 0000000..146dc02 --- /dev/null +++ b/task/manifest.rake @@ -0,0 +1,9 @@ +desc 'Generates the MANIFEST file' +task :manifest do + generated = GENERATED_FILES.map { |path| File.expand_path(path) } + files = (`git ls-files`.split("\n") | generated).sort + handle = File.open(File.expand_path('../../MANIFEST', __FILE__), 'w') + + handle.write(files.join("\n")) + handle.close +end diff --git a/task/parser.rake b/task/parser.rake new file mode 100644 index 0000000..8b5a1a4 --- /dev/null +++ b/task/parser.rake @@ -0,0 +1,8 @@ +rule '.rb' => '.y' do |task| + Cliver.assert('racc', '~> 1.4') + + sh "racc -l -o #{task.name} #{task.source}" +end + +desc 'Generates the parser' +task :parser => [PARSER_OUTPUT] diff --git a/task/tag.rake b/task/tag.rake new file mode 100644 index 0000000..ba738ac --- /dev/null +++ b/task/tag.rake @@ -0,0 +1,6 @@ +desc 'Creates a Git tag for the current version' +task :tag do + version = Oga::VERSION + + sh %Q{git tag -a -m "Version #{version}" #{version}} +end diff --git a/task/test.rake b/task/test.rake new file mode 100644 index 0000000..f56a887 --- /dev/null +++ b/task/test.rake @@ -0,0 +1,4 @@ +desc 'Runs the tests' +task :test => [:regenerate] do + sh 'rspec spec' +end