Justicar 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -1
- data/README.mdown +16 -13
- data/lib/Justicar/version.rb +1 -1
- data/lib/Justicar.rb +34 -12
- data/template/Rakefile +2 -1
- data/template/src/articles/crab.pre.rb +8 -0
- data/template/src/articles/fish.pre.rb +8 -0
- data/template/src/articles/index.post.rb +28 -0
- data/template/src/articles/lion.pre.rb +8 -0
- data/template/src/index.html.rb +1 -1
- data/template/src/script.js.rb +6 -0
- data/template/src/style.css.rb +6 -1
- metadata +6 -3
- data/template/public/favicon.png +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55c8b42fbd2198f01391f1237b4dc15e5acf89954692873f634467ff9179a439
|
4
|
+
data.tar.gz: c03016ed7a911179be462872b6b6f1cd766676e30b23cb6fd607bab42533931d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9144011fa2a1f37e7c9c8aa8294e4e7d1d355ad8a065da791bbc766b8cbdabff9863705921df553217b303b81e6a880123162f562f1835834f250f3026cb7e5f
|
7
|
+
data.tar.gz: d1606efa29997c3c8a31acedc8a31d2bfc9bbbc089378e7662116034815c29e521c62f5681452b39d727dfae74f4fa051db7ba9ad6662eb0d7bca5820d552d00
|
data/CHANGELOG.md
CHANGED
data/README.mdown
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
<img src="https://github.com/realtradam/Justicar/blob/master/template/public/justicar.png?raw=true" height="280" alt="Justicar"/>
|
2
2
|
|
3
3
|
# Justicar
|
4
4
|
|
@@ -25,25 +25,28 @@ $ rake build # <- generates the website
|
|
25
25
|
$ rake serve # <- locally host the project
|
26
26
|
```
|
27
27
|
|
28
|
-
### How it works
|
28
|
+
### How it works when your run `rake serve`:
|
29
29
|
|
30
|
-
|
30
|
+
1. Preproces special files in Source Dir
|
31
|
+
2. Process remaining files in Source Dir
|
32
|
+
3. Copy Public Dir to Build Dir
|
33
|
+
4. Write the Source Hash into Build Dir
|
34
|
+
- Note this can cause the Source Hash to overwrite files copied from the Public Dir
|
31
35
|
|
32
|
-
|
36
|
+
### File types
|
33
37
|
|
34
|
-
|
38
|
+
##### `.html.rb, .css.rb`
|
39
|
+
These files are executed and the resulting string gets saved in a file using its respective relative path as well as using its filename(sans the `.rb`) as the resulting file's name
|
35
40
|
|
36
|
-
|
41
|
+
##### `.js.rb`
|
42
|
+
These files get read and passed into the Opal parser to generate the resulting javascript. This gets saved in a file similiarly as `html.rb` files.
|
37
43
|
|
38
|
-
|
44
|
+
##### `.pre.rb`
|
45
|
+
These are files that are executed before the file generation phase but do not get written anywhere. Here you should create a proc and store it in `Justicar::PreProcessor` (see sample project for an example). These are files generally used for templates or articles where you want a table of contents.
|
39
46
|
|
40
|
-
|
47
|
+
##### `.post.rb`
|
48
|
+
These are files that are executed during the file generation phase but do not themselves get written anywhere. These files are generally used for programmatically generating multiple files (such as creating a bunch of article pages stored in the preprocessor). See sample project for an example.
|
41
49
|
|
42
|
-
## Development
|
43
|
-
|
44
|
-
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
45
|
-
|
46
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
47
50
|
|
48
51
|
## Contributing
|
49
52
|
|
data/lib/Justicar/version.rb
CHANGED
data/lib/Justicar.rb
CHANGED
@@ -3,16 +3,20 @@
|
|
3
3
|
require_relative "Justicar/version"
|
4
4
|
require "paggio"
|
5
5
|
require "opal"
|
6
|
+
require "ostruct"
|
6
7
|
|
7
8
|
class Justicar
|
8
9
|
class << self
|
9
10
|
|
10
|
-
def
|
11
|
-
Dir.each_child(dir) do |
|
12
|
-
|
13
|
-
|
11
|
+
def load_preprocessors(dir)
|
12
|
+
Dir.each_child(dir) do |full_file_name|
|
13
|
+
file_name, extension, _rb = full_file_name.split('.')
|
14
|
+
if File.directory?("#{dir}/#{full_file_name}")
|
15
|
+
self.load_preprocessors("#{dir}/#{full_file_name}")
|
14
16
|
else
|
15
|
-
|
17
|
+
if ['pre'].include? extension
|
18
|
+
load "#{dir}/#{full_file_name}"
|
19
|
+
end
|
16
20
|
end
|
17
21
|
end
|
18
22
|
end
|
@@ -28,14 +32,21 @@ class Justicar
|
|
28
32
|
Dir.each_child(dir) do |full_file_name|
|
29
33
|
file_name, extension, _rb = full_file_name.split('.')
|
30
34
|
if File.directory?("#{dir}/#{full_file_name}")
|
31
|
-
target[full_file_name]
|
35
|
+
target[full_file_name] ||= {}
|
32
36
|
self.build_source("#{dir}/#{full_file_name}", target[full_file_name])
|
33
37
|
else
|
38
|
+
# single html and css files
|
34
39
|
if ['html', 'css'].include? extension
|
35
40
|
File.open("#{dir}/#{full_file_name}", 'r') do |file|
|
36
41
|
target[full_file_name] = instance_eval(file.read)
|
37
42
|
end
|
38
|
-
|
43
|
+
# does "post processing" and lets you execute custom code depending on preprocessing
|
44
|
+
elsif ['post'].include? extension
|
45
|
+
File.open("#{dir}/#{full_file_name}", 'r') do |file|
|
46
|
+
# use dir and target
|
47
|
+
instance_eval(file.read)
|
48
|
+
end
|
49
|
+
elsif ['js'].include? extension
|
39
50
|
opl_file, _dot, _extension = full_file_name.partition('.')
|
40
51
|
opl_file = "#{"#{dir}/".partition('/').last}#{opl_file}"
|
41
52
|
target[full_file_name] = opl.build(opl_file).to_s
|
@@ -44,7 +55,7 @@ class Justicar
|
|
44
55
|
end
|
45
56
|
end
|
46
57
|
|
47
|
-
def
|
58
|
+
def build_initialize(target_dir, public_dir, hash = self.output)
|
48
59
|
if Dir.exist? target_dir
|
49
60
|
FileUtils.rm_r target_dir
|
50
61
|
end
|
@@ -53,6 +64,10 @@ class Justicar
|
|
53
64
|
else
|
54
65
|
FileUtils.mkdir target_dir
|
55
66
|
end
|
67
|
+
build(target_dir, public_dir, hash)
|
68
|
+
end
|
69
|
+
|
70
|
+
def build(target_dir, public_dir, hash = self.output)
|
56
71
|
hash.each do |key, val|
|
57
72
|
if val.is_a? String
|
58
73
|
file_name, type, _rb = key.to_s.split('.')
|
@@ -60,14 +75,19 @@ class Justicar
|
|
60
75
|
file.write(val)
|
61
76
|
end
|
62
77
|
else
|
63
|
-
|
64
|
-
|
65
|
-
end
|
66
|
-
self.build("#{target_dir}/#{key}", hash)
|
78
|
+
ensure_dir "#{target_dir}/#{key}"
|
79
|
+
self.build("#{target_dir}/#{key}", public_dir, hash[key])
|
67
80
|
end
|
68
81
|
end
|
69
82
|
end
|
70
83
|
|
84
|
+
def ensure_dir(dir)
|
85
|
+
unless Dir.exist? dir
|
86
|
+
FileUtils.mkdir dir
|
87
|
+
end
|
88
|
+
File.directory? dir
|
89
|
+
end
|
90
|
+
|
71
91
|
def output
|
72
92
|
@output ||= {}
|
73
93
|
end
|
@@ -80,4 +100,6 @@ class Justicar
|
|
80
100
|
|
81
101
|
end
|
82
102
|
|
103
|
+
PreProcessor = OpenStruct.new
|
104
|
+
|
83
105
|
end
|
data/template/Rakefile
CHANGED
@@ -3,8 +3,9 @@ require 'opal-browser'
|
|
3
3
|
|
4
4
|
desc "Build your website"
|
5
5
|
task :build do
|
6
|
+
Justicar.load_preprocessors('src')
|
6
7
|
Justicar.build_source('src')
|
7
|
-
Justicar.
|
8
|
+
Justicar.build_initialize('build', 'public')
|
8
9
|
end
|
9
10
|
|
10
11
|
desc "Create a server and open your site in your browser"
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# note: `target` will always be relative to the current directory for
|
2
|
+
# postprocessor files
|
3
|
+
|
4
|
+
# this generates all of our preprocessed articles we stored
|
5
|
+
# note: you need to use the param `|_|` for paggio to allow us
|
6
|
+
# to use local variables in the proc
|
7
|
+
Justicar::PreProcessor.articles.each do |key, val|
|
8
|
+
target[key] = Paggio.html do |_|
|
9
|
+
_.html do
|
10
|
+
val
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# this creates the articles page which contains links to
|
16
|
+
# all of our articles
|
17
|
+
target["index.html"] = Paggio.html do |_|
|
18
|
+
_.html do
|
19
|
+
_.h1 do
|
20
|
+
'Here is a list of all the articles!'
|
21
|
+
end
|
22
|
+
Justicar::PreProcessor.articles.each do |key, val|
|
23
|
+
_.p do
|
24
|
+
_.a.articles(href: "#{key}") { key.delete_suffix('.html').upcase + "!" }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/template/src/index.html.rb
CHANGED
@@ -2,7 +2,7 @@ Paggio.html do
|
|
2
2
|
script type: "text/javascript", src: "script.js"
|
3
3
|
link rel: "stylesheet", href: "style.css"
|
4
4
|
link rel: 'icon', type: 'image/x-icon', href: 'favicon.ico'
|
5
|
-
img.justicar(src: 'justicar.png', alt: 'Justicar', height: '400px')
|
5
|
+
img.justicar(src: '/justicar.png', alt: 'Justicar', height: '400px')
|
6
6
|
h1 { "Hello world from Justicar" }
|
7
7
|
hr
|
8
8
|
h2.paggio do
|
data/template/src/script.js.rb
CHANGED
@@ -9,5 +9,11 @@ $document.ready do
|
|
9
9
|
"Hello World from Opal!"
|
10
10
|
end
|
11
11
|
p.opal {"This part was generated by Opal from Javascript (:"}
|
12
|
+
h2.articles do
|
13
|
+
"Here is some articles that were generated using the processing system:"
|
14
|
+
end
|
15
|
+
p.articles do
|
16
|
+
a(href: '/articles').articles { "Articles" }
|
17
|
+
end
|
12
18
|
end.append_to($document.body)
|
13
19
|
end
|
data/template/src/style.css.rb
CHANGED
@@ -5,7 +5,7 @@ Paggio.css do
|
|
5
5
|
|
6
6
|
rule '.justicar' do
|
7
7
|
top 134.px
|
8
|
-
left
|
8
|
+
left 400.px
|
9
9
|
opacity 0.7
|
10
10
|
position 'absolute'
|
11
11
|
width 400.px
|
@@ -20,6 +20,11 @@ Paggio.css do
|
|
20
20
|
color :goldenrod
|
21
21
|
end
|
22
22
|
|
23
|
+
rule '.articles' do
|
24
|
+
color :limegreen
|
25
|
+
max width: 400.px
|
26
|
+
end
|
27
|
+
|
23
28
|
rule 'h1' do
|
24
29
|
font style: :italic
|
25
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Justicar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- _Tradam
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-04-
|
11
|
+
date: 2022-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: paggio
|
@@ -75,8 +75,11 @@ files:
|
|
75
75
|
- template/Gemfile.lock
|
76
76
|
- template/Rakefile
|
77
77
|
- template/public/favicon.ico
|
78
|
-
- template/public/favicon.png
|
79
78
|
- template/public/justicar.png
|
79
|
+
- template/src/articles/crab.pre.rb
|
80
|
+
- template/src/articles/fish.pre.rb
|
81
|
+
- template/src/articles/index.post.rb
|
82
|
+
- template/src/articles/lion.pre.rb
|
80
83
|
- template/src/index.html.rb
|
81
84
|
- template/src/script.js.rb
|
82
85
|
- template/src/style.css.rb
|
data/template/public/favicon.png
DELETED
Binary file
|