From f36f3ed0fb9220d010439cc583e66903a64493e2 Mon Sep 17 00:00:00 2001 From: gemmaro Date: Tue, 30 Jan 2024 21:24:23 +0900 Subject: [PATCH 1/4] Set binary directory and change directory name for executables --- gmi2html.gemspec | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gmi2html.gemspec b/gmi2html.gemspec index a3d83c6..131bc21 100644 --- a/gmi2html.gemspec +++ b/gmi2html.gemspec @@ -19,7 +19,8 @@ Gem::Specification.new do |gem| 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.bindir = "exe" + gem.executables = gem.files.grep(%r{^exe/}).map { |f| File.basename(f) } gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.require_paths = %w[lib] gem.required_ruby_version = '>= 2.5.0' From 945a1a0375172ff9424a780041fc1629e9a5b511 Mon Sep 17 00:00:00 2001 From: gemmaro Date: Tue, 30 Jan 2024 21:25:02 +0900 Subject: [PATCH 2/4] Add gmi2html command line tool --- CHANGELOG.md | 3 +++ README.md | 3 +++ exe/gmi2html | 29 +++++++++++++++++++++++++++++ gmi2html.gemspec | 6 +++--- 4 files changed, 38 insertions(+), 3 deletions(-) create mode 100755 exe/gmi2html 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 131bc21..c2c9b7e 100644 --- a/gmi2html.gemspec +++ b/gmi2html.gemspec @@ -17,9 +17,9 @@ 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.bindir = "exe" + f.match(%r{^(\.|spec)}) + end + gem.bindir = 'exe' gem.executables = gem.files.grep(%r{^exe/}).map { |f| File.basename(f) } gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.require_paths = %w[lib] From 38d9b1f35c9ec9870f1b45f078168ccd357fe8cf Mon Sep 17 00:00:00 2001 From: gemmaro Date: Tue, 30 Jan 2024 21:41:51 +0900 Subject: [PATCH 3/4] Correct existing specs: Define prev/next nodes in link renderer spec --- spec/gmi2html/node_renderers/link_spec.rb | 3 +++ 1 file changed, 3 insertions(+) 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) From af9d70a5b4b10fd19051664b91c456251b8fc6cd Mon Sep 17 00:00:00 2001 From: gemmaro Date: Tue, 30 Jan 2024 21:43:13 +0900 Subject: [PATCH 4/4] Lint codes with RuboCop with updating its config --- .rubocop.yml | 2 +- gmi2html.gemspec | 3 +-- spec/gmi2html/node_renderers/base_spec.rb | 2 +- spec/gmi2html_spec.rb | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) 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/gmi2html.gemspec b/gmi2html.gemspec index c2c9b7e..041ee1b 100644 --- a/gmi2html.gemspec +++ b/gmi2html.gemspec @@ -21,7 +21,6 @@ Gem::Specification.new do |gem| end gem.bindir = 'exe' gem.executables = gem.files.grep(%r{^exe/}).map { |f| File.basename(f) } - gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.require_paths = %w[lib] gem.required_ruby_version = '>= 2.5.0' @@ -29,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_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