hyphae 0.2.1 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/hyphae +31 -5
  3. data/lib/hyphae.rb +17 -15
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 26fffd773e8c0b6c43d8a286fd4be72a835246377634ee003cd41adead85234c
4
- data.tar.gz: 37abf4892e01b535f8e8585cbf616eae7bbce2d3a27663cb318f3f514d49b4b7
3
+ metadata.gz: 1670c429ca926af6c3b09782b36692bc1085d563e47e3afcb972dad93c1a2a9d
4
+ data.tar.gz: 3d4c0ac0eb83219a4831c8313d566390dac69171f60115d04c7241df23d51c2f
5
5
  SHA512:
6
- metadata.gz: 5aecfc870811743bcd373bbdab8942982e0781554d30f867df1045597550f29caa20bff837d1c461b89925f4632dfcd6f73a7e17b3a73dcf47a01d5aeea750ad
7
- data.tar.gz: e09d2ac065b089110e335d556494a3fbec5eb80c6456c8f2aa6c0cf66ecd9fd6df58f4023cbe0545149adbd6ca4bcc0d1b45e59f6b60a675c23874ec713414cc
6
+ metadata.gz: 3cf2606f5da537bc67f790c3bc9f3ec1bf51c41412895dedaa6b4942e6286397466787199ada09d47c7ef997a5890c888de2d2dcd3980de92b1826dc891be715
7
+ data.tar.gz: '093727d7c6bdd8b85d7f4f1ae6d0a22cdc9f888cd69584d3385e5925d543c0847fcfba2eee9b45e45ee09d61b03567f0c81bf4f01fafb8f72fcf4890548cb1aa'
data/bin/hyphae CHANGED
@@ -1,20 +1,46 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
+ require 'optparse'
3
4
  require 'hyphae'
4
5
 
5
6
  ###################
6
7
  ### Main Script ###
7
8
  ###################
8
9
 
9
- # The first argument given is the site input directory
10
- input_dir = ARGV[0] || "site"
10
+ # Default options
11
+ options = {
12
+ input_dir: 'site',
13
+ output_dir: '_build',
14
+ no_file_ext: false
15
+ }
16
+
17
+ # Get options
18
+ OptionParser.new do |opts|
19
+ opts.banner = "Usage: hyphae [options]"
20
+
21
+ opts.on("-i", "--input PATH", "Change input directory") do |path|
22
+ options[:input_dir] = path
23
+ end
24
+
25
+ opts.on("-o", "--output PATH", "Change output directory") do |path|
26
+ options[:output_dir] = path
27
+ end
28
+
29
+ opts.on("-n", "--no-file-ext", "Name built page files without .html extension") do
30
+ options[:no_file_ext] = true
31
+ end
32
+
33
+ end.parse!
34
+
35
+ # Site input directory
36
+ input_dir = options[:input_dir]
11
37
  if not Dir.exist?(input_dir) then
12
38
  puts "ERROR: No input directory '#{input_dir}'"
13
39
  exit
14
40
  end
15
41
 
16
42
  # The second argument is the rendered html site output directory
17
- output_dir = ARGV[1] || "_build"
43
+ output_dir = options[:output_dir]
18
44
 
19
45
  # Builds the page tree of the site
20
46
  if not Dir.exist?(input_dir + "/pages") then
@@ -48,7 +74,7 @@ end
48
74
  FileUtils.cp_r(input_dir + '/static', output_dir)
49
75
 
50
76
  # Builds html pages
51
- page_tree.build(output_dir, template)
77
+ page_tree.build(output_dir, template, options)
52
78
 
53
79
  # Build site index
54
- page_tree.build_index(output_dir, template, index_content)
80
+ page_tree.build_index(output_dir, template, index_content, options)
data/lib/hyphae.rb CHANGED
@@ -90,28 +90,28 @@ module Hyphae
90
90
  end
91
91
 
92
92
  # Returns the html for each child's nav menu link
93
- def menu_items(open_path=[])
94
- @children.map { |x| x.nav_link(open_path) }.join
93
+ def menu_items(open_path=[], options={})
94
+ @children.map { |x| x.nav_link(open_path, options) }.join
95
95
  end
96
96
 
