Justicar 0.1.0 → 1.0.1

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: 408dfbb73b156132cf179a3f64fa235ef7b9075f5f3742e1245b6ebdb2a1e12f
4
- data.tar.gz: c39d1918d45a312c9ad4c05edcc4dcca5ef2de37e286d7a3621f38925289ec28
3
+ metadata.gz: 85d3d8d716701511ea15be92cdc99a55072a43f2b4f5f755eb43d904653f63ae
4
+ data.tar.gz: cf17e0bfc411d56b09e2f62dc9ba8191fffda95ba2a622a0dd0f70b362bb67d5
5
5
  SHA512:
6
- metadata.gz: 3398a9b7c42ad27cf586671e3c24d93c1affcdceb21d4905129e80755b9e79fb7790ae846bab0434d9e5de2493c1f2db474604c47975c2de7c8d8762eff45d69
7
- data.tar.gz: ccf19ce74161fcedad9b5a7f505c1e2bc6eea525d3205e4df7c754cf60fda081026e70031691565bedc958310865c0da47982fcba2eb01e6fef6acdbcbc49fe0
6
+ metadata.gz: 22f6291626fb0f9bcf24424b618bf2c3d9bf5313ee82b149701f0ae60cf01c2c5f193190e26c3f2c90514f8cb43e3d78542548fbeb3c8a7d6a09b36f7b7981a0
7
+ data.tar.gz: ca15c21f90c17c5977f2fa69f20716999bf6c16a534ba5466f84776b87be9070a746dbdf51de75ceca172f0d397066b4bcdb0a88efb5887ae6a45a1e372982e2
data/CHANGELOG.md CHANGED
@@ -1,4 +1,15 @@
1
- ## [Unreleased]
1
+ ## [1.0.1] - 2022-04-22
2
+ - Updated the template's Gemfile
3
+
4
+ ## [1.0.0] - 2022-04-22
5
+ - Added processing feature
6
+ - Updated template to showcase processing
7
+
8
+ ## [0.1.1] - 2022-04-21
9
+
10
+ - Better template
11
+ - Cleanup some print statements
12
+ - Logos and prettified readme
2
13
 
3
14
  ## [0.1.0] - 2022-04-20
4
15
 
data/Justicar.gemspec CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
25
  spec.files = Dir.chdir(__dir__) do
26
26
  `git ls-files -z`.split("\x0").reject do |f|
