bhook 0.2.1 → 0.3.1

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: 144ecf729bff710fb2848d0e64a1bd2c9aa2b1178ce079760f3cb7f0fa3cbb74
4
- data.tar.gz: a615cb26c8c45647ca9dba86f382c84344e76e0710c7f1408f5cffee0022cc09
3
+ metadata.gz: 1e5a2ce989dc5f18be7fe40f71b3c2afbec926f43a8abd417a40b9b738af1075
4
+ data.tar.gz: 6f20fc641d2c96deaf22a6def9547b8da373ceeec507f96ef92542ae110397ec
5
5
  SHA512:
6
- metadata.gz: 37caec4b0a9144b8a918b9af5d30ed84ae1882f22e2d29e1bd17dcfd03671865027c1a18cd8cd1c6f6931013cfac766a9f9e1096234cb9d8034ca49f791314fb
7
- data.tar.gz: afe25a780b1f31a937876d33178142b0236341eccce7092db264668863f0cdfa8ed1473a4c0159465b1211e00bd7ea8761830be3b578852ab80d87c9e21a7659
6
+ metadata.gz: 91851c0792324aa103da6c6c157b64924187afe33901566f004d808e12437821598502e0bb487bd449b3e154d030734a3c81641156f02b12200926c77855b5b5
7
+ data.tar.gz: 78c3ebb19723089cd939ed8de447343240fd9ae5c4389b89185fdb65c6a8a06cbe55759f88ee5d210ec49c6638e8b6a0aaab5429d7a3c9b78d861007a90f9a71
data/.rubocop.yml CHANGED
@@ -32,4 +32,5 @@ Metrics/BlockLength:
32
32
  Metrics/AbcSize:
33
33
  Exclude:
34
34
  - lib/bhook/args_parser.rb
35
+ - spec/**/*_spec.rb
35
36
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bhook (0.2.1)
4
+ bhook (0.3.1)
5
5
  git (~> 1.10)
6
6
  kramdown (~> 2.3)
7
7
  listen (~> 3.7)
data/README.md CHANGED
@@ -9,11 +9,15 @@
9
9
 
10
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).
11
11
 
12
+ Since you control the source markdown, Bhook applies no restrictions on what you can put in there. Wanna embed a YouTube video in an `iframe`? Sure thing!
13
+
12
14
  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.
13
15
 
14
16
  ## Installation
15
17
 