97
97
  # Returns the html for this SiteDir's nav menu link
98
- def nav_link(open_path=[])
98
+ def nav_link(open_path=[], options={})
99
99
  return "" if @hidden
100
100
  link = Hyphae::make_tag('span', @name, {'class' => 'nav_menu_link'})
101
101
  menu_attrs = { 'class' => 'nav_menu_items' }
102
102
  menu_attrs['class'] += ' open' if open_path.first == @slug
103
- menu = Hyphae::make_tag('div', menu_items(open_path[1..-1] || []), menu_attrs)
103
+ menu = Hyphae::make_tag('div', menu_items(open_path[1..-1] || [], options), menu_attrs)
104
104
  Hyphae::make_tag('div', link + menu, {'class' => 'nav_menu'})
105
105
  end
106
106
 
107
107
  # Recursively builds pages for all children
108
- def build(build_dir, template)
109
- @children.each { |child| child.build(build_dir, template) }
108
+ def build(build_dir, template, options={})
109
+ @children.each { |child| child.build(build_dir, template, options) }
110
110
  end
111
111
 
112
112
  # Builds an index page for this SiteDir
113
- def build_index(build_dir, template, index_content='')
114
- page_html = template.gsub('{{navbar}}', menu_items).gsub("{{content}}", index_content).gsub('{{index_class}}', ' index_page')
113
+ def build_index(build_dir, template, index_content='', options={})
114
+ page_html = template.gsub('{{navbar}}', menu_items([], options)).gsub("{{content}}", index_content).gsub('{{index_class}}', ' index_page')
115
115
  File.open("#{build_dir}/index.html", 'w') { |f| f << page_html }
116
116
  end
117
117
  end
@@ -126,20 +126,22 @@ module Hyphae
126
126
  end
127
127
 
128
128
  # Builds the nav menu tag for this page
129
- def nav_link(open_path=[])
129
+ def nav_link(open_path=[], options={})
130
130
  return "" if @hidden
131
- attrs = { 'class' => 'nav_page', 'href' => "/#{@path.join('/')}.html" }
131
+ file_ext = options[:no_file_ext] ? '' : '.html'
132
+ attrs = { 'class' => 'nav_page', 'href' => "/#{@path.join('/')}#{file_ext}" }
132
133
  attrs['class'] += ' current_page' if @slug == open_path.first
133
134
  Hyphae::make_tag('a', @name, attrs)
134
135
  end
135
136
 
136
137
  # Builds html page
137
- def build(build_dir, template)
138
- nav = root.menu_items(@path)
138
+ def build(build_dir, template, options={})
139
+ nav = root.menu_items(@path, options)
139
140
  page_html = template.gsub('{{navbar}}', nav).gsub("{{content}}", @html).gsub('{{index_class}}', '')
140
141
  page_dir_path = "#{build_dir}/#{@parent.path.join('/')}"
142
+ file_ext = options[:no_file_ext] ? '' : '.html'
141
143
  FileUtils.mkdir_p page_dir_path
142
- File.open("#{page_dir_path}/#{@slug}.html", 'w') { |f| f << page_html }
144
+ File.open("#{page_dir_path}/#{@slug}#{file_ext}", 'w') { |f| f << page_html }
143
145
  end
144
146
  end
145
147
 
@@ -152,14 +154,14 @@ module Hyphae
152
154
  end
153
155
 
154
156
  # Builds the nav menu tag for this page
155
- def nav_link(open_path=[])
157
+ def nav_link(open_path=[], options={})
156
158
  return "" if @hidden
157
159
  attrs = { 'class' => 'nav_link', 'href' => @link }
158
160
  Hyphae::make_tag('a', @name, attrs)
159
161
  end
160
162
 
161
163
  # Builds html page (does nothing for a link)
162
- def build(build_dir, template)
164
+ def build(build_dir, template, options={})
163
165
  end
164
166
  end
165
167
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyphae
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
  - Nicholas Rakita
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-25 00:00:00.000000000 Z
11
+ date: 2023-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown
@@ -52,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  requirements: []
55
- rubygems_version: 3.3.7
55
+ rubygems_version: 3.3.25
56
56
  signing_key:
57
57
  specification_version: 4
58
58
  summary: Hyphae