hyphae 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/hyphae +31 -5
- data/lib/hyphae.rb +16 -14
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 304adf1bcf2fcbb35c21f00ad6e5a62c2ff28b615eb59392dec40aea7d555311
|
4
|
+
data.tar.gz: 36a4dce01b02ace408768818c76ed1a131a379cbf5714ac89831766c1f2457a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 873eb59645e28e8588485a792d325c0b01b2c8a5d1294c650bdf6dd4672899482c8607e704e30e267d3b787d70c70ab89e128590dbbe16c715bf835595b7580c
|
7
|
+
data.tar.gz: 7f117b02ecbc4eb3045930852d4196d800aa8efd074367add83d5fd3530bb4fd6a86a127b342575b4c0bb60c9f3c9c441a413c152d84e1aec7874effac4bb112
|
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
|
-
#
|
10
|
-
|
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 =
|
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,27 +90,27 @@ 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='')
|
113
|
+
def build_index(build_dir, template, index_content='', options={})
|
114
114
|
page_html = template.gsub('{{navbar}}', menu_items).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
|
@@ -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
|
-
|
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}
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicholas Rakita
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-19 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.
|
55
|
+
rubygems_version: 3.3.25
|
56
56
|
signing_key:
|
57
57
|
specification_version: 4
|
58
58
|
summary: Hyphae
|