16
- Install it yourself as:
18
+ `bhook` requires [`ruby`](https://www.ruby-lang.org/en/documentation/installation/). If you are on OSX or Linux, it is likely to already be installed.
19
+
20
+ To install `bhook` run:
17
21
 
18
22
  $ gem install bhook
19
23
 
@@ -22,7 +26,7 @@ Install it yourself as:
22
26
  Getting help:
23
27
 
24
28
  $ bhook --help
25
- Bhook version 0.2.0
29
+ Bhook version 0.3.0
26
30
  Usage: bhook --source /source/path --output /output/path
27
31
  -s, --source=SOURCE Path to version controlled directory containing source md files
28
32
  -o, --output=OUTPUT Path to directory where output files are to be generated
@@ -33,11 +37,20 @@ Getting help:
33
37
  --benchmark Run a performance benchmark for the specified source
34
38
  -h, --help Prints this help
35
39
 
36
- How I use it:
40
+ ### 1-to-1 mode
37
41
 
38
42
  ➜ essays git:(main) ✗ bhook -s . -o /tmp/out -t /tmp/out/theme -w -v
39
43
 
40
- Here's an example `.bhook.yml` [config file](https://gitlab.com/india-startups/wiki/-/blob/master/.bhook.yml).
44
+ Here's an example `.bhook.yml` [config file](https://gitlab.com/india-startups/wiki/-/blob/master/.bhook.yml) for a source directory.
45
+
46
+ ### n-to-1 mode
47
+
48
+ This requires the destination directory to have a `.bhook.yml` config file set up that describes all the sources.
49
+
50
+ ➜ kaiwren.github.com git:(main) ✗ bhook -w -v
51
+
52
+ Here's an example `.bhook.yml` [config file](https://github.com/kaiwren/kaiwren.github.com/blob/master/.bhook.yml) for a destination directory
53
+ with multiple source directories.
41
54
 
42
55
  ## Development
43
56
 
data/Rakefile CHANGED
@@ -31,4 +31,4 @@ namespace :ci do
31
31
  task spec: %i[spec]
32
32
  end
33
33
 
34
- task default: %i[autocorrect_basic_style_issues rubocop sorbet spec]
34
+ task default: %i[autocorrect_basic_style_issues sorbet spec rubocop]
data/bin/bhook CHANGED
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'bundler/setup'
5
- require 'bhook'
5
+ require_relative File.join('..', 'lib', 'bhook')
6
6
 
7
7
  puts "Bhook version #{Bhook::VERSION}"
8
8
  parser = Bhook::ArgsParser.new(ARGV)
@@ -15,24 +15,35 @@ if args.help
15
15
  exit
16
16
  end
17
17
 
18
+ Bhook::L.level = args.verbose ? Logger::DEBUG : Logger::INFO
19
+
18
20
  if args.generate_theme
19
21
  Bhook::L.level = Logger::DEBUG
20
22
  Bhook::ThemeGenerator.new(args.generate_theme).generate!
21
23
  exit
22
24
  end
23
25
 
24
- Bhook::L.level = args.verbose ? Logger::DEBUG : Logger::INFO
26
+ workspaces = Bhook::Workspaces.new
25
27
 
26
- workspace = Bhook::Workspace.new(args.source, args.output, args.theme)
28
+ if args.mount
29
+ args.mount.each do |project, from_to|
30
+ from = File.expand_path(from_to['from'])
31
+ to = File.expand_path(from_to['to'])
32
+ Bhook::L.debug "Mounting: #{project} \n\tfrom #{from} \n\tto #{to}"
33
+ workspaces.mount(Bhook::Workspace.new(from, to, args.theme))
34
+ end
35
+ else
36
+ workspaces.mount(Bhook::Workspace.new(args.source, args.output, args.theme))
37
+ end
27
38
 
28
39
  if args.benchmark
29
40
  require 'benchmark'
30
41
  n = 10
31
42
  Benchmark.bmbm do |bench|
32
43
  Bhook::L.level = Logger::WARN
33
- bench.report("Generate HTML #{n} times") { n.times { workspace.process! } }
44
+ bench.report("Generate HTML #{n} times") { n.times { workspaces.each(&:process!) } }
34
45
  end
35
46
  exit
36
47
  end
37
48
 
38
- args.watch ? workspace.watch! : workspace.process!
49
+ args.watch ? workspaces.watch! : workspaces.process!
@@ -5,25 +5,29 @@ module Bhook
5
5
  class ArgsParser
6
6
  extend T::Sig
7
7
 
8
- Options = Struct.new(:source, :output, :watch, :verbose, :theme, :generate_theme, :benchmark, :help)
8
+ Options = Struct.new(:source, :output, :watch, :verbose, :theme, :generate_theme, :benchmark, :mount, :help)
9
9
 
10
10
  def initialize(argv)
11
- @args = Options.new(nil, nil, false, false, Bhook::THEME_DIR_PATH, nil, false, false)
11
+ @args = Options.new(nil, nil, false, false, Bhook::THEME_DIR_PATH, nil, false, nil, false)
12
12
  @argv = argv.clone
13
13
  @opt_parser = build_opt_parser
14
14
  end
15
15
 
16
16
  def parse
17
+ if (mount = detect_and_read_mount_args_from_config_in_pwd)
18
+ @args.mount = mount
19
+ end
20
+
17
21
  begin
18
22
  @opt_parser.parse(@argv)
19
- if generate_theme_missing? && help_missing? && source_or_output_paths_missing?
23
+ if generate_theme_missing? && help_missing? &&
24
+ source_or_output_paths_missing? && mount_config_missing?
20
25
  raise OptionParser::MissingArgument, 'See --help.'
21
26
  end
22
27
  rescue OptionParser::ParseError => e
23
28
  puts "\nError! #{e.message}\n"
24
29
  return nil
25
30
  end
26
-
27
31
  @args
28
32
  end
29
33
 
@@ -33,6 +37,17 @@ module Bhook
33
37
 
34
38
  private
35
39
 
40
+ def detect_and_read_mount_args_from_config_in_pwd
41
+ bhook_config_path = File.join(Dir.pwd, SourceConfig::BHOOK_CONFIG_FILE)
42
+ return unless File.exist?(bhook_config_path)
43
+
44
+ YAML.safe_load(File.read(bhook_config_path))['mount']
45
+ end
46
+
47
+ def mount_config_missing?
48
+ !@args.mount
49
+ end
50
+
36
51
  def help_missing?
37
52
  !@args.help
38
53
  end
@@ -8,15 +8,15 @@ module Bhook
8
8
  GIT_DIR = '.git'
9
9
  MD_EXT = '.md'
10
10
 
11
- sig { params(src_path: Pathname, out_path: Pathname).returns(Bhook::Directory) }
11
+ sig { params(src_path: Pathname, out_path: Pathname).returns(Bhook::RootDirectory) }
12
12
  def self.new_root_directory(src_path, out_path)
13
- new(src_path, out_path, Git.open(src_path), Bhook::Config.new(src_path))
13
+ RootDirectory.new(src_path, out_path)
14
14
  end
15
15
 
16
- sig { params(src_path: Pathname, out_path: Pathname, git: Git::Base, config: Bhook::Config).void }
16
+ sig { params(src_path: Pathname, out_path: Pathname, git: Git::Base, config: Bhook::SourceConfig).void }
17
17
  def initialize(src_path, out_path, git, config)
18
18
  @src_path = src_path
19
- @out_path = T.let(out_path.join(src_path.basename), Pathname)
19
+ @out_path = T.let(build_out_path(src_path, out_path), Pathname)
20
20
  @git = git
21
21
  @config = config
22
22
  @sub_dirs = T.let([], T::Array[Directory])
@@ -46,6 +46,11 @@ module Bhook
46
46
 
47
47
  private
48
48
 
49
+ sig { params(src_path: Pathname, out_path: Pathname).returns(Pathname) }
50
+ def build_out_path(src_path, out_path)
51
+ out_path.join(src_path.basename)
52
+ end
53
+
49
54
  sig { void }
50
55
  def build_next_level_nodes
51
56
  children = @src_path.children
data/lib/bhook/md_file.rb CHANGED
@@ -17,7 +17,7 @@ module Bhook
17
17
  sig { returns(String) }
18
18
  attr_reader :md
19
19
 
20
- sig { params(src_file_path: Pathname, out_path: Pathname, git: Git::Base, config: Bhook::Config).void }
20
+ sig { params(src_file_path: Pathname, out_path: Pathname, git: Git::Base, config: Bhook::SourceConfig).void }
21
21
  def initialize(src_file_path, out_path, git, config)
22
22
  L.debug "Reading: #{src_file_path}"
23
23
  @md = T.let(File.read(src_file_path), String)
@@ -0,0 +1,20 @@
1
+ # typed: strict
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), Bhook::SourceConfig.new(src_path))
11
+ end
12
+
13
+ private
14
+
15
+ sig { params(_src_path: Pathname, out_path: Pathname).returns(Pathname) }
16
+ def build_out_path(_src_path, out_path)
17
+ out_path
18
+ end
19
+ end
20
+ end
@@ -8,7 +8,7 @@ module Bhook
8
8
  # - link to place in the footer
