diff --git a/.rubocop.yml b/.rubocop.yml index 3e72169..1837b30 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -7,7 +7,7 @@ AllCops: NewCops: enable Metrics/BlockLength: - IgnoredMethods: ['describe'] + AllowedMethods: ['describe'] Style/Documentation: Enabled: false diff --git a/CHANGELOG.md b/CHANGELOG.md index 46d4e64..0c12689 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +Unreleased +* Add a command line tool `gmi2html` + v0.2.0 * Group consecutive links under single paragraph tag * Remove spec and hidden files from built gem diff --git a/README.md b/README.md index 7a8bcf4..aef12b6 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,9 @@ html_string = File.open('capsule/my_gemtext.gmi', 'r') do |f| end ``` +There is also a command line tool called `gmi2html`. +Please refer to the help message (`gmi2html --help`) for its usage. + ## Status Second release but should be feature complete diff --git a/exe/gmi2html b/exe/gmi2html new file mode 100755 index 0000000..4a4a3a8 --- /dev/null +++ b/exe/gmi2html @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require 'gmi2html' +require 'optparse' + +input = $stdin unless $stdin.tty? +output = $stdout + +parser = OptionParser.new +parser.on('-o', '--output=PATH', 'Output HTML path. Standard output is used by default.') do |path| + output = File.open(path, 'w') +end +parser.on('-i', '--input=PATH', 'Input Gemtext path. Standard input is used by default.') do |path| + input = File.open(path) +end +parser.parse! + +unless input + warn 'No input provided. Please specify input path or use stdin.' + puts parser + exit 1 +end + +html = Gmi2html::Document.new(input).to_html +input.close + +output.write(html) +output.close diff --git a/gmi2html.gemspec b/gmi2html.gemspec index a3d83c6..041ee1b 100644 --- a/gmi2html.gemspec +++ b/gmi2html.gemspec @@ -17,10 +17,10 @@ Gem::Specification.new do |gem| gem.license = 'MIT' gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR).reject do |f| - f.match(%r{^(\.|spec)}) - end - gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) } - gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) + f.match(%r{^(\.|spec)}) + end + gem.bindir = 'exe' + gem.executables = gem.files.grep(%r{^exe/}).map { |f| File.basename(f) } gem.require_paths = %w[lib] gem.required_ruby_version = '>= 2.5.0' @@ -28,7 +28,7 @@ Gem::Specification.new do |gem| 'homepage_uri' => 'https://github.com/jebw/gmi2html/', 'changelog_uri' => 'https://github.com/jebw/gmi2html/blob/main/CHANGELOG.md', 'source_code_uri' => 'https://github.com/jebw/gmi2html/', - 'documentation_uri' => "https://github.com/jebw/gmi2html/blob/main/README.md", + 'documentation_uri' => 'https://github.com/jebw/gmi2html/blob/main/README.md', 'bug_tracker_uri' => 'https://github.com/jebw/gmi2html/issues', 'rubygems_mfa_required' => 'true' } diff --git a/spec/gmi2html/node_renderers/base_spec.rb b/spec/gmi2html/node_renderers/base_spec.rb index a684ee8..eb9773b 100644 --- a/spec/gmi2html/node_renderers/base_spec.rb +++ b/spec/gmi2html/node_renderers/base_spec.rb @@ -19,7 +19,7 @@ def tag let(:instance) { described_class.for_gemtext node } it 'will return a Gmi2html::NodeRenderers::Text' do - expect(instance).to be_kind_of Gmi2html::NodeRenderers::Text + expect(instance).to be_a Gmi2html::NodeRenderers::Text end it 'will assign the content' do diff --git a/spec/gmi2html/node_renderers/link_spec.rb b/spec/gmi2html/node_renderers/link_spec.rb index 29c4dce..f448a6a 100644 --- a/spec/gmi2html/node_renderers/link_spec.rb +++ b/spec/gmi2html/node_renderers/link_spec.rb @@ -12,6 +12,9 @@ let(:link) { Gemtext::Link.new '/my-capsule my capsule' } context 'when only link' do + let(:prev_node) { nil } + let(:next_node) { nil } + it 'will render opening and closing p tags in addition to the a tag' do expect(rendered).to eql \ %(

\nmy capsule\n

\n) diff --git a/spec/gmi2html_spec.rb b/spec/gmi2html_spec.rb index e4ae6a4..72a89fa 100644 --- a/spec/gmi2html_spec.rb +++ b/spec/gmi2html_spec.rb @@ -6,6 +6,6 @@ describe 'VERSION' do subject { described_class::VERSION } - it { is_expected.to eql '0.1.0' } + it { is_expected.to eql '0.2.0' } end end