bhook 0.1.3 → 0.1.4

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: b4ef3049d516cd681eac21ac34923cf9cdd292cbb79ca238d7228e1a18a9a323
4
- data.tar.gz: 942754c6193f0e19d1b2dc028aa13e9033e7d2e4f5a01e3edb76248ce2d1e3f6
3
+ metadata.gz: 5ffd9eb1c5db23eb8abdd4a3fab6932720c3774697c27656ecf4ddcae1732eeb
4
+ data.tar.gz: cf87062c2146ca04a7dc3e64e85909a8dd5d53799e6f6cea8aeccf2d197701e3
5
5
  SHA512:
6
- metadata.gz: cb421ebe8b1ea40155b8fec5139d249b99c99bdc17f44587b07d4af8824a2519ca3edba0134f1029475df2be577da5f140149a0a11d7ea05273de23734c2fcc3
7
- data.tar.gz: 9563f8a81b32da179e8f4582f36dfa619076237fe64880fdd3047feafc7f89826bc8098e884ce8ef3c59afc35c155d882d709a74d9e41cf54936b0af2fd21862
6
+ metadata.gz: d2071d0b4baf4b58dd94ec675323f416bc4864f964506e79c04db3618a4338c44f7d151aff1137467f174c07df06ce26bc2cbf2d13b0f66476b6f47ef960305f
7
+ data.tar.gz: 3e3693defc38e9e1598c1cca637c48fbc305bfb012602d4b458f916c024f9260de650863ed25a4ba15737a4933fc4e5b037a75b70f7fcd70559e561cdb285752
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bhook (0.1.3)
4
+ bhook (0.1.4)
5
5
  git (~> 1.10)
6
6
  kramdown (~> 2.3)
7
7
  listen (~> 3.7)
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.2
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:
@@ -8,7 +8,7 @@ module Bhook
8
8
  Options = Struct.new(:source, :output, :watch, :verbose, :theme, :generate_theme, :benchmark)
9
9
 
10
10
  def initialize(argv)
11
- @args = Options.new(nil, nil, false, false, nil, nil, false)
11
+ @args = Options.new(nil, nil, false, false, Bhook::THEME_DIR_PATH, nil, false)
12
12
  @argv = argv.clone
13
13
  @opt_parser = build_opt_parser
14
14
  end
@@ -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).void }
11
+ def initialize(root_dir_path)
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
+ {}
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
+ URI::join(@website_url, "#{src_file_sha}/#{relative_file_path}").to_s
27
+ end
28
+ end
29
+ end
30
+ end
@@ -8,11 +8,18 @@ module Bhook
8
8
  GIT_DIR = '.git'
9
9
  MD_EXT = '.md'
10
10
 
11
- sig { params(src_path: Pathname, out_path: Pathname, git: Git::Base).void }
12
- def initialize(src_path, out_path, git)
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
@@ -50,9 +57,9 @@ module Bhook
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/md_file.rb CHANGED
@@ -11,18 +11,15 @@ module Bhook
11
11
  sig { returns(Pathname) }
12
12
  attr_reader :src_file_path
13
13
 
14
- sig { params(src_file_path: Pathname, out_path: Pathname, git: Git::Base).void }
15
- def initialize(src_file_path, out_path, git)
14
+ sig { params(src_file_path: Pathname, out_path: Pathname, git: Git::Base, config: Bhook::Config).void }
15
+ def initialize(src_file_path, out_path, git, config)
16
16
  L.debug "Reading: #{src_file_path}"
17
17
  @md = T.let(File.read(src_file_path), String)
18
18
  @src_file_path = src_file_path
19
19
  @out_path = out_path
20
- src_file_date, src_file_sha = git.lib.send(:command, 'log',
21
- '-n 1',
22
- '--pretty=format:%ad|%h',
23
- '--date=short',
24
- '--',
25
- @src_file_path).split('|')
20
+ @git = git
21
+ @config = config
22
+ src_file_date, src_file_sha = load_git_file_metadata
26
23
  @src_file_date = T.let(src_file_date, T.nilable(String))
27
24
  @src_file_sha = T.let(src_file_sha, T.nilable(String))
28
25
  end
@@ -31,9 +28,10 @@ module Bhook
31
28
  def write!(theme)
32
29
  out_file_name = @src_file_path.basename.sub(/\.md$/, '.html')
33
30
  out_file_path = @out_path.join(out_file_name)
31
+ file_url = @config.website_url_for(@src_file_path, @src_file_sha)
34
32
 
35
33
  L.debug "Processing: #{@src_file_sha || 'unversioned'} #{@src_file_path}"
36
- rendered_page = theme.render_page(@md, @src_file_sha, @src_file_date)
34
+ rendered_page = theme.render_page(@md, @src_file_sha, @src_file_date, file_url)
37
35
 
38
36
  L.debug "Writing: #{@src_file_sha} #{out_file_path}"
39
37
  File.write(out_file_path, rendered_page)
@@ -43,5 +41,17 @@ module Bhook
43
41
  def to_s
44
42
  @src_file_path.to_s
45
43
  end
44
+
45
+ private
46
+
47
+ sig { returns(T::Array[String]) }
48
+ def load_git_file_metadata
49
+ @git.lib.send(:command, 'log',
50
+ '-n 1',
51
+ '--pretty=format:%ad|%H',
52
+ '--date=short',
53
+ '--',
54
+ @src_file_path).split('|')
55
+ end
46
56
  end
47
57
  end
@@ -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
- v. <%= src_file_sha -%>, <%= src_file_date -%> © <a href="https://sidu.in">Sidu Ponnappa</a>
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), src_file_date: T.nilable(String)).returns(String) }
17
- def render_page(md, src_file_sha, src_file_date)
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)
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.3'
5
+ VERSION = '0.1.4'
6
6
  end
@@ -4,7 +4,7 @@
4
4
  module Bhook
5
5
  class Workspace
6
6
  extend T::Sig
7
-
7
+
8
8
  sig { params(src_path: String, out_path: String, theme_path: String).void }
9
9
  def initialize(src_path, out_path, theme_path)
10
10
  @src_path = T.let(Pathname.new(src_path).expand_path, Pathname)
@@ -36,10 +36,10 @@ module Bhook
36
36
  root_dir.all_md_files
37
37
  end
38
38
 
39
- private
40
- sig { returns(Bhook::RootDirectory) }
39
+ private
40
+ sig { returns(Bhook::Directory) }
41
41
  def root_dir
42
- RootDirectory.new(@src_path, @out_path)
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'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bhook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sidu Ponnappa
@@ -169,11 +169,11 @@ files:
169
169
  - bin/bhook
170
170
  - lib/bhook.rb
171
171
  - lib/bhook/args_parser.rb
172
+ - lib/bhook/config.rb
172
173
  - lib/bhook/converter/html.rb
173
174
  - lib/bhook/directory.rb
174
175
  - lib/bhook/logger.rb
175
176
  - lib/bhook/md_file.rb
176
- - lib/bhook/root_directory.rb
177
177
  - lib/bhook/theme.rb
178
178
  - lib/bhook/theme/_after_h1.erb
179
179
  - lib/bhook/theme/page.erb
@@ -1,13 +0,0 @@
1
- # typed: false
2
- # frozen_string_literal: true
3
-
4
- module Bhook
5
- class RootDirectory < Directory
6
- extend T::Sig
7
-
8
- sig { params(src_path: Pathname, out_path: Pathname).void }
9
- def initialize(src_path, out_path)
10
- super(src_path, out_path, Git.open(src_path))
11
- end
12
- end
13
- end