bhook 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 17b89ce589acd0d94792144dd145e2470612ebdd7ea566cba91e4174e9bc414c
4
- data.tar.gz: d819bec1768b629f94ef192f9053e35df93a9c966246d50c85dc3684bc4fa543
3
+ metadata.gz: b8daa36a6bba5cff236d6bf93f33ff088d7baa4abb975fe372674c94746e3600
4
+ data.tar.gz: 499905877d932384d7cb982290ed6bfced51398b63a85ef3101a625783f2113b
5
5
  SHA512:
6
- metadata.gz: b4c46ca4fd8820d9898bf5cefe79c8fd82bff9f2aebfa9aba41f75c1920d898441624be2740c528b357f1548e537f1651dc737df26a7f9c888278aa2aff91e79
7
- data.tar.gz: 9b8fbcfec88fc338ab13ec03cafe6cbe73752ed3b3cae23cb4f98117f0f8913756743e3d930f62d91d5b3c0ff71e3cbe864f99fab0db110539ecbcba9f767213
6
+ metadata.gz: e7538dd31e1790aab7fabca99e652ff97752c52bd0afeb7ade8d42d517eee6bd2f6687e642c06b95afe4e51cc48724b84646f6f9ee5803d3a73ae9b23f64023e
7
+ data.tar.gz: 1d5aa665979f1be6f1ba0a96d7068622c782e604a1407a0757e6d254f538dde59507972e15412fcb7141d38f430ff0897c9e95ca8b3a6227b727f575d32bfb36
data/.rubocop.yml CHANGED
@@ -4,3 +4,32 @@ require:
4
4
 
5
5
  AllCops:
6
6
  NewCops: enable
7
+
8
+ Style/AccessorGrouping:
9
+ Enabled: false
10
+
11
+ Style/Documentation:
12
+ Enabled: false
13
+
14
+ Naming/MethodParameterName:
15
+ Enabled: false
16
+
17
+ RSpec/MessageSpies:
18
+ Enabled: false
19
+
20
+ RSpec/MultipleExpectations:
21
+ Exclude:
22
+ - spec/bhook/theme_generator_spec.rb
23
+
24
+ Metrics/MethodLength:
25
+ Exclude:
26
+ - lib/bhook/args_parser.rb
27
+
28
+ Metrics/BlockLength:
29
+ Exclude:
30
+ - lib/bhook/args_parser.rb
31
+
32
+ Metrics/AbcSize:
33
+ Exclude:
34
+ - lib/bhook/args_parser.rb
35
+
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bhook (0.1.6)
4
+ bhook (0.2.0)
5
5
  git (~> 1.10)
6
6
  kramdown (~> 2.3)
7
7
  listen (~> 3.7)
@@ -14,15 +14,15 @@ GEM
14
14
  diff-lcs (1.5.0)
15
15
  docile (1.4.0)
16
16
  ffi (1.15.5)
17
- git (1.10.2)
17
+ git (1.11.0)
18
18
  rchardet (~> 1.8)
19
- kramdown (2.3.2)
19
+ kramdown (2.4.0)
20
20
  rexml
21
21
  listen (3.7.1)
22
22
  rb-fsevent (~> 0.10, >= 0.10.3)
23
23
  rb-inotify (~> 0.9, >= 0.9.10)
24
- parallel (1.21.0)
25
- parser (3.1.1.0)
24
+ parallel (1.22.1)
25
+ parser (3.1.2.0)
26
26
  ast (~> 2.4.1)
27
27
  rainbow (3.1.1)
28
28
  rake (13.0.6)
@@ -30,7 +30,7 @@ GEM
30
30
  rb-inotify (0.10.1)
31
31
  ffi (~> 1.0)
32
32
  rchardet (1.8.0)
33
- regexp_parser (2.2.1)
33
+ regexp_parser (2.5.0)
34
34
  rexml (3.2.5)
35
35
  rspec (3.11.0)
