bhook 0.1.3 → 0.1.6
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 +11 -6
- data/lib/bhook/args_parser.rb +49 -44
- data/lib/bhook/config.rb +30 -0
- data/lib/bhook/directory.rb +17 -10
- data/lib/bhook/logger.rb +4 -3
- data/lib/bhook/md_file.rb +41 -22
- data/lib/bhook/theme/page.erb +24 -13
- 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: 17b89ce589acd0d94792144dd145e2470612ebdd7ea566cba91e4174e9bc414c
|
4
|
+
data.tar.gz: d819bec1768b629f94ef192f9053e35df93a9c966246d50c85dc3684bc4fa543
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4c46ca4fd8820d9898bf5cefe79c8fd82bff9f2aebfa9aba41f75c1920d898441624be2740c528b357f1548e537f1651dc737df26a7f9c888278aa2aff91e79
|
7
|
+
data.tar.gz: 9b8fbcfec88fc338ab13ec03cafe6cbe73752ed3b3cae23cb4f98117f0f8913756743e3d930f62d91d5b3c0ff71e3cbe864f99fab0db110539ecbcba9f767213
|
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.6)
|
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,23 @@ 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)
|
22
27
|
|
data/lib/bhook/args_parser.rb
CHANGED
@@ -1,95 +1,100 @@
|
|
1
|
-
# typed:
|
1
|
+
# typed: true
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
module Bhook
|
5
5
|
class ArgsParser
|
6
6
|
extend T::Sig
|
7
|
-
|
8
|
-
Options = Struct.new(:source, :output, :watch, :verbose, :theme, :generate_theme, :benchmark)
|
9
|
-
|
7
|
+
|
8
|
+
Options = Struct.new(:source, :output, :watch, :verbose, :theme, :generate_theme, :benchmark, :help)
|
9
|
+
|
10
10
|
def initialize(argv)
|
11
|
-
@args = Options.new(nil, nil, false, false,
|
11
|
+
@args = Options.new(nil, nil, false, false, Bhook::THEME_DIR_PATH, nil, false, false)
|
12
12
|
@argv = argv.clone
|
13
13
|
@opt_parser = build_opt_parser
|
14
14
|
end
|
15
|
-
|
15
|
+
|
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
|
23
|
+
end
|
19
24
|
rescue OptionParser::ParseError => e
|
20
|
-
puts
|
21
|
-
|
22
|
-
puts
|
23
|
-
puts @opt_parser
|
24
|
-
exit
|
25
|
-
end
|
26
|
-
|
27
|
-
if source_or_output_paths_missing? && generate_theme_missing?
|
28
|
-
puts @opt_parser
|
29
|
-
exit
|
25
|
+
puts "\nError! #{e.message}\n"
|
26
|
+
return nil
|
30
27
|
end
|
28
|
+
|
31
29
|
@args
|
32
30
|
end
|
33
|
-
|
31
|
+
|
32
|
+
def help_text
|
33
|
+
@opt_parser.to_s
|
34
|
+
end
|
35
|
+
|
34
36
|
private
|
35
|
-
|
37
|
+
|
38
|
+
def help_missing?
|
39
|
+
!@args.help
|
40
|
+
end
|
41
|
+
|
36
42
|
def source_or_output_paths_missing?
|
37
43
|
!@args.source || !@args.output
|
38
44
|
end
|
39
|
-
|
45
|
+
|
40
46
|
def generate_theme_missing?
|
41
47
|
!@args.generate_theme
|
42
48
|
end
|
43
|
-
|
44
|
-
def build_opt_parser
|
49
|
+
|
50
|
+
def build_opt_parser
|
45
51
|
OptionParser.new do |opts|
|
46
|
-
opts.banner =
|
52
|
+
opts.banner = 'Usage: bhook --source /source/path --output /output/path'
|
47
53
|
|
48
|
-
opts.on(
|
49
|
-
String,
|
54
|
+
opts.on('-sSOURCE', '--source=SOURCE',
|
55
|
+
String, 'Path to version controlled directory containing source md files') do |source_path|
|
50
56
|
@args.source = source_path
|
51
57
|
end
|
52
58
|
|
53
|
-
opts.on(
|
54
|
-
String,
|
59
|
+
opts.on('-oOUTPUT', '--output=OUTPUT',
|
60
|
+
String, 'Path to directory where output files are to be generated') do |out_path|
|
55
61
|
@args.output = out_path
|
56
62
|
end
|
57
63
|
|
58
|
-
opts.on(
|
59
|
-
FalseClass,
|
60
|
-
|
64
|
+
opts.on('-w', '--watch',
|
65
|
+
FalseClass,
|
66
|
+
'Continuously watch the source directory for changes and generate output') do
|
61
67
|
@args.watch = true
|
62
68
|
end
|
63
69
|
|
64
|
-
opts.on(
|
65
|
-
FalseClass,
|
66
|
-
|
70
|
+
opts.on('-v', '--verbose',
|
71
|
+
FalseClass,
|
72
|
+
'Print detailed information about files as they are processed') do
|
67
73
|
@args.verbose = true
|
68
74
|
end
|
69
75
|
|
70
|
-
opts.on(
|
71
|
-
String,
|
72
|
-
|
76
|
+
opts.on('-tPATH', '--theme=PATH',
|
77
|
+
String,
|
78
|
+
'Path to directory containing theme files to use when generating html') do |path|
|
73
79
|
@args.theme = path
|
74
80
|
end
|
75
81
|
|
76
|
-
opts.on(
|
77
|
-
String,
|
78
|
-
|
82
|
+
opts.on('--generate-theme=PATH',
|
83
|
+
String,
|
84
|
+
'Generate a baseline theme that you can then modify to your needs') do |path|
|
79
85
|
@args.generate_theme = path
|
80
86
|
end
|
81
87
|
|
82
|
-
opts.on(
|
88
|
+
opts.on('--benchmark',
|
83
89
|
FalseClass,
|
84
|
-
|
90
|
+
'Run a performance benchmark for the specified source') do
|
85
91
|
@args.benchmark = true
|
86
92
|
end
|
87
93
|
|
88
|
-
opts.on(
|
89
|
-
|
90
|
-
exit
|
94
|
+
opts.on('-h', '--help', FalseClass, 'Prints this help') do |help|
|
95
|
+
@args.help = true
|
91
96
|
end
|
92
|
-
end
|
97
|
+
end
|
93
98
|
end
|
94
99
|
end
|
95
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
|
@@ -23,13 +30,13 @@ module Bhook
|
|
23
30
|
FileUtils.mkdir_p(@out_path)
|
24
31
|
L.debug("mkdir: #{@out_path}")
|
25
32
|
@sub_dirs.each { |dir| dir.write!(theme) }
|
26
|
-
@md_files.map do |file|
|
33
|
+
@md_files.map do |file|
|
27
34
|
Thread.new { file.write!(theme) }
|
28
35
|
end.each do |thread|
|
29
36
|
thread.join
|
30
37
|
end
|
31
38
|
end
|
32
|
-
|
39
|
+
|
33
40
|
sig { returns(T::Array[MdFile]) }
|
34
41
|
def all_md_files
|
35
42
|
@md_files + @sub_dirs.map(&:all_md_files).flatten
|
@@ -39,20 +46,20 @@ module Bhook
|
|
39
46
|
def to_s
|
40
47
|
@src_path.to_s
|
41
48
|
end
|
42
|
-
|
49
|
+
|
43
50
|
private
|
44
51
|
|
45
52
|
sig { void }
|
46
53
|
def build_next_level_nodes
|
47
54
|
children = @src_path.children
|
48
55
|
children.delete(@src_path.join(GIT_DIR))
|
49
|
-
|
56
|
+
|
50
57
|
file_threads = []
|
51
58
|
children.each do |child_path|
|
52
59
|
if child_path.directory?
|
53
|
-
@sub_dirs << Directory.new(child_path, @out_path, @git)
|
60
|
+
@sub_dirs << Directory.new(child_path, @out_path, @git, @config)
|
54
61
|
elsif child_path.extname == MD_EXT
|
55
|
-
file_threads << Thread.new { MdFile.new(child_path, @out_path, @git) }
|
62
|
+
file_threads << Thread.new { MdFile.new(child_path, @out_path, @git, @config) }
|
56
63
|
end
|
57
64
|
end
|
58
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,8 +40,24 @@
|
|
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
|
+
<!-- Global site tag (gtag.js) - Google Analytics -->
|
52
|
+
<script async src="https://www.googletagmanager.com/gtag/js?id=G-CT9TWBW0WR"></script>
|
53
|
+
<script>
|
54
|
+
window.dataLayer = window.dataLayer || [];
|
55
|
+
function gtag(){dataLayer.push(arguments);}
|
56
|
+
gtag('js', new Date());
|
57
|
+
|
58
|
+
gtag('config', 'G-CT9TWBW0WR');
|
59
|
+
</script>
|
60
|
+
<title><%= src_title -%></title>
|
45
61
|
</head>
|
46
62
|
<body>
|
47
63
|
<div class="body container">
|
@@ -52,20 +68,15 @@
|
|
52
68
|
</div>
|
53
69
|
<div class="footer d-flex justify-content-center">
|
54
70
|
<div>
|
55
|
-
|
71
|
+
<% short_sha = src_file_sha ? src_file_sha[0..7] : nil -%>
|
72
|
+
<% if file_url && short_sha -%>
|
73
|
+
v. <a href="<%= file_url -%>"><%= short_sha -%></a>,
|
74
|
+
<% elsif short_sha -%>
|
75
|
+
v. <%= short_sha -%>,
|
76
|
+
<% end -%>
|
77
|
+
<%= src_file_date -%> © <a href="https://sidu.in">Sidu Ponnappa</a>
|
56
78
|
</div>
|
57
79
|
</div>
|
58
80
|
</div>
|
59
|
-
<script type='text/javascript'>
|
60
|
-
var _gaq = _gaq || [];
|
61
|
-
_gaq.push(['_setAccount', 'UA-24685691-1']);
|
62
|
-
_gaq.push(['_trackPageview']);
|
63
|
-
|
64
|
-
(function() {
|
65
|
-
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
66
|
-
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
67
|
-
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
68
|
-
})();
|
69
|
-
</script>
|
70
81
|
</body>
|
71
82
|
</html>
|
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
|