From 34d393f83e26b95ecbd78d058f0cf53c17fa4fff Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Fri, 18 Oct 2024 16:32:34 +0400 Subject: [PATCH] Initialize gem --- .gitignore | 41 +++++++++++++ .rubocop.yml | 46 ++++++++++++++ .rubocop_todo.yml | 129 +++++++++++++++++++++++++++++++++++++++ .yardopts | 4 ++ Gemfile | 14 ++++- Rakefile | 70 +++++++++++++++++++++ bin/console | 9 +++ bin/setup | 5 ++ lib/repubmark.rb | 4 ++ lib/repubmark/version.rb | 6 ++ repubmark.gemspec | 52 ++++++++++++++++ 11 files changed, 378 insertions(+), 2 deletions(-) create mode 100644 .rubocop.yml create mode 100644 .rubocop_todo.yml create mode 100644 .yardopts create mode 100644 Rakefile create mode 100755 bin/console create mode 100755 bin/setup create mode 100644 lib/repubmark/version.rb create mode 100644 repubmark.gemspec diff --git a/.gitignore b/.gitignore index 1adbebc..4834e46 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,44 @@ +*.gem +*.rbc +*.so + +/.byebug_history +/.config/ +/.rake_tasks~ +/InstalledFiles/ +/pkg/ +/tmp/ + +# Used by dotenv library to load environment variables. +/.env + +# RSpec configuration and generated files. +/.rspec +/coverage/ +/spec/examples.txt +/spec/reports/ +/test/tmp/ +/test/version_tmp/ + +# Documentation cache and generated files. +/.yardoc/ +/_yardoc/ +/doc/ +/rdoc/ + +# Environment normalization. +/.bundle/ +/vendor/bundle/ +/lib/bundler/man/ + +# For a library or gem, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in. /Gemfile.lock /.ruby-version /.ruby-gemset + +# Unless supporting rvm < 1.11.0 or doing something fancy, ignore this. +/.rvmrc + +# Used by RuboCop. Remote config files pulled in from inherit_from directive. +/.rubocop-https?--* diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..f34db8d --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,46 @@ +inherit_from: .rubocop_todo.yml + +require: + - rubocop-performance + - rubocop-rake + +AllCops: + TargetRubyVersion: 3.2 + DisplayCopNames: true + NewCops: enable + +Layout/AccessModifierIndentation: + EnforcedStyle: outdent + +Layout/LineLength: + Max: 80 + +Lint/AmbiguousOperatorPrecedence: + Enabled: false + +Lint/ReturnInVoidContext: + Enabled: false + +Style/AndOr: + EnforcedStyle: conditionals + +Style/DoubleNegation: + Enabled: false + +Style/HashAsLastArrayItem: + Enabled: false + +Style/PerlBackrefs: + Enabled: false + +Style/TrailingCommaInArguments: + EnforcedStyleForMultiline: comma + +Style/TrailingCommaInArrayLiteral: + EnforcedStyleForMultiline: comma + +Style/TrailingCommaInHashLiteral: + EnforcedStyleForMultiline: comma + +Style/VariableInterpolation: + Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..47477d5 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,129 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2024-10-18 14:41:13 UTC using RuboCop version 1.67.0. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: with_first_argument, with_fixed_indentation +Layout/ArgumentAlignment: + Exclude: + - 'Rakefile' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns. +# URISchemes: http, https +Layout/LineLength: + Exclude: + - 'lib/repubmark/elems/footnote.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowedMethods. +# AllowedMethods: present?, blank?, presence, try, try!, in? +Lint/SafeNavigationChain: + Exclude: + - 'lib/repubmark/elems/article.rb' + +# Offense count: 1 +# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. +Metrics/AbcSize: + Max: 35 + +# Offense count: 1 +# Configuration parameters: CountComments, CountAsOne. +Metrics/ClassLength: + Max: 104 + +# Offense count: 1 +# Configuration parameters: AllowedMethods, AllowedPatterns. +Metrics/CyclomaticComplexity: + Max: 10 + +# Offense count: 5 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. +Metrics/MethodLength: + Max: 33 + +# Offense count: 1 +# Configuration parameters: AllowedMethods, AllowedPatterns. +Metrics/PerceivedComplexity: + Max: 11 + +# Offense count: 2 +Performance/MapMethodChain: + Exclude: + - 'lib/repubmark/elems/footnotes_category.rb' + +# Offense count: 14 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowOnlyRestArgument, UseAnonymousForwarding, RedundantRestArgumentNames, RedundantKeywordRestArgumentNames, RedundantBlockArgumentNames. +# RedundantRestArgumentNames: args, arguments +# RedundantKeywordRestArgumentNames: kwargs, options, opts +# RedundantBlockArgumentNames: blk, block, proc +Style/ArgumentsForwarding: + Exclude: + - 'lib/repubmark/elems/canvas.rb' + - 'lib/repubmark/elems/footnotes_category.rb' + - 'lib/repubmark/elems/joint.rb' + - 'lib/repubmark/elems/link.rb' + +# Offense count: 34 +# Configuration parameters: AllowedConstants. +Style/Documentation: + Enabled: false + +# Offense count: 7 +# Configuration parameters: AllowedVariables. +Style/GlobalVars: + Exclude: + - 'exe/repubmark' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowIfModifier. +Style/IfInsideElse: + Exclude: + - 'lib/repubmark/elems/footnote.rb' + +# Offense count: 4 +# This cop supports safe autocorrection (--autocorrect). +Style/RedundantFreeze: + Exclude: + - 'lib/repubmark/elems/fraction.rb' + - 'lib/repubmark/elems/power.rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +Style/RedundantStringEscape: + Exclude: + - 'lib/repubmark/elems/footnote.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowModifier. +Style/SoleNestedConditional: + Exclude: + - 'lib/repubmark/elems/footnote.rb' + +# Offense count: 7 +# This cop supports safe autocorrection (--autocorrect). +Style/SuperArguments: + Exclude: + - 'lib/repubmark/elems/annotation.rb' + - 'lib/repubmark/elems/blockquote.rb' + - 'lib/repubmark/elems/canvas.rb' + - 'lib/repubmark/elems/caption.rb' + - 'lib/repubmark/elems/figures.rb' + - 'lib/repubmark/elems/joint.rb' + - 'lib/repubmark/elems/paragraph.rb' + +# Offense count: 24 +# This cop supports safe autocorrection (--autocorrect). +Style/SuperWithArgsParentheses: + Enabled: false diff --git a/.yardopts b/.yardopts new file mode 100644 index 0000000..505c853 --- /dev/null +++ b/.yardopts @@ -0,0 +1,4 @@ +--markup markdown +--readme README.md +--protected +--private diff --git a/Gemfile b/Gemfile index 46eb342..d3b131c 100644 --- a/Gemfile +++ b/Gemfile @@ -2,5 +2,15 @@ source 'https://rubygems.org' -gem 'addressable', '~> 2.8' -gem 'i18n', '~> 1.14' +# Specify your gem's dependencies in repubmark.gemspec +gemspec + +group :development do + gem 'bundler', '~> 2.4' + gem 'pry', '~> 0.14' + gem 'rake', '~> 13.2' + gem 'rubocop', '~> 1.67' + gem 'rubocop-performance', '~> 1.22' + gem 'rubocop-rake', '~> 0.6.0' + gem 'yard', '~> 0.9.37' +end diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..43c2505 --- /dev/null +++ b/Rakefile @@ -0,0 +1,70 @@ +# frozen_string_literal: true + +require 'bundler/gem_tasks' + +module Bundler + class GemHelper + def tag_version(*) + yield if block_given? + end + + def git_push(*); end + + def perform_git_push(*); end + end +end + +CLEAN << '.yardoc' +CLEAN << 'coverage' +CLEAN << 'doc' + +desc 'Run default checks' +task default: %i[test lint] + +desc 'Run tests' +task test: :tests + +desc 'Run code analysis tools' +task lint: %i[rubocop yard:cov] + +desc 'Fix code style (rubocop --auto-correct)' +task fix: 'rubocop:auto_correct' + +begin + require 'rubocop/rake_task' + RuboCop::RakeTask.new +rescue LoadError + nil +end + +begin + require 'yard' + YARD::Rake::YardocTask.new +rescue LoadError + nil +end + +desc 'Open development console' +task :console do + sh 'bundle', 'exec', + File.expand_path(File.join('bin', 'console'), __dir__) +end + +desc 'Run tests' +task :tests do + sh 'bundle', 'exec', + File.expand_path(File.join('tests', 'examples.rb'), __dir__) +end + +namespace :yard do + desc 'Measure documentation coverage' + task :cov do + result = `bundle exec yard stats`.lines.last.strip.freeze + m = result.match(/\A(\d+(\.\d+)?)% documented\z/) + raise 'Invalid result' if m.nil? + + coverage = m[1].to_f.round(2) + puts "Documentation coverage: #{coverage}%" + raise 'Not fully documented!' if coverage < 38.32 + end +end diff --git a/bin/console b/bin/console new file mode 100755 index 0000000..78f97aa --- /dev/null +++ b/bin/console @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require 'bundler/setup' + +require 'pry' +require 'repubmark' + +Pry.start diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..b804c0a --- /dev/null +++ b/bin/setup @@ -0,0 +1,5 @@ +#!/bin/sh + +set -euvx + +bundle install diff --git a/lib/repubmark.rb b/lib/repubmark.rb index 0a5f568..b8aebb7 100644 --- a/lib/repubmark.rb +++ b/lib/repubmark.rb @@ -63,6 +63,10 @@ require_relative 'repubmark/elems/power' # Always inside FootnotesCategory require_relative 'repubmark/elems/footnote' +## +# A Markdown-inspired markup language that can be compiled into HTML and +# Gemtext. +# module Repubmark FORMATS = %i[chapters gemtext html summary_plain word_count].freeze diff --git a/lib/repubmark/version.rb b/lib/repubmark/version.rb new file mode 100644 index 0000000..f3dfeab --- /dev/null +++ b/lib/repubmark/version.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +module Repubmark + # Gem version. + VERSION = '0.0.0' +end diff --git a/repubmark.gemspec b/repubmark.gemspec new file mode 100644 index 0000000..30e705f --- /dev/null +++ b/repubmark.gemspec @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +require_relative 'lib/repubmark/version' + +Gem::Specification.new do |spec| + repo = 'https://git.causa-arcana.com/causa-arcana/repubmark' + mail = 'me+repubmark@kotovalexarian.com' + home = repo + # bugs = "mailto:#{mail}" + docs = "https://www.rubydoc.info/gems/repubmark/#{Repubmark::VERSION}" + + spec.name = 'repubmark' + spec.version = Repubmark::VERSION + spec.license = 'MIT' + spec.homepage = home + + spec.required_ruby_version = '~> 3.2' + + spec.authors = ['Alex Kotov'] + spec.email = [mail] + + spec.summary = + 'A Markdown-inspired markup language ' \ + 'that can be compiled into HTML and Gemtext' + + spec.description = <<~DESCRIPTION.split("\n").map(&:strip).join ' ' + A Markdown-inspired markup language that can be compiled into HTML and + Gemtext + DESCRIPTION + + spec.metadata['rubygems_mfa_required'] = 'true' + spec.metadata['homepage_uri'] = home + spec.metadata['source_code_uri'] = home + # spec.metadata['bug_tracker_uri'] = FIXME: bugs + spec.metadata['documentation_uri'] = docs + # spec.metadata['changelog_uri'] = 'TODO: changelog' + + spec.bindir = 'exe' + spec.require_paths = ['lib'] + + spec.files = Dir.chdir __dir__ do + `git ls-files -z`.split("\x0").reject do |f| + (File.expand_path(f) == __FILE__) || + f.start_with?(*%w[.git bin/ test/ spec/ features/ Gemfile]) + end + end + + spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename f } + + spec.add_dependency 'addressable', '~> 2.8' + spec.add_dependency 'i18n', '~> 1.14' +end