36
36
  rspec-core (~> 3.11.0)
@@ -41,36 +41,39 @@ GEM
41
41
  rspec-expectations (3.11.0)
42
42
  diff-lcs (>= 1.2.0, < 2.0)
43
43
  rspec-support (~> 3.11.0)
44
- rspec-mocks (3.11.0)
44
+ rspec-mocks (3.11.1)
45
45
  diff-lcs (>= 1.2.0, < 2.0)
46
46
  rspec-support (~> 3.11.0)
47
47
  rspec-support (3.11.0)
48
- rubocop (1.26.0)
48
+ rubocop (1.30.0)
49
49
  parallel (~> 1.10)
50
50
  parser (>= 3.1.0.0)
51
51
  rainbow (>= 2.2.2, < 4.0)
52
52
  regexp_parser (>= 1.8, < 3.0)
53
- rexml
54
- rubocop-ast (>= 1.16.0, < 2.0)
53
+ rexml (>= 3.2.5, < 4.0)
54
+ rubocop-ast (>= 1.18.0, < 2.0)
55
55
  ruby-progressbar (~> 1.7)
56
56
  unicode-display_width (>= 1.4.0, < 3.0)
57
- rubocop-ast (1.16.0)
57
+ rubocop-ast (1.18.0)
58
58
  parser (>= 3.1.1.0)
59
59
  rubocop-rake (0.6.0)
60
60
  rubocop (~> 1.0)
61
- rubocop-rspec (2.9.0)
61
+ rubocop-rspec (2.11.1)
62
62
  rubocop (~> 1.19)
63
63
  ruby-progressbar (1.11.0)
64
64
  simplecov (0.21.2)
65
65
  docile (~> 1.1)
66
66
  simplecov-html (~> 0.11)
67
67
  simplecov_json_formatter (~> 0.1)
68
+ simplecov-cobertura (2.1.0)
69
+ rexml
70
+ simplecov (~> 0.19)
68
71
  simplecov-html (0.12.3)
69
72
  simplecov_json_formatter (0.1.4)
70
- sorbet (0.5.9775)
71
- sorbet-static (= 0.5.9775)
72
- sorbet-runtime (0.5.9775)
73
- sorbet-static (0.5.9775-universal-darwin-21)
73
+ sorbet (0.5.10042)
74
+ sorbet-static (= 0.5.10042)
75
+ sorbet-runtime (0.5.10042)
76
+ sorbet-static (0.5.10042-universal-darwin-21)
74
77
  unicode-display_width (2.1.0)
75
78
 
76
79
  PLATFORMS
@@ -84,6 +87,7 @@ DEPENDENCIES
84
87
  rubocop-rake (~> 0.6)
85
88
  rubocop-rspec (~> 2.8)
86
89
  simplecov (~> 0.21)
90
+ simplecov-cobertura (~> 2.1.0)
87
91
  sorbet (~> 0.5)
88
92
 
89
93
  BUNDLED WITH
data/README.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Bhook
2
2
 