9
9
  # - exclude
10
10
  # - list of .md file paths relative to config files
11
- class Config
11
+ class SourceConfig
12
12
  extend T::Sig
13
13
  BHOOK_CONFIG_FILE = T.let('.bhook.yml', String)
14
14
  WEBSITE_KEY = T.let('website', String)
@@ -40,7 +40,7 @@ module Bhook
40
40
 
41
41
  sig { params(excluded_files: T::Array[String]).returns(T::Array[Pathname]) }
42
42
  def parse_excluded_files(excluded_files)
43
- excluded_files.map { |file_path| @root_dir_path.join(file_path) }
43
+ excluded_files.map { |file_path| @root_dir_path.join(file_path) if file_path }.compact
44
44
  end
45
45
 
46
46
  sig do
@@ -51,8 +51,25 @@
51
51
  margin-bottom: 1.5em;
52
52
  }
53
53
 
54
+ div.youtube-video {
55
+ margin: 1em 0 1em 0;
56
+ width: 100%;
57
+ justify-content: center;
58
+ display: flex;
59
+ }
60
+
61
+ div.content {
62
+ }
63
+
54
64
  div.footer {
55
- margin: 0.5em 0 1.5em 0;
65
+ margin: 0.5em 0 0.5em 0;
66
+ }
67
+
68
+ div.bhook-cta a {
69
+ font-size: x-small;
70
+ text-decoration: none;
71
+ margin-bottom: 1.5em;
72
+ color: #bbbbbb;
56
73
  }
57
74
 
