bhook 0.1.2 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -1
- data/Gemfile.lock +21 -13
- data/README.md +2 -1
- data/Rakefile +12 -1
- data/bin/bhook +22 -6
- data/lib/bhook/args_parser.rb +56 -40
- data/lib/bhook/config.rb +30 -0
- data/lib/bhook/directory.rb +19 -11
- data/lib/bhook/logger.rb +4 -3
- data/lib/bhook/md_file.rb +41 -22
- data/lib/bhook/theme/page.erb +14 -1
- data/lib/bhook/theme.rb +3 -2
- data/lib/bhook/theme_generator.rb +6 -4
- data/lib/bhook/version.rb +1 -1
- data/lib/bhook/workspace.rb +7 -7
- data/lib/bhook.rb +3 -1
- data/sorbet/rbi/gems/bhook.rbi +2 -1
- data/sorbet/rbi/gems/docile.rbi +36 -0
- data/sorbet/rbi/gems/kramdown.rbi +1 -1
- data/sorbet/rbi/gems/parser.rbi +1 -1
- data/sorbet/rbi/gems/regexp_parser.rbi +2 -1
- data/sorbet/rbi/gems/rubocop-ast.rbi +1 -1
- data/sorbet/rbi/gems/rubocop-rspec.rbi +11 -1
- data/sorbet/rbi/gems/rubocop.rbi +17 -6
- data/sorbet/rbi/gems/simplecov-html.rbi +35 -0
- data/sorbet/rbi/gems/simplecov.rbi +419 -0
- data/sorbet/rbi/gems/simplecov_json_formatter.rbi +47 -0
- data/sorbet/rbi/hidden-definitions/errors.txt +51 -49
- data/sorbet/rbi/hidden-definitions/hidden.rbi +106 -9
- metadata +21 -3
- data/lib/bhook/root_directory.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39c52c51debcaf48107b16abf83358b72740cd6372229b28d1d8bf40b026990f
|
4
|
+
data.tar.gz: bf55558bfdb2a19282ff64104bf5d909a1d83713af3f8ebf8b1751cf5758ed6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a94bfa98e43a47608d0c5caf83b9f70cb710ae759ee7e051aa2043ea36f23b2f81a98b7040902ba178f88132e5129ab3b4c881ab1ac4d190b414bed6020532f
|
7
|
+
data.tar.gz: 2aa3aabcd3e8431f0a296f8264cd486037a13074cea31f64942c8416b7ec2481aad99f2802a11931bbaf3417ad213fa88ee7f478f405f144c816f6a7113c543b
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
bhook (0.1.
|
4
|
+
bhook (0.1.5)
|
5
5
|
git (~> 1.10)
|
6
6
|
kramdown (~> 2.3)
|
7
7
|
listen (~> 3.7)
|
@@ -12,16 +12,17 @@ GEM
|
|
12
12
|
specs:
|
13
13
|
ast (2.4.2)
|
14
14
|
diff-lcs (1.5.0)
|
15
|
+
docile (1.4.0)
|
15
16
|
ffi (1.15.5)
|
16
17
|
git (1.10.2)
|
17
18
|
rchardet (~> 1.8)
|
18
|
-
kramdown (2.3.
|
19
|
+
kramdown (2.3.2)
|
19
20
|
rexml
|
20
21
|
listen (3.7.1)
|
21
22
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
22
23
|
rb-inotify (~> 0.9, >= 0.9.10)
|
23
24
|
parallel (1.21.0)
|
24
|
-
parser (3.1.
|
25
|
+
parser (3.1.1.0)
|
25
26
|
ast (~> 2.4.1)
|
26
27
|
rainbow (3.1.1)
|
27
28
|
rake (13.0.6)
|
@@ -29,7 +30,7 @@ GEM
|
|
29
30
|
rb-inotify (0.10.1)
|
30
31
|
ffi (~> 1.0)
|
31
32
|
rchardet (1.8.0)
|
32
|
-
regexp_parser (2.2.
|
33
|
+
regexp_parser (2.2.1)
|
33
34
|
rexml (3.2.5)
|
34
35
|
rspec (3.11.0)
|
35
36
|
rspec-core (~> 3.11.0)
|
@@ -44,26 +45,32 @@ GEM
|
|
44
45
|
diff-lcs (>= 1.2.0, < 2.0)
|
45
46
|
rspec-support (~> 3.11.0)
|
46
47
|
rspec-support (3.11.0)
|
47
|
-
rubocop (1.
|
48
|
+
rubocop (1.26.0)
|
48
49
|
parallel (~> 1.10)
|
49
50
|
parser (>= 3.1.0.0)
|
50
51
|
rainbow (>= 2.2.2, < 4.0)
|
51
52
|
regexp_parser (>= 1.8, < 3.0)
|
52
53
|
rexml
|
53
|
-
rubocop-ast (>= 1.
|
54
|
+
rubocop-ast (>= 1.16.0, < 2.0)
|
54
55
|
ruby-progressbar (~> 1.7)
|
55
56
|
unicode-display_width (>= 1.4.0, < 3.0)
|
56
|
-
rubocop-ast (1.
|
57
|
-
parser (>= 3.
|
57
|
+
rubocop-ast (1.16.0)
|
58
|
+
parser (>= 3.1.1.0)
|
58
59
|
rubocop-rake (0.6.0)
|
59
60
|
rubocop (~> 1.0)
|
60
|
-
rubocop-rspec (2.
|
61
|
+
rubocop-rspec (2.9.0)
|
61
62
|
rubocop (~> 1.19)
|
62
63
|
ruby-progressbar (1.11.0)
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
simplecov (0.21.2)
|
65
|
+
docile (~> 1.1)
|
66
|
+
simplecov-html (~> 0.11)
|
67
|
+
simplecov_json_formatter (~> 0.1)
|
68
|
+
simplecov-html (0.12.3)
|
69
|
+
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)
|
67
74
|
unicode-display_width (2.1.0)
|
68
75
|
|
69
76
|
PLATFORMS
|
@@ -76,6 +83,7 @@ DEPENDENCIES
|
|
76
83
|
rubocop (~> 1.0)
|
77
84
|
rubocop-rake (~> 0.6)
|
78
85
|
rubocop-rspec (~> 2.8)
|
86
|
+
simplecov (~> 0.21)
|
79
87
|
sorbet (~> 0.5)
|
80
88
|
|
81
89
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -15,7 +15,7 @@ Install it yourself as:
|
|
15
15
|
Getting help:
|
16
16
|
|
17
17
|
$ bhook --help
|
18
|
-
Bhook version 0.1.
|
18
|
+
Bhook version 0.1.4
|
19
19
|
Usage: bhook --source /source/path --output /output/path
|
20
20
|
-s, --source=SOURCE Path to version controlled directory containing source md files
|
21
21
|
-o, --output=OUTPUT Path to directory where output files are to be generated
|
@@ -23,6 +23,7 @@ Getting help:
|
|
23
23
|
-v, --verbose Print detailed information about files as they are processed
|
24
24
|
-t, --theme=PATH Path to directory containing theme files to use when generating html
|
25
25
|
--generate-theme=PATH Generate a baseline theme that you can then modify to your needs
|
26
|
+
--benchmark Run a performance benchmark for the specified source
|
26
27
|
-h, --help Prints this help
|
27
28
|
|
28
29
|
How I use it:
|
data/Rakefile
CHANGED
@@ -10,4 +10,15 @@ task :sorbet do
|
|
10
10
|
sh('bundle exec srb tc')
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
cops = %w[
|
14
|
+
Layout/TrailingWhitespace
|
15
|
+
Layout/SpaceInsideBlockBraces
|
16
|
+
Style/StringLiterals
|
17
|
+
]
|
18
|
+
|
19
|
+
desc "Apply #{cops.join(', ')}"
|
20
|
+
task :lint_with_autocorrect do
|
21
|
+
sh("bundle exec rubocop -a --only #{cops.join(',')}")
|
22
|
+
end
|
23
|
+
|
24
|
+
task default: %i[lint_with_autocorrect sorbet spec]
|
data/bin/bhook
CHANGED
@@ -5,18 +5,34 @@ require 'bundler/setup'
|
|
5
5
|
require 'bhook'
|
6
6
|
|
7
7
|
puts "Bhook version #{Bhook::VERSION}"
|
8
|
-
|
8
|
+
parser = Bhook::ArgsParser.new(ARGV)
|
9
|
+
args = parser.parse
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
exit unless args
|
12
|
+
|
13
|
+
if args.help
|
14
|
+
puts parser.help_text
|
15
|
+
exit
|
14
16
|
end
|
15
17
|
|
16
18
|
if args.generate_theme
|
19
|
+
Bhook::L.level = Logger::DEBUG
|
17
20
|
Bhook::ThemeGenerator.new(args.generate_theme).generate!
|
18
21
|
exit
|
19
|
-
end
|
22
|
+
end
|
23
|
+
|
24
|
+
Bhook::L.level = args.verbose ? Logger::DEBUG : Logger::INFO
|
20
25
|
|
21
26
|
workspace = Bhook::Workspace.new(args.source, args.output, args.theme)
|
27
|
+
|
28
|
+
if args.benchmark
|
29
|
+
require 'benchmark'
|
30
|
+
n = 10
|
31
|
+
Benchmark.bmbm do |bench|
|
32
|
+
Bhook::L.level = Logger::WARN
|
33
|
+
bench.report("Generate HTML #{n} times") { n.times { workspace.process! } }
|
34
|
+
end
|
35
|
+
exit
|
36
|
+
end
|
37
|
+
|
22
38
|
args.watch ? workspace.watch! : workspace.process!
|
data/lib/bhook/args_parser.rb
CHANGED
@@ -1,84 +1,100 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
1
4
|
module Bhook
|
2
5
|
class ArgsParser
|
3
|
-
|
4
|
-
|
6
|
+
extend T::Sig
|
7
|
+
|
8
|
+
Options = Struct.new(:source, :output, :watch, :verbose, :theme, :generate_theme, :benchmark, :help)
|
9
|
+
|
5
10
|
def initialize(argv)
|
6
|
-
@args = Options.new(nil, nil, false, false, nil,
|
11
|
+
@args = Options.new(nil, nil, false, false, Bhook::THEME_DIR_PATH, nil, false, false)
|
7
12
|
@argv = argv.clone
|
8
13
|
@opt_parser = build_opt_parser
|
9
14
|
end
|
10
|
-
|
15
|
+
|
11
16
|
def parse
|
12
17
|
begin
|
13
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
|
23
|
+
end
|
14
24
|
rescue OptionParser::ParseError => e
|
15
|
-
puts
|
16
|
-
|
17
|
-
puts
|
18
|
-
puts @opt_parser
|
19
|
-
exit
|
20
|
-
end
|
21
|
-
|
22
|
-
if source_or_output_paths_missing? && generate_theme_missing?
|
23
|
-
puts @opt_parser
|
24
|
-
exit
|
25
|
+
puts "\nError! #{e.message}\n"
|
26
|
+
return nil
|
25
27
|
end
|
28
|
+
|
26
29
|
@args
|
27
30
|
end
|
28
|
-
|
31
|
+
|
32
|
+
def help_text
|
33
|
+
@opt_parser.to_s
|
34
|
+
end
|
35
|
+
|
29
36
|
private
|
30
|
-
|
37
|
+
|
38
|
+
def help_missing?
|
39
|
+
!@args.help
|
40
|
+
end
|
41
|
+
|
31
42
|
def source_or_output_paths_missing?
|
32
43
|
!@args.source || !@args.output
|
33
44
|
end
|
34
|
-
|
45
|
+
|
35
46
|
def generate_theme_missing?
|
36
47
|
!@args.generate_theme
|
37
48
|
end
|
38
|
-
|
39
|
-
def build_opt_parser
|
49
|
+
|
50
|
+
def build_opt_parser
|
40
51
|
OptionParser.new do |opts|
|
41
|
-
opts.banner =
|
52
|
+
opts.banner = 'Usage: bhook --source /source/path --output /output/path'
|
42
53
|
|
43
|
-
opts.on(
|
44
|
-
String,
|
54
|
+
opts.on('-sSOURCE', '--source=SOURCE',
|
55
|
+
String, 'Path to version controlled directory containing source md files') do |source_path|
|
45
56
|
@args.source = source_path
|
46
57
|
end
|
47
58
|
|
48
|
-
opts.on(
|
49
|
-
String,
|
59
|
+
opts.on('-oOUTPUT', '--output=OUTPUT',
|
60
|
+
String, 'Path to directory where output files are to be generated') do |out_path|
|
50
61
|
@args.output = out_path
|
51
62
|
end
|
52
63
|
|
53
|
-
opts.on(
|
54
|
-
FalseClass,
|
55
|
-
|
64
|
+
opts.on('-w', '--watch',
|
65
|
+
FalseClass,
|
66
|
+
'Continuously watch the source directory for changes and generate output') do
|
56
67
|
@args.watch = true
|
57
68
|
end
|
58
69
|
|
59
|
-
opts.on(
|
60
|
-
FalseClass,
|
61
|
-
|
70
|
+
opts.on('-v', '--verbose',
|
71
|
+
FalseClass,
|
72
|
+
'Print detailed information about files as they are processed') do
|
62
73
|
@args.verbose = true
|
63
74
|
end
|
64
75
|
|
65
|
-
opts.on(
|
66
|
-
String,
|
67
|
-
|
76
|
+
opts.on('-tPATH', '--theme=PATH',
|
77
|
+
String,
|
78
|
+
'Path to directory containing theme files to use when generating html') do |path|
|
68
79
|
@args.theme = path
|
69
80
|
end
|
70
81
|
|
71
|
-
opts.on(
|
72
|
-
String,
|
73
|
-
|
82
|
+
opts.on('--generate-theme=PATH',
|
83
|
+
String,
|
84
|
+
'Generate a baseline theme that you can then modify to your needs') do |path|
|
74
85
|
@args.generate_theme = path
|
75
86
|
end
|
76
87
|
|
77
|
-
opts.on(
|
78
|
-
|
79
|
-
|
88
|
+
opts.on('--benchmark',
|
89
|
+
FalseClass,
|
90
|
+
'Run a performance benchmark for the specified source') do
|
91
|
+
@args.benchmark = true
|
92
|
+
end
|
93
|
+
|
94
|
+
opts.on('-h', '--help', FalseClass, 'Prints this help') do |help|
|
95
|
+
@args.help = true
|
80
96
|
end
|
81
|
-
end
|
97
|
+
end
|
82
98
|
end
|
83
99
|
end
|
84
100
|
end
|
data/lib/bhook/config.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Bhook
|
5
|
+
class Config
|
6
|
+
extend T::Sig
|
7
|
+
BHOOK_CONFIG_FILE = T.let('.bhook', String)
|
8
|
+
WEBSITE_KEY = T.let('website', String)
|
9
|
+
|
10
|
+
sig { params(root_dir_path: Pathname, additional_options: T::Hash[String, String]).void }
|
11
|
+
def initialize(root_dir_path, additional_options = {})
|
12
|
+
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
|
18
|
+
@root_dir_path = root_dir_path
|
19
|
+
@website_url = T.let(config[WEBSITE_KEY], T.nilable(String))
|
20
|
+
end
|
21
|
+
|
22
|
+
sig { params(src_file_path: Pathname, src_file_sha: T.nilable(String)).returns(T.nilable(String)) }
|
23
|
+
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)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/bhook/directory.rb
CHANGED
@@ -4,15 +4,22 @@
|
|
4
4
|
module Bhook
|
5
5
|
class Directory
|
6
6
|
extend T::Sig
|
7
|
-
|
7
|
+
|
8
8
|
GIT_DIR = '.git'
|
9
9
|
MD_EXT = '.md'
|
10
|
-
|
11
|
-
sig { params(src_path: Pathname, out_path: Pathname
|
12
|
-
def
|
10
|
+
|
11
|
+
sig { params(src_path: Pathname, out_path: Pathname).returns(Bhook::Directory) }
|
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))
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
sig { params(src_path: Pathname, out_path: Pathname, git: Git::Base, config: Bhook::Config).void }
|
18
|
+
def initialize(src_path, out_path, git, config)
|
13
19
|
@src_path = src_path
|
14
20
|
@out_path = T.let(out_path.join(src_path.basename), Pathname)
|
15
21
|
@git = git
|
22
|
+
@config = config
|
16
23
|
@sub_dirs = T.let([], T::Array[Directory])
|
17
24
|
@md_files = T.let([], T::Array[MdFile])
|
18
25
|
build_next_level_nodes
|
@@ -20,15 +27,16 @@ module Bhook
|
|
20
27
|
|
21
28
|
sig { params(theme: Theme).void }
|
22
29
|
def write!(theme)
|
23
|
-
FileUtils.mkdir_p(@out_path
|
30
|
+
FileUtils.mkdir_p(@out_path)
|
31
|
+
L.debug("mkdir: #{@out_path}")
|
24
32
|
@sub_dirs.each { |dir| dir.write!(theme) }
|
25
|
-
@md_files.map do |file|
|
33
|
+
@md_files.map do |file|
|
26
34
|
Thread.new { file.write!(theme) }
|
27
35
|
end.each do |thread|
|
28
36
|
thread.join
|
29
37
|
end
|
30
38
|
end
|
31
|
-
|
39
|
+
|
32
40
|
sig { returns(T::Array[MdFile]) }
|
33
41
|
def all_md_files
|
34
42
|
@md_files + @sub_dirs.map(&:all_md_files).flatten
|
@@ -38,20 +46,20 @@ module Bhook
|
|
38
46
|
def to_s
|
39
47
|
@src_path.to_s
|
40
48
|
end
|
41
|
-
|
49
|
+
|
42
50
|
private
|
43
51
|
|
44
52
|
sig { void }
|
45
53
|
def build_next_level_nodes
|
46
54
|
children = @src_path.children
|
47
55
|
children.delete(@src_path.join(GIT_DIR))
|
48
|
-
|
56
|
+
|
49
57
|
file_threads = []
|
50
58
|
children.each do |child_path|
|
51
59
|
if child_path.directory?
|
52
|
-
@sub_dirs << Directory.new(child_path, @out_path, @git)
|
60
|
+
@sub_dirs << Directory.new(child_path, @out_path, @git, @config)
|
53
61
|
elsif child_path.extname == MD_EXT
|
54
|
-
file_threads << Thread.new { MdFile.new(child_path, @out_path, @git) }
|
62
|
+
file_threads << Thread.new { MdFile.new(child_path, @out_path, @git, @config) }
|
55
63
|
end
|
56
64
|
end
|
57
65
|
file_threads.each { |thread| @md_files << thread.value }
|
data/lib/bhook/logger.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
# typed:
|
1
|
+
# typed: true
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
module Bhook
|
5
|
-
|
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
9
|
end
|
data/lib/bhook/md_file.rb
CHANGED
@@ -4,44 +4,63 @@
|
|
4
4
|
module Bhook
|
5
5
|
class MdFile
|
6
6
|
extend T::Sig
|
7
|
-
|
7
|
+
|
8
8
|
PAGE_TEMPLATE = T.let(File.read(Bhook::PAGE_TEMPLATE_PATH), String)
|
9
9
|
AFTER_H1_TEMPLATE = T.let(File.read(Bhook::AFTER_H1_TEMPLATE_PATH), String)
|
10
|
-
|
10
|
+
|
11
11
|
sig { returns(Pathname) }
|
12
|
-
attr_reader :src_file_path
|
13
|
-
|
14
|
-
sig {
|
15
|
-
|
12
|
+
attr_reader :src_file_path, :out_file_path
|
13
|
+
|
14
|
+
sig { returns(T.nilable(String)) }
|
15
|
+
attr_reader :src_file_date, :src_file_sha, :src_file_url
|
16
|
+
|
17
|
+
sig { returns(String) }
|
18
|
+
attr_reader :md
|
19
|
+
|
20
|
+
sig { params(src_file_path: Pathname, out_path: Pathname, git: Git::Base, config: Bhook::Config).void }
|
21
|
+
def initialize(src_file_path, out_path, git, config)
|
16
22
|
L.debug "Reading: #{src_file_path}"
|
17
23
|
@md = T.let(File.read(src_file_path), String)
|
18
24
|
@src_file_path = src_file_path
|
19
25
|
@out_path = out_path
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
@
|
27
|
-
@
|
26
|
+
@git = git
|
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
|
+
@out_file_path = T.let(@out_path.join(out_file_name), Pathname)
|
33
|
+
@src_file_url = T.let(file_url, T.nilable(String))
|
28
34
|
end
|
29
35
|
|
30
36
|
sig { params(theme: Bhook::Theme).void }
|
31
37
|
def write!(theme)
|
32
|
-
out_file_name = @src_file_path.basename.sub(/\.md$/, '.html')
|
33
|
-
out_file_path = @out_path.join(out_file_name)
|
34
|
-
|
35
38
|
L.debug "Processing: #{@src_file_sha || 'unversioned'} #{@src_file_path}"
|
36
|
-
rendered_page = theme.render_page(@md, @src_file_sha, @src_file_date)
|
39
|
+
rendered_page = theme.render_page(@md, @src_file_sha, @src_file_date, @src_file_url)
|
37
40
|
|
38
41
|
L.debug "Writing: #{@src_file_sha} #{out_file_path}"
|
39
|
-
File.write(out_file_path, rendered_page)
|
42
|
+
File.write(@out_file_path, rendered_page)
|
40
43
|
end
|
41
44
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
+
private
|
46
|
+
sig { returns(Pathname) }
|
47
|
+
def out_file_name
|
48
|
+
@src_file_path.basename.sub(/\.md$/, '.html')
|
49
|
+
end
|
50
|
+
|
51
|
+
sig { returns(T.nilable(String)) }
|
52
|
+
def file_url
|
53
|
+
@config.website_url_for(@src_file_path, @src_file_sha)
|
54
|
+
end
|
55
|
+
|
56
|
+
sig { returns(T::Array[String]) }
|
57
|
+
def load_git_file_metadata
|
58
|
+
@git.lib.send(:command, 'log',
|
59
|
+
'-n 1',
|
60
|
+
'--pretty=format:%ad|%H',
|
61
|
+
'--date=short',
|
62
|
+
'--',
|
63
|
+
@src_file_path).split('|')
|
45
64
|
end
|
46
65
|
end
|
47
66
|
end
|
data/lib/bhook/theme/page.erb
CHANGED
@@ -40,6 +40,13 @@
|
|
40
40
|
padding: 0.1em 1em 0.1em 1em;
|
41
41
|
border: 1px solid #bbbbbb;
|
42
42
|
}
|
43
|
+
|
44
|
+
blockquote {
|
45
|
+
border-left: 10px solid #cccccc;
|
46
|
+
background: #eeeeee;
|
47
|
+
display: inline-block;
|
48
|
+
padding: 1em;
|
49
|
+
}
|
43
50
|
</style>
|
44
51
|
<title><%= src_title -%></title>
|
45
52
|
</head>
|
@@ -52,7 +59,13 @@
|
|
52
59
|
</div>
|
53
60
|
<div class="footer d-flex justify-content-center">
|
54
61
|
<div>
|
55
|
-
|
62
|
+
<% short_sha = src_file_sha ? src_file_sha[0..7] : nil -%>
|
63
|
+
<% if file_url && short_sha -%>
|
64
|
+
v. <a href="<%= file_url -%>"><%= short_sha -%></a>,
|
65
|
+
<% elsif short_sha -%>
|
66
|
+
v. <%= short_sha -%>,
|
67
|
+
<% end -%>
|
68
|
+
<%= src_file_date -%> © <a href="https://sidu.in">Sidu Ponnappa</a>
|
56
69
|
</div>
|
57
70
|
</div>
|
58
71
|
</div>
|
data/lib/bhook/theme.rb
CHANGED
@@ -13,8 +13,9 @@ 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
|
-
|
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) }
|
18
|
+
def render_page(md, src_file_sha, src_file_date, file_url)
|
18
19
|
src_title = T.let('', String)
|
19
20
|
|
20
21
|
doc = Kramdown::Document.new(md)
|
@@ -5,17 +5,19 @@ module Bhook
|
|
5
5
|
class ThemeGenerator
|
6
6
|
extend T::Sig
|
7
7
|
|
8
|
-
sig {params(output_path: String).void}
|
8
|
+
sig { params(output_path: String).void }
|
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
12
|
Bhook::AFTER_H1_TEMPLATE_PATH], T::Array[String])
|
13
13
|
end
|
14
14
|
|
15
|
-
sig {void}
|
15
|
+
sig { void }
|
16
16
|
def generate!
|
17
|
-
FileUtils.mkdir_p(@output_path
|
18
|
-
|
17
|
+
FileUtils.mkdir_p(@output_path)
|
18
|
+
L.debug("mkdir: #{@output_path}")
|
19
|
+
FileUtils.cp(@template_files, @output_path)
|
20
|
+
L.debug("cp: #{@template_files.join(' ')} #{@output_path}")
|
19
21
|
end
|
20
22
|
end
|
21
23
|
end
|
data/lib/bhook/version.rb
CHANGED
data/lib/bhook/workspace.rb
CHANGED
@@ -13,9 +13,9 @@ module Bhook
|
|
13
13
|
end
|
14
14
|
|
15
15
|
sig { void }
|
16
|
-
def process!
|
16
|
+
def process!
|
17
17
|
root_dir.write!(@theme)
|
18
|
-
L.info
|
18
|
+
L.info 'Done!'
|
19
19
|
end
|
20
20
|
|
21
21
|
sig { void }
|
@@ -24,7 +24,7 @@ module Bhook
|
|
24
24
|
|
25
25
|
L.info "Watching: #{@src_path} for changes..."
|
26
26
|
listener = Listen.to(@src_path.to_s, File.join(@src_path.to_s, '.git')) do |_modified, _added, _removed|
|
27
|
-
L.info
|
27
|
+
L.info 'Detected changes...'
|
28
28
|
process!
|
29
29
|
end
|
30
30
|
listener.start
|
@@ -35,11 +35,11 @@ module Bhook
|
|
35
35
|
def all_md_files
|
36
36
|
root_dir.all_md_files
|
37
37
|
end
|
38
|
-
|
39
|
-
private
|
40
|
-
sig { returns(Bhook::
|
38
|
+
|
39
|
+
private
|
40
|
+
sig { returns(Bhook::Directory) }
|
41
41
|
def root_dir
|
42
|
-
|
42
|
+
Directory.new_root_directory(@src_path, @out_path)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
data/lib/bhook.rb
CHANGED
@@ -7,6 +7,8 @@ require 'pathname'
|
|
7
7
|
require 'erb'
|
8
8
|
require 'optparse'
|
9
9
|
require 'logger'
|
10
|
+
require 'uri'
|
11
|
+
require 'yaml'
|
10
12
|
require 'sorbet-runtime'
|
11
13
|
require 'git'
|
12
14
|
require 'kramdown'
|
@@ -25,10 +27,10 @@ end
|
|
25
27
|
require_relative 'bhook/version'
|
26
28
|
require_relative 'bhook/logger'
|
27
29
|
require_relative 'bhook/args_parser'
|
30
|
+
require_relative 'bhook/config'
|
28
31
|
require_relative 'bhook/theme_generator'
|
29
32
|
require_relative 'bhook/theme'
|
30
33
|
require_relative 'bhook/converter/html'
|
31
34
|
require_relative 'bhook/directory'
|
32
|
-
require_relative 'bhook/root_directory'
|
33
35
|
require_relative 'bhook/md_file'
|
34
36
|
require_relative 'bhook/workspace'
|