bhook 0.2.2 → 0.3.2

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: ca377d9173c2c530530b76f74aac1b3cceeec7665577f7514e5929ce374d4ee4
4
+ data.tar.gz: 40cc3cdee60aea179938e6a11f0262c384866c9adff2daaacbc34b20e8a78e2f
5
5
  SHA512:
6
- metadata.gz: 01afd14cbb7f1e607b8306399cbad5e3a1de627be32923c5107868e3c06fce031266c6222f4bcf466cd3a19fd2c8ceb9c5a52a7e4ab535abd287a8fb1b5dcc98
7
- data.tar.gz: 208dd8b71184dff3c7ebcc1d16c5f631c03a725166ec9dc532ce06a1a59a0705804480ad322a4547276c31a8e0ac2fcda54cc6968c04a4b70ab4c796d25ec599
6
+ metadata.gz: 8458e574ee89eb350d863e1373063b020414dfe94ba731a9b6b5db5f18d63184e4c2df444f734bfd7f7011bf0a307390a42d96fce50d5a34c25eacf9119e8b8a
7
+ data.tar.gz: d59b9f4a545a6f5ffcd84934f73670773234c890e5d2bd766bd4abc3a41083e2cd1588194a3e0f1a7e57761ed8c652f5b6d630e2ceab342dc697a2f82a51b6bb
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.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
@@ -5,25 +5,59 @@
5
5
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1">
7
7
  <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
8
- <link href='https://fonts.googleapis.com/css?family=Fira+Sans' rel='stylesheet' type='text/css'>
8
+ <link href='https://fonts.googleapis.com/css?family=Fira+Sans:500,400&display=swap' rel='stylesheet' type='text/css'>
9
9
 
10
10
  <!-- Bootstrap -->
11
11
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
12
12
  <style>
13
+ :root {
14
+ --header-margin-top: 0.5em;
15
+ --header-margin-bottom: 0.5em;
16
+ --body-font-size: 1.1rem;
17
+ --title-font-family: 'Fira Sans';
18
+ --title-font-size: 3.5rem;
19
+ --title-font-weight: 500;
20
+ --header-font-family: 'Fira Sans';
21
+ --header-font-weight: 500;
22
+ --content-font-family: 'Fira Sans';
23
+ --content-line-height: 1.7rem;
24
+ --content-font-weight: 400;
25
+ --paragraph-spacing: 1rem;
26
+ --toc-font-weight: 400;
27
+ }
28
+
13
29
  body {
14
- font-family: 'Fira Sans', sans-serif;
30
+ font-family: sans-serif;
31
+ font-size: var(--body-font-size);
15
32
  color: #000000;
16
33
  }
17
34
 
18
- h2, h3, h4, h5 {
19
- margin-bottom: 0.5em;
20
- margin-top: 0.5em;
35
+ div.content-wrapper {
36
+ }
37
+
38
+ div.content {
39
+ line-height: var(--content-line-height);
40
+ font-weight: var(--content-font-weight);
41
+ font-family: var(--content-font-family);
42
+ }
43
+
44
+ h1 {
45
+ font-family: var(--title-font-family);
46
+ font-size: var(--title-font-size);
47
+ font-weight: var(--title-font-weight);
21
48
  }
22
49
 
23
50
  h2 {
24
51
  border-bottom: 1px solid #eaeaea;
25
52
  }
26
53
 
54
+ h2, h3, h4, h5 {
55
+ font-family: var(--header-font-family);
56
+ font-weight: var(--header-font-weight);
57
+ margin-bottom: var(--header-margin-top);
58
+ margin-top: var(--header-margin-bottom);
59
+ }
60
+
27
61
  h2 a.header-anchor, h3 a.header-anchor,
28
62
  h4 a.header-anchor, h5 a.header-anchor {
29
63
  float: left;
@@ -46,13 +80,35 @@
46
80
  visibility: visible;
47
81
  }
48
82
 
83
+ div.content p {
84
+ margin-bottom: var(--paragraph-spacing);
85
+ }
86
+
87
+ ol#markdown-toc {
88
+ font-weight: var(--toc-font-weight);
89
+ }
90
+
49
91
  div.after-h1 {
50
92
  border-bottom: 1px solid #bbbbbb;
51
93
  margin-bottom: 1.5em;
52
94
  }
53
95
 
96
+ div.youtube-video {
97
+ margin: 1em 0 1em 0;
98
+ width: 100%;
99
+ justify-content: center;
100
+ display: flex;
101
+ }
102
+
54
103
  div.footer {
55
- margin: 0.5em 0 1.5em 0;
104
+ margin: 0.5em 0 0.5em 0;
105
+ }
106
+
107
+ div.bhook-cta a {
108
+ font-size: x-small;
109
+ text-decoration: none;
110
+ margin-bottom: 1.5em;
111
+ color: #bbbbbb;
56
112
  }
57
113
 
58
114
  table {
@@ -87,8 +143,8 @@
87
143
  </head>
88
144
  <body>
89
145
  <div class="body container">
90
- <div class="content row justify-content-center">
91
- <div class="col-10">
146
+ <div class="content-wrapper row justify-content-center">
147
+ <div class="content col-10">
92
148
  <%= output %>
93
149
  </div>
94
150
  </div>
@@ -103,6 +159,9 @@
103
159
  <%= src_file_date -%> © <a href="https://sidu.in">Sidu Ponnappa</a>
104
160
  </div>
105
161
  </div>
162
+ <div class="bhook-cta d-flex justify-content-center">
163
+ <a href="https://gitlab.com/kaiwren/bhook" target="_blank">powered by bhook</a>
164
+ </div>
106
165
  </div>
107
166
  </body>
108
167
  </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.2'
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.2
4
+ version: 0.3.2
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-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