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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b22adc821ecbac4e53ae63316017a6098442d2d5322a55b62499e6abadc1ca0
4
- data.tar.gz: ce181785fe42f0176369dc9f25ee8fffa3e330d82d7575ab9971a00fab66df4e
3
+ metadata.gz: 55c8b42fbd2198f01391f1237b4dc15e5acf89954692873f634467ff9179a439
4
+ data.tar.gz: c03016ed7a911179be462872b6b6f1cd766676e30b23cb6fd607bab42533931d
5
5
  SHA512:
6
- metadata.gz: 3b77f4efe139580d9d3b4899067364f54d50c1ac44e9c4424dc71c49e179042dce33a1d5ff2915eb60629f83afd1853cbcf11155afb6420de6f1b1c38cbaaced
7
- data.tar.gz: 2b550a0eb34ad79807eb03a12819e9f64ebc175be3ef57208e367ee4e76ce96f8d5cd1a1c5141f3cf349dfa7d3d15eda3ae1e354c041fb1988cb96371eb8e4e5
6
+ metadata.gz: 9144011fa2a1f37e7c9c8aa8294e4e7d1d355ad8a065da791bbc766b8cbdabff9863705921df553217b303b81e6a880123162f562f1835834f250f3026cb7e5f
7
+ data.tar.gz: d1606efa29997c3c8a31acedc8a31d2bfc9bbbc089378e7662116034815c29e521c62f5681452b39d727dfae74f4fa051db7ba9ad6662eb0d7bca5820d552d00
data/CHANGELOG.md CHANGED
@@ -1,4 +1,6 @@
1
- ## [Unreleased]
1
+ ## [1.0.0] - 2022-04-22
2
+ - Added processing feature
3
+ - Updated template to showcase processing
2
4
 
3
5
  ## [0.1.1] - 2022-04-21
4
6
 
data/README.mdown CHANGED
@@ -1,4 +1,4 @@
1
- ![Justicar](https://github.com/realtradam/Justicar/blob/master/template/public/justicar.png?raw=true)
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
- #### Source Dir:
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
- HTML and CSS gets compiled using Paggio while Js gets compiled using Opal.
36
+ ### File types
33
37
 
34
- #### Public Dir:
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
- This is where static non-generated files go such as Images.
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
- #### Build Dir:
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
- Build is where your generated site gets exported to.
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Justicar
4
- VERSION = "0.1.1"
4
+ VERSION = "1.0.0"
5
5
  end
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 load_templates(dir)
11
- Dir.each_child(dir) do |file|
12
- if File.directory? "#{dir}/#{file}"
13
- self.load_templates "#{dir}/#{file}"
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
- load "#{dir}/#{file}"
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
- elsif extension == 'js'
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 build(target_dir, public_dir, hash = self.output)
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
- unless Dir.exist? "#{target_dir}/#{key}"
64
- FileUtils.mkdir "#{target_dir}/#{key}"
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.build('build', 'public')
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,8 @@
1
+ Justicar::PreProcessor.articles ||= {} # ensure the has exists
2
+
3
+ # assign the result to a hash to be generated later
4
+ Justicar::PreProcessor.articles["crab.html"] = Paggio.html! do
5
+ h2 do
6
+ "This is an article about CRABS!"
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ Justicar::PreProcessor.articles ||= {} # ensure the has exists
2
+
3
+ # assign the result to a hash to be generated later
4
+ Justicar::PreProcessor.articles["fish.html"] = Paggio.html! do
5
+ h2 do
6
+ "This is an article about FISH!"
7
+ end
8
+ end
@@ -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
@@ -0,0 +1,8 @@
1
+ Justicar::PreProcessor.articles ||= {} # ensure the has exists
2
+
3
+ # assign the result to a hash to be generated later
4
+ Justicar::PreProcessor.articles["lion.html"] = Paggio.html! do
5
+ h2 do
6
+ "This is an article about LIONS!"
7
+ end
8
+ end
@@ -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
@@ -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
@@ -5,7 +5,7 @@ Paggio.css do
5
5
 
6
6
  rule '.justicar' do
7
7
  top 134.px
8
- left 360.px
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.1.1
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-21 00:00:00.000000000 Z
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
Binary file