3
+ [![Build Status](https://gitlab.com/kaiwren/bhook/badges/main/pipeline.svg)](https://gitlab.com/kaiwren/bhook/commits/main)
4
+ [![Coverage Report](https://gitlab.com/kaiwren/bhook/badges/main/coverage.svg)](https://gitlab.com/kaiwren/bhook/commits/main)
5
+ [![Gem Version](https://badge.fury.io/rb/bhook.svg)](https://rubygems.org/gems/bhook)
6
+ [![Downloads](http://ruby-gem-downloads-badge.herokuapp.com/bhook?type=total)](https://rubygems.org/gems/bhook)
7
+
8
+
9
+
3
10
  Bhook is a static website generator that works off a git repo containing a markdown file based wiki, like for example, the [India Startup Wiki](https://gitlab.com/india-startups/wiki).
4
11
 
5
12
  I use this to create [HTML versions of the wiki](https://sidu.in/wiki/startups) and of [my essays](https://sidu.in/essays/) that I can publish.
@@ -15,7 +22,7 @@ Install it yourself as:
15
22
  Getting help:
16
23
 
17
24
  $ bhook --help
18
- Bhook version 0.1.4
25
+ Bhook version 0.2.0
19
26
  Usage: bhook --source /source/path --output /output/path
20
27
  -s, --source=SOURCE Path to version controlled directory containing source md files
21
28
  -o, --output=OUTPUT Path to directory where output files are to be generated
@@ -30,6 +37,8 @@ How I use it:
30
37
 
31
38
  ➜ essays git:(main) ✗ bhook -s . -o /tmp/out -t /tmp/out/theme -w -v
32
39
 
40
+ Here's an example `.bhook.yml` [config file](https://gitlab.com/india-startups/wiki/-/blob/master/.bhook.yml).
41
+
33
42
  ## Development
34
43
 
35
44
  1. `git clone --recursive git@gitlab.com:kaiwren/bhook.git`
data/Rakefile CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  require 'bundler/gem_tasks'
4
4
  require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
5
6
 
7
+ RuboCop::RakeTask.new
6
8
  RSpec::Core::RakeTask.new(:spec)
7
9
 
8
10
  desc 'Run Sorbet Typechecker'
@@ -10,15 +12,23 @@ task :sorbet do
10
12
  sh('bundle exec srb tc')
11
13
  end
12
14
 
13
- cops = %w[
15
+ basic_style_cops = %w[
14
16
  Layout/TrailingWhitespace
15
17
  Layout/SpaceInsideBlockBraces
16
18
  Style/StringLiterals
17
19
  ]
18
20
 
19
- desc "Apply #{cops.join(', ')}"
20
- task :lint_with_autocorrect do
21
- sh("bundle exec rubocop -a --only #{cops.join(',')}")
21
+ desc "Apply #{basic_style_cops.join(', ')}"
22
+ task :autocorrect_basic_style_issues do
23
+ sh("bundle exec rubocop -a --only #{basic_style_cops.join(',')}")
22
24
  end
23
25
 
24
- task default: %i[lint_with_autocorrect sorbet spec]
26
+ namespace :ci do
27
+ desc 'Tasks to run in Gitlab CI build stage'
28
+ task build: %i[sorbet rubocop]
29
+
30
+ desc 'Tasks to run in Gitlab CI spec stage'
31
+ task spec: %i[spec]
32
+ end
33
+
34
+ task default: %i[autocorrect_basic_style_issues rubocop sorbet spec]
@@ -16,10 +16,8 @@ module Bhook
16
16
  def parse
17
17
  begin
18
18
  @opt_parser.parse(@argv)
19
- if generate_theme_missing? && help_missing?
20
- if source_or_output_paths_missing?
21
- raise OptionParser::MissingArgument.new('See --help.')
22
- end
19
+ if generate_theme_missing? && help_missing? && source_or_output_paths_missing?
20
+ raise OptionParser::MissingArgument, 'See --help.'
23
21
  end
24
22
  rescue OptionParser::ParseError => e
25
23
  puts "\nError! #{e.message}\n"
@@ -91,7 +89,7 @@ module Bhook
91
89
  @args.benchmark = true
92
90
  end
93
91
 
94
- opts.on('-h', '--help', FalseClass, 'Prints this help') do |help|
92
+ opts.on('-h', '--help', FalseClass, 'Prints this help') do |_help|
95
93
  @args.help = true
96
94
  end
97
95
  end
data/lib/bhook/config.rb CHANGED
@@ -2,29 +2,58 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Bhook
5
+ #
6
+ # Valid keys:
7
+ # - website
8
+ # - link to place in the footer
9
+ # - exclude
10
+ # - list of .md file paths relative to config files
5
11
  class Config
6
12
  extend T::Sig
7
- BHOOK_CONFIG_FILE = T.let('.bhook', String)
13
+ BHOOK_CONFIG_FILE = T.let('.bhook.yml', String)
8
14
  WEBSITE_KEY = T.let('website', String)
15
+ EXCLUDE_KEY = T.let('exclude', String)
9
16
 
10
17
  sig { params(root_dir_path: Pathname, additional_options: T::Hash[String, String]).void }
11
18
  def initialize(root_dir_path, additional_options = {})
12
19
  config_file_path = root_dir_path.join(BHOOK_CONFIG_FILE)
13
- config = if File.exist?(config_file_path)
14
- YAML.load(File.read(config_file_path))
15
- else
16
- {}.merge(additional_options)
17
- end
20
+ config = load_config(config_file_path).merge(additional_options)
18
21
  @root_dir_path = root_dir_path
19
22
  @website_url = T.let(config[WEBSITE_KEY], T.nilable(String))
23
+ @excluded_files = T.let(parse_excluded_files(config[EXCLUDE_KEY] || []), T::Array[Pathname])
20
24
  end
21
25
 
22
26
  sig { params(src_file_path: Pathname, src_file_sha: T.nilable(String)).returns(T.nilable(String)) }
23
27
  def website_url_for(src_file_path, src_file_sha)
24
- if @website_url && src_file_sha
25
- relative_file_path = src_file_path.relative_path_from(@root_dir_path)
26
- File.join(@website_url, src_file_sha, relative_file_path)
28
+ return unless @website_url && src_file_sha
29
+
30
+ relative_file_path = src_file_path.relative_path_from(@root_dir_path)
31
+ File.join(@website_url, src_file_sha, relative_file_path)
32
+ end
33
+
34
+ sig { params(pathname: Pathname).returns(T::Boolean) }
35
+ def excluded?(pathname)
36
+ @excluded_files.include?(pathname)
37
+ end
38
+
39
+ private
40
+
41
+ sig { params(excluded_files: T::Array[String]).returns(T::Array[Pathname]) }
42
+ def parse_excluded_files(excluded_files)
43
+ excluded_files.map { |file_path| @root_dir_path.join(file_path) }
44
+ end
45
+
46
+ sig do
47
+ params(config_file_path: Pathname).returns(T::Hash[String, T.untyped])
48
+ end
49
+ def load_config(config_file_path)
50
+ if File.exist?(config_file_path)
51
+ L.debug("Config found: #{config_file_path}")
52
+ YAML.safe_load(File.read(config_file_path))
53
+ else
54
+ L.debug("Config not found: #{config_file_path}")
55
+ {}
27
56
  end
28
57
  end
29
58
  end
30
- end
59
+ end
@@ -25,14 +25,12 @@ module Bhook
25
25
  sig { params(el: Kramdown::Element, indent: Integer).returns(String) }
26
26
  def convert_header(el, indent)
27
27
  header = super(el, indent)
28
- after_h1_strategy = @options[:after_h1_strategy]
29
- h1_callback = @options[:h1_callback]
30
28
  src_title = el.options[:raw_text]
31
- after_h1_html = after_h1_strategy.call(binding)
29
+ after_h1_html = @options[:after_h1_strategy].call(binding)
32
30
 
33
31
  level = output_header_level(el.options[:level])
34
32
  if level == 1
35
- h1_callback.call(src_title)
33
+ @options[:h1_callback].call(src_title)
36
34
  "#{header}#{' ' * indent}#{after_h1_html}"
37
35
  else
38
36
  header
@@ -10,10 +10,9 @@ module Bhook
10
10
 
11
11
  sig { params(src_path: Pathname, out_path: Pathname).returns(Bhook::Directory) }
12
12
  def self.new_root_directory(src_path, out_path)
13
- self.new(src_path, out_path, Git.open(src_path), Bhook::Config.new(src_path))
13
+ new(src_path, out_path, Git.open(src_path), Bhook::Config.new(src_path))
14
14
  end
15
15
 
16
-
17
16
  sig { params(src_path: Pathname, out_path: Pathname, git: Git::Base, config: Bhook::Config).void }
18
17
  def initialize(src_path, out_path, git, config)
19
18
  @src_path = src_path
@@ -32,9 +31,7 @@ module Bhook
32
31
  @sub_dirs.each { |dir| dir.write!(theme) }
33
32
  @md_files.map do |file|
34
33
  Thread.new { file.write!(theme) }
35
- end.each do |thread|
36
- thread.join
37
- end
34
+ end.each(&:join)
38
35
  end
39
36
 
40
37
  sig { returns(T::Array[MdFile]) }
@@ -53,12 +50,16 @@ module Bhook
53
50
  def build_next_level_nodes
54
51
  children = @src_path.children
55
52
  children.delete(@src_path.join(GIT_DIR))
53
+ build_nodes(children)
54
+ end
56
55
 
56
+ sig { params(children: T::Array[Pathname]).void }
57
+ def build_nodes(children)
57
58
  file_threads = []
58
59
  children.each do |child_path|
59
60
  if child_path.directory?
60
61
  @sub_dirs << Directory.new(child_path, @out_path, @git, @config)
61
- elsif child_path.extname == MD_EXT
62
+ elsif child_path.extname == MD_EXT && !@config.excluded?(child_path)
62
63
  file_threads << Thread.new { MdFile.new(child_path, @out_path, @git, @config) }
63
64
  end
64
65
  end
data/lib/bhook/logger.rb CHANGED
@@ -2,8 +2,8 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Bhook
5
- LOG_FORMATTER = proc { |severity, datetime, progname, msg|
5
+ LOG_FORMATTER = proc { |_severity, _datetime, _progname, msg|
6
6
  "#{Thread.current.object_id} #{msg}\n"
7
7
  }
8
- L = Logger.new(STDOUT, formatter: LOG_FORMATTER)
8
+ L = Logger.new($stdout, formatter: LOG_FORMATTER)
9
9
  end
data/lib/bhook/md_file.rb CHANGED
@@ -25,12 +25,8 @@ module Bhook
25
25
  @out_path = out_path
26
26
  @git = git
27
27
  @config = config
28
-
29
- file_date, file_sha = load_git_file_metadata
30
- @src_file_date = T.let(file_date, T.nilable(String))
31
- @src_file_sha = T.let(file_sha, T.nilable(String))
32
28
  @out_file_path = T.let(@out_path.join(out_file_name), Pathname)
33
- @src_file_url = T.let(file_url, T.nilable(String))
29
+ initialize_file_details
34
30
  end
35
31
 
36
32
  sig { params(theme: Bhook::Theme).void }
@@ -43,6 +39,7 @@ module Bhook
43
39
  end
44
40
 
45
41
  private
42
+
46
43
  sig { returns(Pathname) }
47
44
  def out_file_name
48
45
  @src_file_path.basename.sub(/\.md$/, '.html')
@@ -62,5 +59,13 @@ module Bhook
62
59
  '--',
63
60
  @src_file_path).split('|')
64
61
  end
62
+
63
+ sig { void }
64
+ def initialize_file_details
65
+ file_date, file_sha = load_git_file_metadata
66
+ @src_file_date = T.let(file_date, T.nilable(String))
67
+ @src_file_sha = T.let(file_sha, T.nilable(String))
68
+ @src_file_url = T.let(file_url, T.nilable(String))
69
+ end
65
70
  end
66
71
  end
data/lib/bhook/theme.rb CHANGED
@@ -13,8 +13,10 @@ module Bhook
13
13
  @after_h1_strategy = T.let(strategy, T.proc.params(binding_instance: Binding).returns(String))
14
14
  end
15
15
 
16
- sig { params(md: String, src_file_sha: T.nilable(String),
17
- src_file_date: T.nilable(String), file_url: T.nilable(String)).returns(String) }
16
+ sig do
17
+ params(md: String, src_file_sha: T.nilable(String),
18
+ src_file_date: T.nilable(String), file_url: T.nilable(String)).returns(String)
19
+ end
18
20
  def render_page(md, src_file_sha, src_file_date, file_url)
19
21
  src_title = T.let('', String)
20
22
 
@@ -9,7 +9,7 @@ module Bhook
9
9
  def initialize(output_path)
10
10
  @output_path = T.let(File.join(output_path, 'theme'), String)
11
11
  @template_files = T.let([Bhook::PAGE_TEMPLATE_PATH,
12
- Bhook::AFTER_H1_TEMPLATE_PATH], T::Array[String])
12
+ Bhook::AFTER_H1_TEMPLATE_PATH], T::Array[String])
13
13
  end
14
14
 
15
15
  sig { void }
data/lib/bhook/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Bhook
5
- VERSION = '0.1.6'
5
+ VERSION = '0.2.0'
6
6
  end
@@ -37,6 +37,7 @@ module Bhook
37
37
  end
38
38
 
39
39
  private
40
+
40
41
  sig { returns(Bhook::Directory) }
41
42
  def root_dir
42
43
  Directory.new_root_directory(@src_path, @out_path)
@@ -7,7 +7,7 @@
7
7
  #
8
8
  # https://github.com/sorbet/sorbet-typed/new/master?filename=lib/bhook/all/bhook.rbi
9
9
  #
10
- # bhook-0.1.4
10
+ # bhook-0.2.0
11
11
 
12
12
  module Bhook
13
13
  extend T::Sig
@@ -7,7 +7,7 @@
7
7
  #
8
8
  # https://github.com/sorbet/sorbet-typed/new/master?filename=lib/git/all/git.rbi
9
9
  #
10
- # git-1.10.2
10
+ # git-1.11.0
11
11
 
12
12
  module Git
13
13
  def config(name = nil, value = nil); end
@@ -7,7 +7,7 @@
7
7
  #
8
8
  # https://github.com/sorbet/sorbet-typed/new/master?filename=lib/kramdown/all/kramdown.rbi
9
9
  #
10
- # kramdown-2.3.2
10
+ # kramdown-2.4.0
11
11
 
12
12
  module Kramdown
13
13
  def self.data_dir; end
@@ -7,7 +7,7 @@
7
7
  #
8
8
  # https://github.com/sorbet/sorbet-typed/new/master?filename=lib/parallel/all/parallel.rbi
9
9
  #
10
- # parallel-1.21.0
10
+ # parallel-1.22.1
11
11
 
12
12
  module Parallel
13
13
  def self.add_progress_bar!(job_factory, options); end
@@ -21,6 +21,8 @@ module Parallel
21
21
  def self.flat_map(*args, &block); end
22
22
  def self.in_processes(options = nil, &block); end
23
23
  def self.in_threads(options = nil); end
24
+ def self.instrument_finish(item, index, result, options); end
25
+ def self.instrument_start(item, index, options); end
24
26
  def self.map(source, options = nil, &block); end
25
27
  def self.map_with_index(array, options = nil, &block); end
26
28
  def self.process_incoming_jobs(read, write, job_factory, options, &block); end
@@ -28,6 +30,7 @@ module Parallel
28
30
  def self.with_instrumentation(item, index, options); end
29
31
  def self.work_direct(job_factory, options, &block); end
30
32
  def self.work_in_processes(job_factory, options, &blk); end
33
+ def self.work_in_ractors(job_factory, options); end
31
34
  def self.work_in_threads(job_factory, options, &block); end
32
35
  def self.worker(job_factory, options, &block); end
33
36
  def self.worker_number; end
@@ -7,7 +7,7 @@
7
7
  #
8
8
  # https://github.com/sorbet/sorbet-typed/new/master?filename=lib/parser/all/parser.rbi
9
9
  #
10
- # parser-3.1.1.0
10
+ # parser-3.1.2.0
11
11
 
12
12
  module Parser
13
13
  end