27
- (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
27
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|logo|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
28
28
  end
29
29
  end
30
30
  spec.bindir = "exe"
data/README.mdown CHANGED
@@ -1,5 +1,10 @@
1
+ <img src="https://github.com/realtradam/Justicar/blob/master/template/public/justicar.png?raw=true" height="280" alt="Justicar"/>
2
+
1
3
  # Justicar
2
4
 
5
+ [![MIT License](https://img.shields.io/github/license/realtradam/Justicar?style=flat)](https://github.com/realtradam/Justicar/blob/master/LICENSE.txt)
6
+ [![Ko-Fi](https://img.shields.io/static/v1?message=Buy%20me%20a%20coffee&logo=kofi&labelColor=ff5e5b&color=434B57&logoColor=white&label=%20)](https://ko-fi.com/tradam)
7
+
3
8
  A Ruby obsessed static website generator that does web development Justice!
4
9
 
5
10
  ## Installation
@@ -20,25 +25,28 @@ $ rake build # <- generates the website
20
25
  $ rake serve # <- locally host the project
21
26
  ```
22
27
 
23
- ### How it works:
24
-
25
- #### Source Dir:
26
-
27
- HTML and CSS gets compiled using Paggio while Js gets compiled using Opal.
28
+ ### How it works when your run `rake serve`:
28
29
 
29
- #### Public Dir:
30
+ 1. Preprocess 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
30
35
 
31
- This is where static non-generated files go such as Images.
36
+ ### File types
32
37
 
33
- #### Build 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
34
40
 
35
- Build is where your generated site gets exported to.
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.
36
43
 
37
- ## Development
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.
38
46
 
39
- 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.
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.
40
49
 
41
- 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).
42
50
 
43
51
  ## Contributing
44
52
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Justicar
4
- VERSION = "0.1.0"
4
+ VERSION = "1.0.1"
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,22 +64,28 @@ 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
- puts "key: #{key}, val: #{val}"
58
72
  if val.is_a? String
59
73
  file_name, type, _rb = key.to_s.split('.')
60
- puts "filename: #{file_name}, type: #{type}"
61
74
  File.open("#{target_dir}/#{file_name}.#{type}", "w") do |file|
62
75
  file.write(val)
63
76
  end
64
77
  else
65
- unless Dir.exist? "#{target_dir}/#{key}"
66
- FileUtils.mkdir "#{target_dir}/#{key}"
67
- end
68
- self.build("#{target_dir}/#{key}", hash)
78
+ ensure_dir "#{target_dir}/#{key}"
79
+ self.build("#{target_dir}/#{key}", public_dir, hash[key])
69
80
  end
70
81
  end
71
- puts File.expand_path(File.dirname(__FILE__))
82
+ end
83
+
84
+ def ensure_dir(dir)
85
+ unless Dir.exist? dir
86
+ FileUtils.mkdir dir
87
+ end
88
+ File.directory? dir
72
89
  end
73
90
 
74
91
  def output
@@ -83,4 +100,6 @@ class Justicar
83
100
 
84
101
  end
85
102
 
103
+ PreProcessor = OpenStruct.new
104
+
86
105
  end
data/template/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "webrick", "~> 1.7"
6
+
7
+ gem "opal-browser", "~> 0.3.3"
8
+
9
+ gem "Justicar", "~> 1.0.1"
10
+
11
+ gem "rake", "~> 13.0"
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"
Binary file
Binary file
@@ -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
@@ -1,6 +1,8 @@
1
1
  Paggio.html do
2
2
  script type: "text/javascript", src: "script.js"
3
3
  link rel: "stylesheet", href: "style.css"
4
+ link rel: 'icon', type: 'image/x-icon', href: 'favicon.ico'
5
+ img.justicar(src: '/justicar.png', alt: 'Justicar', height: '400px')
4
6
  h1 { "Hello world from Justicar" }
5
7
  hr
6
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
@@ -1,4 +1,17 @@
1
1
  Paggio.css do
2
+ rule 'body' do
3
+ height 100.vh
4
+ end
5
+
6
+ rule '.justicar' do
7
+ top 134.px
8
+ left 400.px
9
+ opacity 0.7
10
+ position 'absolute'
11
+ width 400.px
12
+ height 'auto'
13
+ end
14
+
2
15
  rule '.opal' do
3
16
  color :dodgerblue
4
17
  end
@@ -7,6 +20,11 @@ Paggio.css do
7
20
  color :goldenrod
8
21
  end
9
22
 
23
+ rule '.articles' do
24
+ color :limegreen
25
+ max width: 400.px
26
+ end
27
+
10
28
  rule 'h1' do
11
29
  font style: :italic
12
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.0
4
+ version: 1.0.1
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
@@ -71,7 +71,14 @@ files:
71
71
  - lib/Justicar.rb
72
72
  - lib/Justicar/version.rb
73
73
  - sig/Justicar.rbs
74
+ - template/Gemfile
74
75
  - template/Rakefile
76
+ - template/public/favicon.ico
77
+ - template/public/justicar.png
78
+ - template/src/articles/crab.pre.rb
79
+ - template/src/articles/fish.pre.rb
80
+ - template/src/articles/index.post.rb
81
+ - template/src/articles/lion.pre.rb
75
82
  - template/src/index.html.rb
76
83
  - template/src/script.js.rb
77
84
  - template/src/style.css.rb