58
75
  table {
@@ -86,9 +103,6 @@
86
103
  <title><%= src_title -%></title>
87
104
  </head>
88
105
  <body>
89
- <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
90
- <path fill="#333" fill-rule="evenodd" d="M9.683 6.676l-.047-.048C8.27 5.26 6.07 5.243 4.726 6.588l-2.29 2.29c-1.344 1.344-1.328 3.544.04 4.91 1.366 1.368 3.564 1.385 4.908.04l1.753-1.752c-.695.074-1.457-.078-2.176-.444L5.934 12.66c-.634.634-1.67.625-2.312-.017-.642-.643-.65-1.677-.017-2.312L6.035 7.9c.634-.634 1.67-.625 2.312.017.024.024.048.05.07.075l.003-.002c.36.36.943.366 1.3.01.355-.356.35-.938-.01-1.3l-.027-.024zM6.58 9.586l.048.05c1.367 1.366 3.565 1.384 4.91.04l2.29-2.292c1.344-1.343 1.328-3.542-.04-4.91-1.366-1.366-3.564-1.384-4.908-.04L7.127 4.187c.695-.074 1.457.078 2.176.444l1.028-1.027c.635-.634 1.67-.624 2.313.017.643.644.652 1.678.018 2.312l-2.43 2.432c-.635.634-1.67.624-2.313-.018-.024-.024-.048-.05-.07-.075l-.003.004c-.36-.362-.943-.367-1.3-.01-.355.355-.35.937.01 1.3.01.007.018.015.027.023z"/>
91
- </svg>
92
106
  <div class="body container">
93
107
  <div class="content row justify-content-center">
94
108
  <div class="col-10">
@@ -106,6 +120,9 @@
106
120
  <%= src_file_date -%> © <a href="https://sidu.in">Sidu Ponnappa</a>
107
121
  </div>
108
122
  </div>
123
+ <div class="bhook-cta d-flex justify-content-center">
124
+ <a href="https://gitlab.com/kaiwren/bhook" target="_blank">powered by bhook</a>
125
+ </div>
109
126
  </div>
110
127
  </body>
111
128
  </html>
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.2.1'
5
+ VERSION = '0.3.1'
6
6
  end
@@ -28,19 +28,13 @@ module Bhook
28
28
  process!
29
29
  end
30
30
  listener.start
31
- sleep
32
- end
33
-
34
- sig { returns(T::Array[MdFile]) }
35
- def all_md_files
36
- root_dir.all_md_files
37
31
  end
38
32
 
39
33
  private
40
34
 
41
35
  sig { returns(Bhook::Directory) }
42
36
  def root_dir
43
- Directory.new_root_directory(@src_path, @out_path)
37
+ RootDirectory.new(@src_path, @out_path)
44
38
  end
45
39
  end
46
40
  end
@@ -0,0 +1,29 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Bhook
5
+ class Workspaces
6
+ extend T::Sig
7
+
8
+ sig { void }
9
+ def initialize
10
+ @workspaces = T.let([], T::Array[Bhook::Workspace])
11
+ end
12
+
13
+ sig { params(workspace: Workspace).void }
14
+ def mount(workspace)
15
+ @workspaces << workspace
16
+ end
17
+
18
+ sig { void }
19
+ def process!
20
+ @workspaces.each(&:process!)
21
+ end
22
+
23
+ sig { void }
24
+ def watch!
25
+ @workspaces.each(&:watch!)
26
+ Kernel.sleep
27
+ end
28
+ end
29
+ end
data/lib/bhook.rb CHANGED
@@ -27,10 +27,12 @@ end
27
27
  require_relative 'bhook/version'
28
28
  require_relative 'bhook/logger'
29
29
  require_relative 'bhook/args_parser'
30
- require_relative 'bhook/config'
30
+ require_relative 'bhook/source_config'
31
31
  require_relative 'bhook/theme_generator'
32
32
  require_relative 'bhook/theme'
33
33
  require_relative 'bhook/converter/html'
34
34
  require_relative 'bhook/directory'
35
+ require_relative 'bhook/root_directory'
35
36
  require_relative 'bhook/md_file'
36
37
  require_relative 'bhook/workspace'
38
+ require_relative 'bhook/workspaces'
@@ -28,7 +28,7 @@ class Bhook::ArgsParser::Options
28
28
  def self.members(); end
29
29
  end
30
30
 
31
- class Bhook::Config
31
+ class Bhook::SourceConfig
32
32
  extend ::T::Private::Methods::MethodHooks
33
33
  extend ::T::Private::Methods::SingletonMethodHooks
34
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bhook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sidu Ponnappa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-12 00:00:00.000000000 Z
11
+ date: 2022-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
@@ -197,17 +197,19 @@ files:
197
197
  - bin/bhook
198
198
  - lib/bhook.rb
199
199
  - lib/bhook/args_parser.rb
200
- - lib/bhook/config.rb
201
200
  - lib/bhook/converter/html.rb
202
201
  - lib/bhook/directory.rb
203
202
  - lib/bhook/logger.rb
204
203
  - lib/bhook/md_file.rb
204
+ - lib/bhook/root_directory.rb
205
+ - lib/bhook/source_config.rb
205
206
  - lib/bhook/theme.rb
206
207
  - lib/bhook/theme/_after_h1.erb
207
208
  - lib/bhook/theme/page.erb
208
209
  - lib/bhook/theme_generator.rb
209
210
  - lib/bhook/version.rb
210
211
  - lib/bhook/workspace.rb
212
+ - lib/bhook/workspaces.rb
211
213
  - sorbet/config
212
214
  - sorbet/rbi/gems/ast.rbi
213
215
  - sorbet/rbi/gems/bhook.rbi