bhook 0.2.2 → 0.3.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: 3fbf30bb96c81aaa4b89f0709d42b878c1a53a0c87fed519d42796f15502adcc
4
- data.tar.gz: f191aa122210048ce00af81de973a5adce5821a84851e774fcc864a89a300d08
3
+ metadata.gz: 90521640ce67d31a8e080b88cb860559033426b3afc55f1a03d09d42d0a415c5
4
+ data.tar.gz: f10067505bfdaa6c8e6bc4892340bd07d6937c0882b5472772f815705ca463ec
5
5
  SHA512:
6
- metadata.gz: 01afd14cbb7f1e607b8306399cbad5e3a1de627be32923c5107868e3c06fce031266c6222f4bcf466cd3a19fd2c8ceb9c5a52a7e4ab535abd287a8fb1b5dcc98
7
- data.tar.gz: 208dd8b71184dff3c7ebcc1d16c5f631c03a725166ec9dc532ce06a1a59a0705804480ad322a4547276c31a8e0ac2fcda54cc6968c04a4b70ab4c796d25ec599
6
+ metadata.gz: ee03d8c7ea7a5e39db17acbf3638dcf53c3d2f37a55b897e6800ca24a0dde2efd4037806619438ea8097781a7c75e15de6a5a34bb25c7693cdd1b98f069f4193
7
+ data.tar.gz: 94bf726b2a6a3afb8490f172a01f992ea8bfd063a54ed2143b3ace48c644c15b93c5b5faf2a68f110b0a04a79bbed7b167846a60ec44e7bb206c1d24e5d5cfb3
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.2)
4
+ bhook (0.3.0)
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, Config::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
16
  sig { params(src_path: Pathname, out_path: Pathname, git: Git::Base, config: Bhook::Config).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
@@ -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::Config.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
@@ -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 {
@@ -103,6 +120,9 @@
103
120
  <%= src_file_date -%> © <a href="https://sidu.in">Sidu Ponnappa</a>
104
121
  </div>
105
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>
106
126
  </div>
107
127
  </body>
108
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.2'
5
+ VERSION = '0.3.0'
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
@@ -32,5 +32,7 @@ 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'
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.2
4
+ version: 0.3.0
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-13 00:00:00.000000000 Z
11
+ date: 2022-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
@@ -202,12 +202,14 @@ files:
202
202
  - lib/bhook/directory.rb
203
203
  - lib/bhook/logger.rb
204
204
  - lib/bhook/md_file.rb
205
+ - lib/bhook/root_directory.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