summaryrefslogtreecommitdiffhomepage
path: root/lib/Justicar.rb
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2022-04-22 07:17:49 -0400
committerrealtradam <[email protected]>2022-04-22 07:17:49 -0400
commit99099c284982863480ffc6d4aa741d29dc2ea92a (patch)
tree66a2f4c543617f647d970db6fce07622feafd393 /lib/Justicar.rb
parent6150ed8ba86e960a2833b4000c2f9474a2292129 (diff)
downloadJusticar-99099c284982863480ffc6d4aa741d29dc2ea92a.tar.gz
Justicar-99099c284982863480ffc6d4aa741d29dc2ea92a.zip
version 1.0v1.0.0
Diffstat (limited to 'lib/Justicar.rb')
-rw-r--r--lib/Justicar.rb46
1 files changed, 34 insertions, 12 deletions
diff --git a/lib/Justicar.rb b/lib/Justicar.rb
index 5abf901..3dd73c1 100644
--- a/lib/Justicar.rb
+++ b/lib/Justicar.rb
@@ -3,16 +3,20 @@
require_relative "Justicar/version"
require "paggio"
require "opal"
+require "ostruct"
class Justicar
class << self
- def load_templates(dir)
- Dir.each_child(dir) do |file|
- if File.directory? "#{dir}/#{file}"
- self.load_templates "#{dir}/#{file}"
+ def load_preprocessors(dir)
+ Dir.each_child(dir) do |full_file_name|
+ file_name, extension, _rb = full_file_name.split('.')
+ if File.directory?("#{dir}/#{full_file_name}")
+ self.load_preprocessors("#{dir}/#{full_file_name}")
else
- load "#{dir}/#{file}"
+ if ['pre'].include? extension
+ load "#{dir}/#{full_file_name}"
+ end
end
end
end
@@ -28,14 +32,21 @@ class Justicar
Dir.each_child(dir) do |full_file_name|
file_name, extension, _rb = full_file_name.split('.')
if File.directory?("#{dir}/#{full_file_name}")
- target[full_file_name] = {}
+ target[full_file_name] ||= {}
self.build_source("#{dir}/#{full_file_name}", target[full_file_name])
else
+ # single html and css files
if ['html', 'css'].include? extension
File.open("#{dir}/#{full_file_name}", 'r') do |file|
target[full_file_name] = instance_eval(file.read)
end
- elsif extension == 'js'
+ # does "post processing" and lets you execute custom code depending on preprocessing
+ elsif ['post'].include? extension
+ File.open("#{dir}/#{full_file_name}", 'r') do |file|
+ # use dir and target
+ instance_eval(file.read)
+ end
+ elsif ['js'].include? extension
opl_file, _dot, _extension = full_file_name.partition('.')
opl_file = "#{"#{dir}/".partition('/').last}#{opl_file}"
target[full_file_name] = opl.build(opl_file).to_s
@@ -44,7 +55,7 @@ class Justicar
end
end
- def build(target_dir, public_dir, hash = self.output)
+ def build_initialize(target_dir, public_dir, hash = self.output)
if Dir.exist? target_dir
FileUtils.rm_r target_dir
end
@@ -53,6 +64,10 @@ class Justicar
else
FileUtils.mkdir target_dir
end
+ build(target_dir, public_dir, hash)
+ end
+
+ def build(target_dir, public_dir, hash = self.output)
hash.each do |key, val|
if val.is_a? String
file_name, type, _rb = key.to_s.split('.')
@@ -60,14 +75,19 @@ class Justicar
file.write(val)
end
else
- unless Dir.exist? "#{target_dir}/#{key}"
- FileUtils.mkdir "#{target_dir}/#{key}"
- end
- self.build("#{target_dir}/#{key}", hash)
+ ensure_dir "#{target_dir}/#{key}"
+ self.build("#{target_dir}/#{key}", public_dir, hash[key])
end
end
end
+ def ensure_dir(dir)
+ unless Dir.exist? dir
+ FileUtils.mkdir dir
+ end
+ File.directory? dir
+ end
+
def output
@output ||= {}
end
@@ -80,4 +100,6 @@ class Justicar
end
+ PreProcessor = OpenStruct.new
+
end