black-widow 0.0.1.alpha → 0.0.2.alpha
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.
- checksums.yaml +4 -4
- data/.gitignore +5 -1
- data/Gemfile +4 -0
- data/README.md +4 -1
- data/Rakefile +6 -0
- data/bin/{black-widow → blackwidow} +84 -50
- data/black-widow.gemspec +1 -0
- data/lib/black-widow.rb +37 -32
- data/lib/black-widow/command.rb +14 -0
- data/lib/black-widow/config.rb +64 -0
- data/lib/black-widow/engine.rb +28 -1
- data/lib/black-widow/renderer.rb +6 -0
- data/lib/black-widow/version.rb +1 -1
- metadata +21 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 876454d736fa938ca409a2c89c2407fe6fd03b755a6cfbf7cc9e3230c46d9581
|
|
4
|
+
data.tar.gz: 79106c4d5e2c27b11f585cd367e39a0d10446048cac23fc64d94d714b96b9baa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 32abef3685b16d28669aeb962415c759886fc8c46d2a6cd60ac0a6548afb44401197b3a9abbdb1f3832e3f0077f033a18c58d6ff712ccbd9a06feff796fb6493
|
|
7
|
+
data.tar.gz: 323c360361b4d4bad1eaffa5c7f4fade0db735dea4d0f369d52b14df8c87487c04e75d41fcb90990a2d8405874b9afe0f2a941e90590c9abd7c8caff77dd787b
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
task default: %w[test]
|
|
2
2
|
|
|
3
3
|
task :test do
|
|
4
|
+
raise NotImplementedError.new "Testing has not yet been implemented."
|
|
4
5
|
ruby "test/driver.rb"
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# Generates documentation, putting the resulting .html files in doc/
|
|
9
|
+
task :gendocs do
|
|
10
|
+
`yard doc --readme README.md - LICENSE`
|
|
5
11
|
end
|
|
@@ -9,6 +9,78 @@ require 'pathname'
|
|
|
9
9
|
require 'getoptlong'
|
|
10
10
|
require 'black-widow'
|
|
11
11
|
|
|
12
|
+
##
|
|
13
|
+
# Creates a new BlackWidow project skeleton
|
|
14
|
+
#
|
|
15
|
+
# This function creates a new project directory and populates it with a
|
|
16
|
+
# config.yaml file and folders for view components.
|
|
17
|
+
#
|
|
18
|
+
# @param name: String
|
|
19
|
+
# The name of the project. This will also be the name of the project
|
|
20
|
+
# directory.
|
|
21
|
+
#
|
|
22
|
+
# @return void
|
|
23
|
+
#
|
|
24
|
+
def init_project name
|
|
25
|
+
root = Pathname.new Dir.pwd
|
|
26
|
+
if (root + name).exist? then
|
|
27
|
+
raise ArgumentError 'Project could not be created; directory already exists.'
|
|
28
|
+
end
|
|
29
|
+
root += name
|
|
30
|
+
root.mkpath
|
|
31
|
+
|
|
32
|
+
BlackWidow::ViewEngine::VIEW_FOLDERS.each_value do |dir|
|
|
33
|
+
(root + dir).mkpath
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
config = File.new root.join(BlackWidow.CONFIG_FILE_NAME), 'w+'
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def render_project opts = {}
|
|
40
|
+
out_dir = opts[:out_dir] || 'dist/'
|
|
41
|
+
# TODO: put default layout in config. Magic strings are no bueno :(
|
|
42
|
+
layout = opts[:layout] || 'application'
|
|
43
|
+
# Project root directory is the directory with the config file
|
|
44
|
+
engine = nil
|
|
45
|
+
dest = Pathname.new(Dir.pwd) + out_dir
|
|
46
|
+
|
|
47
|
+
begin
|
|
48
|
+
engine = BlackWidow::ViewEngine.new File.dirname BlackWidow::resolve_config
|
|
49
|
+
rescue IOError => e
|
|
50
|
+
err e, 4
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
Pathname.new(engine.root).each_child do |file|
|
|
54
|
+
if file.directory?
|
|
55
|
+
puts "Directory #{file} reached. TODO: Implement namespace rendering"
|
|
56
|
+
else
|
|
57
|
+
# Extract the filename, which is the same as the view name
|
|
58
|
+
view = file.basename.split('.')[0]
|
|
59
|
+
page_contents = engine.render view, opts
|
|
60
|
+
|
|
61
|
+
page_file = File.new dest + (view + '.html'), 'w+'
|
|
62
|
+
page_file.write page_contents
|
|
63
|
+
page_file.close
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
##
|
|
68
|
+
# Prints an error message and exits with an error status
|
|
69
|
+
#
|
|
70
|
+
# @param err: Exception | RuntimeException | StandardErr | String
|
|
71
|
+
# The error being thrown.
|
|
72
|
+
#
|
|
73
|
+
# @param status: Number
|
|
74
|
+
# The exit status. Defaults to 1.
|
|
75
|
+
#
|
|
76
|
+
def err err, status = 1
|
|
77
|
+
err_type = if err.is_a? Exception then err.class.name else 'Error' end
|
|
78
|
+
err_msg = if err.is_a? Exception then err.message else err end
|
|
79
|
+
|
|
80
|
+
puts "BlackWidow: - #{err_type} #{err_msg}"
|
|
81
|
+
exit status
|
|
82
|
+
end
|
|
83
|
+
|
|
12
84
|
# Base command usage message
|
|
13
85
|
USAGE = {}
|
|
14
86
|
HELP = {}
|
|
@@ -65,6 +137,10 @@ EOF
|
|
|
65
137
|
HELP[:render] = <<-EOF
|
|
66
138
|
EOF
|
|
67
139
|
|
|
140
|
+
################################################################################
|
|
141
|
+
################################ START OF SCRIPT ###############################
|
|
142
|
+
################################################################################
|
|
143
|
+
|
|
68
144
|
# :_ key is all unnamed arguments from ARGV
|
|
69
145
|
ARGS = { _: [] }
|
|
70
146
|
next_arg = :command # First unnamed arg is expected to be a sub command
|
|
@@ -84,7 +160,8 @@ ARGV.each do |arg|
|
|
|
84
160
|
end
|
|
85
161
|
end
|
|
86
162
|
|
|
87
|
-
|
|
163
|
+
# Help is specified, or no args are passed.
|
|
164
|
+
if ARGS[:help] || ARGV.length == 0
|
|
88
165
|
if ARGS[:command] && HELP.include?(ARGS[:command].to_sym)
|
|
89
166
|
puts HELP[ARGS[:command].to_sym]
|
|
90
167
|
else
|
|
@@ -102,8 +179,12 @@ case ARGS[:command]
|
|
|
102
179
|
# Handle 'new' command
|
|
103
180
|
when 'n', 'new'
|
|
104
181
|
unless ARGS[:name]
|
|
105
|
-
|
|
182
|
+
err USAGE[:new]
|
|
106
183
|
exit 1
|
|
184
|
+
else
|
|
185
|
+
puts ARGS[:name]
|
|
186
|
+
init_project ARGS[:name]
|
|
187
|
+
exit 0
|
|
107
188
|
end
|
|
108
189
|
# Handle 'generate' command
|
|
109
190
|
when 'g', 'gen', 'generate'
|
|
@@ -127,58 +208,11 @@ when 'r', 'render'
|
|
|
127
208
|
|
|
128
209
|
exit 0
|
|
129
210
|
else
|
|
130
|
-
puts USAGE
|
|
211
|
+
puts USAGE[:base]
|
|
131
212
|
exit 1
|
|
132
213
|
end
|
|
133
214
|
|
|
134
|
-
##
|
|
135
|
-
# Creates a new BlackWidow project skeleton
|
|
136
|
-
#
|
|
137
|
-
# This function creates a new project directory and populates it with a
|
|
138
|
-
# config.yaml file and folders for view components.
|
|
139
|
-
#
|
|
140
|
-
# @param name: String
|
|
141
|
-
# The name of the project. This will also be the name of the project
|
|
142
|
-
# directory.
|
|
143
|
-
#
|
|
144
|
-
# @return void
|
|
145
|
-
#
|
|
146
|
-
def init_project name
|
|
147
|
-
root = Pathname.new Dir.pwd
|
|
148
|
-
if (root + name).exist? then
|
|
149
|
-
raise ArgumentError 'Project could not be created; directory already exists.'
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
root.mkpath name
|
|
153
|
-
root.join name
|
|
154
|
-
ViewEngine::FOLDERS.each_value do |dir|
|
|
155
|
-
root.mkpath dir
|
|
156
|
-
end
|
|
157
|
-
config = File.new root.join(BlackWidow::CONFIG_FILE_NAME), 'w+'
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
def render_project
|
|
161
|
-
# Project root directory is the directory with the config file
|
|
162
|
-
root = File.dirname BlackWidow::resolve_config
|
|
163
|
-
Dir.chdir root
|
|
164
|
-
end
|
|
165
215
|
|
|
166
|
-
##
|
|
167
|
-
# Prints an error message and exits with an error status
|
|
168
|
-
#
|
|
169
|
-
# @param err: Exception | RuntimeException | StandardErr | String
|
|
170
|
-
# The error being thrown.
|
|
171
|
-
#
|
|
172
|
-
# @param status: Number
|
|
173
|
-
# The exit status. Defaults to 1.
|
|
174
|
-
#
|
|
175
|
-
def err err, status = 1
|
|
176
|
-
err_type = if err.is_a? Error then err.class.name else 'Error' end
|
|
177
|
-
err_msg = err.message || err
|
|
178
|
-
|
|
179
|
-
puts "BlackWidow: - #{err.type} #{err_msg}"
|
|
180
|
-
exit status
|
|
181
|
-
end
|
|
182
216
|
|
|
183
217
|
# engine = BlackWidow::ViewEngine.new Pathname.new(Dir.pwd).join 'src'
|
|
184
218
|
# puts(engine.render 'index')
|
data/black-widow.gemspec
CHANGED
data/lib/black-widow.rb
CHANGED
|
@@ -3,46 +3,51 @@
|
|
|
3
3
|
# Black Widow
|
|
4
4
|
# by Donald Isaac (https://www.opensourceryumd.com)
|
|
5
5
|
# Copyright (c) 2019 Open Sourcery. See LICENSE for license details.
|
|
6
|
-
require 'black-widow/engine'
|
|
7
6
|
require 'pathname'
|
|
8
7
|
require 'yaml'
|
|
9
8
|
|
|
10
9
|
module BlackWidow
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
# Internal requires
|
|
11
|
+
autoload :ViewEngine 'black-widow/engine'
|
|
12
|
+
autoload :Config 'black-widow/config'
|
|
13
|
+
# autoload :command 'black-widow/command'
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
#
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
15
|
+
class << self
|
|
16
|
+
CONFIG_FILE_NAME = '.black-widow.yaml'
|
|
17
|
+
@config = nil
|
|
18
|
+
|
|
19
|
+
##
|
|
20
|
+
# Resolves the location of the config file.
|
|
21
|
+
#
|
|
22
|
+
# If no config file exists in the current directory, then the parent
|
|
23
|
+
# directory is checked. This is done until the file is found or the root
|
|
24
|
+
# directory is reached, in which case an IOError is raised.
|
|
25
|
+
#
|
|
26
|
+
# @raise [IOError] If the config file could not be found
|
|
27
|
+
#
|
|
28
|
+
# @return [String] The absolute path to the config file.
|
|
29
|
+
#
|
|
30
|
+
def resolve_config
|
|
31
|
+
config_path = Pathname.new Dir.pwd
|
|
32
|
+
|
|
33
|
+
# Ascend up the file tree until a .black-widow.yaml file is found
|
|
34
|
+
until config_path.children(false).include? CONFIG_FILE_NAME do
|
|
35
|
+
# A path is equal to its parent if and only if it is the root directory
|
|
36
|
+
if config_path == config_path.parent
|
|
37
|
+
raise IOError.new 'BlackWidow: Could not find a ' + CONFIG_FILE_NAME +
|
|
38
|
+
' file. Are you running this command in your project directory?'
|
|
39
|
+
else
|
|
40
|
+
config_path = config_path.parent
|
|
41
|
+
end
|
|
34
42
|
end
|
|
43
|
+
|
|
44
|
+
config_path.join CONFIG_FILE_NAME
|
|
35
45
|
end
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def self.config
|
|
41
|
-
if !@config
|
|
42
|
-
@config = resolve_config
|
|
43
|
-
else
|
|
44
|
-
@config
|
|
46
|
+
|
|
47
|
+
def config
|
|
48
|
+
@config ||= resolve_config
|
|
45
49
|
end
|
|
46
50
|
end
|
|
51
|
+
|
|
47
52
|
|
|
48
53
|
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
module BlackWidow
|
|
2
|
+
##
|
|
3
|
+
# Manages system configuration data.
|
|
4
|
+
#
|
|
5
|
+
# @author Donald Isaac
|
|
6
|
+
#
|
|
7
|
+
class Config
|
|
8
|
+
# Default name of the user's configuration file
|
|
9
|
+
DEFAULT_CONFIG_FILE_NAME = 'config.yml'.freeze
|
|
10
|
+
|
|
11
|
+
# Default configuration
|
|
12
|
+
DEFAULTS = Hash[
|
|
13
|
+
'out_dir' => 'dist/', # Where the compiled site will go
|
|
14
|
+
'src_dir' => 'src/', # Where view components are
|
|
15
|
+
'asset_dir' => 'assets/' # Where to find view assets
|
|
16
|
+
].map {|k, v| v.freeze}.freeze
|
|
17
|
+
|
|
18
|
+
attr_accessor :config
|
|
19
|
+
|
|
20
|
+
def initialize config_file
|
|
21
|
+
_user_config = load_from config_file
|
|
22
|
+
@config = DEFAULTS.merge _user_config
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
##
|
|
27
|
+
# Resolves the project's root directory.
|
|
28
|
+
#
|
|
29
|
+
# Starting at the current working directory, this function looks for a
|
|
30
|
+
# 'config.yml' file. If none is found, the parent is checked. This
|
|
31
|
+
# continues until the config file is found or the root directory is
|
|
32
|
+
# reached, upon which an IOError is thrown.
|
|
33
|
+
#
|
|
34
|
+
# @raise [IOError] if the config file could not be found.
|
|
35
|
+
#
|
|
36
|
+
# @return the absoulte path to the project's root directory.
|
|
37
|
+
#
|
|
38
|
+
def resolve_root
|
|
39
|
+
config_path = Pathname.new Dir.pwd
|
|
40
|
+
|
|
41
|
+
# Ascend up the file tree until a config.yml file is found
|
|
42
|
+
until config_path.children(false).include? CONFIG_FILE_NAME do
|
|
43
|
+
# A path is equal to its parent if and only if it is the root directory
|
|
44
|
+
if config_path == config_path.parent
|
|
45
|
+
raise IOError.new 'BlackWidow: Could not find a ' + CONFIG_FILE_NAME +
|
|
46
|
+
' file. Are you sure you\'re running this command in your project directory?'
|
|
47
|
+
else
|
|
48
|
+
config_path = config_path.parent
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
return config_path
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
##
|
|
56
|
+
# Gets the project's root directory.
|
|
57
|
+
#
|
|
58
|
+
# @return the absolute path to the project's root directory.
|
|
59
|
+
def root
|
|
60
|
+
@root ||= resolve_root
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
end
|
|
64
|
+
end
|
data/lib/black-widow/engine.rb
CHANGED
|
@@ -127,10 +127,37 @@ module BlackWidow
|
|
|
127
127
|
@view_components
|
|
128
128
|
end
|
|
129
129
|
|
|
130
|
+
##
|
|
131
|
+
# Gets the absolute path of each view component directory.
|
|
132
|
+
#
|
|
133
|
+
# The set of available view componets is specified in the VIEW_FOLDERS
|
|
134
|
+
# Hash. You can also access the project's root directory by passing
|
|
135
|
+
# :root
|
|
136
|
+
#
|
|
137
|
+
# @param component: String | Symbol
|
|
138
|
+
# The view component type.
|
|
139
|
+
#
|
|
140
|
+
# @return The absolute path to the view component directory.
|
|
141
|
+
#
|
|
142
|
+
def component_path component
|
|
143
|
+
# When the argument is a string, convert it into a symbol
|
|
144
|
+
component = component.to_sym if component.is_a? String
|
|
145
|
+
raise ArgumentError.new "Argument must be a symbol." unless component.is_a? Symbol
|
|
146
|
+
|
|
147
|
+
if component == :root
|
|
148
|
+
@root_dir
|
|
149
|
+
elsif @view_components[component]
|
|
150
|
+
selected = @view_components[component]
|
|
151
|
+
selected[:dir]
|
|
152
|
+
else
|
|
153
|
+
raise ArgumentError.new "Component type '#{component}' does not exist"
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
130
157
|
private
|
|
131
158
|
|
|
132
159
|
##
|
|
133
|
-
# Renders a view to HTML.
|
|
160
|
+
# Renders a page view to HTML.
|
|
134
161
|
#
|
|
135
162
|
# A view is the collection of data associated with a specific page.
|
|
136
163
|
# This data includes the erb template and it's associated context data.
|
data/lib/black-widow/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: black-widow
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2.alpha
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Donald Isaac
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-06-
|
|
11
|
+
date: 2019-06-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|
|
@@ -24,10 +24,24 @@ dependencies:
|
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: yard
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
27
41
|
description: A simple static site generator powered by eRuby
|
|
28
42
|
email:
|
|
29
43
|
executables:
|
|
30
|
-
-
|
|
44
|
+
- blackwidow
|
|
31
45
|
extensions: []
|
|
32
46
|
extra_rdoc_files: []
|
|
33
47
|
files:
|
|
@@ -36,10 +50,13 @@ files:
|
|
|
36
50
|
- LICENSE
|
|
37
51
|
- README.md
|
|
38
52
|
- Rakefile
|
|
39
|
-
- bin/
|
|
53
|
+
- bin/blackwidow
|
|
40
54
|
- black-widow.gemspec
|
|
41
55
|
- lib/black-widow.rb
|
|
56
|
+
- lib/black-widow/command.rb
|
|
57
|
+
- lib/black-widow/config.rb
|
|
42
58
|
- lib/black-widow/engine.rb
|
|
59
|
+
- lib/black-widow/renderer.rb
|
|
43
60
|
- lib/black-widow/version.rb
|
|
44
61
|
- test/driver.rb
|
|
45
62
|
homepage: https://www.opensourceryumd.com
|